Skip to content

Commit

Permalink
minor refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian Hoffmann committed Nov 2, 2016
1 parent d6b6b3a commit ba22ff0
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = function (grunt) {
}, {
browserName: "firefox",
platform: "Linux",
version: "49.0"
version: "45.0"
},
// internet explorer
{
Expand Down Expand Up @@ -82,7 +82,7 @@ module.exports = function (grunt) {
}, {
browserName: "safari",
platform: "OS X 10.11",
version: "10.0"
version: "9.0"
}];

grunt.initConfig({
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"main": "src/justlazy.js",
"author": "Fabian Hoffmann",
"description": "Lightweight javascript plugin to lazy load images",
"version": "1.5.1",
"version": "1.6.0",
"homepage": "http://fhopeman.github.io/justlazy",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion src/justlazy.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* justlazy 1.5.1
* justlazy 1.6.0
*
* Repo: https://github.com/fhopeman/justlazy
* Demo: http://fhopeman.github.io/justlazy
Expand Down
21 changes: 13 additions & 8 deletions src/justlazy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* justlazy 1.5.1
* justlazy 1.6.0
*
* Repo: https://github.com/fhopeman/justlazy
* Demo: http://fhopeman.github.io/justlazy
Expand Down Expand Up @@ -34,7 +34,6 @@
onloadCallback.call(img);
}
};

if (!!imgAttributes.title) {
img.title = imgAttributes.title;
}
Expand All @@ -56,7 +55,9 @@
*
* @param {Object} imgPlaceholder Image placeholder html node.
* @param {Object} img Image node itself.
* @param {Function} onReplaceCallback Optional onReplace callback function.
* @param {Function} onreplaceCallback Optional callback function which
* will be invoked directly after the replacement
* of the placeholder.
*/
var _replacePlaceholderWithImage = function(imgPlaceholder, img, onreplaceCallback) {
var parentNode = imgPlaceholder.parentNode;
Expand Down Expand Up @@ -103,17 +104,18 @@
* replacement of the lazy placeholder fails (e.g. mandatory
* attributes missing).
* - onreplaceCallback:
* Optional callback which is invoked after the image placeholder is replaced with the image
* Optional callback which will be invoked after the image placeholder
* is replaced with the image.
*/
var lazyLoad = function(imgPlaceholder, options) {
var imgAttributes = _resolveImageAttributes(imgPlaceholder);
options = _validateOptions(options);
var validatedOptions = _validateOptions(options);

if (!!imgAttributes.src && (!!imgAttributes.alt || imgAttributes.alt === "")) {
_createImage(imgPlaceholder, imgAttributes, options.onloadCallback, options.onreplaceCallback);
_createImage(imgPlaceholder, imgAttributes, validatedOptions.onloadCallback, validatedOptions.onreplaceCallback);
} else {
if (!!options.onerrorCallback) {
options.onerrorCallback.call(imgPlaceholder);
if (!!validatedOptions.onerrorCallback) {
validatedOptions.onerrorCallback.call(imgPlaceholder);
}
}
};
Expand Down Expand Up @@ -155,6 +157,9 @@
* Optional error handler which is invoked if the
* replacement of the lazy placeholder fails (e.g. mandatory
* attributes missing).
* - onreplaceCallback:
* Optional callback which will be invoked after the image placeholder
* is replaced with the image.
* - threshold:
* The image is loaded the defined pixels before it appears
* on the screen. E.g. 200px before it become visible.
Expand Down
2 changes: 1 addition & 1 deletion src/justlazy.min.js

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

0 comments on commit ba22ff0

Please sign in to comment.