Skip to content

Commit

Permalink
Refactoring demos.
Browse files Browse the repository at this point in the history
- moved them in a single folder
- made a separate `npm install` thing
- removed Grunt from Imager dependencies
  • Loading branch information
thom4parisot committed Feb 24, 2014
1 parent c4677ea commit a0f367a
Show file tree
Hide file tree
Showing 26 changed files with 130 additions and 138 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ node_modules
.jpg
.png
.gif
Generated
.DS_Store
44 changes: 0 additions & 44 deletions Demo - Grunt/index.html

This file was deleted.

2 changes: 2 additions & 0 deletions demos/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Generated
node_modules
21 changes: 8 additions & 13 deletions Gruntfile.js → demos/Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
module.exports = function (grunt) {
'use strict';

// Project configuration.
grunt.initConfig({

// Store your Package file so you can reference its specific data whenever necessary
pkg: grunt.file.readJSON('package.json'),
wd: '<%= grunt.task.current.args[0] || "grunt" %>/Assets/Images',

imageDirectory: {
default: 'Demo - Grunt/Assets/Images/',
lazyload: 'Demo - Lazy Load/Assets/Images/'
},

// grunt responsive_images:dev:default
// grunt responsive_images:dev:grunt
// grunt responsive_images:dev:lazyload
responsive_images: {
dev: {
options: {
sizes: [
{
width: 320,
width: 320
},
{
width: 640
Expand All @@ -30,9 +25,9 @@ module.exports = function (grunt) {
},
files: [{
expand: true,
cwd: '<%= imageDirectory[grunt.task.current.args[0]] %>',
src: ['*.{jpg,gif,png}'],
dest: '<%= imageDirectory[grunt.task.current.args[0]] %>Generated/'
cwd: '<%= wd %>',
src: '*.{jpg,gif,png}',
dest: '<%= wd %>/Generated'
}]
}
}
Expand All @@ -43,6 +38,6 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-responsive-images');

// Default Task
grunt.registerTask('default', ['responsive_images:dev']);
grunt.registerTask('default', ['responsive_images:dev:grunt', 'responsive_images:dev:lazyload']);

};
88 changes: 51 additions & 37 deletions demos/README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,61 @@
# Grunt Responsive Image Demo
# Imager.js Demos

This demo requires the following commands to be run...
This folder contains several demonstrations of how to use Imager.

Prior to run them, you need to clone or download this `git` repository:

- `npm install` (all dependencies specified in package.json)
- `brew install imagemagick` (for other installations see [http://www.imagemagick.org/script/binary-releases.php](http://www.imagemagick.org/script/binary-releases.php))

Review the `Gruntfile.js` and update the custom sizes that you want to use (if no sizes are specified in the Gruntfile then 320, 640, 1024 are used)...

```js
options: {
sizes: [
{
width: 320,
height: 240
},
{
name: 'large',
width: 640
},
{
name : 'large',
width : 1024,
suffix : '_x2',
quality: 0.6
}
]
}
```bash
git clone https://github.com/BBC-News/Imager.js.git
cd Imager.js/demos
```

...be aware the names of the files need to change within your HTML...
## Standard Demo

This example in a simple use case using [placehold.it](http://placehold.it/) to refrl the configured breakpoints.

### Running the demo

```bash
open default/index.html
```

## Generating Responsives Images with Grunt

This example demonstrates how to use [Grunt](http://gruntjs.com/) to generate your own responsive images
and how to wire them with Imager.

### Requirements

```html
<div class="delayed-image-load" data-src="Assets/Images/Generated/A-320.jpg" data-width="1024" alt="alternative text A"></div>
<div class="delayed-image-load" data-src="Assets/Images/Generated/B-320.jpg" data-width="1024" alt="alternative text B"></div>
<div class="delayed-image-load" data-src="Assets/Images/Generated/C-320.jpg" data-width="1024" alt="alternative text C"></div>
This demo requires the following commands to be run...

```bash
brew install imagemagick graphicsmagick
npm install -g grunt-cli
npm install
```

You can then pass those image sizes through to Imager.js along with a regex for Imager to parse the information...
[Check out `graphicsmagick` install notes for other systems](http://www.graphicsmagick.org/README.html) if needed.

You can also review the `Gruntfile.js` and update the custom sizes that you want to use [according to `grunt-responsive-images` documentation](https://github.com/andismith/grunt-responsive-images#readme)...

```js
var imager = new Imager({
availableWidths: [320, 640, 1024]
});
```bash
grunt
open grunt/index.html
```

For full details of the Grunt task options see the [grunt-responsive-images](https://github.com/andismith/grunt-responsive-images/) repo on GitHub.
## Lazyloading images

This examples demonstrates how to lazy load responsive images as the user scrolls.

It is a proof of concept rather than a production recommendation.

### Requirements

Please follow the requirements of *Generating Responsives Images with Grunt*.

### Running the demo

```bash
grunt
open lazyload/index.html
```
File renamed without changes.
8 changes: 4 additions & 4 deletions Demo/index.html → demos/default/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ <h1>Imager.js</h1>
<img src="http://placehold.it/340">

<p>Below are three <code>&lt;div&gt;</code> elements that are enhanced using Imager.js and so they will lazy-load more images (as long as JavaScript is enabled).</p>
<div class="delayed-image-load" data-src="http://placehold.it/340" data-width="340"></div>
<div class="delayed-image-load" data-src="http://placehold.it/340" data-width="340"></div>
<div class="delayed-image-load" data-src="http://placehold.it/340" data-width="340"></div>
<div class="delayed-image-load" data-src="http://placehold.it/{width}" data-width="340"></div>
<div class="delayed-image-load" data-src="http://placehold.it/{width}" data-width="340"></div>
<div class="delayed-image-load" data-src="http://placehold.it/{width}" data-width="340"></div>

<script src="../Imager.js"></script>
<script src="../../Imager.js"></script>
<script>
var imager = new Imager();
</script>
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
25 changes: 25 additions & 0 deletions demos/grunt/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!doctype html>
<html dir="ltr" lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Imager.js</title>
<link rel="stylesheet" href="Assets/Styles/base.css">
</head>
<body>
<h1>Imager.js</h1>
<p>Here we're using Grunt to generate a list of image sizes for us.</p>
<p>We then pass those sizes into Imager.</p>

<div class="delayed-image-load" data-src="Assets/Images/Generated/A-{width}.jpg" data-width="1024"></div>
<div class="delayed-image-load" data-src="Assets/Images/Generated/B-{width}.jpg" data-width="1024"></div>
<div class="delayed-image-load" data-src="Assets/Images/Generated/C-{width}.jpg" data-width="1024"></div>

<script src="../../Imager.js"></script>
<script>
var imager = new Imager({
availableWidths: [320, 640, 1024]
});
</script>
</body>
</html>
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
52 changes: 16 additions & 36 deletions Demo - Lazy Load/index.html → demos/lazyload/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,24 @@ <h1>Imager.js</h1>
<p>To initialise Imager press the following button <button onclick="startImager();">Start Imager</button></p>
<p>We've also set the scrollDelay (i.e. the delay between scrolling and replacing a placeholder with an image) to be very high (two seconds). This is so you can visually see the lazy-loading of images as they happen.</p>
<p>The default value is 250ms but you can override that to your own preference.</p>
<div class="delayed-image-load" data-src="Assets/Images/Generated/A-320.jpg" data-width="640"></div>
<div class="delayed-image-load" data-src="Assets/Images/Generated/B-320.jpg" data-width="640"></div>
<div class="delayed-image-load" data-src="Assets/Images/Generated/C-320.jpg" data-width="640"></div>
<div class="delayed-image-load" data-src="Assets/Images/Generated/D-320.jpg" data-width="640"></div>
<div class="delayed-image-load" data-src="Assets/Images/Generated/E-320.jpg" data-width="640"></div>
<div class="delayed-image-load" data-src="Assets/Images/Generated/F-320.jpg" data-width="640"></div>
<div class="delayed-image-load" data-src="Assets/Images/Generated/G-320.jpg" data-width="640"></div>
<div class="delayed-image-load" data-src="Assets/Images/Generated/H-320.jpg" data-width="640"></div>
<div class="delayed-image-load" data-src="Assets/Images/Generated/I-320.jpg" data-width="640"></div>

<script src="../Imager.js"></script>
<div class="delayed-image-load" data-src="Assets/Images/Generated/A-{width}.jpg" data-width="640"></div>
<div class="delayed-image-load" data-src="Assets/Images/Generated/B-{width}.jpg" data-width="640"></div>
<div class="delayed-image-load" data-src="Assets/Images/Generated/C-{width}.jpg" data-width="640"></div>
<div class="delayed-image-load" data-src="Assets/Images/Generated/D-{width}.jpg" data-width="640"></div>
<div class="delayed-image-load" data-src="Assets/Images/Generated/E-{width}.jpg" data-width="640"></div>
<div class="delayed-image-load" data-src="Assets/Images/Generated/F-{width}.jpg" data-width="640"></div>
<div class="delayed-image-load" data-src="Assets/Images/Generated/G-{width}.jpg" data-width="640"></div>
<div class="delayed-image-load" data-src="Assets/Images/Generated/H-{width}.jpg" data-width="640"></div>
<div class="delayed-image-load" data-src="Assets/Images/Generated/I-{width}.jpg" data-width="640"></div>

<script src="../../Imager.js"></script>
<script>
function startImager(){
var imager = new Imager({
lazyload: true,
scrollDelay: 2000, // We'll set this quite high so we get a chance to see the lazy loading happening
availableWidths: [320, 640, 1024],

/*
This regex captures 3 pieces of information:
1. the path to the image -> Assets/Images/Generated/
^(Assets\/Images\/Generated\/)
2. the start of the file name -> A-, B-, C-
(\w-)
3. the file extension -> .jpg
(\.(?:jpg|png|gif))$
The only other part of the regex isn't captured and that is the number specified in the file name.
One other thing to note is the use of the non-capturing group -> (?: )
This means we can use parenthesis as a way to 'group' a part of the regex without needing to capture it
*/
regex: /^(Assets\/Images\/Generated\/)(\w-)\d+(\.(?:jpg|png|gif))$/i
});
}
new Imager({
lazyload: true,
scrollDelay: 2000, // We'll set this quite high so we get a chance to see the lazy loading happening
availableWidths: [320, 640, 1024]
});
</script>
</body>
</html>
23 changes: 23 additions & 0 deletions demos/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "imager.js-demos",
"version": "0.0.0",
"private": true,
"description": "Imager.js Demos",
"main": "Gruntfile.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"imager",
"bbc",
"responsive",
"images",
"rwd"
],
"author": "",
"license": "Apache-2",
"dependencies": {
"grunt": "^0.4.2",
"grunt-responsive-images": "^0.1.1"
}
}
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
],
"license": "Apache-2.0",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-responsive-images": "~0.1.1",
"karma-mocha": "~0.1.0",
"mocha": "~1.17.1",
"karma-phantomjs-launcher": "~0.1.0",
Expand All @@ -50,6 +48,6 @@
"expect.js": "~0.2.0",
"karma-expect": "~1.0.0",
"sinon": "~1.8.1",
"github-changes": "0.0.5"
"github-changes": "^0.0.5"
}
}

0 comments on commit a0f367a

Please sign in to comment.