-
Notifications
You must be signed in to change notification settings - Fork 0
/
pjax-backbone-view.js
42 lines (35 loc) · 1019 Bytes
/
pjax-backbone-view.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
var PjaxView = Backbone.View.extend({
events: {
'click a[data-pjax]': 'getPjax'
},
// Ensures `replacementEl` and pjax is defined
initialize: function() {
if ('undefined' == typeof this.replacementEl) {
throw '[Initialize Error] `replacementEl` needs to be defined';
} else {
this.$replacementEl = $(this.replacementEl);
}
if (!$.support.pjax) {
throw '[Initialize Error] pjax is not present'
}
$(document).on('pjax:start', this.startCallback);
$(document).on('pjax:end', this.endCallback);
$(document).on('pjax:error', this.errorCallback);
},
// Requests `href` via pjax
getPjax: function(evnt) {
$.pjax.click(evnt, this.$replacementEl);
},
// Default start callback
startCallback: function() {
console.log('Pjax starts.');
},
// Default end callback
endCallback: function() {
console.log('Pjax finished.');
},
// Default success callback
errorCallback: function() {
console.log('Pjax failed.');
}
});