// button ( 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 ) { // -------------------------- InfiniteScrollButton -------------------------- // class InfiniteScrollButton { constructor( element, infScroll ) { this.element = element; this.infScroll = infScroll; // events this.clickHandler = this.onClick.bind( this ); this.element.addEventListener( 'click', this.clickHandler ); infScroll.on( 'request', this.disable.bind( this ) ); infScroll.on( 'load', this.enable.bind( this ) ); infScroll.on( 'error', this.hide.bind( this ) ); infScroll.on( 'last', this.hide.bind( this ) ); } onClick( event ) { event.preventDefault(); this.infScroll.loadNextPage(); } enable() { this.element.removeAttribute('disabled'); } disable() { this.element.disabled = 'disabled'; } hide() { this.element.style.display = 'none'; } destroy() { this.element.removeEventListener( 'click', this.clickHandler ); } } // -------------------------- InfiniteScroll methods -------------------------- // // InfiniteScroll.defaults.button = null; InfiniteScroll.create.button = function() { let buttonElem = utils.getQueryElement( this.options.button ); if ( buttonElem ) { this.button = new InfiniteScrollButton( buttonElem, this ); } }; InfiniteScroll.destroy.button = function() { if ( this.button ) this.button.destroy(); }; // -------------------------- -------------------------- // InfiniteScroll.Button = InfiniteScrollButton; return InfiniteScroll; } ) );