Skip to content

Commit

Permalink
improve rias plugin + add some docu + 0.4.0-RC1
Browse files Browse the repository at this point in the history
  • Loading branch information
aFarkas committed Nov 5, 2014
1 parent 2069121 commit b279258
Show file tree
Hide file tree
Showing 8 changed files with 295 additions and 122 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "lazysizes",
"repo": "afarkas/lazysizes",
"version": "0.4.0-pre",
"version": "0.4.0-RC1",
"main": "lazysizes.min.js",
"scripts": [
"lazysizes.min.js"
Expand Down
2 changes: 1 addition & 1 deletion component.json
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",
"repo": "afarkas/lazysizes",
"main": "lazysizes.min.js",
"scripts": ["lazysizes.min.js"],
Expand Down
2 changes: 1 addition & 1 deletion lazysizes.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
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"
},
Expand Down
2 changes: 1 addition & 1 deletion plugins/maxdpr/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#lazysizes maxdpr plugin

**lazysizes** maxdpr plugin helps you to limit/constrain the maximum resolution in case the **w descriptor** is used by adding the attribute ``data-maxdpr="1.6"``.
**lazysizes** maxdpr plugin helps you to limit/constrain the maximum resolution in case the **w descriptor** is used. Simply add the attribute ``data-maxdpr="1.6"`` to constrain the max resolution to 1.6.

It gives you therefore more control to trade perceived quality against perceived performance on HD retina devices, than the HTML responsive image standard gives you.

Expand Down
120 changes: 120 additions & 0 deletions plugins/rias/README.md
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.
Loading

0 comments on commit b279258

Please sign in to comment.