-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathbutton.js
81 lines (64 loc) · 1.9 KB
/
button.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// 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;
} ) );