Skip to content

Commit afddcc2

Browse files
committed
Documentation cleanup.
1 parent 77d79c6 commit afddcc2

File tree

7 files changed

+237
-301
lines changed

7 files changed

+237
-301
lines changed

.ruby-version

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 8 additions & 212 deletions
Original file line numberDiff line numberDiff line change
@@ -175,220 +175,13 @@ This will result in the following HTML output:
175175
</div>
176176
```
177177

178-
---
179-
180178
# Documentation
181179

182-
## HTML Attributes
183-
184-
The *HTML API* helps you control how Imager works from the *content point of view*.
185-
186-
### `data-src`
187-
188-
Available placeholders are:
189-
190-
- `{width}`: best available image width (numeric value)
191-
- `{pixel_ratio}`: device pixel ratio (either *blank* or `-1.3x`, `-2x`, `-3x` etc.)
192-
193-
194-
So the following HTML...
195-
196-
```html
197-
<div data-src="http://placehold.it/{width}"></div>
198-
```
199-
200-
...is converted to...
201-
202-
```html
203-
<img src="http://placehold.it/260" data-src="http://placehold.it/{width}" class="image-replace">
204-
```
205-
206-
### `data-width`
207-
208-
`data-width` is the enforced size of the image placeholder; where the actual image will eventually be loaded.
209-
210-
This can be especially useful if you don't want to depend on the image container width.
211-
212-
So the following HTML...
213-
214-
```html
215-
<div style="width:600px">
216-
<div data-src="http://placehold.it/{width}" data-width="300" data-alt="alternative text"></div>
217-
</div>
218-
```
219-
220-
...is converted to...
221-
222-
```html
223-
<div style="width:600px">
224-
<img src="http://placehold.it/300" data-src="http://placehold.it/{width}" width="300" alt="alternative text" class="image-replace">
225-
</div>
226-
```
227-
228-
### `data-alt` and `data-class`
229-
230-
These two `data-*` attributes are copied from the responsive placeholder to the response `img` element.nnot process images or who have image loading disabled. It is converted to the `alt` attribute of the `img element.
231-
232-
So the following HTML...
233-
234-
```html
235-
<div data-src="http://placehold.it/{width}" data-alt="alternative text"></div>
236-
<div data-src="http://placehold.it/{width}" data-class="london calling"></div>
237-
```
238-
239-
...is converted to...
240-
241-
```html
242-
<img src="http://placehold.it/260" data-src="http://placehold.it/{width}" alt="alternative text" class="image-replace">
243-
<img src="http://placehold.it/260" data-src="http://placehold.it/{width}" alt="" class="london calling image-replace">
244-
```
245-
246-
## JavaScript Configuration
247-
248-
You can create one or several concurrent configurations of Imager within the same page. Its configuration options are
249-
described below.
250-
251-
[Advanced JavaScript API documentation lies in the `docs/` folder](docs/js-api.md).
252-
253-
### `availableWidths`
254-
255-
This option is intended to reflect the available widths of each responsive image. These values will be used as replacements
256-
for the `{width}` variable in `data-src` placeholders.
257-
258-
The following examples demonstrate the results of passing through different object types for the `availableWidths` option...
259-
260-
`Array`: the widths are represented as numeric values
261-
262-
```js
263-
new Imager({
264-
availableWidths: [240, 320, 640]
265-
});
266-
```
267-
268-
`Object`: the widths associate a string value for their numeric counterpart
269-
270-
```js
271-
new Imager({
272-
availableWidths: {
273-
240: 'small',
274-
320: 'medium',
275-
640: 'large'
276-
}
277-
});
278-
```
279-
280-
`Function`: must return a value for the provided width argument
281-
282-
```js
283-
// will return a double sized image width as a numeric value
284-
new Imager({
285-
availableWidths: function (image) {
286-
return image.clientWidth * 2;
287-
}
288-
});
289-
```
290-
291-
### `availablePixelRatios`
292-
293-
An Array which indicates what are the available pixel ratios available for your responsive images.
294-
295-
These values will be used as replacements for the `{pixel_ratio}` variable in `data-src` placeholders.
296-
297-
```js
298-
new Imager({ availablePixelRatios: [1, 2] });
299-
```
300-
301-
**Default value**: `[1, 2]`
302-
303-
### `className`
304-
305-
A String which indicates what the `className` value will be added on the newly created responsive image.
306-
307-
```js
308-
new Imager({ className: 'image-replace' });
309-
```
310-
311-
**Default value**: `image-replace`
312-
313-
### `scrollDelay`
314-
315-
An Integer value (in milliseconds) to indicate when Imager will check if a scroll has ended. If a scroll has stopped after this delay and the `lazyload` option is `true`, Imager will update the `src` attribute of the relevant images.
316-
317-
**Default value**: `250`
318-
319-
```js
320-
new Imager({ scrollDelay: 250 });
321-
```
322-
323-
**Notice**: set the `scrollDelay` value to `0` at your own risk; unless you know what you're doing, setting the value to zero will make the user experience totally janky! (and that would be an odd thing to do as you have chosen to use Imager to improve the user experience)
324-
325-
### `onResize`
326-
327-
A Boolean value. If set to `true`, Imager will update the `src` attribute of the relevant images.
328-
329-
**Default value**: `true`
330-
331-
```js
332-
new Imager({ onResize: true });
333-
```
180+
Browse Imager public APIs and options – versioned alongside the source code of the project:
334181

