| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
;( function( $, window ) { |
| 7 |
'use strict'; |
| 8 |
var ts = $.tablesorter; |
| 9 |
|
| 10 |
ts.lazyload = { |
| 11 |
init : function( c, wo ) { |
| 12 |
if ( wo.lazyload_event === 'scrollstop' && !ts.addScrollStopDone ) { |
| 13 |
ts.addScrollStop(); |
| 14 |
ts.addScrollStopDone = true; |
| 15 |
$.event.special.scrollstop.latency = wo.lazyload_latency || 250; |
| 16 |
} |
| 17 |
ts.lazyload.update( c, wo ); |
| 18 |
var namespace = c.namespace + 'lazyload ', |
| 19 |
events = [ |
| 20 |
wo.lazyload_update, |
| 21 |
'pagerUpdate', |
| 22 |
wo.columnSelector_updated || 'columnUpdate', |
| 23 |
'' |
| 24 |
].join( namespace ); |
| 25 |
c.$table |
| 26 |
.on( events, function() { |
| 27 |
ts.lazyload.update( c, c.widgetOptions ); |
| 28 |
}) |
| 29 |
.on( 'filterEnd' + namespace, function() { |
| 30 |
|
| 31 |
$(window).scroll(); |
| 32 |
}); |
| 33 |
}, |
| 34 |
update : function( c, wo ) { |
| 35 |
|
| 36 |
var sel = ( /(\.|#)/.test( wo.lazyload_imageClass ) ? '' : '.' ) + wo.lazyload_imageClass; |
| 37 |
c.$table.find( sel ).lazyload({ |
| 38 |
threshold : wo.lazyload_threshold, |
| 39 |
failure_limit : wo.lazyload_failure_limit, |
| 40 |
event : wo.lazyload_event, |
| 41 |
effect : wo.lazyload_effect, |
| 42 |
container : wo.lazyload_container, |
| 43 |
data_attribute : wo.lazyload_data_attribute, |
| 44 |
skip_invisible : wo.lazyload_skip_invisible, |
| 45 |
appear : wo.lazyload_appear, |
| 46 |
load : wo.lazyload_load, |
| 47 |
placeholder : wo.lazyload_placeholder |
| 48 |
}); |
| 49 |
|
| 50 |
setTimeout(function() { |
| 51 |
$(window).scroll(); |
| 52 |
}, 1); |
| 53 |
}, |
| 54 |
remove : function( c ) { |
| 55 |
c.$table.off( c.namespace + 'lazyload' ); |
| 56 |
} |
| 57 |
}; |
| 58 |
|
| 59 |
ts.addWidget({ |
| 60 |
id: 'lazyload', |
| 61 |
options: { |
| 62 |
|
| 63 |
lazyload_imageClass : 'lazy', |
| 64 |
lazyload_update : 'lazyloadUpdate', |
| 65 |
|
| 66 |
lazyload_latency : 250, |
| 67 |
|
| 68 |
lazyload_threshold : 0, |
| 69 |
lazyload_failure_limit : 0, |
| 70 |
lazyload_event : 'scrollstop', |
| 71 |
lazyload_effect : 'show', |
| 72 |
lazyload_container : window, |
| 73 |
lazyload_data_attribute : 'original', |
| 74 |
lazyload_skip_invisible : true, |
| 75 |
lazyload_appear : null, |
| 76 |
lazyload_load : null, |
| 77 |
lazyload_placeholder : 'data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==' |
| 78 |
}, |
| 79 |
init: function( table, thisWidget, c, wo ) { |
| 80 |
ts.lazyload.init( c, wo ); |
| 81 |
}, |
| 82 |
remove : function( table, c, wo ) { |
| 83 |
ts.lazyload.remove( c, wo ); |
| 84 |
} |
| 85 |
}); |
| 86 |
|
| 87 |
|
| 88 |
ts.addScrollStop = function() { |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
var dispatch = $.event.dispatch || $.event.handle; |
| 115 |
|
| 116 |
var special = $.event.special, |
| 117 |
uid1 = 'D' + (+new Date()), |
| 118 |
uid2 = 'D' + (+new Date() + 1); |
| 119 |
|
| 120 |
special.scrollstart = { |
| 121 |
setup: function(data) { |
| 122 |
var _data = $.extend({ |
| 123 |
latency: special.scrollstop.latency |
| 124 |
}, data); |
| 125 |
|
| 126 |
var timer, |
| 127 |
handler = function(evt) { |
| 128 |
var _self = this, |
| 129 |
_args = arguments; |
| 130 |
if (timer) { |
| 131 |
clearTimeout(timer); |
| 132 |
} else { |
| 133 |
evt.type = 'scrollstart'; |
| 134 |
dispatch.apply(_self, _args); |
| 135 |
} |
| 136 |
timer = setTimeout(function() { |
| 137 |
timer = null; |
| 138 |
}, _data.latency); |
| 139 |
}; |
| 140 |
$(this).bind('scroll', handler).data(uid1, handler); |
| 141 |
}, |
| 142 |
teardown: function() { |
| 143 |
$(this).unbind('scroll', $(this).data(uid1)); |
| 144 |
} |
| 145 |
}; |
| 146 |
special.scrollstop = { |
| 147 |
latency: 250, |
| 148 |
setup: function(data) { |
| 149 |
var _data = $.extend({ |
| 150 |
latency: special.scrollstop.latency |
| 151 |
}, data); |
| 152 |
var timer, |
| 153 |
handler = function(evt) { |
| 154 |
var _self = this, |
| 155 |
_args = arguments; |
| 156 |
if (timer) { |
| 157 |
clearTimeout(timer); |
| 158 |
} |
| 159 |
timer = setTimeout(function() { |
| 160 |
timer = null; |
| 161 |
evt.type = 'scrollstop'; |
| 162 |
dispatch.apply(_self, _args); |
| 163 |
}, _data.latency); |
| 164 |
}; |
| 165 |
$(this).bind('scroll', handler).data(uid2, handler); |
| 166 |
}, |
| 167 |
teardown: function() { |
| 168 |
$(this).unbind('scroll', $(this).data(uid2)); |
| 169 |
} |
| 170 |
}; |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
}; |
| 176 |
|
| 177 |
|
| 178 |
})( jQuery, window ); |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
(function($, window, document, undefined) { |
| 196 |
var $window = $(window); |
| 197 |
$.fn.lazyload = function(options) { |
| 198 |
var elements = this; |
| 199 |
var $container; |
| 200 |
var settings = { |
| 201 |
threshold : 0, |
| 202 |
failure_limit : 0, |
| 203 |
event : 'scroll', |
| 204 |
effect : 'show', |
| 205 |
container : window, |
| 206 |
data_attribute : 'original', |
| 207 |
skip_invisible : false, |
| 208 |
appear : null, |
| 209 |
load : null, |
| 210 |
placeholder : 'data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==' |
| 211 |
}; |
| 212 |
function update() { |
| 213 |
var counter = 0; |
| 214 |
elements.each(function() { |
| 215 |
var $this = $(this); |
| 216 |
if (settings.skip_invisible && !$this.is(':visible')) { |
| 217 |
return; |
| 218 |
} |
| 219 |
if ($.abovethetop(this, settings) || $.leftofbegin(this, settings)) { |
| 220 |
|
| 221 |
} else if (!$.belowthefold(this, settings) && !$.rightoffold(this, settings)) { |
| 222 |
$this.trigger('appear'); |
| 223 |
|
| 224 |
counter = 0; |
| 225 |
} else { |
| 226 |
if (++counter > settings.failure_limit) { |
| 227 |
return false; |
| 228 |
} |
| 229 |
} |
| 230 |
}); |
| 231 |
} |
| 232 |
if (options) { |
| 233 |
|
| 234 |
if (undefined !== options.failurelimit) { |
| 235 |
options.failure_limit = options.failurelimit; |
| 236 |
delete options.failurelimit; |
| 237 |
} |
| 238 |
if (undefined !== options.effectspeed) { |
| 239 |
options.effect_speed = options.effectspeed; |
| 240 |
delete options.effectspeed; |
| 241 |
} |
| 242 |
$.extend(settings, options); |
| 243 |
} |
| 244 |
|
| 245 |
$container = (settings.container === undefined || |
| 246 |
settings.container === window) ? $window : $(settings.container); |
| 247 |
|
| 248 |
if (0 === settings.event.indexOf('scroll')) { |
| 249 |
$container.bind(settings.event, function() { |
| 250 |
return update(); |
| 251 |
}); |
| 252 |
} |
| 253 |
this.each(function() { |
| 254 |
var self = this; |
| 255 |
var $self = $(self); |
| 256 |
self.loaded = false; |
| 257 |
|
| 258 |
if ($self.attr('src') === undefined || $self.attr('src') === false) { |
| 259 |
if ($self.is('img')) { |
| 260 |
$self.attr('src', settings.placeholder); |
| 261 |
} |
| 262 |
} |
| 263 |
|
| 264 |
$self.one('appear', function() { |
| 265 |
if (!this.loaded) { |
| 266 |
if (settings.appear) { |
| 267 |
var elements_left = elements.length; |
| 268 |
settings.appear.call(self, elements_left, settings); |
| 269 |
} |
| 270 |
$('<img />') |
| 271 |
.bind('load', function() { |
| 272 |
var original = $self.attr('data-' + settings.data_attribute); |
| 273 |
$self.hide(); |
| 274 |
if ($self.is('img')) { |
| 275 |
$self.attr('src', original); |
| 276 |
} else { |
| 277 |
$self.css('background-image', 'url("' + original + '")'); |
| 278 |
} |
| 279 |
$self[settings.effect](settings.effect_speed); |
| 280 |
self.loaded = true; |
| 281 |
|
| 282 |
var temp = $.grep(elements, function(element) { |
| 283 |
return !element.loaded; |
| 284 |
}); |
| 285 |
elements = $(temp); |
| 286 |
if (settings.load) { |
| 287 |
var elements_left = elements.length; |
| 288 |
settings.load.call(self, elements_left, settings); |
| 289 |
} |
| 290 |
}) |
| 291 |
.attr('src', $self.attr('data-' + settings.data_attribute)); |
| 292 |
} |
| 293 |
}); |
| 294 |
|
| 295 |
|
| 296 |
if (0 !== settings.event.indexOf('scroll')) { |
| 297 |
$self.bind(settings.event, function() { |
| 298 |
if (!self.loaded) { |
| 299 |
$self.trigger('appear'); |
| 300 |
} |
| 301 |
}); |
| 302 |
} |
| 303 |
}); |
| 304 |
|
| 305 |
$window.bind('resize', function() { |
| 306 |
update(); |
| 307 |
}); |
| 308 |
|
| 309 |
|
| 310 |
if ((/(?:iphone|ipod|ipad).*os 5/gi).test(navigator.appVersion)) { |
| 311 |
$window.bind('pageshow', function(event) { |
| 312 |
if (event.originalEvent && event.originalEvent.persisted) { |
| 313 |
elements.each(function() { |
| 314 |
$(this).trigger('appear'); |
| 315 |
}); |
| 316 |
} |
| 317 |
}); |
| 318 |
} |
| 319 |
|
| 320 |
$(document).ready(function() { |
| 321 |
update(); |
| 322 |
}); |
| 323 |
return this; |
| 324 |
}; |
| 325 |
|
| 326 |
|
| 327 |
$.belowthefold = function(element, settings) { |
| 328 |
var fold; |
| 329 |
if (settings.container === undefined || settings.container === window) { |
| 330 |
fold = (window.innerHeight ? window.innerHeight : $window.height()) + $window.scrollTop(); |
| 331 |
} else { |
| 332 |
fold = $(settings.container).offset().top + $(settings.container).height(); |
| 333 |
} |
| 334 |
return fold <= $(element).offset().top - settings.threshold; |
| 335 |
}; |
| 336 |
$.rightoffold = function(element, settings) { |
| 337 |
var fold; |
| 338 |
if (settings.container === undefined || settings.container === window) { |
| 339 |
fold = $window.width() + $window.scrollLeft(); |
| 340 |
} else { |
| 341 |
fold = $(settings.container).offset().left + $(settings.container).width(); |
| 342 |
} |
| 343 |
return fold <= $(element).offset().left - settings.threshold; |
| 344 |
}; |
| 345 |
$.abovethetop = function(element, settings) { |
| 346 |
var fold; |
| 347 |
if (settings.container === undefined || settings.container === window) { |
| 348 |
fold = $window.scrollTop(); |
| 349 |
} else { |
| 350 |
fold = $(settings.container).offset().top; |
| 351 |
} |
| 352 |
return fold >= $(element).offset().top + settings.threshold + $(element).height(); |
| 353 |
}; |
| 354 |
$.leftofbegin = function(element, settings) { |
| 355 |
var fold; |
| 356 |
if (settings.container === undefined || settings.container === window) { |
| 357 |
fold = $window.scrollLeft(); |
| 358 |
} else { |
| 359 |
fold = $(settings.container).offset().left; |
| 360 |
} |
| 361 |
return fold >= $(element).offset().left + settings.threshold + $(element).width(); |
| 362 |
}; |
| 363 |
$.inviewport = function(element, settings) { |
| 364 |
return !$.rightoffold(element, settings) && !$.leftofbegin(element, settings) && |
| 365 |
!$.belowthefold(element, settings) && !$.abovethetop(element, settings); |
| 366 |
}; |
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
$.extend($.expr[':'], { |
| 371 |
'below-the-fold' : function(a) { return $.belowthefold(a, {threshold : 0}); }, |
| 372 |
'above-the-top' : function(a) { return !$.belowthefold(a, {threshold : 0}); }, |
| 373 |
'right-of-screen': function(a) { return $.rightoffold(a, {threshold : 0}); }, |
| 374 |
'left-of-screen' : function(a) { return !$.rightoffold(a, {threshold : 0}); }, |
| 375 |
'in-viewport' : function(a) { return $.inviewport(a, {threshold : 0}); }, |
| 376 |
|
| 377 |
'above-the-fold' : function(a) { return !$.belowthefold(a, {threshold : 0}); }, |
| 378 |
'right-of-fold' : function(a) { return $.rightoffold(a, {threshold : 0}); }, |
| 379 |
'left-of-fold' : function(a) { return !$.rightoffold(a, {threshold : 0}); } |
| 380 |
}); |
| 381 |
})(jQuery, window, document); |