Rev 385 | Rev 405 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 385 | Rev 399 | ||
---|---|---|---|
Line 23... | Line 23... | ||
23 | var popstate_running = false; |
23 | var popstate_running = false; |
24 | // DEFAULT_LANGUAGE will be set by oidplus.min.js.php |
24 | // DEFAULT_LANGUAGE will be set by oidplus.min.js.php |
25 | // language_messages will be set by oidplus.min.js.php |
25 | // language_messages will be set by oidplus.min.js.php |
26 | // language_tblprefix will be set by oidplus.min.js.php |
26 | // language_tblprefix will be set by oidplus.min.js.php |
27 | 27 | ||
- | 28 | var pageChangeCallbacks = []; |
|
- | 29 | var pageChangeRequestCallbacks = []; |
|
- | 30 | ||
28 | function isInternetExplorer() { |
31 | function isInternetExplorer() { |
29 | var ua = window.navigator.userAgent; |
32 | var ua = window.navigator.userAgent; |
30 | return ((ua.indexOf("MSIE ") > 0) || (ua.indexOf("Trident/") > 0)); |
33 | return ((ua.indexOf("MSIE ") > 0) || (ua.indexOf("Trident/") > 0)); |
31 | } |
34 | } |
32 | 35 | ||
Line 38... | Line 41... | ||
38 | } |
41 | } |
39 | return array; |
42 | return array; |
40 | }; |
43 | }; |
41 | 44 | ||
42 | String.prototype.htmlentities = function () { |
45 | String.prototype.htmlentities = function () { |
43 | return this.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'); |
46 | return this.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');//" |
44 | }; |
47 | }; |
45 | 48 | ||
46 | String.prototype.html_entity_decode = function () { |
49 | String.prototype.html_entity_decode = function () { |
47 | return $('<textarea />').html(this).text(); |
50 | return $('<textarea />').html(this).text(); |
48 | }; |
51 | }; |
Line 88... | Line 91... | ||
88 | : "ajax.php?action=tree_load"; |
91 | : "ajax.php?action=tree_load"; |
89 | } |
92 | } |
90 | 93 | ||
91 | function reloadContent() { |
94 | function reloadContent() { |
92 | // window.location.href = "?goto="+encodeURIComponent(current_node); |
95 | // window.location.href = "?goto="+encodeURIComponent(current_node); |
93 | openOidInPanel(current_node, false); |
96 | if (openOidInPanel(current_node, false)) { |
94 | $('#oidtree').jstree("refresh"); |
97 | $('#oidtree').jstree("refresh"); |
95 | } |
98 | } |
- | 99 | } |
|
96 | 100 | ||
97 | function x_rec(x_data, i) { |
101 | function x_rec(x_data, i) { |
98 | $('#oidtree').jstree('open_node', x_data[i], function(e, data) { |
102 | $('#oidtree').jstree('open_node', x_data[i], function(e, data) { |
99 | if (i+1 < x_data.length) { |
103 | if (i+1 < x_data.length) { |
100 | x_rec(x_data, i+1); |
104 | x_rec(x_data, i+1); |
Line 109... | Line 113... | ||
109 | } |
113 | } |
110 | } |
114 | } |
111 | }); |
115 | }); |
112 | } |
116 | } |
113 | 117 | ||
- | 118 | function performCloseQueryCB() { |
|
- | 119 | for (var i=0; i<pageChangeRequestCallbacks.length; i++) { |
|
- | 120 | if (!pageChangeRequestCallbacks[i][0](pageChangeRequestCallbacks[i][1])) return false; |
|
- | 121 | } |
|
- | 122 | pageChangeRequestCallbacks = []; |
|
- | 123 | return true; // may close |
|
- | 124 | } |
|
- | 125 | ||
- | 126 | function performCloseCB() { |
|
- | 127 | for (var i=0; i<pageChangeCallbacks.length; i++) { |
|
- | 128 | pageChangeCallbacks[i][0](pageChangeCallbacks[i][1]); |
|
- | 129 | } |
|
- | 130 | pageChangeCallbacks = []; |
|
- | 131 | } |
|
- | 132 | ||
114 | function openOidInPanel(id, reselect/*=false*/, anchor/*=''*/) { |
133 | function openOidInPanel(id, reselect/*=false*/, anchor/*=''*/, force/*=false*/) { |
115 | reselect = (typeof reselect === 'undefined') ? false : reselect; |
134 | reselect = (typeof reselect === 'undefined') ? false : reselect; |
116 | anchor = (typeof anchor === 'undefined') ? '' : anchor; |
135 | anchor = (typeof anchor === 'undefined') ? '' : anchor; |
- | 136 | force = (typeof force === 'undefined') ? false : force; |
|
- | 137 | ||
- | 138 | var mayClose = performCloseQueryCB(); |
|
- | 139 | if (!force && !mayClose) return false; |
|
- | 140 | ||
- | 141 | performCloseCB(); |
|
117 | 142 | ||
118 | if (reselect) { |
143 | if (reselect) { |
119 | $('#oidtree').jstree('deselect_all'); |
144 | $('#oidtree').jstree('deselect_all'); |
120 | 145 | ||
121 | popstate_running = true; // don't call openOidInPanel during tree selection |
146 | popstate_running = true; // don't call openOidInPanel during tree selection |
Line 206... | Line 231... | ||
206 | }) |
231 | }) |
207 | .catch(function(error) { |
232 | .catch(function(error) { |
208 | alert(_L("Failed to load content: %1",error)); |
233 | alert(_L("Failed to load content: %1",error)); |
209 | console.error(error); |
234 | console.error(error); |
210 | }); |
235 | }); |
- | 236 | ||
- | 237 | return true; |
|
211 | } |
238 | } |
212 | 239 | ||
213 | // This function opens the "parentID" node, and then selects the "childID" node (which should be beneath the parent node) |
240 | // This function opens the "parentID" node, and then selects the "childID" node (which should be beneath the parent node) |
214 | function openAndSelectNode(childID, parentID) { |
241 | function openAndSelectNode(childID, parentID) { |
215 | if ($('#oidtree').jstree(true).get_node(parentID)) { |
242 | if ($('#oidtree').jstree(true).get_node(parentID)) { |
Line 228... | Line 255... | ||
228 | window.location.href = "?goto="+encodeURIComponent(childID); |
255 | window.location.href = "?goto="+encodeURIComponent(childID); |
229 | } |
256 | } |
230 | } |
257 | } |
231 | 258 | ||
232 | $(window).on("popstate", function(e) { |
259 | $(window).on("popstate", function(e) { |
- | 260 | if (!performCloseQueryCB()) { |
|
- | 261 | // TODO: does not work!!! The "back/forward" action will be cancelled, but the browser still thinks it was successful, |
|
- | 262 | // so if you do it again, you will then jump 2 pages back, etc! |
|
- | 263 | // This does also not help: |
|
- | 264 | //window.history.pushState(e.originalEvent.state, e.originalEvent.title, e.originalEvent.url); |
|
- | 265 | //window.history.forward(); |
|
- | 266 | return; |
|
- | 267 | } |
|
- | 268 | ||
233 | popstate_running = true; |
269 | popstate_running = true; |
234 | try { |
270 | try { |
235 | var data = e.originalEvent.state; |
271 | var data = e.originalEvent.state; |
236 | 272 | ||
237 | current_node = data.node_id; |
273 | current_node = data.node_id; |
Line 247... | Line 283... | ||
247 | popstate_running = false; |
283 | popstate_running = false; |
248 | } |
284 | } |
249 | }); |
285 | }); |
250 | 286 | ||
251 | $(document).ready(function () { |
287 | $(document).ready(function () { |
- | 288 | /* |
|
- | 289 | window.onbeforeunload = function(e) { |
|
- | 290 | // TODO: This won't be called because TinyMCE overrides it?? |
|
- | 291 | // TODO: when the user accepted the query in performCloseQueryCB(), then the message will be shown again by the browser! |
|
- | 292 | if (!performCloseQueryCB()) { |
|
- | 293 | // Cancel the event |
|
- | 294 | e.preventDefault(); // If you prevent default behavior in Mozilla Firefox prompt will always be shown |
|
- | 295 | // Chrome requires returnValue to be set |
|
- | 296 | e.returnValue = ''; |
|
- | 297 | } else { |
|
- | 298 | // the absence of a returnValue property on the event will guarantee the browser unload happens |
|
- | 299 | delete e['returnValue']; |
|
- | 300 | } |
|
- | 301 | }; |
|
- | 302 | */ |
|
252 | 303 | ||
253 | // --- JsTree |
304 | // --- JsTree |
254 | 305 | ||
255 | $('#oidtree') |
306 | $('#oidtree') |
256 | .jstree({ |
307 | .jstree({ |
Line 266... | Line 317... | ||
266 | }, |
317 | }, |
267 | 'conditionalselect' : function (node) { |
318 | 'conditionalselect' : function (node) { |
268 | if (node.original.conditionalselect !== undefined) { |
319 | if (node.original.conditionalselect !== undefined) { |
269 | return eval(node.original.conditionalselect); |
320 | return eval(node.original.conditionalselect); |
270 | } else { |
321 | } else { |
271 | return true; // allow select |
322 | return performCloseQueryCB(); |
272 | } |
323 | } |
273 | }, |
324 | }, |
274 | }) |
325 | }) |
275 | .on('ready.jstree', function (e, data) { |
326 | .on('ready.jstree', function (e, data) { |
276 | var url = new URL(window.location.href); |
327 | var url = new URL(window.location.href); |
Line 296... | Line 347... | ||
296 | .on('select_node.jstree', function (node, selected, event) { |
347 | .on('select_node.jstree', function (node, selected, event) { |
297 | mobileNavClose(); |
348 | mobileNavClose(); |
298 | 349 | ||
299 | var id = selected.node.id; |
350 | var id = selected.node.id; |
300 | if ((!popstate_running) && (current_node != id)) { |
351 | if ((!popstate_running) && (current_node != id)) { |
- | 352 | // 4th argument: we force the reload (because in the |
|
- | 353 | // conditional select above, we already asked if |
|
- | 354 | // tinyMCE needs to be saved) |
|
301 | openOidInPanel(id, false); |
355 | openOidInPanel(id, false, '', true); |
302 | } |
356 | } |
303 | }); |
357 | }); |
304 | 358 | ||
305 | // --- Layout |
359 | // --- Layout |
306 | 360 |