-
Notifications
You must be signed in to change notification settings - Fork 7.3k
/
fireCallback.js
75 lines (64 loc) · 2.21 KB
/
fireCallback.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
import * as utils from '../common/utils.js';
import { getOptions, getContainer } from '../common/options.js';
import { nullOrSection } from './nullOrSection.js';
import { nullOrSlide } from './nullOrSlide.js';
import { getState } from '../common/state.js';
/**
* Dispatch events & callbacks
*/
export function fireCallback(eventName, v){
var eventData = getEventData(eventName, v);
utils.trigger(getContainer(), eventName, eventData);
if(getOptions()[eventName].apply(eventData[Object.keys(eventData)[0]], utils.toArray(eventData)) === false){
return false;
}
return true;
}
/**
* Gets the event's data for the given event on the right format.
*/
function getEventData(eventName, v){
//using functions to run only the necessary bits within the object
var paramsPerEvent = {
afterRender: function(){
return {
section: nullOrSection(getState().activeSection),
slide: nullOrSlide(getState().activeSection.activeSlide)
};
},
onLeave: function(){
return {
origin: nullOrSection(v.items.origin),
destination: nullOrSection(v.items.destination),
direction: v.direction,
trigger: getState().scrollTrigger
};
},
afterLoad: function(){
return paramsPerEvent.onLeave();
},
afterSlideLoad: function(){
return {
section: nullOrSection(v.items.section),
origin: nullOrSection(v.items.origin),
destination: nullOrSection(v.items.destination),
direction: v.direction,
trigger: getState().scrollTrigger
};
},
onSlideLeave: function(){
return paramsPerEvent.afterSlideLoad();
},
beforeLeave: function(){
return paramsPerEvent.onLeave();
},
onScrollOverflow: function(){
return {
section: nullOrSection(getState().activeSection),
slide: nullOrSlide(getState().activeSection.activeSlide),
position: v.position
};
}
};
return paramsPerEvent[eventName]();
}