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
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;
}
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.
+
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