Skip to content

Commit

Permalink
Add WebP type support back into core.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wilto committed Jun 17, 2015
1 parent ae59939 commit 3c716de
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/picturefill.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,25 @@
types["image/gif"] = true;
types["image/png"] = true;

function detectTypeSupport( type, typeUri ) {
// based on Modernizr's lossless img-webp test
// note: asynchronous
var image = new w.Image();
image.onerror = function() {
pf.types[ type ] = false;
picturefill();
};
image.onload = function() {
pf.types[ type ] = image.width === 1;
picturefill();
};
image.src = typeUri;
return "pending";
};

// test svg support
types[ "image/svg+xml" ] = document.implementation.hasFeature( "http://wwwindow.w3.org/TR/SVG11/feature#Image", "1.1" );
types[ "image/webp" ] = detectTypeSupport("image/webp", "data:image/webp;base64,UklGRkoAAABXRUJQVlA4WAoAAAAQAAAAAAAAAAAAQUxQSAwAAAABBxAR/Q9ERP8DAABWUDggGAAAADABAJ0BKgEAAQADADQlpAADcAD++/1QAA==" );

/**
* updates the internal vW property with the current viewport width in px
Expand Down
1 change: 0 additions & 1 deletion src/plugins/typesupport/pf.type.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
img.src = url;
};

picturefill.testTypeSupport("image/webp", "data:image/webp;base64,UklGRkoAAABXRUJQVlA4WAoAAAAQAAAAAAAAAAAAQUxQSAwAAAABBxAR/Q9ERP8DAABWUDggGAAAADABAJ0BKgEAAQADADQlpAADcAD++/1QAA==", 1);
picturefill.testTypeSupport("image/jp2 image/jpx image/jpm", "data:image/jp2;base64,/0//UQAyAAAAAAABAAAAAgAAAAAAAAAAAAAABAAAAAQAAAAAAAAAAAAEBwEBBwEBBwEBBwEB/1IADAAAAAEAAAQEAAH/XAAEQED/ZAAlAAFDcmVhdGVkIGJ5IE9wZW5KUEVHIHZlcnNpb24gMi4wLjD/kAAKAAAAAABYAAH/UwAJAQAABAQAAf9dAAUBQED/UwAJAgAABAQAAf9dAAUCQED/UwAJAwAABAQAAf9dAAUDQED/k8+kEAGvz6QQAa/PpBABr994EAk//9k=", 1);
picturefill.testTypeSupport("image/vnd.ms-photo", "data:image/vnd.ms-photo;base64,SUm8AQgAAAAFAAG8AQAQAAAASgAAAIC8BAABAAAAAQAAAIG8BAABAAAAAQAAAMC8BAABAAAAWgAAAMG8BAABAAAAHwAAAAAAAAAkw91vA07+S7GFPXd2jckNV01QSE9UTwAZAYBxAAAAABP/gAAEb/8AAQAAAQAAAA==", 1);
picturefill.testTypeSupport("video/vnd.mozilla.apng video/x-apng video/x-mng video/x-png", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACGFjVEwAAAABAAAAAcMq2TYAAAANSURBVAiZY2BgYPgPAAEEAQB9ssjfAAAAGmZjVEwAAAAAAAAAAQAAAAEAAAAAAAAAAAD6A+gBAbNU+2sAAAARZmRBVAAAAAEImWNgYGBgAAAABQAB6MzFdgAAAABJRU5ErkJggg==", false, true);
Expand Down

0 comments on commit 3c716de

Please sign in to comment.