bzr branch
http://darksoft.org/webbzr/adei/trunk
1
by Suren A. Chilingaryan
Initial import |
1 |
function HISTORY(callback) { |
2 |
window.dhtmlHistory.create({ |
|
3 |
toJSON: function(o) { |
|
4 |
return Object.toJSON(o); |
|
5 |
},
|
|
6 |
fromJSON: function(s) { |
|
7 |
return s.evalJSON(); |
|
8 |
}
|
|
9 |
});
|
|
10 |
||
11 |
dhtmlHistory.initialize(); |
|
12 |
// dhtmlHistory.addListener(callback);
|
|
13 |
||
11
by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc. |
14 |
var curtime = new Date(); |
15 |
this.busy = curtime.getTime(); |
|
16 |
||
17 |
this.endpos = false; |
|
18 |
this.automode = false; |
|
1
by Suren A. Chilingaryan
Initial import |
19 |
this.started = false; |
20 |
this.callback = callback; |
|
21 |
dhtmlHistory.addListener(this.onHistoryEvent(this)); |
|
22 |
}
|
|
23 |
||
24 |
HISTORY.prototype.onHistoryEvent = function(self) { |
|
25 |
return function(newLocation, historyData) { |
|
26 |
if (newLocation == "__startup__") { |
|
27 |
history.forward(); |
|
11
by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc. |
28 |
if (!self.automode) { |
29 |
adeiReportError(translate("History is exhausted")); |
|
30 |
}
|
|
31 |
||
32 |
return; |
|
1
by Suren A. Chilingaryan
Initial import |
33 |
}
|
34 |
||
11
by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc. |
35 |
var props = self.GetProps(newLocation); |
36 |
var hid = self.GetID(newLocation); |
|
37 |
||
38 |
var res = self.callback(props, historyData, hid); |
|
39 |
||
40 |
self.automode = false; |
|
41 |
||
42 |
var curtime = new Date(); |
|
43 |
self.busy = curtime.getTime(); |
|
44 |
||
45 |
return res; |
|
1
by Suren A. Chilingaryan
Initial import |
46 |
}
|
47 |
}
|
|
48 |
||
11
by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc. |
49 |
HISTORY.prototype.GetProps = function(res) { |
50 |
if (typeof res == "undefined") |
|
51 |
var res = dhtmlHistory.getCurrentLocation(); |
|
52 |
||
53 |
return res.replace(/\&history_id=\d+/,""); |
|
54 |
}
|
|
55 |
||
56 |
HISTORY.prototype.GetID = function(res) { |
|
57 |
if (typeof res == "undefined") |
|
58 |
var res = dhtmlHistory.getCurrentLocation(); |
|
59 |
||
60 |
var m = /\&history_id=(\d+)/.exec(res); |
|
61 |
if (m) return m[1]; |
|
62 |
return 0; |
|
63 |
}
|
|
64 |
||
65 |
HISTORY.prototype.CreateLocation = function(props, hid) { |
|
66 |
/* if (props.indexOf("#")>=0) {*/
|
|
67 |
var res = props + "&history_id=" + hid; |
|
68 |
/* } else {
|
|
69 |
var res = props + "#history_id=" + hid;
|
|
70 |
}*/
|
|
71 |
return res; |
|
1
by Suren A. Chilingaryan
Initial import |
72 |
}
|
73 |
||
74 |
HISTORY.prototype.Add = function(page, cfg) { |
|
75 |
if (!this.started) { |
|
76 |
dhtmlHistory.add("__startup__", cfg); |
|
77 |
this.started = true; |
|
78 |
}
|
|
11
by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc. |
79 |
|
80 |
var curtime = new Date(); |
|
81 |
this.endpos = curtime.getTime(); |
|
82 |
||
83 |
var loc = this.CreateLocation(page, this.endpos) |
|
84 |
dhtmlHistory.add(loc, cfg); |
|
85 |
}
|
|
86 |
||
87 |
HISTORY.prototype.ReplaceLocation = function(new_props, props, hid) { |
|
88 |
if (typeof current == "undefined") { |
|
89 |
var current = dhtmlHistory.getCurrentLocation(); |
|
90 |
||
91 |
if (typeof hid == "undefined") |
|
92 |
var hid = this.GetID(current); |
|
93 |
}
|
|
1
by Suren A. Chilingaryan
Initial import |
94 |
|
11
by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc. |
95 |
var loc = this.CreateLocation(props, hid) |
96 |
var new_loc = this.CreateLocation(new_props, hid) |
|
97 |
||
98 |
var orig = window.location.toString(); |
|
99 |
var replacement; |
|
100 |
if (orig.match('#')) { |
|
101 |
replacement = orig.replace(/#.*$/, '#' + new_loc); |
|
102 |
this.AddSynonim(loc, new_loc); |
|
103 |
} else replacement = '#' + new_loc; |
|
104 |
||
105 |
window.location.replace(replacement); |
|
1
by Suren A. Chilingaryan
Initial import |
106 |
}
|
107 |
||
108 |
HISTORY.prototype.AddSynonim = function(old_page, new_page) { |
|
109 |
var cfg = historyStorage.get(old_page); |
|
110 |
||
111 |
if (cfg) { |
|
112 |
if (historyStorage.hasKey(new_page)) |
|
113 |
historyStorage.remove(new_page); |
|
114 |
||
115 |
historyStorage.put(new_page, cfg); |
|
116 |
}
|
|
117 |
}
|
|
11
by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc. |
118 |
|
119 |
HISTORY.prototype.Back = function() { |
|
120 |
if (!this.busy) return; |
|
121 |
||
122 |
var curtime = new Date(); |
|
123 |
if ((curtime.getTime() - this.busy) < 50) return; |
|
124 |
||
125 |
this.busy = false; |
|
126 |
this.automode = true; |
|
127 |
history.back(); |
|
128 |
}
|
|
129 |
||
130 |
HISTORY.prototype.Forward = function() { |
|
131 |
var pos = this.GetID(); |
|
132 |
if (pos == this.endpos) return; |
|
133 |
||
134 |
if (!this.busy) return; |
|
135 |
||
136 |
var curtime = new Date(); |
|
137 |
if ((curtime.getTime() - this.busy) < 50) return; |
|
138 |
||
139 |
// if no room to go forward, the busy flag will remain
|
|
140 |
this.busy = false; |
|
141 |
history.forward(); |
|
142 |
}
|
|
143 |