-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve rias plugin + add some docu + 0.4.0-RC1
- Loading branch information
aFarkas
committed
Nov 5, 2014
1 parent
2069121
commit b279258
Showing
8 changed files
with
295 additions
and
122 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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "lazysizes", | ||
"version": "0.4.0-pre", | ||
"version": "0.4.0-RC1", | ||
"engines": { | ||
"node": ">= 0.8.0" | ||
}, | ||
|
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,120 @@ | ||
#lazysizes RIaS extension (Responsive image as a service) | ||
|
||
The RiaS plugin enables lazySizes to hook into any third party (ReSrc, pixulate, mobify ...) or self hosted restful responsive image service. This is currently the best way to serve adaptive and or retina optimized images. | ||
|
||
The rias plugin also allows art direction by combining rias with a ``picture`` element. | ||
|
||
##Basic/quick usage | ||
|
||
* Simply add the rias plugin right after the lazysizes or concat those scripts into your script bundle: | ||
```html | ||
<script src="../lazysizes.js"></script> | ||
<script src="../plugins/rias/ls.rias.js"></script> | ||
``` | ||
* Add the ``lazyload`` class and the ``data-sizes="auto"`` attribute to your image and include the placeholder ``{width}`` at the point, where your image service expects the requested width of the image. | ||
```html | ||
<img | ||
src="http://placehold.it/100" | ||
data-src="http://placehold.it/{width}" | ||
data-sizes="auto" | ||
class="lazyload" | ||
alt="" /> | ||
``` | ||
|
||
##[Demo](http://afarkas.github.io/lazysizes/rias/) | ||
A [demo with markup and code examples can be seen here](http://afarkas.github.io/lazysizes/rias/). | ||
|
||
##Configuration/Options | ||
|
||
The rias plugin can be configured through the ``lazySizesConfig.rias`` option object, which should be configured before the lazysizes script. | ||
|
||
```js | ||
window.lazySizesConfig = window.lazySizesConfig || {}; | ||
window.lazySizesConfig.rias = window.lazySizesConfig.rias || {}; | ||
|
||
window.lazySizesConfig.rias.maxdpr = 1.8; | ||
window.lazySizesConfig.rias.encodeSrc = true; | ||
``` | ||
|
||
or element specifc with a corresponding ``data-*`` attribute: | ||
|
||
```html | ||
<img | ||
data-maxdpr="1.6" | ||
data-encodesrc="false" | ||
src="http://placehold.it/100" | ||
data-src="http://placehold.it/{width}" | ||
data-sizes="auto" | ||
class="lazyload" | ||
alt="" /> | ||
``` | ||
|
||
All rias options, which represent primitive data types (i.e.: string, numbers or boolean) can also be used as ``data-*`` attributes. | ||
|
||
###URL generation and {placeholder}s | ||
|
||
The url is dynmically generated by replacing placeholder values, which are enclosed by curly brackets. | ||
|
||
Most usefull placeholders are: | ||
|
||
* ``{width}`` represents the width of the image multiplyed by the devicePixelRatio | ||
* ``{height}`` represents the height of the image multiplyed with devicePixelRatio | ||
* ``{quality}`` represents the quality (mostly for JPEG compression) | ||
* ``{dpr}`` represents the current devicePixelRatio (Note: You won't need this often, because {width} already includes this information.) | ||
|
||
```html | ||
<img | ||
data-quality="80" | ||
src="http://placehold.it/100x50" | ||
data-src="http://placehold.it/{width}x{height}?quality={quality}" | ||
data-sizes="auto" | ||
class="lazyload" | ||
alt="" /> | ||
``` | ||
|
||
All rias options, which represent primitive data types (i.e.: string, numbers or boolean) can also be used as {placeholder} inside the url. | ||
|
||
###List of Options | ||
|
||
|
||
* ``lazySizesConfig.rias.srcsetAttr`` (default: ``"data-src"``): The attribute, which should be transformed to ``src``. | ||
* ``lazySizesConfig.rias.quality`` (default: 85): The default quality value for replacing the {quality} placeholder. | ||
* ``lazySizesConfig.rias.formats`` (``number``|``array of numbers`` or ``false``): The formats option reduces the calculated ``width`` to the allowed formats. In case of a ``number`` (i.e.: ``100``) the rias plugin will round the calculated ``width`` number. In case of an ``array`` the rias plugin will take the nearest number inside of this array. | ||
* ``lazySizesConfig.rias.hdQuality`` (default: 70): On higher resolutions it is often possible to use heavier compressed images without reducing the perceived image quality. If a retina device is used the {quality} placeholder is replaced by the ``hdQuality`` option instead of the normal ``quality`` option. | ||
* ``lazySizesConfig.rias.maxdpr`` (default: ``2``): Some images do not gain perceived image quality on higher resolution. With the ``maxdpr`` option the calculated ``width`` can be constrained. | ||
* ``lazySizesConfig.rias.absUrl`` (default: ``false``): Wether the value of the ``data-src``/``srcsetAttr`` attribute should be resolved to an absolute url. | ||
* ``lazySizesConfig.rias.encodeSrc`` (default: ``false``): Wether the value of the ``data-src``/``srcsetAttr`` should be encoded using ``encodeURIComponent`` | ||
* ``lazySizesConfig.rias.modifyOptions`` (default: ``function`` noop ): A ``function`` that gets the option as first and the corresponding ``img`` elment as the second argument. Can be used to modify existing options/placholder values or to add new placeholder values. | ||
|
||
```js | ||
window.lazySizesConfig = window.lazySizesConfig || {}; | ||
window.lazySizesConfig.rias = window.lazySizesConfig.rias || {}; | ||
|
||
window.lazySizesConfig.rias.formats = [320, 640, 940]; | ||
window.lazySizesConfig.rias.modifyOptions = function(opts, img){ | ||
var widthMap = { | ||
320: 'small', | ||
640: 'medium', | ||
940: 'large' | ||
}; | ||
return widthMap[opts.width]; | ||
}; | ||
``` | ||
|
||
* ``lazySizesConfig.rias.modifySrc`` (default: ``function`` noop ): A function that gets passed the generated src, the ``img``/``source`` element and the option object. The function can modify/change the generated src and return it. | ||
* ``lazySizesConfig.rias.prefix`` (default: ``""``): A string, which is prepended to the generated src. | ||
```html | ||
<script> | ||
window.lazySizesConfig = window.lazySizesConfig || {}; | ||
window.lazySizesConfig.rias = { | ||
prefix: 'http://placehold.it/' | ||
}; | ||
</script> | ||
<img | ||
src="http://placehold.it/100" | ||
data-src="{width}" | ||
data-sizes="auto" | ||
class="lazyload" | ||
alt="" /> | ||
``` | ||
* ``lazySizesConfig.rias.postfix`` (default: ``""`` ): A string, which is appended to the generated src. |
Oops, something went wrong.