Last active
December 16, 2015 09:59
-
-
Save ruemic/5416647 to your computer and use it in GitHub Desktop.
A simple picture fill extension for Webpop
This file contains hidden or 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
<pop:content> | |
<pop:picture:responsive field="image" resize="fit" width="300"/> | |
</pop:content> |
This file contains hidden or 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
exports.responsive = (options, enclosed, scope) -> | |
image = scope.lookup(options.field) | |
resize = options.resize | |
width = options.width | |
height = options.height | |
output = | |
'<div data-picture data-alt="' + image.alt + '">' + | |
'<div data-src="' + image.src({ resize: resize, width: Math.round(width/2), height: Math.round(height/2) }) + '"> </div>' + | |
'<div data-src="' + image.src({ resize: resize, width: width, height: height }) + '" data-media="(min-device-pixel-ratio: 2.0)"> </div>' + | |
'<div data-src="' + image.src({ resize: resize, width: width, height: height }) + '" data-media="(min-width: 768px)"> </div>' + | |
'<div data-src="' + image.src({ resize: resize, width: width*2, height: height*2 }) + '" data-media="(min-width: 768px) and (min-device-pixel-ratio: 2.0)"> </div>' + | |
'</div>'+ | |
'<noscript>' + | |
'<img src="' + image.src({ resize: resize, width: width, height: height*2 }) + '" alt="' + image.alt + '" >' + | |
'</noscript>' | |
return html: output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment