-
Notifications
You must be signed in to change notification settings - Fork 7.3k
/
bindings.js
38 lines (28 loc) · 982 Bytes
/
bindings.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
import * as utils from './common/utils.js';
import { EventEmitter } from './common/eventEmitter.js';
import { setState } from './common/state.js';
EventEmitter.on('bindEvents', bindEvents);
function bindEvents(){
//Scrolls to the section when clicking the navigation bullet
//simulating the jQuery .on('click') event using delegation
['click', 'touchstart'].forEach(function(eventName){
utils.docAddEvent(eventName, delegatedEvents);
});
utils.windowAddEvent('focus', focusHandler);
internalEvents();
}
function internalEvents(){
EventEmitter.on('onDestroy', onDestroy);
}
function delegatedEvents(e){
EventEmitter.emit('onClickOrTouch', {e: e, target: e.target});
}
function onDestroy(){
['click', 'touchstart'].forEach(function(eventName){
utils.docRemoveEvent(eventName, delegatedEvents);
});
}
// changing isWindowFocused to true on focus event
function focusHandler(){
setState({isWindowFocused: true});
}