tablesorter/dist/js/widgets/widget-lazyload.min.js
2015-10-31 11:06:09 -05:00

73 lines
7.6 KiB
JavaScript

/*! Widget: lazyload (BETA) - 10/31/2015 (v2.24.0) */
/*
* Requires tablesorter v2.8+ and jQuery 1.7+
* by Rob Garrison
*/
/*jshint browser:true, jquery:true, unused:false */
!function(a,b){"use strict";var c=a.tablesorter;c.lazyload={init:function(b,d){"scrollstop"!==d.lazyload_event||c.addScrollStopDone||(c.addScrollStop(),c.addScrollStopDone=!0,a.event.special.scrollstop.latency=d.lazyload_latency||250),c.lazyload.update(b,d);var e=[d.lazyload_update,"pagerUpdate",d.columnSelector_updated||"columnUpdate",""].join(b.namespace+"lazyload ");b.$table.on(e,function(){c.lazyload.update(b,b.widgetOptions)})},update:function(a,b){
// add '.' if not already included
var c=(/(\.|#)/.test(b.lazyload_imageClass)?"":".")+b.lazyload_imageClass;a.$table.find(c).lazyload({threshold:b.lazyload_threshold,failure_limit:b.lazyload_failure_limit,event:b.lazyload_event,effect:b.lazyload_effect,container:b.lazyload_container,data_attribute:b.lazyload_data_attribute,skip_invisible:b.lazyload_skip_invisible,appear:b.lazyload_appear,load:b.lazyload_load,placeholder:b.lazyload_placeholder})},remove:function(a,b){a.$table.off(a.namespace+"lazyload")}},c.addWidget({id:"lazyload",options:{
// widget options
lazyload_imageClass:"lazy",lazyload_update:"lazyloadUpdate",
// scrollStop option (https://github.com/ssorallen/jquery-scrollstop)
lazyload_latency:250,
// lazyload options (see http://www.appelsiini.net/projects/lazyload)
lazyload_threshold:0,lazyload_failure_limit:0,lazyload_event:"scrollstop",lazyload_effect:"show",lazyload_container:b,lazyload_data_attribute:"original",lazyload_skip_invisible:!1,lazyload_appear:null,lazyload_load:null,lazyload_placeholder:"data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="},init:function(a,b,d,e){c.lazyload.init(d,e)},remove:function(a,b,d){c.lazyload.remove(b,d)}}),
// jscs:disable
c.addScrollStop=function(){
// jQuery Scrollstop Plugin v1.2.0
// https://github.com/ssorallen/jquery-scrollstop
/*
(function (factory) {
// UMD[2] wrapper for jQuery plugins to work in AMD or in CommonJS.
//
// [2] https://github.com/umdjs/umd
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else if (typeof exports === 'object') {
// Node/CommonJS
module.exports = factory(require('jquery'));
} else {
// Browser globals
factory(jQuery);
}
}(function ($) { */
// $.event.dispatch was undocumented and was deprecated in jQuery 1.7[1]. It
// was replaced by $.event.handle in jQuery 1.9.
//
// Use the first of the available functions to support jQuery <1.8.
//
// [1] https://github.com/jquery/jquery-migrate/blob/master/src/event.js#L25
var b=a.event.dispatch||a.event.handle,c=a.event.special,d="D"+ +new Date,e="D"+(+new Date+1);c.scrollstart={setup:function(e){var f,g=a.extend({latency:c.scrollstop.latency},e),h=function(a){var c=this,d=arguments;f?clearTimeout(f):(a.type="scrollstart",b.apply(c,d)),f=setTimeout(function(){f=null},g.latency)};a(this).bind("scroll",h).data(d,h)},teardown:function(){a(this).unbind("scroll",a(this).data(d))}},c.scrollstop={latency:250,setup:function(d){var f,g=a.extend({latency:c.scrollstop.latency},d),h=function(a){var c=this,d=arguments;f&&clearTimeout(f),f=setTimeout(function(){f=null,a.type="scrollstop",b.apply(c,d)},g.latency)};a(this).bind("scroll",h).data(e,h)},teardown:function(){a(this).unbind("scroll",a(this).data(e))}}}}(jQuery,window),
// jscs:disable
/*!
* 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(a,b,c,d){var e=a(b);a.fn.lazyload=function(f){function g(){var b=0;i.each(function(){var c=a(this);if(!j.skip_invisible||c.is(":visible"))if(a.abovethetop(this,j)||a.leftofbegin(this,j));else if(a.belowthefold(this,j)||a.rightoffold(this,j)){if(++b>j.failure_limit)return!1}else c.trigger("appear"),/* if we found an image we'll load, reset the counter */
b=0})}var h,i=this,j={threshold:0,failure_limit:0,event:"scroll",effect:"show",container:b,data_attribute:"original",skip_invisible:!1,appear:null,load:null,placeholder:"data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="};/* Maintain BC for a couple of versions. */
/* Cache container as jQuery as object. */
/* Fire one scroll event per scroll. Not one scroll event per image. */
/* Check if something appears when window is resized. */
/* With IOS5 force loading images when navigating with back button. */
/* Non optimal workaround. */
/* Force initial check if images should appear. */
return f&&(d!==f.failurelimit&&(f.failure_limit=f.failurelimit,delete f.failurelimit),d!==f.effectspeed&&(f.effect_speed=f.effectspeed,delete f.effectspeed),a.extend(j,f)),h=j.container===d||j.container===b?e:a(j.container),0===j.event.indexOf("scroll")&&h.bind(j.event,function(){return g()}),this.each(function(){var b=this,c=a(b);b.loaded=!1,(c.attr("src")===d||c.attr("src")===!1)&&c.is("img")&&c.attr("src",j.placeholder),c.one("appear",function(){if(!this.loaded){if(j.appear){var d=i.length;j.appear.call(b,d,j)}a("<img />").bind("load",function(){var d=c.attr("data-"+j.data_attribute);c.hide(),c.is("img")?c.attr("src",d):c.css("background-image","url('"+d+"')"),c[j.effect](j.effect_speed),b.loaded=!0;var e=a.grep(i,function(a){return!a.loaded});if(i=a(e),j.load){var f=i.length;j.load.call(b,f,j)}}).attr("src",c.attr("data-"+j.data_attribute))}}),0!==j.event.indexOf("scroll")&&c.bind(j.event,function(){b.loaded||c.trigger("appear")})}),e.bind("resize",function(){g()}),/(?:iphone|ipod|ipad).*os 5/gi.test(navigator.appVersion)&&e.bind("pageshow",function(b){b.originalEvent&&b.originalEvent.persisted&&i.each(function(){a(this).trigger("appear")})}),a(c).ready(function(){g()}),this},/* Convenience methods in jQuery namespace. */
/* Use as $.belowthefold(element, {threshold : 100, container : window}) */
a.belowthefold=function(c,f){var g;return g=f.container===d||f.container===b?(b.innerHeight?b.innerHeight:e.height())+e.scrollTop():a(f.container).offset().top+a(f.container).height(),g<=a(c).offset().top-f.threshold},a.rightoffold=function(c,f){var g;return g=f.container===d||f.container===b?e.width()+e.scrollLeft():a(f.container).offset().left+a(f.container).width(),g<=a(c).offset().left-f.threshold},a.abovethetop=function(c,f){var g;return g=f.container===d||f.container===b?e.scrollTop():a(f.container).offset().top,g>=a(c).offset().top+f.threshold+a(c).height()},a.leftofbegin=function(c,f){var g;return g=f.container===d||f.container===b?e.scrollLeft():a(f.container).offset().left,g>=a(c).offset().left+f.threshold+a(c).width()},a.inviewport=function(b,c){return!(a.rightoffold(b,c)||a.leftofbegin(b,c)||a.belowthefold(b,c)||a.abovethetop(b,c))},/* Custom selectors for your convenience. */
/* Use as $("img:below-the-fold").something() or */
/* $("img").filter(":below-the-fold").something() which is faster */
a.extend(a.expr[":"],{"below-the-fold":function(b){return a.belowthefold(b,{threshold:0})},"above-the-top":function(b){return!a.belowthefold(b,{threshold:0})},"right-of-screen":function(b){return a.rightoffold(b,{threshold:0})},"left-of-screen":function(b){return!a.rightoffold(b,{threshold:0})},"in-viewport":function(b){return a.inviewport(b,{threshold:0})},/* Maintain BC for couple of versions. */
"above-the-fold":function(b){return!a.belowthefold(b,{threshold:0})},"right-of-fold":function(b){return a.rightoffold(b,{threshold:0})},"left-of-fold":function(b){return!a.rightoffold(b,{threshold:0})}})}(jQuery,window,document);