335-
### `lazyload`
336-
337-
An *experimental* Boolean value. If set to `true`, Imager will update the `src` attribute only of visible (and nearly visible) images.
338-
339-
**Default value**: `false`
340-
341-
```js
342-
new Imager({ lazyload: true });
343-
```
344-
345-
### `lazyloadOffset`
346-
347-
A `Number` of extra pixels below the fold taken in account by the lazyloading mechanism.
348-
349-
**Default value**: `0`
350-
351-
```js
352-
new Imager({ lazyload: true, lazyloadOffset: 300 });
353-
```
354-
355-
### `onImagesReplaced`
356-
357-
A callback `Function`. Runs after Imager updates the `src` attribute of all relevant images.
358-
359-
Its first and unique argument is an `Array` of `HTMLImageElement`, the ones processed by Imager.
360-
361-
```js
362-
new Imager({
363-
onImagesReplaced: function(images) {
364-
console.log('the src of all relevant images has been updated');
365-
}
366-
});
367-
```
368-
369-
## JavaScript API
370-
371-
### `.ready(fn)`
372-
373-
Executes a function when Imager is ready to work.
374-
375-
```js
376-
new Imager({ ... }).ready(function(){
377-
console.log('Placeholders divs have been replaced');
378-
});
379-
```
380-
381-
### `.add(elements | selector)`
382-
383-
Add new elements to the existing pool of responsive images.
384-
385-
```js
386-
var imgr = new Imager('.delayed-image-load');
387-
388-
imgr.add('.new-delayed-image-load-selector');
389-
imgr.add(newElements);
390-
imgr.add(); // reuses the constructor selector ('.delayed-image-load')
391-
```
182+
- [HTML options](docs/html-api.md)
183+
- [JavaScript options](docs/js-options.md)
184+
- [JavaScript API](docs/js-api.md)
392185

393186
# Demos
394187

@@ -398,8 +191,10 @@ Additional and fully working examples lie in the [`demos` folder](demos/).
398191
# They are using it
399192

