* Takes a source element and checks if its type attribute is present and if so, supported
* Note: for type tests that require a async logic,
* you can define them as a function that'll run only if that type needs to be tested. Just make the test function call picturefill again when it is complete.
* see the async webp test above for example
*/
pf.verifyTypeSupport=function(source){
vartype=source.getAttribute("type");
// if type attribute exists, return test result, otherwise return true
if(type===null||type===""){
returntrue;
}
else{
// if the type test is a function, run it and return "pending" status. The function will rerun picturefill on pending elements once finished.
if(typeof(pf.types[type])==="function"){
pf.types[type]();
return"pending";
}
else{
returnpf.types[type];
}
}
};
/**
* Parses an individual `size` and returns the length, and optional media query
* if it's an img element and it has a srcset property,
* we need to remove the attribute so we can manipulate src
* (the property's existence infers native srcset support, and a srcset-supporting browser will prioritize srcset's value over our winning picture candidate)
* this moves srcset's value to memory for later use and removes the attr
*/
pf.dodgeSrcset=function(img){
if(img.srcset){
img[pf.ns].srcset=img.srcset;
img.removeAttribute("srcset");
}
};
/*
* Accept a source or img element and process its srcset and sizes attrs
*/
pf.processSourceSet=function(el){
varsrcset=el.getAttribute("srcset"),
sizes=el.getAttribute("sizes"),
candidates=[];
// if it's an img element, use the cached srcset property (defined or not)