-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
250 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,31 @@ | ||
{ | ||
"name": "pictyrePolyfill", | ||
"version": "1.0.1", | ||
"main": "", | ||
"name": "picturePolyfill", | ||
"version": "1.0.0", | ||
"main": "picturePolyfill.js", | ||
"ignore": [ | ||
".idea", | ||
".gitignore" | ||
".gitignore", | ||
"**/.*", | ||
"node_modules", | ||
"bower_components", | ||
"test", | ||
"tests" | ||
], | ||
"dependencies": {}, | ||
"devDependencies": {} | ||
} | ||
"homepage": "https://github.com/verlok/picturePolyfill", | ||
"authors": [ | ||
"Andrea Verlicchi <[email protected]>" | ||
], | ||
"description": "The real <picture> polyfill to use responsive images today", | ||
"keywords": [ | ||
"picture", | ||
"polyfill", | ||
"picturefill", | ||
"responsive", | ||
"images", | ||
"responsive", | ||
"design", | ||
"responsive", | ||
"images" | ||
], | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Responsive images with picturePolyfill - by Andrea Verlicchi</title> | ||
<meta name="viewport" content="width=device-width"> | ||
<style> | ||
body { margin: 0; padding: 0; text-align: center; } | ||
.element a, .element span, .element img { display: block; } | ||
img { width: 100%; height: auto; border: 0; } | ||
.element h2 { padding: 0 16px; } | ||
.element:hover h2 { text-decoration: underline; } | ||
</style> | ||
</head> | ||
<body> | ||
<div id="container"> | ||
<h1>picturePolyfill Test</h1> | ||
<p>To test script solidness.</p> | ||
<div class="element"> | ||
<h2>Most complex usage</h2> | ||
<span data-alt="A beautiful image" data-picture='[ | ||
{"srcset": "../img/320x320.gif"}, | ||
{"srcset": ["../img/768x768.gif", "../img/768x768x2.gif"], "media": "(min-width: 321px)"}, | ||
{"srcset": ["../img/1024x1024.gif", "../img/1024x1024x2.gif"], "media": "(min-width: 769px)"}, | ||
{"srcset": ["../img/1280x1280.gif", "../img/1280x1280x2.gif"], "media": "(min-width: 1025px)"}, | ||
{"srcset": ["../img/1440x1440.gif", "../img/1440x1440x2.gif"], "media": "(min-width: 1281px)"}, | ||
{"srcset": ["../img/1920x1920.gif", "../img/1920x1920x2.gif"], "media": "(min-width: 1441px)"} | ||
]'> | ||
<noscript> | ||
<img src="../img/1280x1280.gif" alt="A beautiful image"/> | ||
</noscript> | ||
</span> | ||
</div> | ||
</div> | ||
<script src="../external/matchMedia.js"></script> | ||
<script src="../picturePolyfill.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Responsive images with picturePolyfill - by Andrea Verlicchi</title> | ||
<style> | ||
body { margin: 0; padding: 0; text-align: center; } | ||
.intro { padding: 0 16px; } | ||
.outro { padding: 1px 16px; clear: both; } | ||
.element a, .element span, .element img { display: block; } | ||
img { width: 100%; height: auto; border: 0; } | ||
.element h2 { padding: 0 16px; } | ||
.element:hover h2 { text-decoration: underline; } | ||
@media screen and (min-width: 481px) { | ||
.element { float: left; width: 50%; } | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="container"> | ||
<div class="intro"> | ||
<h1>Responsive images using PicturePolyfill - Demo</h1> | ||
<p>The following link contains two <strong>responsive images</strong> created using a <code><span></code> element, inline JSON (instead of <code><source></code> markup), and the <a href="https://github.com/verlok/picturePolyfill">picturePolyfill</a> script.</p> | ||
</div> | ||
<div class="element"> | ||
<h2>With HD (Retina) display support</h2> | ||
<a href="#someLink1"> | ||
<picture data-alt="A beautiful responsive image"> | ||
<source srcset="http://demo.api.pixtulate.com/demo/large-2.jpg?w=480, http://demo.api.pixtulate.com/demo/large-2.jpg?w=960 2x"/> | ||
<source srcset="http://demo.api.pixtulate.com/demo/large-2.jpg?w=512, http://demo.api.pixtulate.com/demo/large-2.jpg?w=1024 2x" media="(min-width: 481px)"/> | ||
<source srcset="http://demo.api.pixtulate.com/demo/large-2.jpg?w=960, http://demo.api.pixtulate.com/demo/large-2.jpg?w=1920 2x" media="(min-width: 1025px)"/> | ||
<noscript><img src="http://demo.api.pixtulate.com/demo/large-2.jpg?w=512" alt="A beautiful responsive image"/></noscript> | ||
</picture> | ||
</a> | ||
</div> | ||
<div class="element"> | ||
<h2>Without HD (Retina) display support</h2> | ||
<a href="#someLink2"> | ||
<picture id="second" data-alt="A beautiful responsive image"> | ||
<source srcset="http://demo.api.pixtulate.com/demo/large-2.jpg?w=480"/> | ||
<source srcset="http://demo.api.pixtulate.com/demo/large-2.jpg?w=512" media="(min-width: 481px)"/> | ||
<source srcset="http://demo.api.pixtulate.com/demo/large-2.jpg?w=960" media="(min-width: 1025px)"/> | ||
<noscript> | ||
<img src="http://demo.api.pixtulate.com/demo/large-2.jpg?w=512" alt="A beautiful responsive image"/> | ||
</noscript> | ||
</picture> | ||
</a> | ||
</div> | ||
<div class="outro"> | ||
<p>Real time server side scaling is provided by <a href="http://www.pixtulate.com">Pixtulate</a>.</p> | ||
</div> | ||
</div> | ||
<script> | ||
|
||
(function(){ | ||
|
||
var picture; | ||
|
||
function replacePictureWithPictureWithImg(picture, imgSrc) { | ||
var newImage = document.createElement("img"), | ||
newPicture = document.createElement("picture"); | ||
newImage.setAttribute('src', imgSrc); | ||
newPicture.appendChild(newImage); | ||
picture.parentNode.replaceChild(newPicture, picture); | ||
} | ||
|
||
function updateImgSrcOrReplacePicture(picture, imgSrc) { | ||
var imgs = picture.getElementsByTagName("img"); | ||
if (imgs.length === 0) { | ||
replacePictureWithPictureWithImg(picture, imgSrc); | ||
} | ||
else { | ||
imgs[0].setAttribute("img", imgSrc); | ||
} | ||
} | ||
|
||
var appendImageIsAllowed, pictures; | ||
|
||
pictures = document.getElementsByTagName("picture"); | ||
|
||
for (var i=0, len=pictures.length; i<len; i+=1) { | ||
picture = pictures[i]; | ||
replacePictureWithPictureWithImg(picture, 'http://www.placehold.it/500x500'); | ||
} | ||
|
||
picture = pictures[1]; | ||
replacePictureWithPictureWithImg(picture, 'http://www.placehold.it/500x500/f00ba5'); | ||
|
||
}()); | ||
|
||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.