Permalink
Browse files

Forgot to bring in picturefill for the browserify-ed build

  • Loading branch information...
1 parent 61544ac commit 249cc0ff6058251cf18e0f3d3596644cd17d8215 @jansepar jansepar committed Mar 4, 2014
Showing with 179 additions and 11 deletions.
  1. +164 −8 build/mobify.js
  2. +1 −1 build/mobify.min.js
  3. +12 −2 src/external/picturefill.js
  4. +2 −0 src/mobify-library.js
View
@@ -556,7 +556,7 @@ return Capture;
}));
-},{"./patchAnchorLinks.js":5,"./utils.js":8}],2:[function(require,module,exports){
+},{"./patchAnchorLinks.js":6,"./utils.js":9}],2:[function(require,module,exports){
/**
* cssOptimize - Client code to a css optimization service
*/
@@ -661,7 +661,161 @@ return CssOptimize;
}));
-},{"./utils.js":8}],3:[function(require,module,exports){
+},{"./utils.js":9}],3:[function(require,module,exports){
+(function (root, factory) {
+ if (typeof define === 'function' && define.amd) {
+ // AMD. Register as an anonymous module.
+ define(['mobifyjs/utils', 'mobifyjs/capture'], factory);
+ } else if (typeof exports === 'object') {
+ // Node. Does not work with strict CommonJS, but
+ // only CommonJS-like environments that support module.exports,
+ // like Node.
+ module.exports = factory(require('../utils.js'), require('../capture.js'));
+ }
+}(this, function (Utils, Capture) {
+
+var capturing = window.Mobify && window.Mobify.capturing || false;
+
+if (capturing) {
+ // Override renderCapturedDoc to disable img elements in picture elements
+ var oldRenderCapturedDoc = Capture.prototype.renderCapturedDoc;
+ Capture.prototype.renderCapturedDoc = function(options) {
+ // Change attribute of any img element inside a picture element
+ // so it does not load post-flood
+ var imgsInPicture = this.capturedDoc.querySelectorAll('picture img');
+ for (var i = 0, len = imgsInPicture.length; i < len; i++) {
+ var disableImg = imgsInPicture[i];
+ var srcAttr = window.Mobify && window.Mobify.prefix + 'src';
+ disableImg.setAttribute('data-orig-src', disableImg.getAttribute(srcAttr));
+ disableImg.removeAttribute(srcAttr);
+ }
+ oldRenderCapturedDoc.apply(this, arguments);
+ }
+
+ return;
+}
+
+window.matchMedia = window.matchMedia || Utils.matchMedia(document);
+
+/* https://github.com/Wilto/picturefill-proposal */
+/*! Picturefill - Author: Scott Jehl, 2012 | License: MIT/GPLv2 */
+/*
+ Picturefill: A polyfill for proposed behavior of the picture element, which does not yet exist, but should. :)
+ * Notes:
+ * For active discussion of the picture element, see http://www.w3.org/community/respimg/
+ * While this code does work, it is intended to be used only for example purposes until either:
+ A) A W3C Candidate Recommendation for <picture> is released
+ B) A major browser implements <picture>
+*/
+(function( w ){
+ // Enable strict mode
+ "use strict";
+
+ // User preference for HD content when available
+ var prefHD = false || w.localStorage && w.localStorage[ "picturefill-prefHD" ] === "true",
+ hasHD;
+
+ // Test if `<picture>` is supported natively, if so, exit - no polyfill needed.
+ if ( !!( w.document.createElement( "picture" ) && w.document.createElement( "source" ) && w.HTMLPictureElement ) ){
+ return;
+ }
+
+ w.picturefill = function() {
+ var ps = w.document.getElementsByTagName( "picture" );
+
+ // Loop the pictures
+ for( var i = 0, il = ps.length; i < il; i++ ){
+ var sources = ps[ i ].getElementsByTagName( "source" ),
+ picImg = null,
+ matches = [];
+
+ // If no sources are found, they're likely erased from the DOM. Try finding them inside comments.
+ if( !sources.length ){
+ var picText = ps[ i ].innerHTML,
+ frag = w.document.createElement( "div" ),
+ // For IE9, convert the source elements to divs
+ srcs = picText.replace( /(<)source([^>]+>)/gmi, "$1div$2" ).match( /<div[^>]+>/gmi );
+
+ frag.innerHTML = srcs.join( "" );
+ sources = frag.getElementsByTagName( "div" );
+ }
+
+ // See which sources match
+ for( var j = 0, jl = sources.length; j < jl; j++ ){
+ var media = sources[ j ].getAttribute( "media" );
+ // if there's no media specified, OR w.matchMedia is supported
+ if( !media || ( w.matchMedia && w.matchMedia( media ).matches ) ){
+ matches.push( sources[ j ] );
+ }
+ }
+
+ // Find any existing img element in the picture element
+ picImg = ps[ i ].getElementsByTagName( "img" )[ 0 ];
+
+ if( matches.length ){
+ // Grab the most appropriate (last) match.
+ var match = matches.pop(),
+ srcset = match.getAttribute( "srcset" );
+
+ if( !picImg ){
+ picImg = w.document.createElement( "img" );
+ picImg.alt = ps[ i ].getAttribute( "alt" );
+ ps[ i ].appendChild( picImg );
+ }
+
+ if( srcset ) {
+ var screenRes = ( prefHD && w.devicePixelRatio ) || 1, // Is it worth looping through reasonable matchMedia values here?
+ sources = srcset.split(","); // Split comma-separated `srcset` sources into an array.
+
+ hasHD = w.devicePixelRatio > 1;
+
+ for( var res = sources.length, r = res - 1; r >= 0; r-- ) { // Loop through each source/resolution in `srcset`.
+ var source = sources[ r ].replace(/^\s*/, '').replace(/\s*$/, '').split(" "), // Remove any leading whitespace, then split on spaces.
+ resMatch = parseFloat( source[1], 10 ); // Parse out the resolution for each source in `srcset`.
+
+ if( screenRes >= resMatch ) {
+ if( picImg.getAttribute( "src" ) !== source[0] ) {
+ var newImg = document.createElement("img");
+
+ newImg.src = source[0];
+ // When the image is loaded, set a width equal to that of the original’s intrinsic width divided by the screen resolution:
+ newImg.onload = function() {
+ // Clone the original image into memory so the width is unaffected by page styles:
+ this.width = ( this.cloneNode( true ).width / resMatch );
+ }
+ picImg.parentNode.replaceChild( newImg, picImg );
+ }
+ break; // We’ve matched, so bail out of the loop here.
+ }
+ }
+ } else {
+ // No `srcset` in play, so just use the `src` value:
+ picImg.src = match.getAttribute( "src" );
+ }
+ }
+ }
+ };
+
+ // Run on resize and domready (w.load as a fallback)
+ if( w.addEventListener ){
+ w.addEventListener( "resize", w.picturefill, false );
+ w.addEventListener( "DOMContentLoaded", function(){
+ w.picturefill();
+ // Run once only
+ w.removeEventListener( "load", w.picturefill, false );
+ }, false );
+ w.addEventListener( "load", w.picturefill, false );
+ }
+ else if( w.attachEvent ){
+ w.attachEvent( "onload", w.picturefill );
+ }
+})( this );
+
+return;
+
+}));
+
+},{"../capture.js":1,"../utils.js":9}],4:[function(require,module,exports){
/**
* The Jazzcat client is a library for loading JavaScript from the Jazzcat
* webservice. Jazzcat provides a JSONP HTTP endpoint for fetching multiple HTTP
@@ -1277,7 +1431,7 @@ return CssOptimize;
return Jazzcat;
}));
-},{"./utils.js":8}],4:[function(require,module,exports){
+},{"./utils.js":9}],5:[function(require,module,exports){
(function (root, factory) {
if (typeof require === 'function' && typeof define === 'function' &&
define.amd) {
@@ -1298,6 +1452,8 @@ return CssOptimize;
var Jazzcat = require('./jazzcat');
var CssOptimize = require('./cssOptimize');
var Unblockify = require('./unblockify');
+ require('./external/picturefill');
+
module.exports = factory(Utils, Capture, ResizeImages, Jazzcat,
Unblockify, CssOptimize);
}
@@ -1314,7 +1470,7 @@ return CssOptimize;
}));
-},{"./capture":1,"./cssOptimize":2,"./jazzcat":3,"./resizeImages":6,"./unblockify":7,"./utils":8}],5:[function(require,module,exports){
+},{"./capture":1,"./cssOptimize":2,"./external/picturefill":3,"./jazzcat":4,"./resizeImages":7,"./unblockify":8,"./utils":9}],6:[function(require,module,exports){
// Fixes anchor links (on FF)
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
@@ -1441,7 +1597,7 @@ return CssOptimize;
return patchAnchorLinks;
}));
-},{"./utils.js":8}],6:[function(require,module,exports){
+},{"./utils.js":9}],7:[function(require,module,exports){
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
@@ -1845,7 +2001,7 @@ return ResizeImages;
}));
-},{"./utils.js":8}],7:[function(require,module,exports){
+},{"./utils.js":9}],8:[function(require,module,exports){
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
@@ -1895,7 +2051,7 @@ return Unblockify;
}));
-},{"./capture.js":1,"./utils.js":8}],8:[function(require,module,exports){
+},{"./capture.js":1,"./utils.js":9}],9:[function(require,module,exports){
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
@@ -2206,4 +2362,4 @@ return Utils;
}));
-},{}]},{},[4])
+},{}]},{},[5])
Oops, something went wrong.

0 comments on commit 249cc0f

Please sign in to comment.