forked from barbajs/barba
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.html
57 lines (43 loc) · 1.67 KB
/
views.html
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
---
# Front matter comment to ensure Jekyll properly reads file.
---
{% include header.html %}
{% include nav.html %}
<div id="barba-wrapper">
<div class="barba-container">
<h1>Views</h1>
<p>One of the hardest things with a pushstate navigation is to handle and take care of all the javascript states/events in the different pages.</p>
<p>Barba.js gives a nice helper, that will help you to associate a <code>Container</code> with a <code>View</code>.</p>
<p>All the transitions need to extend the <a href="https://github.com/luruke/barba.js/blob/master/src/View/BaseView.js" target="_blank">Barba.BaseView</a> object.</p>
<p>To associate a <code>View</code> with a <code>Container</code>, it's enough to specify a common namespace:</p>
{% highlight html %}
<div class="barba-container" data-namespace="homepage">
{% endhighlight %}
{% highlight javascript %}
var Homepage = Barba.BaseView.extend({
namespace: 'homepage',
onEnter: function() {
// The new Container is ready and attached to the DOM.
},
onEnterCompleted: function() {
// The Transition has just finished.
},
onLeave: function() {
// A new Transition toward a new page has just started.
},
onLeaveCompleted: function() {
// The Container has just been removed from the DOM.
}
});
// Don't forget to init the view!
Homepage.init();
{% endhighlight %}
<blockquote>
<p>Is suggested to .init() the Views before calling Pjax.start() - In this way Pjax.start() will emit onEnter() and onEnterCompleted() for the current view.</p>
</blockquote>
<blockquote>
<p>If you don't like data-namespace you can change it, see the API section.</p>
</blockquote>
</div>
</div>
{% include footer.html %}