mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 17:59:55 +02:00
102 lines
2.4 KiB
JavaScript
102 lines
2.4 KiB
JavaScript
// status
|
|
( function( window, factory ) {
|
|
// universal module definition
|
|
if ( typeof module == 'object' && module.exports ) {
|
|
// CommonJS
|
|
module.exports = factory(
|
|
window,
|
|
require('./core'),
|
|
require('fizzy-ui-utils'),
|
|
);
|
|
} else {
|
|
// browser global
|
|
factory(
|
|
window,
|
|
window.InfiniteScroll,
|
|
window.fizzyUIUtils,
|
|
);
|
|
}
|
|
|
|
}( window, function factory( window, InfiniteScroll, utils ) {
|
|
|
|
let proto = InfiniteScroll.prototype;
|
|
|
|
// InfiniteScroll.defaults.status = null;
|
|
|
|
InfiniteScroll.create.status = function() {
|
|
let statusElem = utils.getQueryElement( this.options.status );
|
|
if ( !statusElem ) return;
|
|
|
|
// elements
|
|
this.statusElement = statusElem;
|
|
this.statusEventElements = {
|
|
request: statusElem.querySelector('.infinite-scroll-request'),
|
|
error: statusElem.querySelector('.infinite-scroll-error'),
|
|
last: statusElem.querySelector('.infinite-scroll-last'),
|
|
};
|
|
// events
|
|
this.on( 'request', this.showRequestStatus );
|
|
this.on( 'error', this.showErrorStatus );
|
|
this.on( 'last', this.showLastStatus );
|
|
this.bindHideStatus('on');
|
|
};
|
|
|
|
proto.bindHideStatus = function( bindMethod ) {
|
|
let hideEvent = this.options.append ? 'append' : 'load';
|
|
this[ bindMethod ]( hideEvent, this.hideAllStatus );
|
|
};
|
|
|
|
proto.showRequestStatus = function() {
|
|
this.showStatus('request');
|
|
};
|
|
|
|
proto.showErrorStatus = function() {
|
|
this.showStatus('error');
|
|
};
|
|
|
|
proto.showLastStatus = function() {
|
|
this.showStatus('last');
|
|
// prevent last then append event race condition from showing last status #706
|
|
this.bindHideStatus('off');
|
|
};
|
|
|
|
proto.showStatus = function( eventName ) {
|
|
show( this.statusElement );
|
|
this.hideStatusEventElements();
|
|
let eventElem = this.statusEventElements[ eventName ];
|
|
show( eventElem );
|
|
};
|
|
|
|
proto.hideAllStatus = function() {
|
|
hide( this.statusElement );
|
|
this.hideStatusEventElements();
|
|
};
|
|
|
|
proto.hideStatusEventElements = function() {
|
|
for ( let type in this.statusEventElements ) {
|
|
let eventElem = this.statusEventElements[ type ];
|
|
hide( eventElem );
|
|
}
|
|
};
|
|
|
|
// -------------------------- -------------------------- //
|
|
|
|
function hide( elem ) {
|
|
setDisplay( elem, 'none' );
|
|
}
|
|
|
|
function show( elem ) {
|
|
setDisplay( elem, 'block' );
|
|
}
|
|
|
|
function setDisplay( elem, value ) {
|
|
if ( elem ) {
|
|
elem.style.display = value;
|
|
}
|
|
}
|
|
|
|
// -------------------------- -------------------------- //
|
|
|
|
return InfiniteScroll;
|
|
|
|
} ) );
|