PageSourceSearch

https://www.ootpdevelopments.com/wp-content/themes/thegem/js/thegem-lazyLoading.js?ver=6.0.16

js ootpdevelopments.com collected 2026-10-01 11:57:06 UTC 15,544 bytes, 615 lines download raw bytes

1(function ($) {
2
3	var lazy_effects = {
4		'clip': {
5			show:	function(element) {
6						$(element.el).animate({
7							transform: 'scale(1.1)',
8						},
9						{
10							duration : 200,
11						}).animate({
12							transform: 'scale(1)',
13						},
14						{
15							duration : 200,
16							complete: function() {
17								if (element.options.queueType == 'sync')
18									element.finishAnimation();
19							}
20						})
21					}
22		},
23
24		'fading': {
25			show:	function(element) {
26						$(element.el).css({
27							opacity: 0
28						}).animate({
29							opacity: 1
30						},
31						{
32							duration : 400,
33							complete: function() {
34								if (element.options.queueType == 'sync')
35									element.finishAnimation();
36							}
37						});
38					}
39		},
40
41		'drop-right': {
42			show:	function(element) {
43						var left = parseInt($(element.el).width()/15);
44						$(element.el).wrapInner('<div style="position: relative; left: ' + left + 'px;"></div>').css({
45							opacity: 1
46						});
47
48						$(element.el).find('> div').css({
49							opacity: 0
50						}).animate({
51							opacity: 1,
52							left: 0,
53						},
54						{
55							duration : 700,
56							complete: function() {
57								var $div = $(element.el).find('> div');
58								$(element.el).append($div.find('> *'));
59								$div.remove();
60								if (element.options.queueType == 'sync')
61									element.finishAnimation();
62							}
63						});
64					}
65		},
66
67		'drop-right-without-wrap': {
68			show:	function(element) {
69						var left = parseInt($(element.el).outerWidth()/15);
70
71						$(element.el).css({
72							opacity: 0,
73							position: 'relative',
74							left: left,
75							transition: 'none'
76						}).animate({
77							opacity: 1,
78							left: 0,
79						},
80						{
81							duration : 700,
82							complete: function() {
83								$(element.el).css({
84									transition: ''
85								});
86
87								if (element.options.queueType == 'sync')
88									element.finishAnimation();
89							}
90						});
91					}
92		},
93
94		'drop-right-unwrap': {
95			show:	function(element) {
96						var left = parseInt($(element.el).width()/15);
97						$(element.el).wrapInner('<div style="position: relative; left: ' + left + 'px;"></div>').css({
98							opacity: 1
99						});
100
101						$(element.el).find('> div').css({
102							opacity: 0
103						}).animate({
104							opacity: 1,
105							left: 0,
106						},
107						{
108							duration : 700,
109							complete: function() {
110								if (element.options.queueType == 'sync')
111									element.finishAnimation();
112							}
113						});
114					}
115		},
116
117		'drop-left': {
118			show:	function(element) {
119						var right = parseInt($(element.el).width()/15);
120						$(element.el).wrapInner('<div style="position: relative; right: ' + right + 'px;"></div>').css({
121							opacity: 1
122						});
123
124						$(element.el).find('> div').css({
125							opacity: 0
126						}).animate({
127							opacity: 1,
128							right: 0
129						},
130						{
131							duration : 700,
132							complete: function() {
133								$(element.el).html($(element.el).find('> div').html());
134								if (element.options.queueType == 'sync')
135									element.finishAnimation();
136							}
137						});
138					}
139		},
140
141		'drop-bottom': {
142			show:	function(element) {
143						var top = parseInt($(element.el).height()/15);
144						$(element.el).wrapInner('<div style="position: relative; top: ' + top + 'px;"></div>').css({
145							opacity: 1
146						});
147
148						$(element.el).find('> div').css({
149							opacity: 0
150						}).animate({
151							opacity: 1,
152							top: 0
153						},
154						{
155							duration : 700,
156							complete: function() {
157								var $div = $(element.el).find('> div');
158								$(element.el).append($div.find('> *'));
159								$div.remove();
160								if (element.options.queueType == 'sync')
161									element.finishAnimation();
162							}
163						});
164					}
165		},
166
167		'drop-top': {
168			show:	function(element) {
169						var step = $(element.el).data('ll-step') || 0.07;
170						step = parseFloat(step);
171						var bottom = parseInt($(element.el).height() * step);
172						$(element.el).wrapInner('<div style="position: relative; bottom: ' + bottom + 'px;"></div>').css({
173							opacity: 1
174						});
175
176						$(element.el).find('> div').css({
177							opacity: 0
178						}).animate({
179							opacity: 1,
180							bottom: 0
181						},
182						{
183							duration : 700,
184							complete: function() {
185								$(element.el).html($(element.el).find('> div').html());
186								if (element.options.queueType == 'sync')
187									element.finishAnimation();
188							}
189						});
190					}
191		},
192
193		'slide-right': {
194			show:	function(element) {
195						if (element.options.firstGroupElement)
196							$(element.el).parent().css({
197								overflow: 'hidden'
198							});
199						$(element.el).css({
200							opacity: 0,
201							position: 'relative',
202							left: '100%'
203						}).animate({left: 0, opacity: 1}, 100).animate({left: -15}, 100).animate({left: 0}, 100, function() {
204							if (element.options.lastGroupElement)
205								$(element.el).parent().css({
206									overflow: 'visible'
207								});
208							if (element.options.queueType == 'sync')
209								element.finishAnimation();
210						});
211					}
212		},
213
214		'move-up': {
215			show:	function(element) {
216				$(element.el).css({
217					opacity: 0,
218					transform: 'translateY(40px)'
219				}).animate({
220					opacity: 1,
221					transform: 'translateY(0px)'
222				},
223				{
224					duration : 1000,
225					complete: function() {
226						if (element.options.queueType == 'sync')
227							element.finishAnimation();
228					}
229				});
230			}
231		},
232
233		'action': {
234			show:	function(element) {
235						var func = $(element.el).data('ll-action-func') || '';
236						if (!func || window[func] == null || window[func] == undefined)
237							return;
238
239						window[func](element.el);
240					}
241		},
242	};
243
244	function Element(el, options) {
245		this.el = el;
246
247		this.options = {
248			offset: 1,
249			delay: -1,
250		};
251		$.extend(this.options, options);
252
253		if (this.options['delay'] == undefined || this.options['delay'] == null)
254			this.options['delay'] = -1;
255		this.options.queueType = this.options.delay == -1 ? 'sync': 'async';
256	}
257
258	function Group(el, options) {
259		this.el = el;
260		this.queue = new Queue(this);
261
262		this.options = {
263			offset: 0.7,
264			delay: -1,
265			queueType: 'sync',
266			isFirst: false,
267			force: false,
268			firstGroupElement: false,
269			lastGroupElement: false
270		};
271		$.extend(this.options, options);
272
273		if (this.options['itemDelay'] == undefined || this.options['itemDelay'] == null)
274			this.options['itemDelay'] = -1;
275		this.options.itemQueueType = this.options.itemDelay == -1 ? 'sync': 'async';
276		this.options['finishDelay'] = this.options['finishDelay'] || 300;
277	}
278
279	function Queue(obj) {
280		this.object = obj;
281		this.queue = [];
282		this.is_exec = false;
283	}
284
285	function LazyLoading(options) {
286		this.options = {
287		};
288		$.extend(this.options, options);
289		this.initialize();
290	}
291
292	$.fn.reverse = [].reverse;
293
294	String.prototype.startsWith = function (str) {
295		return this.indexOf(str) == 0;
296	};
297
298	$.lazyLoading = function(options) {
299		return new LazyLoading(options);
300	}
301
302	function getOffset(elem) {
303		if (elem.getBoundingClientRect && window.gemBrowser.platform.name != 'ios'){
304			var bound = elem.getBoundingClientRect(),
305				html = elem.ownerDocument.documentElement,
306				htmlScroll = getScroll(html),
307				elemScrolls = getScrolls(elem),
308				isFixed = (styleString(elem, 'position') == 'fixed');
309			return {
310				x: parseInt(bound.left) + elemScrolls.x + ((isFixed) ? 0 : htmlScroll.x) - html.clientLeft,
311				y: parseInt(bound.top)  + elemScrolls.y + ((isFixed) ? 0 : htmlScroll.y) - html.clientTop
312			};
313		}
314
315		var element = elem, position = {x: 0, y: 0};
316		if (isBody(elem)) return position;
317
318		while (element && !isBody(element)){
319			position.x += element.offsetLeft;
320			position.y += element.offsetTop;
321
322			if (window.gemBrowser.name == 'firefox'){
323				if (!borderBox(element)){
324					position.x += leftBorder(element);
325					position.y += topBorder(element);
326				}
327				var parent = element.parentNode;
328				if (parent && styleString(parent, 'overflow') != 'visible'){
329					position.x += leftBorder(parent);
330					position.y += topBorder(parent);
331				}
332			} else if (element != elem && window.gemBrowser.name == 'safari'){
333				position.x += leftBorder(element);
334				position.y += topBorder(element);
335			}
336
337			element = element.offsetParent;
338		}
339		if (window.gemBrowser.name == 'firefox' && !borderBox(elem)){
340			position.x -= leftBorder(elem);
341			position.y -= topBorder(elem);
342		}
343		return position;
344	};
345
346	function getScroll(elem){
347		return {x: window.pageXOffset || document.documentElement.scrollLeft, y: window.pageYOffset || document.documentElement.scrollTop};
348	};
349
350	function getScrolls(elem){
351		var element = elem.parentNode, position = {x: 0, y: 0};
352		while (element && !isBody(element)){
353			position.x += element.scrollLeft;
354			position.y += element.scrollTop;
355			element = element.parentNode;
356		}
357		return position;
358	};
359
360	function styleString(element, style) {
361		return $(element).css(style);
362	};
363
364	function styleNumber(element, style){
365		return parseInt(styleString(element, style)) || 0;
366	};
367
368	function borderBox(element){
369		return styleString(element, '-moz-box-sizing') == 'border-box';
370	};
371
372	function topBorder(element){
373		return styleNumber(element, 'border-top-width');
374	};
375
376	function leftBorder(element){
377		return styleNumber(element, 'border-left-width');
378	};
379
380	function isBody(element){
381		return (/^(?:body|html)$/i).test(element.tagName);
382	};
383
384	LazyLoading.prototype = {
385		initialize: function() {
386			this.animated = false;
387			this.groups = [];
388			this.queue = new Queue(this);
389			this.init = true;
390
391			this.hasHeaderVisuals = $('.ls-wp-container').size() > 0;
392
393			$(document).find('.lazy-loading:first').addClass('lazy-loading-first');
394			$(document).find('.lazy-loading').not('.lazy-loading-not-hide').css({visibility: 'hidden'});
395
396			$(document).ready(function() {
397				self.rebuild();
398
399				$(window).resize(function() {
400					if (self.resizeTimeout) {
401						clearTimeout(self.resizeTimeout);
402					}
403					self.rebuild();
404				});
405			});
406
407			var self = this;
408			$(window).scroll(function() {
409				if (!self.animated) {
410					if (self.init)
411						self.buildList();
412					self.init = false;
413					setTimeout(function() {
414						self.scrollPageHandler();
415					}, 100);
416					self.animated = true;
417				}
418			});
419
420			$(window).on('lazy-loading-start', function() {
421				self.rebuild();
422			});
423		},
424
425		rebuild: function() {
426			this.buildList();
427			this.scrollPageHandler();
428		},
429
430		scrollPageHandler: function() {
431			var self = this;
432
433			var new_elements = [];
434			var window_bottom = $(window).scrollTop() + $(window).height();
435			$.each(this.groups, function(index, group) {
436				if (group.is_visible(window_bottom)) {
437					group.show();
438				} else {
439					new_elements.push(group);
440				}
441			});
442			this.queue.next();
443			this.groups = new_elements;
444			this.animated = false;
445		},
446
447		buildList: function() {
448			var self = this;
449			this.groups = [];
450			$(document).find('.lazy-loading').not('.lazy-loading-showed').each(function() {
451				var group = new Group(this, {
452								offset: $(this).data('ll-offset') || 0.7,
453								lazyLoading: self,
454								itemDelay: $(this).data('ll-item-delay'),
455								isFirst: self.hasHeaderVisuals && $(this).hasClass('lazy-loading-first'),
456								finishDelay: $(this).data('ll-finish-delay'),
457								force: $(this).data('ll-force-start') != undefined && $(this).data('ll-force-start') != null
458							});
459
460				var elements = [];
461				$(this).find('.lazy-loading-item').not('.lazy-loading-showed').each(function() {
462					var effect = self.getEffect(this);
463					if (effect == '') {
464						$(this).css({
465							opacity: 1
466						});
467						return;
468					}
469					var el_delay = group.options.itemDelay;
470					var element_delay = $(this).data('ll-item-delay');
471					if (element_delay != null && element_delay != undefined) {
472						el_delay = element_delay;
473					}
474					element = new Element(this, {
475						effect: effect,
476						group: group,
477						delay: el_delay,
478					});
479					elements.push(element);
480				});
481
482				if (elements.length > 0) {
483					group.setElements(elements);
484					self.groups.push(group);
485				}
486			});
487		},
488
489		getEffect: function(element) {
490			return $(element).data('ll-effect') || '';
491		},
492
493		finishAnimation: function() {
494		}
495	};
496
497	Group.prototype = {
498		is_visible: function(window_bottom) {
499			if (this.options.force)
500				return true;
501			var position = getOffset(this.el);
502			if ((position.y + parseFloat(this.options.offset) * this.el.offsetHeight) <= window_bottom) {
503				return true;
504			}
505			else
506				return false;
507		},
508
509		show: function() {
510			this.options.lazyLoading.queue.add(this);
511			$(this.el).addClass('lazy-loading-showed');
512		},
513
514		setElements: function(elements) {
515			this.elements = elements;
516		},
517
518		startAnimation: function() {
519			var self = this;
520
521			$(this.el).css({visibility: 'visible'});
522
523			$.each(this.elements, function(index, element) {
524				if (self.elements[index].options.effect != 'action')
525					if (self.elements[index].options.effect != 'clip')
526						$(self.elements[index].el).css({
527							opacity: 0
528						});
529					else
530						$(self.elements[index].el).css({
531							position: 'relative',
532							transform: 'scale(0)'
533						});
534				if (index == 0)
535					self.elements[index].options.firstGroupElement = true;
536				if (index == self.elements.length - 1) {
537					self.elements[index].options.lastGroupElement = true;
538					self.elements[index].options.queueType = 'sync';
539				}
540				self.elements[index].show();
541			});
542			if (this.options.isFirst) {
543				setTimeout(function() {
544					self.queue.next();
545				}, 500);
546			} else {
547				this.queue.next();
548			}
549			setTimeout(function() {
550				self.finishAnimation();
551			}, this.options.finishDelay);
552		},
553
554		finishAnimation: function() {
555			this.options.lazyLoading.queue.finishPosition();
556		}
557	};
558
559	Element.prototype = {
560		is_visible: function(window_bottom) {
561			var lazy_effect = lazy_effects[this.options.effect] || {};
562			var offset = lazy_effect['offset'] || this.options.offset;
563			var position = getOffset(this.el);
564			if ((position.y + offset * this.el.offsetHeight) <= window_bottom)
565				return true;
566			else
567				return false;
568		},
569
570		show: function() {
571			this.options.group.queue.add(this);
572			$(this.el).addClass('lazy-loading-showed');
573		},
574
575		startAnimation: function() {
576			var self = this;
577			var lazy_effect = lazy_effects[this.options.effect] || {};
578			var func = lazy_effect['show'] || function() {};
579			func(this);
580			if (this.options.delay >= 0 && this.options.queueType == 'async')
581				if (this.options.delay > 0)
582					setTimeout(function() {
583						self.finishAnimation();
584					}, this.options.delay);
585				else
586					self.finishAnimation();
587		},
588
589		finishAnimation: function() {
590			this.options.group.queue.finishPosition();
591		}
592	};
593
594	Queue.prototype = {
595		add: function(obj) {
596			this.queue.push(obj);
597		},
598
599		next: function() {
600			if (this.is_exec || this.queue.length == 0)
601				return false;
602
603			this.is_exec = true;
604			var obj = this.queue.shift();
605			obj.startAnimation();
606		},
607
608		finishPosition: function() {
609			this.is_exec = false;
610			if (this.queue.length > 0)
611				this.next();
612		}
613	};
614
615}(jQuery));

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.