forked from jamiebuilds/marionette-wires
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.js
44 lines (37 loc) · 988 Bytes
/
application.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
import $ from 'jquery';
import _ from 'underscore';
import Radio from 'backbone.radio';
import nprogress from 'nprogress';
import {Application} from 'backbone.marionette';
let routerChannel = Radio.channel('router');
nprogress.configure({
showSpinner: false
});
export default Application.extend({
initialize() {
this.$body = $(document.body);
this.listenTo(routerChannel, {
'before:transition' : this.onBeforeTransition,
'transition' : this.onTransition,
'transition:abort' : this.onTransitionAbort
});
},
onBeforeTransition() {
this.transitioning = true;
// Don't show for synchronous route changes takin more than 50ms
_.delay(() => {
if (this.transitioning) {
nprogress.start();
}
}, 50);
},
onTransition() {
this.transitioning = false;
this.$body.scrollTop(0);
nprogress.done();
},
onTransitionAbort() {
this.transitioning = false;
nprogress.done(true);
}
});