From 03336d23b4fb721e63ffba2b37113372c73a54ad Mon Sep 17 00:00:00 2001 From: Andrea Verlicchi Date: Wed, 12 Mar 2014 19:55:14 +0100 Subject: [PATCH 1/3] Updated "usingPictureMarkup" section Updated "usingPictureMarkup" section, but still doesn't work on IE<10 --- usingPictureMarkup/index.html | 33 +++--- usingPictureMarkup/picturePolyfill.js | 148 +++++++++++++++++--------- 2 files changed, 111 insertions(+), 70 deletions(-) diff --git a/usingPictureMarkup/index.html b/usingPictureMarkup/index.html index 585373c..c7724b2 100644 --- a/usingPictureMarkup/index.html +++ b/usingPictureMarkup/index.html @@ -12,16 +12,12 @@

Responsive images using PicturePolyfill - Demo

The following link contains two responsive images created using a <span> element, inline JSON (instead of <source> markup), and the picturePolyfill script.

-

Without HD (Retina) display support

- - - - - +

With HD (Retina) display support

+
+ + + + @@ -29,22 +25,19 @@

Without HD (Retina) display support

-

With HD (Retina) display support

- - - - - +

Without HD (Retina) display support

+
+ + + +
+

Real time server side scaling is provided by Pixtulate.

diff --git a/usingPictureMarkup/picturePolyfill.js b/usingPictureMarkup/picturePolyfill.js index 9534e1a..d3a0c56 100644 --- a/usingPictureMarkup/picturePolyfill.js +++ b/usingPictureMarkup/picturePolyfill.js @@ -1,37 +1,60 @@ /* PicturePolyfill - Responsive Images that work today. (and mimic the proposed Picture element with span elements). Author: Andrea Verlicchi | License: MIT/GPLv2 */ -(function() { +(function(w) { "use strict"; var timerId, - pixelRatio = window.devicePixelRatio || 1, // The pixel density (2 is for HD aka Retina displays) - mediaQueriesSupported = window.matchMedia && window.matchMedia("only all") !== null && window.matchMedia("only all").matches; + pixelRatio = w.devicePixelRatio || 1, // The pixel density (2 is for HD aka Retina displays) + mediaQueriesSupported = w.matchMedia && w.matchMedia("only all") !== null && w.matchMedia("only all").matches; + + /** + * Activate picture and source tag support for IE8 + */ + + document.createElement("picture"); + document.createElement("source"); + + + /** + * Returns a hash density > src + */ + + function getSrcSetHash(srcSetAttribute) { + var hash = {}, + sources = srcSetAttribute.split(','); + + for (var i=0, len=sources.length; i0) { + function getSrcFromSrcSetArray(srcSetArray, position) { + while (srcSetArray[position]===undefined && position>0) { position-=1; } - return arrayOrString[position]; + return srcSetArray[position]; } /** * Loop through every element of the dataPicture array, check if the media query applies and, * if so, get the src element from the srcSet property based depending on pixel ratio - * @param dataPicture + * @param dataPicture {element} * @returns {string} */ @@ -40,8 +63,8 @@ for (var i=0, len=dataPicture.length; i Date: Thu, 13 Mar 2014 08:34:18 +0100 Subject: [PATCH 2/3] Fixed a bug on non-integer pixel ratio devices --- picturePolyfill.js | 1 + 1 file changed, 1 insertion(+) diff --git a/picturePolyfill.js b/picturePolyfill.js index 0481d9d..002798a 100644 --- a/picturePolyfill.js +++ b/picturePolyfill.js @@ -22,6 +22,7 @@ if (typeof arrayOrString === 'string') { return arrayOrString; } + position = Math.ceil(position); while (arrayOrString[position]===undefined && position>0) { position-=1; } From 4d01312e7104455b0adf7947c98724bc35649be7 Mon Sep 17 00:00:00 2001 From: Andrea Verlicchi Date: Thu, 13 Mar 2014 08:40:06 +0100 Subject: [PATCH 3/3] Added bower.json --- bower.json | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 bower.json diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..bbb115d --- /dev/null +++ b/bower.json @@ -0,0 +1,11 @@ +{ + "name": "pictyrePolyfill", + "version": "1.0.1", + "main": "", + "ignore": [ + ".idea", + ".gitignore" + ], + "dependencies": {}, + "devDependencies": {} +} \ No newline at end of file