-
Notifications
You must be signed in to change notification settings - Fork 3
/
ajax.js
103 lines (91 loc) · 3.67 KB
/
ajax.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
push=0;
$(document).ready(function(){
ajaxInit=function (selector){$(selector).click(function(e){
$('a.ajax').each(function(){$( this ).removeClass( "active" );});
$(this).addClass('active');
/*loading icon*/
$('#wrapper').get(0).innerHTML='<div id="content" white="no"><div class="loading"></div> </div>';
var adresa =this.href;
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4)
{
if(xmlhttp.status == 503 || xmlhttp.status == 404){location.reload();}
xmlDoc=(xmlhttp.responseText);
var title=(/<title>([^<]+)<\/title>/m).exec(xmlDoc)[1];
document.title=title;
var wrapper=(/<div *(id=['"]wrapper['"][^<>]*|(?:[^<>=]+=['"][^'"]+['"] *)?id=['"]wrapper['"]) *>/m).exec(xmlDoc)[0];
var back1=(/<div *(id=['"]back1['"][^<>]*|(?:[^<>=]+=['"][^'"]+['"] *)?id=['"]back1['"]) *>/m).exec(xmlDoc)[0];
xmlDoc=xmlDoc.substring(xmlDoc.indexOf(wrapper),xmlDoc.indexOf(back1));
document.getElementById("wrapper").outerHTML=xmlDoc;
if(/<script[^<>]*>/.test(xmlDoc))
{start=/<script[^<>]*>/.exec(xmlDoc)[0];
end=/<\/script[^<>]*>/.exec(xmlDoc)[0];
console.log(xmlDoc.substring(xmlDoc.indexOf(start)+start.length,xmlDoc.indexOf(end)));
eval(xmlDoc.substring(xmlDoc.indexOf(start)+start.length,xmlDoc.indexOf(end)));
$('#wrapper').fadeOut(0);
$('#wrapper').fadeIn(500);
}
history.pushState({foo:'xxxx'}, 'stranka x', adresa);
push=1;
}
}
xmlhttp.open("GET", this.href ,true);
xmlhttp.send();
e.preventDefault();
return false;
});}
ajaxInit('a.ajax');
/*history*/
window.onpopstate=function(e){
if(!push) { return;}
var popped = ('state' in window.history)
$('a.ajax').each(function(){$( this ).removeClass( "active" );
if(this.href==document.location){$(this).addClass('active')};
});
$('#wrapper').get(0).innerHTML='<div id="content" white="no"><div class="loading"></div> </div>';
var adresa =document.location;
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4)
{
if(xmlhttp.status == 503 || xmlhttp.status == 404){location.reload();}
xmlDoc=(xmlhttp.responseText);
var title=(/<title>([^<]+)<\/title>/m).exec(xmlDoc)[1];
document.title=title;
var wrapper=(/<div *(id=['"]wrapper['"][^<>]*|(?:[^<>=]+=['"][^'"]+['"] *)?id=['"]wrapper['"]) *>/m).exec(xmlDoc)[0];
var back1=(/<div *(id=['"]back1['"][^<>]*|(?:[^<>=]+=['"][^'"]+['"] *)?id=['"]back1['"]) *>/m).exec(xmlDoc)[0];
xmlDoc=xmlDoc.substring(xmlDoc.indexOf(wrapper),xmlDoc.indexOf(back1));
document.getElementById("wrapper").outerHTML=xmlDoc;
if(/<script[^<>]*>/.test(xmlDoc))
{start=/<script[^<>]*>/.exec(xmlDoc)[0];
end=/<\/script[^<>]*>/.exec(xmlDoc)[0];
console.log(xmlDoc.substring(xmlDoc.indexOf(start)+start.length,xmlDoc.indexOf(end)));
eval(xmlDoc.substring(xmlDoc.indexOf(start)+start.length,xmlDoc.indexOf(end)));
$('#wrapper').fadeOut(0);
$('#wrapper').fadeIn(500);
}
}
}
xmlhttp.open("GET", document.location ,true);
xmlhttp.send();
}
});