Skip to content

Commit ed8d2f0

Browse files
committed
1.7.3
- fixed issue #58 - created gulp build script for all files - fixed some bugs and warnings from jshint - fixed some readme anchors - changed some file headers to be consistent
1 parent 5b27a01 commit ed8d2f0

19 files changed

+269
-78
lines changed

README.md

+27-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
* [Custom Content Loaders](#custom-content-loaders)
2121
* [Loader Plugins](#loader-plugins)
2222
* [Configuration Parameters](#configuration-parameters)
23+
* [Build and Validation](#build-and-validation)
24+
* [Available gulp Tasks](#available-gulp-tasks)
2325
* [Bugs / Feature request](#bugs--feature-request)
2426
* [License](#license)
2527
* [Donation](#donation)
@@ -57,12 +59,12 @@ Some examples below:
5759
Lazy and all plugins are available over [cdnjs](http://cdnjs.com) and [jsDelivr](http://jsdelivr.com) CDN and can directly included to every page.
5860
```HTML
5961
<!-- jsDeliver -->
60-
<script type="text/javascript" src="//cdn.jsdelivr.net/jquery.lazy/1.7.2/jquery.lazy.min.js"></script>
61-
<script type="text/javascript" src="//cdn.jsdelivr.net/jquery.lazy/1.7.2/jquery.lazy.plugins.min.js"></script>
62+
<script type="text/javascript" src="//cdn.jsdelivr.net/jquery.lazy/1.7.3/jquery.lazy.min.js"></script>
63+
<script type="text/javascript" src="//cdn.jsdelivr.net/jquery.lazy/1.7.3/jquery.lazy.plugins.min.js"></script>
6264

6365
<!-- cdnjs -->
64-
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery.lazy/1.7.2/jquery.lazy.min.js"></script>
65-
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery.lazy/1.7.2/jquery.plugins.min.js"></script>
66+
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery.lazy/1.7.3/jquery.lazy.min.js"></script>
67+
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery.lazy/1.7.3/jquery.plugins.min.js"></script>
6668
```
6769

6870
#### Self-Hosted
@@ -218,6 +220,27 @@ onError | *function* | *undefined* | Callback function, which
218220
onFinishedAll | *function* | *undefined* | Callback function, which will be called after all elements was loaded or returned an error. The callback has no parameters. `this` is the current Lazy instance.
219221

220222

223+
## Build and Validation
224+
This project includes an automated build script using `gulp`.
225+
To build your own versions of Lazy you need to [install it](#package-managers) via [npm](https://www.npmjs.com/package/jquery-lazy) first.
226+
Afterwards you can use the following command in your console to automatically generate all productive files.
227+
While building these files everything will be checked with `jshint` for validity too.
228+
```sh
229+
$ gulp build
230+
```
231+
232+
### Available `gulp` Tasks:
233+
234+
Name | Description
235+
-------------- | -----------
236+
build | check & build everything
237+
build-main | check & build main project file
238+
build-plugins | check & build single plugin files
239+
concat-plugins | build concatenated plugins file
240+
validate | check all files with `jshint`
241+
watch | watches all files to check & build everything on change
242+
243+
221244
## Bugs / Feature request
222245
Please [report](http://github.com/eisbehr-/jquery.lazy/issues) bugs and feel free to [ask](http://github.com/eisbehr-/jquery.lazy/issues) for new features directly on GitHub.
223246

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "jquery-lazy",
33
"description": "Lazy is a fast, feature-rich and lightweight delayed content loading plugin for jQuery and Zepto. It's designed to speed up page loading times and decrease traffic to your users by only loading the content in view. You can use Lazy in all vertical and horizontal scroll ways. It supports images in 'img' tags and backgrounds, supplied with css like 'background-image', by default. On those elements Lazy can set an default image or a placeholder while loading and supports retina displays as well. But Lazy is even able to load any other content you want by plugins and custom loaders.",
4-
"version": "1.7.2",
4+
"version": "1.7.3",
55
"main": "jquery.lazy.min.js",
66
"license": [
77
"MIT",

gulpfile.js

+152
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
"use strict";
2+
3+
var gulp = require("gulp");
4+
var util = require("gulp-util");
5+
var data = require("gulp-data");
6+
var rename = require("gulp-rename");
7+
var header = require("gulp-header");
8+
var jshint = require("gulp-jshint");
9+
var uglify = require("gulp-uglify");
10+
var concat = require("gulp-concat-util");
11+
var pkg = require("./package.json");
12+
var nl = require("os").EOL;
13+
14+
15+
16+
/*
17+
** CONFIG & PATHS
18+
*/
19+
20+
21+
22+
var config = {
23+
header : "/*! jQuery & Zepto Lazy <%= info %> - <%= pkg.homepage %> - MIT&GPL-2.0 license - Copyright 2012-<%= year %> <%= pkg.author.name %> */",
24+
main : pkg.main,
25+
plugins : [
26+
"plugins/jquery.lazy.*.js",
27+
"!plugins/jquery.lazy.*.min.js"
28+
]
29+
};
30+
31+
32+
33+
/*
34+
** PIPES
35+
*/
36+
37+
38+
39+
var pipes = {};
40+
41+
// check files with jshint
42+
pipes.validateFiles = function(files) {
43+
return gulp.src(files, {base: "./"})
44+
.pipe(jshint())
45+
.pipe(jshint.reporter("jshint-stylish"))
46+
};
47+
48+
// check all files
49+
pipes.validate = function() {
50+
return pipes.validateFiles([config.main].concat(config.plugins));
51+
};
52+
53+
// build main project file
54+
pipes.buildMain = function() {
55+
return pipes.validateFiles(config.main)
56+
.pipe(uglify())
57+
.pipe(header(config.header + nl, {
58+
pkg : pkg,
59+
info : "v" + pkg.version,
60+
year : new Date().getFullYear()
61+
}))
62+
.pipe(rename(function(path) {
63+
path.extname = ".min" + path.extname;
64+
}))
65+
.pipe(gulp.dest("./"));
66+
};
67+
68+
// build plugin files
69+
pipes.buildPlugins = function() {
70+
return pipes.validateFiles(config.plugins)
71+
.pipe(data(function(file) {
72+
var string = String(file.contents).split("\n")[1];
73+
var matches = string.match(/\s-\s([a-z ]+)\s-\sv([0-9.]+)/i);
74+
75+
return {
76+
plugin: {
77+
name : matches[1],
78+
version : matches[2]
79+
}
80+
};
81+
}))
82+
.pipe(uglify())
83+
.pipe(header(config.header.replace("<%= info %>", "- <%= file.data.plugin.name %> v<%= file.data.plugin.version %>") + nl, {
84+
pkg : pkg,
85+
year : new Date().getFullYear()
86+
}))
87+
.pipe(rename(function(path) {
88+
path.extname = ".min" + path.extname;
89+
}))
90+
.pipe(gulp.dest("./"));
91+
};
92+
93+
// concat plugin files
94+
pipes.concatPlugins = function() {
95+
return gulp.src(config.plugins)
96+
.pipe(concat(config.main.replace(".js", ".plugins.js"), {
97+
sep: nl + nl
98+
}))
99+
.pipe(gulp.dest("./"))
100+
.pipe(uglify())
101+
.pipe(header(config.header + nl, {
102+
pkg : pkg,
103+
info : "- All Plugins v" + pkg.version,
104+
year : new Date().getFullYear()
105+
}))
106+
.pipe(rename(function(path) {
107+
path.extname = ".min" + path.extname;
108+
}))
109+
.pipe(gulp.dest("./"));
110+
};
111+
112+
113+
114+
/*
115+
** TASKS
116+
*/
117+
118+
119+
120+
// check & build everything
121+
gulp.task("build", ["build-main", "build-plugins", "concat-plugins"]);
122+
123+
// check & build main project file
124+
gulp.task("build-main", pipes.buildMain);
125+
126+
// check & build single plugin files
127+
gulp.task("build-plugins", pipes.buildPlugins);
128+
129+
// build concatenated plugins file
130+
gulp.task("concat-plugins", pipes.concatPlugins);
131+
132+
// check all files
133+
gulp.task("validate", pipes.validate);
134+
135+
// check, build & watch live changes
136+
gulp.task("watch", ["build"], function() {
137+
// watch main file
138+
gulp.watch(config.main, function() {
139+
var task = pipes.buildMain();
140+
util.log("updated", "'" + util.colors.red("main file") + "'");
141+
return task;
142+
});
143+
144+
// watch plugins
145+
gulp.watch(config.plugins, function() {
146+
var task = pipes.buildPlugins();
147+
util.log("updated", "'" + util.colors.red("plugins") + "'");
148+
pipes.concatPlugins();
149+
util.log("updated", "'" + util.colors.red("concatenated plugins file") + "'");
150+
return task;
151+
});
152+
});

jquery.lazy.js

+40-41
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* jQuery & Zepto Lazy - v1.7.2
2+
* jQuery & Zepto Lazy - v1.7.3
33
* http://jquery.eisbehr.de/lazy/
44
*
55
* Copyright 2012 - 2016, Daniel 'Eisbehr' Kern
@@ -250,7 +250,7 @@
250250
tag = _getElementTagName(this);
251251

252252
return !element.data(config.handledName) &&
253-
(element.attr(config.attribute) || element.attr(srcsetAttribute) || element.attr(loaderAttribute) || forcedTags[tag] != undefined);
253+
(element.attr(config.attribute) || element.attr(srcsetAttribute) || element.attr(loaderAttribute) || forcedTags[tag] !== undefined);
254254
})
255255

256256
// append plugin instance to all elements
@@ -266,7 +266,7 @@
266266
element.attr(srcsetAttribute, _getCorrectedSrcSet(element.attr(srcsetAttribute), elementImageBase));
267267

268268
// add loader to forced element types
269-
if( forcedTags[tag] != undefined && !element.attr(loaderAttribute) )
269+
if( forcedTags[tag] !== undefined && !element.attr(loaderAttribute) )
270270
element.attr(loaderAttribute, forcedTags[tag]);
271271

272272
// set default image on every element without source
@@ -302,39 +302,38 @@
302302
handledName = config.handledName;
303303

304304
// loop all available items
305-
for( var i = 0, l = items.length; i < l; i++ )
306-
(function(item) {
307-
// item is at least in loadable area
308-
if( allItems || _isInLoadableArea(item) ) {
309-
var element = $(item),
310-
tag = _getElementTagName(item),
311-
attribute = element.attr(config.attribute),
312-
elementImageBase = element.attr(config.imageBaseAttribute) || imageBase,
313-
customLoader = element.attr(config.loaderAttribute);
314-
315-
// is not already handled
316-
if( !element.data(handledName) &&
317-
// and is visible or visibility doesn't matter
318-
(!config.visibleOnly || element.is(":visible")) && (
319-
// and image source or source set attribute is available
320-
(attribute || element.attr(srcsetAttribute)) && (
321-
// and is image tag where attribute is not equal source or source set
322-
(tag == _img && (elementImageBase + attribute != element.attr(_src) || element.attr(srcsetAttribute) != element.attr(_srcset))) ||
323-
// or is non image tag where attribute is not equal background
324-
(tag != _img && elementImageBase + attribute != element.css(_backgroundImage))
325-
) ||
326-
// or custom loader is available
327-
customLoader ))
328-
{
329-
// mark element always as handled as this point to prevent double handling
330-
loadTriggered = true;
331-
element.data(handledName, true);
332-
333-
// load item
334-
_handleItem(element, tag, elementImageBase, customLoader);
335-
}
305+
for( var i = 0; i < items.length; i++ ) {
306+
// item is at least in loadable area
307+
if( allItems || _isInLoadableArea(items[i]) ) {
308+
var element = $(items[i]),
309+
tag = _getElementTagName(items[i]),
310+
attribute = element.attr(config.attribute),
311+
elementImageBase = element.attr(config.imageBaseAttribute) || imageBase,
312+
customLoader = element.attr(config.loaderAttribute);
313+
314+
// is not already handled
315+
if( !element.data(handledName) &&
316+
// and is visible or visibility doesn't matter
317+
(!config.visibleOnly || element.is(":visible")) && (
318+
// and image source or source set attribute is available
319+
(attribute || element.attr(srcsetAttribute)) && (
320+
// and is image tag where attribute is not equal source or source set
321+
(tag == _img && (elementImageBase + attribute != element.attr(_src) || element.attr(srcsetAttribute) != element.attr(_srcset))) ||
322+
// or is non image tag where attribute is not equal background
323+
(tag != _img && elementImageBase + attribute != element.css(_backgroundImage))
324+
) ||
325+
// or custom loader is available
326+
customLoader ))
327+
{
328+
// mark element always as handled as this point to prevent double handling
329+
loadTriggered = true;
330+
element.data(handledName, true);
331+
332+
// load item
333+
_handleItem(element, tag, elementImageBase, customLoader);
336334
}
337-
})(items[i]);
335+
}
336+
}
338337

339338
// when something was loaded remove them from remaining items
340339
if( loadTriggered )
@@ -473,7 +472,7 @@
473472
.attr(_src, imageSrc ? imageBase + imageSrc : null);
474473

475474
// call after load even on cached image
476-
imageObj.complete && imageObj.load();
475+
imageObj.complete && imageObj.load(); // jshint ignore : line
477476
}
478477
}
479478

@@ -569,7 +568,7 @@
569568
callback.call(instance, event);
570569
}
571570

572-
timeout && clearTimeout(timeout);
571+
timeout && clearTimeout(timeout); // jshint ignore : line
573572

574573
if( elapsed > delay || !config.enableThrottle || ignoreThrottle ) run();
575574
else timeout = setTimeout(run, delay - elapsed);
@@ -652,7 +651,7 @@
652651
* @access private
653652
* @type {string}
654653
*/
655-
_namespace = _config.name + "-" + ++lazyInstanceId;
654+
_namespace = _config.name + "-" + (++lazyInstanceId);
656655

657656
// noinspection JSUndefinedPropertyAssignment
658657
/**
@@ -680,7 +679,7 @@
680679
* @return {LazyPlugin}
681680
*/
682681
_instance.addItems = function(items) {
683-
_events.a && _events.a($.type(items) === "string" ? $(items) : items);
682+
_events.a && _events.a($.type(items) === "string" ? $(items) : items); // jshint ignore : line
684683
return _instance;
685684
};
686685

@@ -704,7 +703,7 @@
704703
* @return {LazyPlugin}
705704
*/
706705
_instance.update = function(useThrottle) {
707-
_events.e && _events.e({}, !useThrottle);
706+
_events.e && _events.e({}, !useThrottle); // jshint ignore : line
708707
return _instance;
709708
};
710709

@@ -717,7 +716,7 @@
717716
* @return {LazyPlugin}
718717
*/
719718
_instance.loadAll = function() {
720-
_events.e && _events.e({all: true}, true);
719+
_events.e && _events.e({all: true}, true); // jshint ignore : line
721720
return _instance;
722721
};
723722

0 commit comments

Comments
 (0)