Mercurial > kallithea
annotate rhodecode/public/js/native.history.js @ 3237:f5dd76e2a7af beta
disable file editing when not on branch head fixes issue #462
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 27 Jan 2013 00:18:49 +0100 |
parents | 16456e7b2231 |
children | a5888ca796b5 |
rev | line source |
---|---|
3038
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
2 * History.js Native Adapter |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
3 * @author Benjamin Arthur Lupton <contact@balupton.com> |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
4 * @copyright 2010-2011 Benjamin Arthur Lupton <contact@balupton.com> |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
5 * @license New BSD License <http://creativecommons.org/licenses/BSD/> |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
6 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
7 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
8 // Closure |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
9 (function(window,undefined){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
10 "use strict"; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
11 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
12 // Localise Globals |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
13 var History = window.History = window.History||{}; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
14 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
15 // Check Existence |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
16 if ( typeof History.Adapter !== 'undefined' ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
17 throw new Error('History.js Adapter has already been loaded...'); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
18 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
19 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
20 // Add the Adapter |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
21 History.Adapter = { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
22 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
23 * History.Adapter.handlers[uid][eventName] = Array |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
24 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
25 handlers: {}, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
26 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
27 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
28 * History.Adapter._uid |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
29 * The current element unique identifier |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
30 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
31 _uid: 1, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
32 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
33 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
34 * History.Adapter.uid(element) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
35 * @param {Element} element |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
36 * @return {String} uid |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
37 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
38 uid: function(element){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
39 return element._uid || (element._uid = History.Adapter._uid++); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
40 }, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
41 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
42 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
43 * History.Adapter.bind(el,event,callback) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
44 * @param {Element} element |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
45 * @param {String} eventName - custom and standard events |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
46 * @param {Function} callback |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
47 * @return |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
48 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
49 bind: function(element,eventName,callback){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
50 // Prepare |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
51 var uid = History.Adapter.uid(element); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
52 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
53 // Apply Listener |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
54 History.Adapter.handlers[uid] = History.Adapter.handlers[uid] || {}; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
55 History.Adapter.handlers[uid][eventName] = History.Adapter.handlers[uid][eventName] || []; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
56 History.Adapter.handlers[uid][eventName].push(callback); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
57 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
58 // Bind Global Listener |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
59 element['on'+eventName] = (function(element,eventName){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
60 return function(event){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
61 History.Adapter.trigger(element,eventName,event); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
62 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
63 })(element,eventName); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
64 }, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
65 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
66 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
67 * History.Adapter.trigger(el,event) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
68 * @param {Element} element |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
69 * @param {String} eventName - custom and standard events |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
70 * @param {Object} event - a object of event data |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
71 * @return |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
72 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
73 trigger: function(element,eventName,event){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
74 // Prepare |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
75 event = event || {}; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
76 var uid = History.Adapter.uid(element), |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
77 i,n; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
78 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
79 // Apply Listener |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
80 History.Adapter.handlers[uid] = History.Adapter.handlers[uid] || {}; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
81 History.Adapter.handlers[uid][eventName] = History.Adapter.handlers[uid][eventName] || []; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
82 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
83 // Fire Listeners |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
84 for ( i=0,n=History.Adapter.handlers[uid][eventName].length; i<n; ++i ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
85 History.Adapter.handlers[uid][eventName][i].apply(this,[event]); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
86 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
87 }, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
88 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
89 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
90 * History.Adapter.extractEventData(key,event,extra) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
91 * @param {String} key - key for the event data to extract |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
92 * @param {String} event - custom and standard events |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
93 * @return {mixed} |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
94 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
95 extractEventData: function(key,event){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
96 var result = (event && event[key]) || undefined; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
97 return result; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
98 }, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
99 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
100 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
101 * History.Adapter.onDomLoad(callback) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
102 * @param {Function} callback |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
103 * @return |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
104 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
105 onDomLoad: function(callback) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
106 var timeout = window.setTimeout(function(){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
107 callback(); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
108 },2000); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
109 window.onload = function(){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
110 clearTimeout(timeout); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
111 callback(); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
112 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
113 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
114 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
115 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
116 // Try and Initialise History |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
117 if ( typeof History.init !== 'undefined' ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
118 History.init(); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
119 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
120 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
121 })(window); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
122 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
123 * History.js Core |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
124 * @author Benjamin Arthur Lupton <contact@balupton.com> |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
125 * @copyright 2010-2011 Benjamin Arthur Lupton <contact@balupton.com> |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
126 * @license New BSD License <http://creativecommons.org/licenses/BSD/> |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
127 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
128 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
129 (function(window,undefined){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
130 "use strict"; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
131 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
132 // -------------------------------------------------------------------------- |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
133 // Initialise |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
134 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
135 // Localise Globals |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
136 var |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
137 console = window.console||undefined, // Prevent a JSLint complain |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
138 document = window.document, // Make sure we are using the correct document |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
139 navigator = window.navigator, // Make sure we are using the correct navigator |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
140 amplify = window.amplify||false, // Amplify.js |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
141 setTimeout = window.setTimeout, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
142 clearTimeout = window.clearTimeout, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
143 setInterval = window.setInterval, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
144 clearInterval = window.clearInterval, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
145 JSON = window.JSON, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
146 History = window.History = window.History||{}, // Public History Object |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
147 history = window.history; // Old History Object |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
148 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
149 // MooTools Compatibility |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
150 JSON.stringify = JSON.stringify||JSON.encode; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
151 JSON.parse = JSON.parse||JSON.decode; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
152 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
153 // Check Existence |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
154 if ( typeof History.init !== 'undefined' ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
155 throw new Error('History.js Core has already been loaded...'); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
156 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
157 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
158 // Initialise History |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
159 History.init = function(){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
160 // Check Load Status of Adapter |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
161 if ( typeof History.Adapter === 'undefined' ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
162 return false; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
163 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
164 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
165 // Check Load Status of Core |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
166 if ( typeof History.initCore !== 'undefined' ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
167 History.initCore(); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
168 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
169 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
170 // Check Load Status of HTML4 Support |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
171 if ( typeof History.initHtml4 !== 'undefined' ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
172 History.initHtml4(); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
173 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
174 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
175 // Return true |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
176 return true; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
177 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
178 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
179 // -------------------------------------------------------------------------- |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
180 // Initialise Core |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
181 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
182 // Initialise Core |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
183 History.initCore = function(){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
184 // Initialise |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
185 if ( typeof History.initCore.initialized !== 'undefined' ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
186 // Already Loaded |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
187 return false; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
188 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
189 else { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
190 History.initCore.initialized = true; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
191 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
192 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
193 // ---------------------------------------------------------------------- |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
194 // Options |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
195 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
196 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
197 * History.options |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
198 * Configurable options |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
199 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
200 History.options = History.options||{}; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
201 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
202 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
203 * History.options.hashChangeInterval |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
204 * How long should the interval be before hashchange checks |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
205 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
206 History.options.hashChangeInterval = History.options.hashChangeInterval || 100; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
207 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
208 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
209 * History.options.safariPollInterval |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
210 * How long should the interval be before safari poll checks |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
211 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
212 History.options.safariPollInterval = History.options.safariPollInterval || 500; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
213 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
214 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
215 * History.options.doubleCheckInterval |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
216 * How long should the interval be before we perform a double check |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
217 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
218 History.options.doubleCheckInterval = History.options.doubleCheckInterval || 500; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
219 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
220 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
221 * History.options.storeInterval |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
222 * How long should we wait between store calls |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
223 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
224 History.options.storeInterval = History.options.storeInterval || 1000; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
225 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
226 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
227 * History.options.busyDelay |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
228 * How long should we wait between busy events |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
229 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
230 History.options.busyDelay = History.options.busyDelay || 250; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
231 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
232 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
233 * History.options.debug |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
234 * If true will enable debug messages to be logged |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
235 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
236 History.options.debug = History.options.debug || false; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
237 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
238 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
239 * History.options.initialTitle |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
240 * What is the title of the initial state |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
241 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
242 History.options.initialTitle = History.options.initialTitle || document.title; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
243 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
244 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
245 // ---------------------------------------------------------------------- |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
246 // Interval record |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
247 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
248 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
249 * History.intervalList |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
250 * List of intervals set, to be cleared when document is unloaded. |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
251 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
252 History.intervalList = []; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
253 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
254 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
255 * History.clearAllIntervals |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
256 * Clears all setInterval instances. |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
257 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
258 History.clearAllIntervals = function(){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
259 var i, il = History.intervalList; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
260 if (typeof il !== "undefined" && il !== null) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
261 for (i = 0; i < il.length; i++) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
262 clearInterval(il[i]); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
263 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
264 History.intervalList = null; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
265 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
266 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
267 History.Adapter.bind(window,"beforeunload",History.clearAllIntervals); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
268 History.Adapter.bind(window,"unload",History.clearAllIntervals); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
269 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
270 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
271 // ---------------------------------------------------------------------- |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
272 // Debug |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
273 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
274 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
275 * History.debug(message,...) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
276 * Logs the passed arguments if debug enabled |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
277 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
278 History.debug = function(){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
279 if ( (History.options.debug||false) ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
280 History.log.apply(History,arguments); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
281 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
282 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
283 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
284 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
285 * History.log(message,...) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
286 * Logs the passed arguments |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
287 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
288 History.log = function(){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
289 // Prepare |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
290 var |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
291 consoleExists = !(typeof console === 'undefined' || typeof console.log === 'undefined' || typeof console.log.apply === 'undefined'), |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
292 textarea = document.getElementById('log'), |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
293 message, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
294 i,n |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
295 ; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
296 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
297 // Write to Console |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
298 if ( consoleExists ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
299 var args = Array.prototype.slice.call(arguments); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
300 message = args.shift(); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
301 if ( typeof console.debug !== 'undefined' ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
302 console.debug.apply(console,[message,args]); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
303 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
304 else { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
305 console.log.apply(console,[message,args]); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
306 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
307 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
308 else { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
309 message = ("\n"+arguments[0]+"\n"); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
310 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
311 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
312 // Write to log |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
313 for ( i=1,n=arguments.length; i<n; ++i ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
314 var arg = arguments[i]; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
315 if ( typeof arg === 'object' && typeof JSON !== 'undefined' ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
316 try { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
317 arg = JSON.stringify(arg); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
318 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
319 catch ( Exception ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
320 // Recursive Object |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
321 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
322 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
323 message += "\n"+arg+"\n"; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
324 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
325 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
326 // Textarea |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
327 if ( textarea ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
328 textarea.value += message+"\n-----\n"; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
329 textarea.scrollTop = textarea.scrollHeight - textarea.clientHeight; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
330 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
331 // No Textarea, No Console |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
332 else if ( !consoleExists ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
333 alert(message); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
334 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
335 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
336 // Return true |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
337 return true; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
338 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
339 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
340 // ---------------------------------------------------------------------- |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
341 // Emulated Status |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
342 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
343 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
344 * History.getInternetExplorerMajorVersion() |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
345 * Get's the major version of Internet Explorer |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
346 * @return {integer} |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
347 * @license Public Domain |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
348 * @author Benjamin Arthur Lupton <contact@balupton.com> |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
349 * @author James Padolsey <https://gist.github.com/527683> |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
350 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
351 History.getInternetExplorerMajorVersion = function(){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
352 var result = History.getInternetExplorerMajorVersion.cached = |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
353 (typeof History.getInternetExplorerMajorVersion.cached !== 'undefined') |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
354 ? History.getInternetExplorerMajorVersion.cached |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
355 : (function(){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
356 var v = 3, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
357 div = document.createElement('div'), |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
358 all = div.getElementsByTagName('i'); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
359 while ( (div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->') && all[0] ) {} |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
360 return (v > 4) ? v : false; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
361 })() |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
362 ; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
363 return result; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
364 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
365 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
366 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
367 * History.isInternetExplorer() |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
368 * Are we using Internet Explorer? |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
369 * @return {boolean} |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
370 * @license Public Domain |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
371 * @author Benjamin Arthur Lupton <contact@balupton.com> |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
372 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
373 History.isInternetExplorer = function(){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
374 var result = |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
375 History.isInternetExplorer.cached = |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
376 (typeof History.isInternetExplorer.cached !== 'undefined') |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
377 ? History.isInternetExplorer.cached |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
378 : Boolean(History.getInternetExplorerMajorVersion()) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
379 ; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
380 return result; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
381 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
382 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
383 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
384 * History.emulated |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
385 * Which features require emulating? |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
386 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
387 History.emulated = { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
388 pushState: !Boolean( |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
389 window.history && window.history.pushState && window.history.replaceState |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
390 && !( |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
391 (/ Mobile\/([1-7][a-z]|(8([abcde]|f(1[0-8]))))/i).test(navigator.userAgent) /* disable for versions of iOS before version 4.3 (8F190) */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
392 || (/AppleWebKit\/5([0-2]|3[0-2])/i).test(navigator.userAgent) /* disable for the mercury iOS browser, or at least older versions of the webkit engine */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
393 ) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
394 ), |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
395 hashChange: Boolean( |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
396 !(('onhashchange' in window) || ('onhashchange' in document)) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
397 || |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
398 (History.isInternetExplorer() && History.getInternetExplorerMajorVersion() < 8) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
399 ) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
400 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
401 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
402 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
403 * History.enabled |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
404 * Is History enabled? |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
405 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
406 History.enabled = !History.emulated.pushState; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
407 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
408 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
409 * History.bugs |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
410 * Which bugs are present |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
411 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
412 History.bugs = { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
413 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
414 * Safari 5 and Safari iOS 4 fail to return to the correct state once a hash is replaced by a `replaceState` call |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
415 * https://bugs.webkit.org/show_bug.cgi?id=56249 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
416 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
417 setHash: Boolean(!History.emulated.pushState && navigator.vendor === 'Apple Computer, Inc.' && /AppleWebKit\/5([0-2]|3[0-3])/.test(navigator.userAgent)), |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
418 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
419 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
420 * Safari 5 and Safari iOS 4 sometimes fail to apply the state change under busy conditions |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
421 * https://bugs.webkit.org/show_bug.cgi?id=42940 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
422 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
423 safariPoll: Boolean(!History.emulated.pushState && navigator.vendor === 'Apple Computer, Inc.' && /AppleWebKit\/5([0-2]|3[0-3])/.test(navigator.userAgent)), |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
424 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
425 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
426 * MSIE 6 and 7 sometimes do not apply a hash even it was told to (requiring a second call to the apply function) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
427 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
428 ieDoubleCheck: Boolean(History.isInternetExplorer() && History.getInternetExplorerMajorVersion() < 8), |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
429 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
430 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
431 * MSIE 6 requires the entire hash to be encoded for the hashes to trigger the onHashChange event |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
432 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
433 hashEscape: Boolean(History.isInternetExplorer() && History.getInternetExplorerMajorVersion() < 7) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
434 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
435 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
436 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
437 * History.isEmptyObject(obj) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
438 * Checks to see if the Object is Empty |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
439 * @param {Object} obj |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
440 * @return {boolean} |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
441 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
442 History.isEmptyObject = function(obj) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
443 for ( var name in obj ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
444 return false; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
445 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
446 return true; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
447 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
448 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
449 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
450 * History.cloneObject(obj) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
451 * Clones a object |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
452 * @param {Object} obj |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
453 * @return {Object} |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
454 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
455 History.cloneObject = function(obj) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
456 var hash,newObj; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
457 if ( obj ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
458 hash = JSON.stringify(obj); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
459 newObj = JSON.parse(hash); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
460 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
461 else { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
462 newObj = {}; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
463 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
464 return newObj; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
465 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
466 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
467 // ---------------------------------------------------------------------- |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
468 // URL Helpers |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
469 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
470 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
471 * History.getRootUrl() |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
472 * Turns "http://mysite.com/dir/page.html?asd" into "http://mysite.com" |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
473 * @return {String} rootUrl |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
474 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
475 History.getRootUrl = function(){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
476 // Create |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
477 var rootUrl = document.location.protocol+'//'+(document.location.hostname||document.location.host); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
478 if ( document.location.port||false ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
479 rootUrl += ':'+document.location.port; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
480 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
481 rootUrl += '/'; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
482 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
483 // Return |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
484 return rootUrl; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
485 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
486 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
487 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
488 * History.getBaseHref() |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
489 * Fetches the `href` attribute of the `<base href="...">` element if it exists |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
490 * @return {String} baseHref |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
491 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
492 History.getBaseHref = function(){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
493 // Create |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
494 var |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
495 baseElements = document.getElementsByTagName('base'), |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
496 baseElement = null, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
497 baseHref = ''; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
498 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
499 // Test for Base Element |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
500 if ( baseElements.length === 1 ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
501 // Prepare for Base Element |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
502 baseElement = baseElements[0]; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
503 baseHref = baseElement.href.replace(/[^\/]+$/,''); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
504 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
505 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
506 // Adjust trailing slash |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
507 baseHref = baseHref.replace(/\/+$/,''); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
508 if ( baseHref ) baseHref += '/'; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
509 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
510 // Return |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
511 return baseHref; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
512 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
513 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
514 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
515 * History.getBaseUrl() |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
516 * Fetches the baseHref or basePageUrl or rootUrl (whichever one exists first) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
517 * @return {String} baseUrl |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
518 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
519 History.getBaseUrl = function(){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
520 // Create |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
521 var baseUrl = History.getBaseHref()||History.getBasePageUrl()||History.getRootUrl(); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
522 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
523 // Return |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
524 return baseUrl; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
525 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
526 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
527 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
528 * History.getPageUrl() |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
529 * Fetches the URL of the current page |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
530 * @return {String} pageUrl |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
531 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
532 History.getPageUrl = function(){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
533 // Fetch |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
534 var |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
535 State = History.getState(false,false), |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
536 stateUrl = (State||{}).url||document.URL||document.location.href; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
537 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
538 // Create |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
539 var pageUrl = stateUrl.replace(/\/+$/,'').replace(/[^\/]+$/,function(part,index,string){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
540 return (/\./).test(part) ? part : part+'/'; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
541 }); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
542 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
543 // Return |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
544 return pageUrl; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
545 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
546 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
547 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
548 * History.getBasePageUrl() |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
549 * Fetches the Url of the directory of the current page |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
550 * @return {String} basePageUrl |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
551 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
552 History.getBasePageUrl = function(){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
553 // Create |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
554 var basePageUrl = (document.URL||document.location.href).replace(/[#\?].*/,'').replace(/[^\/]+$/,function(part,index,string){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
555 return (/[^\/]$/).test(part) ? '' : part; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
556 }).replace(/\/+$/,'')+'/'; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
557 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
558 // Return |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
559 return basePageUrl; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
560 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
561 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
562 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
563 * History.getFullUrl(url) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
564 * Ensures that we have an absolute URL and not a relative URL |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
565 * @param {string} url |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
566 * @param {Boolean} allowBaseHref |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
567 * @return {string} fullUrl |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
568 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
569 History.getFullUrl = function(url,allowBaseHref){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
570 // Prepare |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
571 var fullUrl = url, firstChar = url.substring(0,1); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
572 allowBaseHref = (typeof allowBaseHref === 'undefined') ? true : allowBaseHref; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
573 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
574 // Check |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
575 if ( /[a-z]+\:\/\//.test(url) ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
576 // Full URL |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
577 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
578 else if ( firstChar === '/' ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
579 // Root URL |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
580 fullUrl = History.getRootUrl()+url.replace(/^\/+/,''); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
581 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
582 else if ( firstChar === '#' ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
583 // Anchor URL |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
584 fullUrl = History.getPageUrl().replace(/#.*/,'')+url; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
585 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
586 else if ( firstChar === '?' ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
587 // Query URL |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
588 fullUrl = History.getPageUrl().replace(/[\?#].*/,'')+url; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
589 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
590 else { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
591 // Relative URL |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
592 if ( allowBaseHref ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
593 fullUrl = History.getBaseUrl()+url.replace(/^(\.\/)+/,''); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
594 } else { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
595 fullUrl = History.getBasePageUrl()+url.replace(/^(\.\/)+/,''); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
596 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
597 // We have an if condition above as we do not want hashes |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
598 // which are relative to the baseHref in our URLs |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
599 // as if the baseHref changes, then all our bookmarks |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
600 // would now point to different locations |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
601 // whereas the basePageUrl will always stay the same |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
602 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
603 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
604 // Return |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
605 return fullUrl.replace(/\#$/,''); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
606 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
607 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
608 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
609 * History.getShortUrl(url) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
610 * Ensures that we have a relative URL and not a absolute URL |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
611 * @param {string} url |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
612 * @return {string} url |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
613 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
614 History.getShortUrl = function(url){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
615 // Prepare |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
616 var shortUrl = url, baseUrl = History.getBaseUrl(), rootUrl = History.getRootUrl(); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
617 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
618 // Trim baseUrl |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
619 if ( History.emulated.pushState ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
620 // We are in a if statement as when pushState is not emulated |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
621 // The actual url these short urls are relative to can change |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
622 // So within the same session, we the url may end up somewhere different |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
623 shortUrl = shortUrl.replace(baseUrl,''); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
624 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
625 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
626 // Trim rootUrl |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
627 shortUrl = shortUrl.replace(rootUrl,'/'); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
628 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
629 // Ensure we can still detect it as a state |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
630 if ( History.isTraditionalAnchor(shortUrl) ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
631 shortUrl = './'+shortUrl; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
632 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
633 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
634 // Clean It |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
635 shortUrl = shortUrl.replace(/^(\.\/)+/g,'./').replace(/\#$/,''); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
636 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
637 // Return |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
638 return shortUrl; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
639 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
640 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
641 // ---------------------------------------------------------------------- |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
642 // State Storage |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
643 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
644 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
645 * History.store |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
646 * The store for all session specific data |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
647 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
648 History.store = amplify ? (amplify.store('History.store')||{}) : {}; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
649 History.store.idToState = History.store.idToState||{}; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
650 History.store.urlToId = History.store.urlToId||{}; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
651 History.store.stateToId = History.store.stateToId||{}; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
652 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
653 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
654 * History.idToState |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
655 * 1-1: State ID to State Object |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
656 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
657 History.idToState = History.idToState||{}; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
658 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
659 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
660 * History.stateToId |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
661 * 1-1: State String to State ID |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
662 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
663 History.stateToId = History.stateToId||{}; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
664 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
665 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
666 * History.urlToId |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
667 * 1-1: State URL to State ID |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
668 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
669 History.urlToId = History.urlToId||{}; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
670 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
671 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
672 * History.storedStates |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
673 * Store the states in an array |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
674 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
675 History.storedStates = History.storedStates||[]; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
676 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
677 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
678 * History.savedStates |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
679 * Saved the states in an array |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
680 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
681 History.savedStates = History.savedStates||[]; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
682 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
683 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
684 * History.getState() |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
685 * Get an object containing the data, title and url of the current state |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
686 * @param {Boolean} friendly |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
687 * @param {Boolean} create |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
688 * @return {Object} State |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
689 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
690 History.getState = function(friendly,create){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
691 // Prepare |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
692 if ( typeof friendly === 'undefined' ) { friendly = true; } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
693 if ( typeof create === 'undefined' ) { create = true; } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
694 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
695 // Fetch |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
696 var State = History.getLastSavedState(); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
697 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
698 // Create |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
699 if ( !State && create ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
700 State = History.createStateObject(); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
701 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
702 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
703 // Adjust |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
704 if ( friendly ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
705 State = History.cloneObject(State); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
706 State.url = State.cleanUrl||State.url; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
707 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
708 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
709 // Return |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
710 return State; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
711 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
712 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
713 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
714 * History.getIdByState(State) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
715 * Gets a ID for a State |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
716 * @param {State} newState |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
717 * @return {String} id |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
718 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
719 History.getIdByState = function(newState){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
720 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
721 // Fetch ID |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
722 var id = History.extractId(newState.url); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
723 if ( !id ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
724 // Find ID via State String |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
725 var str = History.getStateString(newState); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
726 if ( typeof History.stateToId[str] !== 'undefined' ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
727 id = History.stateToId[str]; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
728 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
729 else if ( typeof History.store.stateToId[str] !== 'undefined' ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
730 id = History.store.stateToId[str]; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
731 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
732 else { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
733 // Generate a new ID |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
734 while ( true ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
735 id = String(Math.floor(Math.random()*1000)); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
736 if ( typeof History.idToState[id] === 'undefined' && typeof History.store.idToState[id] === 'undefined' ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
737 break; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
738 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
739 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
740 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
741 // Apply the new State to the ID |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
742 History.stateToId[str] = id; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
743 History.idToState[id] = newState; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
744 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
745 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
746 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
747 // Return ID |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
748 return id; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
749 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
750 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
751 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
752 * History.normalizeState(State) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
753 * Expands a State Object |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
754 * @param {object} State |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
755 * @return {object} |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
756 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
757 History.normalizeState = function(oldState){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
758 // Prepare |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
759 if ( !oldState || (typeof oldState !== 'object') ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
760 oldState = {}; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
761 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
762 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
763 // Check |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
764 if ( typeof oldState.normalized !== 'undefined' ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
765 return oldState; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
766 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
767 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
768 // Adjust |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
769 if ( !oldState.data || (typeof oldState.data !== 'object') ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
770 oldState.data = {}; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
771 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
772 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
773 // ---------------------------------------------------------------------- |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
774 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
775 // Create |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
776 var newState = {}; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
777 newState.normalized = true; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
778 newState.title = oldState.title||''; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
779 newState.url = History.getFullUrl(oldState.url?decodeURIComponent(oldState.url):(document.URL||document.location.href)); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
780 newState.hash = History.getShortUrl(newState.url); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
781 newState.data = History.cloneObject(oldState.data); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
782 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
783 // Fetch ID |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
784 newState.id = History.getIdByState(newState); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
785 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
786 // ---------------------------------------------------------------------- |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
787 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
788 // Clean the URL |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
789 newState.cleanUrl = newState.url.replace(/\??\&_suid.*/,''); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
790 newState.url = newState.cleanUrl; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
791 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
792 // Check to see if we have more than just a url |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
793 var dataNotEmpty = !History.isEmptyObject(newState.data); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
794 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
795 // Apply |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
796 if ( newState.title || dataNotEmpty ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
797 // Add ID to Hash |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
798 newState.hash = History.getShortUrl(newState.url).replace(/\??\&_suid.*/,''); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
799 if ( !/\?/.test(newState.hash) ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
800 newState.hash += '?'; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
801 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
802 newState.hash += '&_suid='+newState.id; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
803 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
804 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
805 // Create the Hashed URL |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
806 newState.hashedUrl = History.getFullUrl(newState.hash); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
807 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
808 // ---------------------------------------------------------------------- |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
809 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
810 // Update the URL if we have a duplicate |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
811 if ( (History.emulated.pushState || History.bugs.safariPoll) && History.hasUrlDuplicate(newState) ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
812 newState.url = newState.hashedUrl; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
813 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
814 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
815 // ---------------------------------------------------------------------- |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
816 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
817 // Return |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
818 return newState; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
819 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
820 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
821 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
822 * History.createStateObject(data,title,url) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
823 * Creates a object based on the data, title and url state params |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
824 * @param {object} data |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
825 * @param {string} title |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
826 * @param {string} url |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
827 * @return {object} |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
828 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
829 History.createStateObject = function(data,title,url){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
830 // Hashify |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
831 var State = { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
832 'data': data, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
833 'title': title, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
834 'url': encodeURIComponent(url||"") |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
835 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
836 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
837 // Expand the State |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
838 State = History.normalizeState(State); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
839 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
840 // Return object |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
841 return State; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
842 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
843 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
844 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
845 * History.getStateById(id) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
846 * Get a state by it's UID |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
847 * @param {String} id |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
848 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
849 History.getStateById = function(id){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
850 // Prepare |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
851 id = String(id); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
852 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
853 // Retrieve |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
854 var State = History.idToState[id] || History.store.idToState[id] || undefined; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
855 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
856 // Return State |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
857 return State; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
858 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
859 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
860 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
861 * Get a State's String |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
862 * @param {State} passedState |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
863 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
864 History.getStateString = function(passedState){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
865 // Prepare |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
866 var State = History.normalizeState(passedState); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
867 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
868 // Clean |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
869 var cleanedState = { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
870 data: State.data, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
871 title: passedState.title, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
872 url: passedState.url |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
873 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
874 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
875 // Fetch |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
876 var str = JSON.stringify(cleanedState); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
877 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
878 // Return |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
879 return str; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
880 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
881 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
882 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
883 * Get a State's ID |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
884 * @param {State} passedState |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
885 * @return {String} id |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
886 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
887 History.getStateId = function(passedState){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
888 // Prepare |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
889 var State = History.normalizeState(passedState); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
890 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
891 // Fetch |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
892 var id = State.id; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
893 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
894 // Return |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
895 return id; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
896 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
897 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
898 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
899 * History.getHashByState(State) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
900 * Creates a Hash for the State Object |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
901 * @param {State} passedState |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
902 * @return {String} hash |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
903 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
904 History.getHashByState = function(passedState){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
905 // Prepare |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
906 var hash, State = History.normalizeState(passedState); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
907 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
908 // Fetch |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
909 hash = State.hash; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
910 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
911 // Return |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
912 return hash; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
913 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
914 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
915 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
916 * History.extractId(url_or_hash) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
917 * Get a State ID by it's URL or Hash |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
918 * @param {string} url_or_hash |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
919 * @return {string} id |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
920 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
921 History.extractId = function ( url_or_hash ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
922 // Prepare |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
923 var id; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
924 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
925 // Extract |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
926 var parts,url; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
927 parts = /(.*)\&_suid=([0-9]+)$/.exec(url_or_hash); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
928 url = parts ? (parts[1]||url_or_hash) : url_or_hash; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
929 id = parts ? String(parts[2]||'') : ''; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
930 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
931 // Return |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
932 return id||false; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
933 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
934 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
935 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
936 * History.isTraditionalAnchor |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
937 * Checks to see if the url is a traditional anchor or not |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
938 * @param {String} url_or_hash |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
939 * @return {Boolean} |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
940 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
941 History.isTraditionalAnchor = function(url_or_hash){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
942 // Check |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
943 var isTraditional = !(/[\/\?\.]/.test(url_or_hash)); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
944 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
945 // Return |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
946 return isTraditional; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
947 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
948 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
949 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
950 * History.extractState |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
951 * Get a State by it's URL or Hash |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
952 * @param {String} url_or_hash |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
953 * @return {State|null} |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
954 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
955 History.extractState = function(url_or_hash,create){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
956 // Prepare |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
957 var State = null; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
958 create = create||false; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
959 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
960 // Fetch SUID |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
961 var id = History.extractId(url_or_hash); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
962 if ( id ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
963 State = History.getStateById(id); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
964 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
965 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
966 // Fetch SUID returned no State |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
967 if ( !State ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
968 // Fetch URL |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
969 var url = History.getFullUrl(url_or_hash); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
970 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
971 // Check URL |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
972 id = History.getIdByUrl(url)||false; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
973 if ( id ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
974 State = History.getStateById(id); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
975 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
976 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
977 // Create State |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
978 if ( !State && create && !History.isTraditionalAnchor(url_or_hash) ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
979 State = History.createStateObject(null,null,url); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
980 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
981 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
982 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
983 // Return |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
984 return State; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
985 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
986 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
987 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
988 * History.getIdByUrl() |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
989 * Get a State ID by a State URL |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
990 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
991 History.getIdByUrl = function(url){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
992 // Fetch |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
993 var id = History.urlToId[url] || History.store.urlToId[url] || undefined; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
994 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
995 // Return |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
996 return id; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
997 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
998 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
999 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1000 * History.getLastSavedState() |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1001 * Get an object containing the data, title and url of the current state |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1002 * @return {Object} State |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1003 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1004 History.getLastSavedState = function(){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1005 return History.savedStates[History.savedStates.length-1]||undefined; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1006 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1007 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1008 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1009 * History.getLastStoredState() |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1010 * Get an object containing the data, title and url of the current state |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1011 * @return {Object} State |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1012 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1013 History.getLastStoredState = function(){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1014 return History.storedStates[History.storedStates.length-1]||undefined; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1015 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1016 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1017 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1018 * History.hasUrlDuplicate |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1019 * Checks if a Url will have a url conflict |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1020 * @param {Object} newState |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1021 * @return {Boolean} hasDuplicate |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1022 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1023 History.hasUrlDuplicate = function(newState) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1024 // Prepare |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1025 var hasDuplicate = false; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1026 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1027 // Fetch |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1028 var oldState = History.extractState(newState.url); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1029 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1030 // Check |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1031 hasDuplicate = oldState && oldState.id !== newState.id; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1032 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1033 // Return |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1034 return hasDuplicate; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1035 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1036 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1037 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1038 * History.storeState |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1039 * Store a State |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1040 * @param {Object} newState |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1041 * @return {Object} newState |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1042 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1043 History.storeState = function(newState){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1044 // Store the State |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1045 History.urlToId[newState.url] = newState.id; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1046 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1047 // Push the State |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1048 History.storedStates.push(History.cloneObject(newState)); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1049 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1050 // Return newState |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1051 return newState; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1052 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1053 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1054 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1055 * History.isLastSavedState(newState) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1056 * Tests to see if the state is the last state |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1057 * @param {Object} newState |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1058 * @return {boolean} isLast |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1059 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1060 History.isLastSavedState = function(newState){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1061 // Prepare |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1062 var isLast = false; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1063 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1064 // Check |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1065 if ( History.savedStates.length ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1066 var |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1067 newId = newState.id, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1068 oldState = History.getLastSavedState(), |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1069 oldId = oldState.id; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1070 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1071 // Check |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1072 isLast = (newId === oldId); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1073 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1074 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1075 // Return |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1076 return isLast; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1077 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1078 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1079 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1080 * History.saveState |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1081 * Push a State |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1082 * @param {Object} newState |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1083 * @return {boolean} changed |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1084 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1085 History.saveState = function(newState){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1086 // Check Hash |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1087 if ( History.isLastSavedState(newState) ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1088 return false; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1089 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1090 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1091 // Push the State |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1092 History.savedStates.push(History.cloneObject(newState)); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1093 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1094 // Return true |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1095 return true; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1096 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1097 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1098 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1099 * History.getStateByIndex() |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1100 * Gets a state by the index |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1101 * @param {integer} index |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1102 * @return {Object} |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1103 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1104 History.getStateByIndex = function(index){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1105 // Prepare |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1106 var State = null; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1107 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1108 // Handle |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1109 if ( typeof index === 'undefined' ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1110 // Get the last inserted |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1111 State = History.savedStates[History.savedStates.length-1]; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1112 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1113 else if ( index < 0 ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1114 // Get from the end |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1115 State = History.savedStates[History.savedStates.length+index]; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1116 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1117 else { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1118 // Get from the beginning |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1119 State = History.savedStates[index]; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1120 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1121 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1122 // Return State |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1123 return State; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1124 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1125 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1126 // ---------------------------------------------------------------------- |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1127 // Hash Helpers |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1128 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1129 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1130 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1131 * History.escapeString() |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1132 * Escape a string |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1133 * @param {String} str |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1134 * @return {string} |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1135 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1136 History.escapeString = function(str){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1137 return encodeURI(url).replace(/%25/g, "%", "g"); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1138 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1139 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1140 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1141 * History.getHash() |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1142 * @param {Location=} location |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1143 * Gets the current document hash |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1144 * Note: unlike location.hash, this is guaranteed to return the escaped hash in all browsers |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1145 * @return {string} |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1146 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1147 History.getHash = function(location){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1148 if ( !location ) location = document.location; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1149 var href = location.href.replace( /^[^#]*/, "" ); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1150 return href.substr(1); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1151 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1152 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1153 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1154 * History.unescapeHash() |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1155 * normalize and Unescape a Hash |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1156 * @param {String} hash |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1157 * @return {string} |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1158 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1159 History.unescapeHash = function(hash){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1160 // Prepare |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1161 var result = History.normalizeHash(hash); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1162 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1163 // Unescape hash |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1164 result = decodeURIComponent(result); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1165 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1166 // Return result |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1167 return result; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1168 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1169 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1170 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1171 * History.normalizeHash() |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1172 * normalize a hash across browsers |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1173 * @return {string} |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1174 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1175 History.normalizeHash = function(hash){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1176 var result = hash.replace(/[^#]*#/,'').replace(/#.*/, ''); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1177 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1178 // Return result |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1179 return result; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1180 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1181 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1182 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1183 * History.setHash(hash) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1184 * Sets the document hash |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1185 * @param {string} hash |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1186 * @return {History} |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1187 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1188 History.setHash = function(hash,queue){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1189 // Handle Queueing |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1190 if ( queue !== false && History.busy() ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1191 // Wait + Push to Queue |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1192 //History.debug('History.setHash: we must wait', arguments); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1193 History.pushQueue({ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1194 scope: History, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1195 callback: History.setHash, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1196 args: arguments, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1197 queue: queue |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1198 }); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1199 return false; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1200 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1201 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1202 // Log |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1203 //History.debug('History.setHash: called',hash); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1204 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1205 // Make Busy + Continue |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1206 History.busy(true); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1207 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1208 // Check if hash is a state |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1209 var State = History.extractState(hash,true); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1210 if ( State && !History.emulated.pushState ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1211 // Hash is a state so skip the setHash |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1212 //History.debug('History.setHash: Hash is a state so skipping the hash set with a direct pushState call',arguments); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1213 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1214 // PushState |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1215 History.pushState(State.data,State.title,State.url,false); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1216 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1217 else if ( History.getHash() !== hash ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1218 // Hash is a proper hash, so apply it |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1219 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1220 // Handle browser bugs |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1221 if ( History.bugs.setHash ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1222 // Fix Safari Bug https://bugs.webkit.org/show_bug.cgi?id=56249 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1223 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1224 // Fetch the base page |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1225 var pageUrl = History.getPageUrl(); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1226 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1227 // Safari hash apply |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1228 History.pushState(null,null,pageUrl+'#'+hash,false); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1229 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1230 else { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1231 // Normal hash apply |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1232 document.location.hash = hash; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1233 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1234 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1235 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1236 // Chain |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1237 return History; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1238 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1239 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1240 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1241 * History.escape() |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1242 * normalize and Escape a Hash |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1243 * @return {string} |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1244 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1245 History.escapeHash = function(hash){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1246 var result = History.normalizeHash(hash); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1247 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1248 // Escape hash |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1249 result = window.encodeURIComponent(result); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1250 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1251 // IE6 Escape Bug |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1252 if ( !History.bugs.hashEscape ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1253 // Restore common parts |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1254 result = result |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1255 .replace(/\%21/g,'!') |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1256 .replace(/\%26/g,'&') |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1257 .replace(/\%3D/g,'=') |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1258 .replace(/\%3F/g,'?'); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1259 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1260 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1261 // Return result |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1262 return result; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1263 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1264 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1265 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1266 * History.getHashByUrl(url) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1267 * Extracts the Hash from a URL |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1268 * @param {string} url |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1269 * @return {string} url |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1270 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1271 History.getHashByUrl = function(url){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1272 // Extract the hash |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1273 var hash = String(url) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1274 .replace(/([^#]*)#?([^#]*)#?(.*)/, '$2') |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1275 ; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1276 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1277 // Unescape hash |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1278 hash = History.unescapeHash(hash); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1279 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1280 // Return hash |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1281 return hash; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1282 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1283 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1284 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1285 * History.setTitle(title) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1286 * Applies the title to the document |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1287 * @param {State} newState |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1288 * @return {Boolean} |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1289 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1290 History.setTitle = function(newState){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1291 // Prepare |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1292 var title = newState.title; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1293 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1294 // Initial |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1295 if ( !title ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1296 var firstState = History.getStateByIndex(0); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1297 if ( firstState && firstState.url === newState.url ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1298 title = firstState.title||History.options.initialTitle; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1299 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1300 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1301 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1302 // Apply |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1303 try { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1304 document.getElementsByTagName('title')[0].innerHTML = title.replace('<','<').replace('>','>').replace(' & ',' & '); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1305 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1306 catch ( Exception ) { } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1307 document.title = title; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1308 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1309 // Chain |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1310 return History; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1311 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1312 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1313 // ---------------------------------------------------------------------- |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1314 // Queueing |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1315 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1316 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1317 * History.queues |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1318 * The list of queues to use |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1319 * First In, First Out |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1320 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1321 History.queues = []; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1322 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1323 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1324 * History.busy(value) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1325 * @param {boolean} value [optional] |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1326 * @return {boolean} busy |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1327 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1328 History.busy = function(value){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1329 // Apply |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1330 if ( typeof value !== 'undefined' ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1331 //History.debug('History.busy: changing ['+(History.busy.flag||false)+'] to ['+(value||false)+']', History.queues.length); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1332 History.busy.flag = value; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1333 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1334 // Default |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1335 else if ( typeof History.busy.flag === 'undefined' ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1336 History.busy.flag = false; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1337 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1338 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1339 // Queue |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1340 if ( !History.busy.flag ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1341 // Execute the next item in the queue |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1342 clearTimeout(History.busy.timeout); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1343 var fireNext = function(){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1344 if ( History.busy.flag ) return; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1345 for ( var i=History.queues.length-1; i >= 0; --i ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1346 var queue = History.queues[i]; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1347 if ( queue.length === 0 ) continue; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1348 var item = queue.shift(); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1349 History.fireQueueItem(item); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1350 History.busy.timeout = setTimeout(fireNext,History.options.busyDelay); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1351 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1352 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1353 History.busy.timeout = setTimeout(fireNext,History.options.busyDelay); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1354 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1355 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1356 // Return |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1357 return History.busy.flag; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1358 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1359 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1360 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1361 * History.fireQueueItem(item) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1362 * Fire a Queue Item |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1363 * @param {Object} item |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1364 * @return {Mixed} result |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1365 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1366 History.fireQueueItem = function(item){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1367 return item.callback.apply(item.scope||History,item.args||[]); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1368 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1369 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1370 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1371 * History.pushQueue(callback,args) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1372 * Add an item to the queue |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1373 * @param {Object} item [scope,callback,args,queue] |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1374 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1375 History.pushQueue = function(item){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1376 // Prepare the queue |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1377 History.queues[item.queue||0] = History.queues[item.queue||0]||[]; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1378 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1379 // Add to the queue |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1380 History.queues[item.queue||0].push(item); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1381 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1382 // Chain |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1383 return History; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1384 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1385 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1386 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1387 * History.queue (item,queue), (func,queue), (func), (item) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1388 * Either firs the item now if not busy, or adds it to the queue |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1389 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1390 History.queue = function(item,queue){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1391 // Prepare |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1392 if ( typeof item === 'function' ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1393 item = { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1394 callback: item |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1395 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1396 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1397 if ( typeof queue !== 'undefined' ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1398 item.queue = queue; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1399 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1400 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1401 // Handle |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1402 if ( History.busy() ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1403 History.pushQueue(item); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1404 } else { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1405 History.fireQueueItem(item); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1406 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1407 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1408 // Chain |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1409 return History; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1410 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1411 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1412 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1413 * History.clearQueue() |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1414 * Clears the Queue |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1415 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1416 History.clearQueue = function(){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1417 History.busy.flag = false; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1418 History.queues = []; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1419 return History; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1420 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1421 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1422 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1423 // ---------------------------------------------------------------------- |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1424 // IE Bug Fix |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1425 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1426 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1427 * History.stateChanged |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1428 * States whether or not the state has changed since the last double check was initialised |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1429 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1430 History.stateChanged = false; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1431 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1432 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1433 * History.doubleChecker |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1434 * Contains the timeout used for the double checks |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1435 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1436 History.doubleChecker = false; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1437 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1438 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1439 * History.doubleCheckComplete() |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1440 * Complete a double check |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1441 * @return {History} |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1442 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1443 History.doubleCheckComplete = function(){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1444 // Update |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1445 History.stateChanged = true; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1446 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1447 // Clear |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1448 History.doubleCheckClear(); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1449 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1450 // Chain |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1451 return History; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1452 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1453 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1454 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1455 * History.doubleCheckClear() |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1456 * Clear a double check |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1457 * @return {History} |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1458 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1459 History.doubleCheckClear = function(){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1460 // Clear |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1461 if ( History.doubleChecker ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1462 clearTimeout(History.doubleChecker); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1463 History.doubleChecker = false; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1464 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1465 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1466 // Chain |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1467 return History; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1468 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1469 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1470 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1471 * History.doubleCheck() |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1472 * Create a double check |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1473 * @return {History} |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1474 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1475 History.doubleCheck = function(tryAgain){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1476 // Reset |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1477 History.stateChanged = false; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1478 History.doubleCheckClear(); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1479 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1480 // Fix IE6,IE7 bug where calling history.back or history.forward does not actually change the hash (whereas doing it manually does) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1481 // Fix Safari 5 bug where sometimes the state does not change: https://bugs.webkit.org/show_bug.cgi?id=42940 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1482 if ( History.bugs.ieDoubleCheck ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1483 // Apply Check |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1484 History.doubleChecker = setTimeout( |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1485 function(){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1486 History.doubleCheckClear(); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1487 if ( !History.stateChanged ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1488 //History.debug('History.doubleCheck: State has not yet changed, trying again', arguments); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1489 // Re-Attempt |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1490 tryAgain(); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1491 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1492 return true; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1493 }, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1494 History.options.doubleCheckInterval |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1495 ); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1496 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1497 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1498 // Chain |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1499 return History; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1500 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1501 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1502 // ---------------------------------------------------------------------- |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1503 // Safari Bug Fix |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1504 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1505 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1506 * History.safariStatePoll() |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1507 * Poll the current state |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1508 * @return {History} |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1509 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1510 History.safariStatePoll = function(){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1511 // Poll the URL |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1512 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1513 // Get the Last State which has the new URL |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1514 var |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1515 urlState = History.extractState(document.URL||document.location.href), |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1516 newState; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1517 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1518 // Check for a difference |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1519 if ( !History.isLastSavedState(urlState) ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1520 newState = urlState; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1521 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1522 else { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1523 return; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1524 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1525 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1526 // Check if we have a state with that url |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1527 // If not create it |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1528 if ( !newState ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1529 //History.debug('History.safariStatePoll: new'); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1530 newState = History.createStateObject(); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1531 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1532 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1533 // Apply the New State |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1534 //History.debug('History.safariStatePoll: trigger'); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1535 History.Adapter.trigger(window,'popstate'); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1536 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1537 // Chain |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1538 return History; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1539 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1540 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1541 // ---------------------------------------------------------------------- |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1542 // State Aliases |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1543 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1544 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1545 * History.back(queue) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1546 * Send the browser history back one item |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1547 * @param {Integer} queue [optional] |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1548 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1549 History.back = function(queue){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1550 //History.debug('History.back: called', arguments); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1551 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1552 // Handle Queueing |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1553 if ( queue !== false && History.busy() ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1554 // Wait + Push to Queue |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1555 //History.debug('History.back: we must wait', arguments); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1556 History.pushQueue({ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1557 scope: History, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1558 callback: History.back, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1559 args: arguments, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1560 queue: queue |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1561 }); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1562 return false; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1563 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1564 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1565 // Make Busy + Continue |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1566 History.busy(true); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1567 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1568 // Fix certain browser bugs that prevent the state from changing |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1569 History.doubleCheck(function(){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1570 History.back(false); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1571 }); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1572 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1573 // Go back |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1574 history.go(-1); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1575 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1576 // End back closure |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1577 return true; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1578 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1579 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1580 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1581 * History.forward(queue) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1582 * Send the browser history forward one item |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1583 * @param {Integer} queue [optional] |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1584 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1585 History.forward = function(queue){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1586 //History.debug('History.forward: called', arguments); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1587 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1588 // Handle Queueing |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1589 if ( queue !== false && History.busy() ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1590 // Wait + Push to Queue |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1591 //History.debug('History.forward: we must wait', arguments); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1592 History.pushQueue({ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1593 scope: History, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1594 callback: History.forward, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1595 args: arguments, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1596 queue: queue |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1597 }); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1598 return false; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1599 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1600 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1601 // Make Busy + Continue |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1602 History.busy(true); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1603 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1604 // Fix certain browser bugs that prevent the state from changing |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1605 History.doubleCheck(function(){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1606 History.forward(false); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1607 }); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1608 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1609 // Go forward |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1610 history.go(1); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1611 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1612 // End forward closure |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1613 return true; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1614 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1615 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1616 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1617 * History.go(index,queue) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1618 * Send the browser history back or forward index times |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1619 * @param {Integer} queue [optional] |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1620 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1621 History.go = function(index,queue){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1622 //History.debug('History.go: called', arguments); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1623 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1624 // Prepare |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1625 var i; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1626 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1627 // Handle |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1628 if ( index > 0 ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1629 // Forward |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1630 for ( i=1; i<=index; ++i ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1631 History.forward(queue); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1632 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1633 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1634 else if ( index < 0 ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1635 // Backward |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1636 for ( i=-1; i>=index; --i ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1637 History.back(queue); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1638 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1639 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1640 else { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1641 throw new Error('History.go: History.go requires a positive or negative integer passed.'); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1642 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1643 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1644 // Chain |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1645 return History; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1646 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1647 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1648 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1649 // ---------------------------------------------------------------------- |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1650 // Initialise |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1651 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1652 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1653 * Create the initial State |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1654 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1655 History.saveState(History.storeState(History.extractState(document.URL||document.location.href,true))); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1656 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1657 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1658 * Bind for Saving Store |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1659 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1660 if ( amplify ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1661 History.onUnload = function(){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1662 // Prepare |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1663 var |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1664 currentStore = amplify.store('History.store')||{}, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1665 item; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1666 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1667 // Ensure |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1668 currentStore.idToState = currentStore.idToState || {}; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1669 currentStore.urlToId = currentStore.urlToId || {}; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1670 currentStore.stateToId = currentStore.stateToId || {}; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1671 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1672 // Sync |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1673 for ( item in History.idToState ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1674 if ( !History.idToState.hasOwnProperty(item) ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1675 continue; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1676 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1677 currentStore.idToState[item] = History.idToState[item]; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1678 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1679 for ( item in History.urlToId ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1680 if ( !History.urlToId.hasOwnProperty(item) ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1681 continue; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1682 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1683 currentStore.urlToId[item] = History.urlToId[item]; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1684 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1685 for ( item in History.stateToId ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1686 if ( !History.stateToId.hasOwnProperty(item) ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1687 continue; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1688 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1689 currentStore.stateToId[item] = History.stateToId[item]; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1690 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1691 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1692 // Update |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1693 History.store = currentStore; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1694 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1695 // Store |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1696 amplify.store('History.store',currentStore); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1697 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1698 // For Internet Explorer |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1699 History.intervalList.push(setInterval(History.onUnload,History.options.storeInterval)); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1700 // For Other Browsers |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1701 History.Adapter.bind(window,'beforeunload',History.onUnload); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1702 History.Adapter.bind(window,'unload',History.onUnload); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1703 // Both are enabled for consistency |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1704 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1705 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1706 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1707 // ---------------------------------------------------------------------- |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1708 // HTML5 State Support |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1709 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1710 if ( History.emulated.pushState ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1711 /* |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1712 * Provide Skeleton for HTML4 Browsers |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1713 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1714 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1715 // Prepare |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1716 var emptyFunction = function(){}; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1717 History.pushState = History.pushState||emptyFunction; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1718 History.replaceState = History.replaceState||emptyFunction; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1719 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1720 else { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1721 /* |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1722 * Use native HTML5 History API Implementation |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1723 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1724 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1725 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1726 * History.onPopState(event,extra) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1727 * Refresh the Current State |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1728 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1729 History.onPopState = function(event){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1730 // Reset the double check |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1731 History.doubleCheckComplete(); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1732 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1733 // Check for a Hash, and handle apporiatly |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1734 var currentHash = History.getHash(); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1735 if ( currentHash ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1736 // Expand Hash |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1737 var currentState = History.extractState(currentHash||document.URL||document.location.href,true); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1738 if ( currentState ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1739 // We were able to parse it, it must be a State! |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1740 // Let's forward to replaceState |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1741 //History.debug('History.onPopState: state anchor', currentHash, currentState); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1742 History.replaceState(currentState.data, currentState.title, currentState.url, false); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1743 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1744 else { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1745 // Traditional Anchor |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1746 //History.debug('History.onPopState: traditional anchor', currentHash); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1747 History.Adapter.trigger(window,'anchorchange'); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1748 History.busy(false); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1749 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1750 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1751 // We don't care for hashes |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1752 History.expectedStateId = false; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1753 return false; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1754 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1755 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1756 // Prepare |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1757 var newState = false; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1758 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1759 // Prepare |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1760 event = event||{}; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1761 if ( typeof event.state === 'undefined' ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1762 // jQuery |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1763 if ( typeof event.originalEvent !== 'undefined' && typeof event.originalEvent.state !== 'undefined' ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1764 event.state = event.originalEvent.state||false; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1765 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1766 // MooTools |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1767 else if ( typeof event.event !== 'undefined' && typeof event.event.state !== 'undefined' ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1768 event.state = event.event.state||false; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1769 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1770 // Ensure |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1771 event.state = (event.state||false); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1772 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1773 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1774 // Fetch State |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1775 if ( event.state ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1776 // Vanilla: Back/forward button was used |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1777 newState = History.getStateById(event.state); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1778 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1779 else if ( History.expectedStateId ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1780 // Vanilla: A new state was pushed, and popstate was called manually |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1781 newState = History.getStateById(History.expectedStateId); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1782 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1783 else { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1784 // Initial State |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1785 newState = History.extractState(document.URL||document.location.href); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1786 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1787 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1788 // The State did not exist in our store |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1789 if ( !newState ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1790 // Regenerate the State |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1791 newState = History.createStateObject(null,null,document.URL||document.location.href); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1792 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1793 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1794 // Clean |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1795 History.expectedStateId = false; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1796 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1797 // Check if we are the same state |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1798 if ( History.isLastSavedState(newState) ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1799 // There has been no change (just the page's hash has finally propagated) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1800 //History.debug('History.onPopState: no change', newState, History.savedStates); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1801 History.busy(false); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1802 return false; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1803 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1804 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1805 // Store the State |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1806 History.storeState(newState); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1807 History.saveState(newState); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1808 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1809 // Force update of the title |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1810 History.setTitle(newState); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1811 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1812 // Fire Our Event |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1813 History.Adapter.trigger(window,'statechange'); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1814 History.busy(false); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1815 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1816 // Return true |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1817 return true; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1818 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1819 History.Adapter.bind(window,'popstate',History.onPopState); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1820 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1821 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1822 * History.pushState(data,title,url) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1823 * Add a new State to the history object, become it, and trigger onpopstate |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1824 * We have to trigger for HTML4 compatibility |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1825 * @param {object} data |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1826 * @param {string} title |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1827 * @param {string} url |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1828 * @return {true} |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1829 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1830 History.pushState = function(data,title,url,queue){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1831 //History.debug('History.pushState: called', arguments); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1832 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1833 // Check the State |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1834 if ( History.getHashByUrl(url) && History.emulated.pushState ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1835 throw new Error('History.js does not support states with fragement-identifiers (hashes/anchors).'); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1836 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1837 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1838 // Handle Queueing |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1839 if ( queue !== false && History.busy() ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1840 // Wait + Push to Queue |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1841 //History.debug('History.pushState: we must wait', arguments); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1842 History.pushQueue({ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1843 scope: History, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1844 callback: History.pushState, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1845 args: arguments, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1846 queue: queue |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1847 }); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1848 return false; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1849 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1850 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1851 // Make Busy + Continue |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1852 History.busy(true); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1853 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1854 // Create the newState |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1855 var newState = History.createStateObject(data,title,url); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1856 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1857 // Check it |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1858 if ( History.isLastSavedState(newState) ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1859 // Won't be a change |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1860 History.busy(false); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1861 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1862 else { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1863 // Store the newState |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1864 History.storeState(newState); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1865 History.expectedStateId = newState.id; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1866 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1867 // Push the newState |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1868 history.pushState(newState.id,newState.title,newState.url); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1869 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1870 // Fire HTML5 Event |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1871 History.Adapter.trigger(window,'popstate'); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1872 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1873 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1874 // End pushState closure |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1875 return true; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1876 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1877 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1878 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1879 * History.replaceState(data,title,url) |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1880 * Replace the State and trigger onpopstate |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1881 * We have to trigger for HTML4 compatibility |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1882 * @param {object} data |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1883 * @param {string} title |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1884 * @param {string} url |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1885 * @return {true} |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1886 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1887 History.replaceState = function(data,title,url,queue){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1888 //History.debug('History.replaceState: called', arguments); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1889 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1890 // Check the State |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1891 if ( History.getHashByUrl(url) && History.emulated.pushState ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1892 throw new Error('History.js does not support states with fragement-identifiers (hashes/anchors).'); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1893 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1894 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1895 // Handle Queueing |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1896 if ( queue !== false && History.busy() ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1897 // Wait + Push to Queue |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1898 //History.debug('History.replaceState: we must wait', arguments); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1899 History.pushQueue({ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1900 scope: History, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1901 callback: History.replaceState, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1902 args: arguments, |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1903 queue: queue |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1904 }); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1905 return false; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1906 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1907 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1908 // Make Busy + Continue |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1909 History.busy(true); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1910 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1911 // Create the newState |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1912 var newState = History.createStateObject(data,title,url); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1913 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1914 // Check it |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1915 if ( History.isLastSavedState(newState) ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1916 // Won't be a change |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1917 History.busy(false); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1918 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1919 else { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1920 // Store the newState |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1921 History.storeState(newState); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1922 History.expectedStateId = newState.id; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1923 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1924 // Push the newState |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1925 history.replaceState(newState.id,newState.title,newState.url); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1926 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1927 // Fire HTML5 Event |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1928 History.Adapter.trigger(window,'popstate'); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1929 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1930 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1931 // End replaceState closure |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1932 return true; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1933 }; |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1934 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1935 // Be aware, the following is only for native pushState implementations |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1936 // If you are wanting to include something for all browsers |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1937 // Then include it above this if block |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1938 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1939 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1940 * Setup Safari Fix |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1941 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1942 if ( History.bugs.safariPoll ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1943 History.intervalList.push(setInterval(History.safariStatePoll, History.options.safariPollInterval)); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1944 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1945 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1946 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1947 * Ensure Cross Browser Compatibility |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1948 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1949 if ( navigator.vendor === 'Apple Computer, Inc.' || (navigator.appCodeName||'') === 'Mozilla' ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1950 /** |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1951 * Fix Safari HashChange Issue |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1952 */ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1953 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1954 // Setup Alias |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1955 History.Adapter.bind(window,'hashchange',function(){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1956 History.Adapter.trigger(window,'popstate'); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1957 }); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1958 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1959 // Initialise Alias |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1960 if ( History.getHash() ) { |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1961 History.Adapter.onDomLoad(function(){ |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1962 History.Adapter.trigger(window,'hashchange'); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1963 }); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1964 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1965 } |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1966 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1967 } // !History.emulated.pushState |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1968 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1969 }; // History.initCore |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1970 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1971 // Try and Initialise History |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1972 History.init(); |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1973 |
16456e7b2231
Fixed url escaping issues in history.js
Marcin Kuzminski <marcin@python-works.com>
parents:
2691
diff
changeset
|
1974 })(window); |