-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdqpt.js
73 lines (59 loc) · 1.55 KB
/
dqpt.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
$(document).ready(function() {
var dqptLink;
var dqptXhrRequest;
var dqptContainer;
var dqptTransitionSpeed = 200;
var urlToLoad;
var current = document.location;
var currentURL = current.href;
var title = document.title;
dqptContainer = $('#dqptContainer');
function dqptresetScrollPosition() {
window.scrollTo(0,0);
}
function dqpterror(e, jqxhr) {}
function dqptInitLinks() {
dqptLink = $('.dqPT');
dqptLink.off('click');
dqptLink.on('click', function(event) {
event.preventDefault();
urlToLoad = this.href;
if (current.href == this.href) {
return;
} else {
history.pushState(urlToLoad, title, urlToLoad);
dqptContainer.fadeOut(dqptTransitionSpeed, function(){
dqptXhrRequest(urlToLoad);
});
}
});
}
function dqptBeforeSend() {}
function dqptSuccess() {}
function dqptProcessData(data) {
var content = $('#dqptContainer', data);
$('#dqptContainer').html(content);
var newTitle = $(data).filter('title').text();
document.title = newTitle;
dqptInitLinks();
dqptresetScrollPosition();
dqptContainer.fadeIn();
}
var dqptXhrRequest = function(urlToLoad) {
$.ajax({
type: "GET",
cache: false,
url: urlToLoad,
dataType: "html",
contentType: "text/html",
beforeSend: dqptBeforeSend,
success: dqptProcessData,
error: dqpterror
});
};
window.onpopstate = function(event) {
urlToLoad = event.state;
dqptXhrRequest(urlToLoad);
}
dqptInitLinks();
});