-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoadify.js
More file actions
43 lines (40 loc) · 1.13 KB
/
Copy pathLoadify.js
File metadata and controls
43 lines (40 loc) · 1.13 KB
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
var Loadify = function() {
var loadify = this;
if(window.history && window.history.pushState && window.history.replaceState) {
window.history.replaceState({ "url" : location.pathname }, "", location.pathname);
$("a[data-loadify-target]").live('click', function(evt) {
return loadify.clickHandler(evt, this);
});
$(window).bind('popstate', function(evt) {
loadify.popStateHandler(evt.originalEvent);
});
}
};
Loadify.prototype = {
clickHandler: function(evt, anchor) {
/* Open in new tab/window actions */
if (evt.which == 2 || evt.metaKey || evt.ctrlKey)
return true;
var
href = evt.target.href,
container = $(anchor).attr('data-loadify-target');
window.history.pushState({ "container": container }, "", href);
loadify.loadHandler({ "container": container }, href);
return false;
},
popStateHandler: function(evt) {
if(evt.state) {
loadify.loadHandler(evt.state, location.pathname);
}
},
loadHandler: function(state, href) {
if(state.url) {
document.location.href = href;
} else if(state.container) {
$(state.container).load(href);
}
}
};
$(function() {
window.loadify = new Loadify();
});