400193
- [BBC News](http://m.bbc.co.uk/news)
194+
- [BBC Sport](http://m.bbc.co.uk/sport)
401195
- [The Guardian](http://www.theguardian.com/)
402196
- [`x-imager` Web Component](https://github.com/addyosmani/x-imager)
197+
- [Imager.jsx React Component](https://www.npmjs.com/package/imager.jsx)
403198

404199
# Background
405200

@@ -415,6 +210,7 @@ Much of this work can be repurposed to work with a more standards-based approach
415210

416211
For the purposes of maintaining a distinguishment between the ImageEnhancer concept built by BBC News and this project, we're calling it **Imager.js**
417212

213+
**[Read more on BBC Responsive News blog](http://responsivenews.co.uk/post/58244240772/imager-js)**.
418214

419215
# Credits
420216

@@ -426,7 +222,7 @@ For the purposes of maintaining a distinguishment between the ImageEnhancer conc
426222

427223
# Licence
428224

429-
> Copyright 2014 British Broadcasting Corporation
225+
> Copyright 2015 British Broadcasting Corporation
430226
>
431227
> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
432228
>

docs/html-api.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Imager.js documentation
2+
3+
- [HTML options](html-api.md)
4+
- [JavaScript options](js-options.md)
5+
- [JavaScript API](js-api.md)
6+
7+
## HTML Attributes
8+
9+
The *HTML API* helps you control how Imager works from the *content point of view*.
10+
11+
### `data-src`
12+
13+
Available placeholders are:
14+
15+
- `{width}`: best available image width (numeric value)
16+
- `{pixel_ratio}`: device pixel ratio (either *blank* or `-1.3x`, `-2x`, `-3x` etc.)
17+
18+
19+
So the following HTML...
20+
21+
```html
22+
<div data-src="http://placehold.it/{width}"></div>
23+
```
24+
25+
...is converted to...
26+
27+
```html
28+
<img src="http://placehold.it/260" data-src="http://placehold.it/{width}" class="image-replace">
29+
```
30+
31+
### `data-width`
32+
33+
`data-width` is the enforced size of the image placeholder; where the actual image will eventually be loaded.
34+
35+
This can be especially useful if you don't want to depend on the image container width.
36+
37+
So the following HTML...
38+
39+
```html
40+
<div style="width:600px">
41+
<div data-src="http://placehold.it/{width}" data-width="300" data-alt="alternative text"></div>
42+
</div>
43+
```
44+
45+
...is converted to...
46+
47+
```html
48+
<div style="width:600px">
49+
<img src="http://placehold.it/300" data-src="http://placehold.it/{width}" width="300" alt="alternative text" class="image-replace">
50+
</div>
51+
```
52+
53+
### `data-alt` and `data-class`
54+
55+
These two `data-*` attributes are copied from the responsive placeholder to the response `img` element.nnot process images or who have image loading disabled. It is converted to the `alt` attribute of the `img element.
56+
57+
So the following HTML...
58+
59+
```html
60+
<div data-src="http://placehold.it/{width}" data-alt="alternative text"></div>
61+
<div data-src="http://placehold.it/{width}" data-class="london calling"></div>
62+
```
63+
64+
...is converted to...
65+
66+
```html
67+
<img src="http://placehold.it/260" data-src="http://placehold.it/{width}" alt="alternative text" class="image-replace">
68+
<img src="http://placehold.it/260" data-src="http://placehold.it/{width}" alt="" class="london calling image-replace">
69+
```

docs/js-api.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Imager.js documentation
2+
3+
- [HTML options](html-api.md)
4+
- [JavaScript options](js-options.md)
5+
- [JavaScript API](js-api.md)
6+
17
## JavaScript API
28

39
The *JavaScript API* helps you instantiate and control how Imager works from a *business logic point of view*.
@@ -6,7 +12,7 @@ The *JavaScript API* helps you instantiate and control how Imager works from a *
612

713
Calling the constructor will initialise responsive images for the provided `elements` or the HTML elements concerned by the `selector`.
814

9-
The `options` bit is an object documented below, in the [JavaScript Options section](#javascript-options).
15+
The `options` bit is an object documented in the [JavaScript Options section](js-options.md).
1016

1117
```js
1218
new Imager('.responsive-image-placeholder');
@@ -28,6 +34,30 @@ new Imager();
2834
```
2935

3036

37+
### `.ready(fn)`
38+
39+
Executes a function when Imager is ready to work.
40+
41+
```js
42+
new Imager({ ... }).ready(function(){
43+
console.log('Placeholders divs have been replaced');
44+
});
45+
```
46+
47+
48+
### `.add(elements | selector)`
49+
50+
Add new elements to the existing pool of responsive images.
51+
52+
```js
53+
var imgr = new Imager('.delayed-image-load');
54+
55+
imgr.add('.new-delayed-image-load-selector');
56+
imgr.add(newElements);
57+
imgr.add(); // reuses the constructor selector ('.delayed-image-load')
58+
```
59+
60+
3161
### `Imager.checkImagesNeedReplacing()`
3262

3363
Updates the `img[src]` attribute if the container width has changed, and if it matches a different `availableWidths` value.
@@ -41,6 +71,7 @@ var imgr = new Imager();
4171
$(document).on('customEvent', $.proxy(imgr.checkImagesNeedReplacing, imgr));
4272
```
4373

74+
4475
### `Imager.registerResizeEvent()`
4576

4677
Registers a `window.onresize` handler which will update the relevant `img[src]` (using `Imager.checkImagesNeedReplacing`)
@@ -55,6 +86,7 @@ var imgr = new Imager();
5586
$(document).on('load', $.proxy(imgr.registerResizeEvent, imgr));
5687
```
5788

89+
5890
### `Imager.registerScrollEvent()`
5991

6092
Registers a `window.onscroll` handler which will update the relevant `img[src]` (using `Imager.checkImagesNeedReplacing`)
@@ -68,4 +100,4 @@ var imgr = new Imager();
68100

69101
// Using jQuery to set-up the event handling and help keep the correct scope when executing the callback
70102
$(document).on('load', $.proxy(imgr.registerScrollEvent, imgr));
71-
```
103+
```

0 commit comments

Comments
 (0)