Site updated: 2019-03-16 15:24:42
This commit is contained in:
22
lib/jquery_lazyload/CONTRIBUTING.html
Normal file
22
lib/jquery_lazyload/CONTRIBUTING.html
Normal file
@ -0,0 +1,22 @@
|
||||
<h1 id="Contributing-to-Lazy-Load"><a href="#Contributing-to-Lazy-Load" class="headerlink" title="Contributing to Lazy Load"></a>Contributing to Lazy Load</h1><h2 id="Only-one-feature-or-change-per-pull-request"><a href="#Only-one-feature-or-change-per-pull-request" class="headerlink" title="Only one feature or change per pull request"></a>Only one feature or change per pull request</h2><p>Make pull requests only one feature or change at the time. For example you have fixed a bug. You also have optimized some code. Optimization is not related to a bug. These should be submitted as separate pull requests. This way I can easily choose what to include. It is also easier to understand the code changes. Commit messages should be descriptive and full sentences.</p>
|
||||
<p>Do not commit minified versions. Do not touch the version number. Make the pull requests against <a href="https://github.com/tuupola/jquery_lazyload/commits/1.9.x">1.9.x branch</a>.</p>
|
||||
<h2 id="Write-meaningful-commit-messages"><a href="#Write-meaningful-commit-messages" class="headerlink" title="Write meaningful commit messages"></a>Write meaningful commit messages</h2><p>Proper commit message is full sentence. It starts with capital letter but does not end with period. Headlines do not end with period. The GitHub default <code>Update filename.js</code> is not enough. When needed include also longer explanation what the commit does.</p>
|
||||
<pre><code>Capitalized, short (50 chars or less) summary
|
||||
|
||||
More detailed explanatory text, if necessary. Wrap it to about 72
|
||||
characters or so. In some contexts, the first line is treated as the
|
||||
subject of an email and the rest of the text as the body. The blank
|
||||
line separating the summary from the body is critical (unless you omit
|
||||
the body entirely); tools like rebase can get confused if you run the
|
||||
two together.
|
||||
</code></pre><p>When in doubt see Tim Pope’s blogpost <a href="http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html">A Note About Git Commit Messages</a></p>
|
||||
<h2 id="Follow-the-existing-coding-standards"><a href="#Follow-the-existing-coding-standards" class="headerlink" title="Follow the existing coding standards"></a>Follow the existing coding standards</h2><p>When contributing to open source project it is polite to follow the original authors coding standars. They might be different than yours. It is not a holy war. Just follow then original.</p>
|
||||
<pre><code class="javascript"><span class="keyword">var</span> snake_case = <span class="string">"something"</span>;
|
||||
|
||||
<span class="function"><span class="keyword">function</span> <span class="title">camelCase</span>(<span class="params">options</span>) </span>{
|
||||
}
|
||||
|
||||
<span class="keyword">if</span> (<span class="literal">true</span> !== <span class="literal">false</span>) {
|
||||
<span class="built_in">console</span>.log(<span class="string">"here be dragons"</span>);
|
||||
}
|
||||
</code></pre>
|
20
lib/jquery_lazyload/README.html
Normal file
20
lib/jquery_lazyload/README.html
Normal file
@ -0,0 +1,20 @@
|
||||
<h1 id="Lazy-Load-Plugin-for-jQuery"><a href="#Lazy-Load-Plugin-for-jQuery" class="headerlink" title="Lazy Load Plugin for jQuery"></a>Lazy Load Plugin for jQuery</h1><p>Lazy Load delays loading of images in long web pages. Images outside of viewport wont be loaded before user scrolls to them. This is opposite of image preloading.</p>
|
||||
<p>Using Lazy Load on long web pages containing many large images makes the page load faster. Browser will be in ready state after loading visible images. In some cases it can also help to reduce server load.</p>
|
||||
<p>Lazy Load is inspired by <a href="http://developer.yahoo.com/yui/imageloader/">YUI ImageLoader</a> Utility by Matt Mlinac.</p>
|
||||
<h2 id="How-to-Use"><a href="#How-to-Use" class="headerlink" title="How to Use?"></a>How to Use?</h2><p>Lazy Load depends on jQuery. Include them both in end of your HTML code:</p>
|
||||
<pre><code class="html"><span class="tag"><<span class="name">script</span> <span class="attr">src</span>=<span class="string">"jquery.js"</span> <span class="attr">type</span>=<span class="string">"text/javascript"</span>></span><span class="undefined"></span><span class="tag"></<span class="name">script</span>></span>
|
||||
<span class="tag"><<span class="name">script</span> <span class="attr">src</span>=<span class="string">"jquery.lazyload.js"</span> <span class="attr">type</span>=<span class="string">"text/javascript"</span>></span><span class="undefined"></span><span class="tag"></<span class="name">script</span>></span>
|
||||
</code></pre>
|
||||
<p>You must alter your HTML code. URL of the real image must be put into data-original attribute. It is good idea to give Lazy Loaded image a specific class. This way you can easily control which images plugin is binded to. Note that you should have width and height attributes in your image tag.</p>
|
||||
<pre><code class="html"><span class="tag"><<span class="name">img</span> <span class="attr">class</span>=<span class="string">"lazy"</span> <span class="attr">data-original</span>=<span class="string">"img/example.jpg"</span> <span class="attr">width</span>=<span class="string">"640"</span> <span class="attr">height</span>=<span class="string">"480"</span>></span>
|
||||
</code></pre>
|
||||
<p>then in your code do:</p>
|
||||
<pre><code class="js">$(<span class="string">"img.lazy"</span>).lazyload();
|
||||
</code></pre>
|
||||
<p>This causes all images of class lazy to be lazy loaded.</p>
|
||||
<p>More information on <a href="http://www.appelsiini.net/projects/lazyload">Lazy Load</a> project page.</p>
|
||||
<h2 id="Install"><a href="#Install" class="headerlink" title="Install"></a>Install</h2><p>You can install with <a href="http://bower.io/">bower</a> or <a href="https://www.npmjs.com/">npm</a>.</p>
|
||||
<pre><code class="sh">$ bower install jquery.lazyload
|
||||
$ npm install jquery-lazyload
|
||||
</code></pre>
|
||||
<h1 id="License"><a href="#License" class="headerlink" title="License"></a>License</h1><p>All code licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT License</a>. All images licensed under <a href="http://creativecommons.org/licenses/by/3.0/deed.en_US">Creative Commons Attribution 3.0 Unported License</a>. In other words you are basically free to do whatever you want. Just don’t remove my name from the source.</p>
|
1
lib/jquery_lazyload/bower.json
Normal file
1
lib/jquery_lazyload/bower.json
Normal file
@ -0,0 +1 @@
|
||||
{"name":"jquery_lazyload","version":"1.9.4","homepage":"http://www.appelsiini.net/projects/lazyload","authors":["Mika Tuupola <tuupola@appelsiini.net>"],"description":"jQuery plugin for lazy loading images","main":["jquery.lazyload.js","jquery.scrollstop.js"],"license":"MIT","ignore":["**/.*","**/*.min.js","**/*.html","**/*.textile","Gruntfile.js","lazyload.jquery.json","package.json","node_modules","bower_components","test","img"]}
|
242
lib/jquery_lazyload/jquery.lazyload.js
Normal file
242
lib/jquery_lazyload/jquery.lazyload.js
Normal file
@ -0,0 +1,242 @@
|
||||
/*!
|
||||
* Lazy Load - jQuery plugin for lazy loading images
|
||||
*
|
||||
* Copyright (c) 2007-2015 Mika Tuupola
|
||||
*
|
||||
* Licensed under the MIT license:
|
||||
* http://www.opensource.org/licenses/mit-license.php
|
||||
*
|
||||
* Project home:
|
||||
* http://www.appelsiini.net/projects/lazyload
|
||||
*
|
||||
* Version: 1.9.7
|
||||
*
|
||||
*/
|
||||
|
||||
(function($, window, document, undefined) {
|
||||
var $window = $(window);
|
||||
|
||||
$.fn.lazyload = function(options) {
|
||||
var elements = this;
|
||||
var $container;
|
||||
var settings = {
|
||||
threshold : 0,
|
||||
failure_limit : 0,
|
||||
event : "scroll",
|
||||
effect : "show",
|
||||
container : window,
|
||||
data_attribute : "original",
|
||||
skip_invisible : false,
|
||||
appear : null,
|
||||
load : null,
|
||||
placeholder : "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC"
|
||||
};
|
||||
|
||||
function update() {
|
||||
var counter = 0;
|
||||
|
||||
elements.each(function() {
|
||||
var $this = $(this);
|
||||
if (settings.skip_invisible && !$this.is(":visible")) {
|
||||
return;
|
||||
}
|
||||
if ($.abovethetop(this, settings) ||
|
||||
$.leftofbegin(this, settings)) {
|
||||
/* Nothing. */
|
||||
} else if (!$.belowthefold(this, settings) &&
|
||||
!$.rightoffold(this, settings)) {
|
||||
$this.trigger("appear");
|
||||
/* if we found an image we'll load, reset the counter */
|
||||
counter = 0;
|
||||
} else {
|
||||
if (++counter > settings.failure_limit) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
if(options) {
|
||||
/* Maintain BC for a couple of versions. */
|
||||
if (undefined !== options.failurelimit) {
|
||||
options.failure_limit = options.failurelimit;
|
||||
delete options.failurelimit;
|
||||
}
|
||||
if (undefined !== options.effectspeed) {
|
||||
options.effect_speed = options.effectspeed;
|
||||
delete options.effectspeed;
|
||||
}
|
||||
|
||||
$.extend(settings, options);
|
||||
}
|
||||
|
||||
/* Cache container as jQuery as object. */
|
||||
$container = (settings.container === undefined ||
|
||||
settings.container === window) ? $window : $(settings.container);
|
||||
|
||||
/* Fire one scroll event per scroll. Not one scroll event per image. */
|
||||
if (0 === settings.event.indexOf("scroll")) {
|
||||
$container.bind(settings.event, function() {
|
||||
return update();
|
||||
});
|
||||
}
|
||||
|
||||
this.each(function() {
|
||||
var self = this;
|
||||
var $self = $(self);
|
||||
|
||||
self.loaded = false;
|
||||
|
||||
/* If no src attribute given use data:uri. */
|
||||
if ($self.attr("src") === undefined || $self.attr("src") === false) {
|
||||
if ($self.is("img")) {
|
||||
$self.attr("src", settings.placeholder);
|
||||
}
|
||||
}
|
||||
|
||||
/* When appear is triggered load original image. */
|
||||
$self.one("appear", function() {
|
||||
if (!this.loaded) {
|
||||
if (settings.appear) {
|
||||
var elements_left = elements.length;
|
||||
settings.appear.call(self, elements_left, settings);
|
||||
}
|
||||
$("<img />")
|
||||
.bind("load", function() {
|
||||
|
||||
var original = $self.attr("data-" + settings.data_attribute);
|
||||
$self.hide();
|
||||
if ($self.is("img")) {
|
||||
$self.attr("src", original);
|
||||
} else {
|
||||
$self.css("background-image", "url('" + original + "')");
|
||||
}
|
||||
$self[settings.effect](settings.effect_speed);
|
||||
|
||||
self.loaded = true;
|
||||
|
||||
/* Remove image from array so it is not looped next time. */
|
||||
var temp = $.grep(elements, function(element) {
|
||||
return !element.loaded;
|
||||
});
|
||||
elements = $(temp);
|
||||
|
||||
if (settings.load) {
|
||||
var elements_left = elements.length;
|
||||
settings.load.call(self, elements_left, settings);
|
||||
}
|
||||
})
|
||||
.attr("src", $self.attr("data-" + settings.data_attribute));
|
||||
}
|
||||
});
|
||||
|
||||
/* When wanted event is triggered load original image */
|
||||
/* by triggering appear. */
|
||||
if (0 !== settings.event.indexOf("scroll")) {
|
||||
$self.bind(settings.event, function() {
|
||||
if (!self.loaded) {
|
||||
$self.trigger("appear");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/* Check if something appears when window is resized. */
|
||||
$window.bind("resize", function() {
|
||||
update();
|
||||
});
|
||||
|
||||
/* With IOS5 force loading images when navigating with back button. */
|
||||
/* Non optimal workaround. */
|
||||
if ((/(?:iphone|ipod|ipad).*os 5/gi).test(navigator.appVersion)) {
|
||||
$window.bind("pageshow", function(event) {
|
||||
if (event.originalEvent && event.originalEvent.persisted) {
|
||||
elements.each(function() {
|
||||
$(this).trigger("appear");
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* Force initial check if images should appear. */
|
||||
$(document).ready(function() {
|
||||
update();
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/* Convenience methods in jQuery namespace. */
|
||||
/* Use as $.belowthefold(element, {threshold : 100, container : window}) */
|
||||
|
||||
$.belowthefold = function(element, settings) {
|
||||
var fold;
|
||||
|
||||
if (settings.container === undefined || settings.container === window) {
|
||||
fold = (window.innerHeight ? window.innerHeight : $window.height()) + $window.scrollTop();
|
||||
} else {
|
||||
fold = $(settings.container).offset().top + $(settings.container).height();
|
||||
}
|
||||
|
||||
return fold <= $(element).offset().top - settings.threshold;
|
||||
};
|
||||
|
||||
$.rightoffold = function(element, settings) {
|
||||
var fold;
|
||||
|
||||
if (settings.container === undefined || settings.container === window) {
|
||||
fold = $window.width() + $window.scrollLeft();
|
||||
} else {
|
||||
fold = $(settings.container).offset().left + $(settings.container).width();
|
||||
}
|
||||
|
||||
return fold <= $(element).offset().left - settings.threshold;
|
||||
};
|
||||
|
||||
$.abovethetop = function(element, settings) {
|
||||
var fold;
|
||||
|
||||
if (settings.container === undefined || settings.container === window) {
|
||||
fold = $window.scrollTop();
|
||||
} else {
|
||||
fold = $(settings.container).offset().top;
|
||||
}
|
||||
|
||||
return fold >= $(element).offset().top + settings.threshold + $(element).height();
|
||||
};
|
||||
|
||||
$.leftofbegin = function(element, settings) {
|
||||
var fold;
|
||||
|
||||
if (settings.container === undefined || settings.container === window) {
|
||||
fold = $window.scrollLeft();
|
||||
} else {
|
||||
fold = $(settings.container).offset().left;
|
||||
}
|
||||
|
||||
return fold >= $(element).offset().left + settings.threshold + $(element).width();
|
||||
};
|
||||
|
||||
$.inviewport = function(element, settings) {
|
||||
return !$.rightoffold(element, settings) && !$.leftofbegin(element, settings) &&
|
||||
!$.belowthefold(element, settings) && !$.abovethetop(element, settings);
|
||||
};
|
||||
|
||||
/* Custom selectors for your convenience. */
|
||||
/* Use as $("img:below-the-fold").something() or */
|
||||
/* $("img").filter(":below-the-fold").something() which is faster */
|
||||
|
||||
$.extend($.expr[":"], {
|
||||
"below-the-fold" : function(a) { return $.belowthefold(a, {threshold : 0}); },
|
||||
"above-the-top" : function(a) { return !$.belowthefold(a, {threshold : 0}); },
|
||||
"right-of-screen": function(a) { return $.rightoffold(a, {threshold : 0}); },
|
||||
"left-of-screen" : function(a) { return !$.rightoffold(a, {threshold : 0}); },
|
||||
"in-viewport" : function(a) { return $.inviewport(a, {threshold : 0}); },
|
||||
/* Maintain BC for couple of versions. */
|
||||
"above-the-fold" : function(a) { return !$.belowthefold(a, {threshold : 0}); },
|
||||
"right-of-fold" : function(a) { return $.rightoffold(a, {threshold : 0}); },
|
||||
"left-of-fold" : function(a) { return !$.rightoffold(a, {threshold : 0}); }
|
||||
});
|
||||
|
||||
})(jQuery, window, document);
|
72
lib/jquery_lazyload/jquery.scrollstop.js
Normal file
72
lib/jquery_lazyload/jquery.scrollstop.js
Normal file
@ -0,0 +1,72 @@
|
||||
/* http://james.padolsey.com/javascript/special-scroll-events-for-jquery/ */
|
||||
|
||||
(function(){
|
||||
|
||||
var special = jQuery.event.special,
|
||||
uid1 = "D" + (+new Date()),
|
||||
uid2 = "D" + (+new Date() + 1);
|
||||
|
||||
special.scrollstart = {
|
||||
setup: function() {
|
||||
|
||||
var timer,
|
||||
handler = function(evt) {
|
||||
|
||||
var _self = this,
|
||||
_args = arguments;
|
||||
|
||||
if (timer) {
|
||||
clearTimeout(timer);
|
||||
} else {
|
||||
evt.type = "scrollstart";
|
||||
jQuery.event.dispatch.apply(_self, _args);
|
||||
}
|
||||
|
||||
timer = setTimeout( function(){
|
||||
timer = null;
|
||||
}, special.scrollstop.latency);
|
||||
|
||||
};
|
||||
|
||||
jQuery(this).bind("scroll", handler).data(uid1, handler);
|
||||
|
||||
},
|
||||
teardown: function(){
|
||||
jQuery(this).unbind( "scroll", jQuery(this).data(uid1) );
|
||||
}
|
||||
};
|
||||
|
||||
special.scrollstop = {
|
||||
latency: 300,
|
||||
setup: function() {
|
||||
|
||||
var timer,
|
||||
handler = function(evt) {
|
||||
|
||||
var _self = this,
|
||||
_args = arguments;
|
||||
|
||||
if (timer) {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
|
||||
timer = setTimeout( function(){
|
||||
|
||||
timer = null;
|
||||
evt.type = "scrollstop";
|
||||
jQuery.event.dispatch.apply(_self, _args);
|
||||
|
||||
|
||||
}, special.scrollstop.latency);
|
||||
|
||||
};
|
||||
|
||||
jQuery(this).bind("scroll", handler).data(uid2, handler);
|
||||
|
||||
},
|
||||
teardown: function() {
|
||||
jQuery(this).unbind( "scroll", jQuery(this).data(uid2) );
|
||||
}
|
||||
};
|
||||
|
||||
})();
|
Reference in New Issue
Block a user