-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (46 loc) · 1.35 KB
/
index.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
import {BaseView, Dispatcher} from 'barba.js'
import Component from '@okiba/component'
import {mixin} from '@okiba/class-utils'
export class BarbaPage {
constructor({namespace, ui, components, transitions = {}}) {
this.namespace = namespace
this.transitions = transitions
this.bindings = {ui, components}
BaseView.init.call(this)
}
initComponent() {
mixin(Component, this, {
...this.bindings,
el: this.container
})
if (this._isComponentinit) return
this._isComponentinit = true
const self = this
Dispatcher.on('transitionCompleted',
(_, oldStatus) => {
if (oldStatus && oldStatus.namespace === this.namespace) {
self.destroy()
}
}
)
}
onEnter() {}
onEnterCompleted() {}
onLeave() {}
onLeaveCompleted() {}
}
import {HistoryManager, Pjax, Prefetch} from 'barba.js'
function getTransition(pages, defaultTransition) {
const { namespace } = HistoryManager.prevStatus()
const { url } = HistoryManager.currentStatus()
const { transitions } = pages[namespace]
const pageName = url.replace(/(#.*|\?.*)/, '')
return transitions[pageName] || transitions.default || defaultTransition
}
export function setupBarba(pages, defaultTransition) {
Pjax.getTransition = function() {
return getTransition(pages, defaultTransition)
}
Pjax.start()
Prefetch.init()
}