mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
minify
This commit is contained in:
parent
82bcca376f
commit
8a6884abef
494 changed files with 256 additions and 120180 deletions
|
@ -1,185 +1 @@
|
|||
define(['visibleinviewport', 'browser', 'dom'], function (visibleinviewport, browser, dom) {
|
||||
'use strict';
|
||||
|
||||
var thresholdX;
|
||||
var thresholdY;
|
||||
|
||||
var requestIdleCallback = window.requestIdleCallback || function (fn) {
|
||||
fn();
|
||||
};
|
||||
|
||||
function resetThresholds() {
|
||||
|
||||
var x = screen.availWidth;
|
||||
var y = screen.availHeight;
|
||||
|
||||
if (browser.touch) {
|
||||
x *= 1.5;
|
||||
y *= 1.5;
|
||||
}
|
||||
|
||||
thresholdX = x;
|
||||
thresholdY = y;
|
||||
}
|
||||
|
||||
dom.addEventListener(window, "orientationchange", resetThresholds, { passive: true });
|
||||
dom.addEventListener(window, 'resize', resetThresholds, { passive: true });
|
||||
resetThresholds();
|
||||
|
||||
function isVisible(elem) {
|
||||
return visibleinviewport(elem, true, thresholdX, thresholdY);
|
||||
}
|
||||
|
||||
var wheelEvent = (document.implementation.hasFeature('Event.wheel', '3.0') ? 'wheel' : 'mousewheel');
|
||||
var self = {};
|
||||
|
||||
function cancelAll(tokens) {
|
||||
for (var i = 0, length = tokens.length; i < length; i++) {
|
||||
|
||||
tokens[i] = true;
|
||||
}
|
||||
}
|
||||
|
||||
function unveilElementsInternal(instance, callback) {
|
||||
|
||||
var unveiledElements = [];
|
||||
var cancellationTokens = [];
|
||||
var loadedCount = 0;
|
||||
|
||||
function unveilInternal(tokenIndex) {
|
||||
|
||||
var anyFound = false;
|
||||
var out = false;
|
||||
|
||||
var elements = instance.elements;
|
||||
// TODO: This out construct assumes left to right, top to bottom
|
||||
|
||||
for (var i = 0, length = elements.length; i < length; i++) {
|
||||
|
||||
if (cancellationTokens[tokenIndex]) {
|
||||
return;
|
||||
}
|
||||
if (unveiledElements[i]) {
|
||||
continue;
|
||||
}
|
||||
var elem = elements[i];
|
||||
if (!out && isVisible(elem)) {
|
||||
anyFound = true;
|
||||
unveiledElements[i] = true;
|
||||
callback(elem);
|
||||
loadedCount++;
|
||||
} else {
|
||||
|
||||
if (anyFound) {
|
||||
out = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (loadedCount >= elements.length) {
|
||||
dom.removeEventListener(document, 'focus', unveil, {
|
||||
capture: true,
|
||||
passive: true
|
||||
});
|
||||
dom.removeEventListener(document, 'scroll', unveil, {
|
||||
capture: true,
|
||||
passive: true
|
||||
});
|
||||
dom.removeEventListener(document, wheelEvent, unveil, {
|
||||
capture: true,
|
||||
passive: true
|
||||
});
|
||||
dom.removeEventListener(window, 'resize', unveil, {
|
||||
capture: true,
|
||||
passive: true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function unveil() {
|
||||
|
||||
cancelAll(cancellationTokens);
|
||||
|
||||
var index = cancellationTokens.length;
|
||||
cancellationTokens.length++;
|
||||
|
||||
setTimeout(function () {
|
||||
unveilInternal(index);
|
||||
}, 1);
|
||||
}
|
||||
|
||||
dom.addEventListener(document, 'focus', unveil, {
|
||||
capture: true,
|
||||
passive: true
|
||||
});
|
||||
dom.addEventListener(document, 'scroll', unveil, {
|
||||
capture: true,
|
||||
passive: true
|
||||
});
|
||||
dom.addEventListener(document, wheelEvent, unveil, {
|
||||
capture: true,
|
||||
passive: true
|
||||
});
|
||||
dom.addEventListener(window, 'resize', unveil, {
|
||||
capture: true,
|
||||
passive: true
|
||||
});
|
||||
|
||||
unveil();
|
||||
}
|
||||
|
||||
function LazyLoader(options) {
|
||||
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
LazyLoader.prototype.createObserver = function () {
|
||||
|
||||
unveilElementsInternal(this, this.options.callback);
|
||||
this.observer = 1;
|
||||
};
|
||||
|
||||
LazyLoader.prototype.addElements = function (elements) {
|
||||
|
||||
this.elements = this.elements || [];
|
||||
|
||||
for (var i = 0, length = elements.length; i < length; i++) {
|
||||
this.elements.push(elements[i]);
|
||||
}
|
||||
|
||||
var observer = this.observer;
|
||||
|
||||
if (!observer) {
|
||||
this.createObserver();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
LazyLoader.prototype.destroyObserver = function (elements) {
|
||||
|
||||
};
|
||||
|
||||
LazyLoader.prototype.destroy = function (elements) {
|
||||
|
||||
this.destroyObserver();
|
||||
this.options = null;
|
||||
};
|
||||
|
||||
function unveilElements(elements, root, callback) {
|
||||
|
||||
if (!elements.length) {
|
||||
return;
|
||||
}
|
||||
var lazyLoader = new LazyLoader({
|
||||
callback: callback
|
||||
});
|
||||
lazyLoader.addElements(elements);
|
||||
}
|
||||
|
||||
LazyLoader.lazyChildren = function (elem, callback) {
|
||||
|
||||
unveilElements(elem.getElementsByClassName('lazy'), elem, callback);
|
||||
};
|
||||
|
||||
return LazyLoader;
|
||||
});
|
||||
define(["visibleinviewport","browser","dom"],function(visibleinviewport,browser,dom){"use strict";function resetThresholds(){var x=screen.availWidth,y=screen.availHeight;browser.touch&&(x*=1.5,y*=1.5),thresholdX=x,thresholdY=y}function isVisible(elem){return visibleinviewport(elem,!0,thresholdX,thresholdY)}function cancelAll(tokens){for(var i=0,length=tokens.length;i<length;i++)tokens[i]=!0}function unveilElementsInternal(instance,callback){function unveilInternal(tokenIndex){for(var anyFound=!1,out=!1,elements=instance.elements,i=0,length=elements.length;i<length;i++){if(cancellationTokens[tokenIndex])return;if(!unveiledElements[i]){var elem=elements[i];!out&&isVisible(elem)?(anyFound=!0,unveiledElements[i]=!0,callback(elem),loadedCount++):anyFound&&(out=!0)}}loadedCount>=elements.length&&(dom.removeEventListener(document,"focus",unveil,{capture:!0,passive:!0}),dom.removeEventListener(document,"scroll",unveil,{capture:!0,passive:!0}),dom.removeEventListener(document,wheelEvent,unveil,{capture:!0,passive:!0}),dom.removeEventListener(window,"resize",unveil,{capture:!0,passive:!0}))}function unveil(){cancelAll(cancellationTokens);var index=cancellationTokens.length;cancellationTokens.length++,setTimeout(function(){unveilInternal(index)},1)}var unveiledElements=[],cancellationTokens=[],loadedCount=0;dom.addEventListener(document,"focus",unveil,{capture:!0,passive:!0}),dom.addEventListener(document,"scroll",unveil,{capture:!0,passive:!0}),dom.addEventListener(document,wheelEvent,unveil,{capture:!0,passive:!0}),dom.addEventListener(window,"resize",unveil,{capture:!0,passive:!0}),unveil()}function LazyLoader(options){this.options=options}function unveilElements(elements,root,callback){if(elements.length){var lazyLoader=new LazyLoader({callback:callback});lazyLoader.addElements(elements)}}var thresholdX,thresholdY;window.requestIdleCallback||function(fn){fn()};dom.addEventListener(window,"orientationchange",resetThresholds,{passive:!0}),dom.addEventListener(window,"resize",resetThresholds,{passive:!0}),resetThresholds();var wheelEvent=document.implementation.hasFeature("Event.wheel","3.0")?"wheel":"mousewheel";return LazyLoader.prototype.createObserver=function(){unveilElementsInternal(this,this.options.callback),this.observer=1},LazyLoader.prototype.addElements=function(elements){this.elements=this.elements||[];for(var i=0,length=elements.length;i<length;i++)this.elements.push(elements[i]);var observer=this.observer;observer||this.createObserver()},LazyLoader.prototype.destroyObserver=function(elements){},LazyLoader.prototype.destroy=function(elements){this.destroyObserver(),this.options=null},LazyLoader.lazyChildren=function(elem,callback){unveilElements(elem.getElementsByClassName("lazy"),elem,callback)},LazyLoader});
|
Loading…
Add table
Add a link
Reference in a new issue