Rev 781 | Rev 818 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4 | daniel-mar | 1 | /* |
2 | * OIDplus 2.0 |
||
781 | daniel-mar | 3 | * Copyright 2019 - 2022 Daniel Marschall, ViaThinkSoft |
4 | daniel-mar | 4 | * |
5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
||
6 | * you may not use this file except in compliance with the License. |
||
7 | * You may obtain a copy of the License at |
||
8 | * |
||
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
||
10 | * |
||
11 | * Unless required by applicable law or agreed to in writing, software |
||
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
||
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
14 | * See the License for the specific language governing permissions and |
||
15 | * limitations under the License. |
||
16 | */ |
||
17 | |||
9 | daniel-mar | 18 | /*jshint esversion: 6 */ |
19 | |||
219 | daniel-mar | 20 | // $('#html').jstree(); |
21 | |||
22 | var current_node = ""; |
||
23 | var popstate_running = false; |
||
362 | daniel-mar | 24 | // DEFAULT_LANGUAGE will be set by oidplus.min.js.php |
360 | daniel-mar | 25 | // language_messages will be set by oidplus.min.js.php |
26 | // language_tblprefix will be set by oidplus.min.js.php |
||
424 | daniel-mar | 27 | // csrf_token will be set by oidplus.min.js.php |
561 | daniel-mar | 28 | // samesite_policy will bet set by oidplus.min.js.php |
219 | daniel-mar | 29 | |
399 | daniel-mar | 30 | var pageChangeCallbacks = []; |
31 | var pageChangeRequestCallbacks = []; |
||
32 | |||
356 | daniel-mar | 33 | function isInternetExplorer() { |
641 | daniel-mar | 34 | // see also includes/functions.inc.php |
356 | daniel-mar | 35 | var ua = window.navigator.userAgent; |
36 | return ((ua.indexOf("MSIE ") > 0) || (ua.indexOf("Trident/") > 0)); |
||
37 | } |
||
38 | |||
2 | daniel-mar | 39 | String.prototype.explode = function (separator, limit) { |
40 | // https://stackoverflow.com/questions/4514323/javascript-equivalent-to-php-explode |
||
41 | const array = this.split(separator); |
||
42 | if (limit !== undefined && array.length >= limit) { |
||
43 | array.push(array.splice(limit - 1).join(separator)); |
||
44 | } |
||
45 | return array; |
||
46 | }; |
||
47 | |||
48 | String.prototype.htmlentities = function () { |
||
399 | daniel-mar | 49 | return this.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');//" |
9 | daniel-mar | 50 | }; |
2 | daniel-mar | 51 | |
52 | String.prototype.html_entity_decode = function () { |
||
53 | return $('<textarea />').html(this).text(); |
||
9 | daniel-mar | 54 | }; |
2 | daniel-mar | 55 | |
781 | daniel-mar | 56 | if (!String.prototype.replaceAll) { |
57 | /** |
||
58 | * String.prototype.replaceAll() polyfill |
||
59 | * https://gomakethings.com/how-to-replace-a-section-of-a-string-with-another-one-with-vanilla-js/ |
||
60 | * @author Chris Ferdinandi |
||
61 | * @license MIT |
||
62 | */ |
||
63 | String.prototype.replaceAll = function(str, newStr){ |
||
64 | // If a regex pattern |
||
65 | if (Object.prototype.toString.call(str).toLowerCase() === '[object regexp]') { |
||
66 | return this.replace(str, newStr); |
||
67 | } |
||
68 | // If a string |
||
69 | return this.replace(new RegExp(str, 'g'), newStr); |
||
70 | }; |
||
71 | } |
||
72 | |||
73 | if (!String.prototype.startsWith) { |
||
74 | // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith#polyfill |
||
75 | Object.defineProperty(String.prototype, 'startsWith', { |
||
76 | value: function(search, rawPos) { |
||
77 | var pos = rawPos > 0 ? rawPos|0 : 0; |
||
78 | return this.substring(pos, pos + search.length) === search; |
||
79 | } |
||
80 | }); |
||
81 | } |
||
82 | |||
112 | daniel-mar | 83 | function getMeta(metaName) { |
561 | daniel-mar | 84 | const metas = $('meta[name='+metaName+']'); |
85 | return (metas.length == 0) ? '' : metas[0].content; |
||
112 | daniel-mar | 86 | } |
87 | |||
88 | function getOidPlusSystemTitle() { |
||
360 | daniel-mar | 89 | return getMeta('OIDplus-SystemTitle'); // do not translate |
112 | daniel-mar | 90 | } |
91 | |||
5 | daniel-mar | 92 | function combine_systemtitle_and_pagetitle(systemtitle, pagetitle) { |
309 | daniel-mar | 93 | // Please also change the function in index.php |
5 | daniel-mar | 94 | if (systemtitle == pagetitle) { |
95 | return systemtitle; |
||
96 | } else { |
||
309 | daniel-mar | 97 | return pagetitle + ' - ' + systemtitle; |
5 | daniel-mar | 98 | } |
99 | } |
||
100 | |||
385 | daniel-mar | 101 | function getSystemUrl(relative) { |
102 | var url = new URL(window.location.href); |
||
103 | if (relative) { |
||
104 | return url.pathname; |
||
105 | } else { |
||
106 | return url.href.substr(0, url.href.length-url.search.length); |
||
107 | } |
||
108 | } |
||
109 | |||
2 | daniel-mar | 110 | function getTreeLoadURL() { |
111 | var url = new URL(window.location.href); |
||
112 | var goto = url.searchParams.get("goto"); |
||
641 | daniel-mar | 113 | return (goto != null) ? "ajax.php?csrf_token="+encodeURIComponent(csrf_token)+"&action=tree_load&anticache="+Date.now()+"&goto="+encodeURIComponent(goto) |
114 | : "ajax.php?csrf_token="+encodeURIComponent(csrf_token)+"&action=tree_load&anticache="+Date.now(); |
||
2 | daniel-mar | 115 | } |
116 | |||
117 | function reloadContent() { |
||
154 | daniel-mar | 118 | // window.location.href = "?goto="+encodeURIComponent(current_node); |
399 | daniel-mar | 119 | if (openOidInPanel(current_node, false)) { |
450 | daniel-mar | 120 | if(!$('#oidtree').jstree(true).get_node(current_node)) { |
121 | // Avoid that a language change at "oidplus:srvreg_status" won't redirect the user to "oidplus:srv_registration" because of the reselection during refresh |
||
122 | $('#oidtree').jstree("deselect_all"); |
||
123 | } |
||
124 | |||
399 | daniel-mar | 125 | $('#oidtree').jstree("refresh"); |
126 | } |
||
2 | daniel-mar | 127 | } |
128 | |||
107 | daniel-mar | 129 | function x_rec(x_data, i) { |
130 | $('#oidtree').jstree('open_node', x_data[i], function(e, data) { |
||
131 | if (i+1 < x_data.length) { |
||
132 | x_rec(x_data, i+1); |
||
133 | } else { |
||
114 | daniel-mar | 134 | popstate_running = true; // don't call openOidInPanel again |
135 | try { |
||
136 | $('#oidtree').jstree('select_node', x_data[i]); |
||
137 | } catch (err) { |
||
138 | popstate_running = false; |
||
139 | } finally { |
||
140 | popstate_running = false; |
||
141 | } |
||
107 | daniel-mar | 142 | } |
143 | }); |
||
144 | } |
||
2 | daniel-mar | 145 | |
399 | daniel-mar | 146 | function performCloseQueryCB() { |
147 | for (var i=0; i<pageChangeRequestCallbacks.length; i++) { |
||
148 | if (!pageChangeRequestCallbacks[i][0](pageChangeRequestCallbacks[i][1])) return false; |
||
149 | } |
||
150 | pageChangeRequestCallbacks = []; |
||
151 | return true; // may close |
||
152 | } |
||
153 | |||
154 | function performCloseCB() { |
||
155 | for (var i=0; i<pageChangeCallbacks.length; i++) { |
||
156 | pageChangeCallbacks[i][0](pageChangeCallbacks[i][1]); |
||
157 | } |
||
158 | pageChangeCallbacks = []; |
||
159 | } |
||
160 | |||
161 | function openOidInPanel(id, reselect/*=false*/, anchor/*=''*/, force/*=false*/) { |
||
699 | daniel-mar | 162 | reselect = (typeof reselect === 'undefined') ? false : reselect; // do not translate |
163 | anchor = (typeof anchor === 'undefined') ? '' : anchor; // do not translate |
||
164 | force = (typeof force === 'undefined') ? false : force; // do not translate |
||
150 | daniel-mar | 165 | |
399 | daniel-mar | 166 | var mayClose = performCloseQueryCB(); |
167 | if (!force && !mayClose) return false; |
||
168 | |||
169 | performCloseCB(); |
||
405 | daniel-mar | 170 | |
704 | daniel-mar | 171 | $.xhrPool.abortAll(); |
172 | |||
107 | daniel-mar | 173 | if (reselect) { |
2 | daniel-mar | 174 | $('#oidtree').jstree('deselect_all'); |
107 | daniel-mar | 175 | |
114 | daniel-mar | 176 | popstate_running = true; // don't call openOidInPanel during tree selection |
177 | try { |
||
178 | // If the node is already loaded in the tree, select it |
||
179 | if (!$('#oidtree').jstree('select_node', id)) { |
||
180 | // If the node is not loaded, then we try to search it. |
||
181 | // If it can be found, then open all parent nodes and select the node |
||
182 | $.ajax({ |
||
183 | url:"ajax.php", |
||
184 | method:"POST", |
||
544 | daniel-mar | 185 | beforeSend: function(jqXHR, settings) { |
704 | daniel-mar | 186 | //$.xhrPool.abortAll(); |
544 | daniel-mar | 187 | $.xhrPool.add(jqXHR); |
188 | }, |
||
189 | complete: function(jqXHR, text) { |
||
190 | $.xhrPool.remove(jqXHR); |
||
191 | }, |
||
114 | daniel-mar | 192 | data:{ |
424 | daniel-mar | 193 | csrf_token:csrf_token, |
114 | daniel-mar | 194 | action:"tree_search", |
641 | daniel-mar | 195 | search:id, |
196 | anticache:Date.now() |
||
114 | daniel-mar | 197 | }, |
198 | error:function(jqXHR, textStatus, errorThrown) { |
||
544 | daniel-mar | 199 | if (errorThrown == "abort") return; |
797 | daniel-mar | 200 | console.error("Tree search failed"); |
360 | daniel-mar | 201 | console.error(_L("Error: %1",errorThrown)); |
114 | daniel-mar | 202 | }, |
203 | success:function(data) { |
||
204 | if ("error" in data) { |
||
797 | daniel-mar | 205 | console.error("Tree search failed"); |
114 | daniel-mar | 206 | console.error(data); |
207 | } else if ((data instanceof Array) && (data.length > 0)) { |
||
208 | x_rec(data, 0); |
||
209 | } else { |
||
797 | daniel-mar | 210 | console.error("Tree search failed"); |
114 | daniel-mar | 211 | console.error(data); |
212 | } |
||
213 | } |
||
214 | }); |
||
107 | daniel-mar | 215 | } |
114 | daniel-mar | 216 | } catch (err) { |
217 | popstate_running = false; |
||
218 | } finally { |
||
219 | popstate_running = false; |
||
220 | } |
||
2 | daniel-mar | 221 | } |
222 | |||
114 | daniel-mar | 223 | // This loads the actual content |
224 | |||
405 | daniel-mar | 225 | // document.title = ""; // <-- we may not do this, otherwise Firefox won't |
226 | // show titles in the browser history (right-click |
||
227 | // on back-button), although document.title() is |
||
499 | daniel-mar | 228 | // set inside the AJAX-callback [Firefox bug?!] |
405 | daniel-mar | 229 | |
2 | daniel-mar | 230 | $('#real_title').html(" "); |
355 | daniel-mar | 231 | $('#real_content').html(_L("Loading...")); |
108 | daniel-mar | 232 | $('#static_link').attr("href", "index.php?goto="+encodeURIComponent(id)); |
183 | daniel-mar | 233 | $("#gotoedit").val(id); |
2 | daniel-mar | 234 | |
235 | // Normal opening of a description |
||
560 | daniel-mar | 236 | $.ajax({ |
237 | url:"ajax.php", |
||
238 | method:"GET", |
||
239 | beforeSend: function(jqXHR, settings) { |
||
704 | daniel-mar | 240 | //$.xhrPool.abortAll(); |
560 | daniel-mar | 241 | $.xhrPool.add(jqXHR); |
242 | }, |
||
243 | complete: function(jqXHR, text) { |
||
244 | $.xhrPool.remove(jqXHR); |
||
245 | }, |
||
246 | data:{ |
||
247 | csrf_token:csrf_token, |
||
248 | action:"get_description", |
||
641 | daniel-mar | 249 | id:id, |
250 | anticache:Date.now() |
||
560 | daniel-mar | 251 | }, |
252 | error:function(jqXHR, textStatus, errorThrown) { |
||
253 | if (errorThrown == "abort") return; |
||
254 | alert(_L("Failed to load content: %1",errorThrown)); |
||
255 | console.error(_L("Error: %1",errorThrown)); |
||
256 | }, |
||
257 | success:function(data) { |
||
107 | daniel-mar | 258 | if ("error" in data) { |
360 | daniel-mar | 259 | alert(_L("Failed to load content: %1",data.error)); |
107 | daniel-mar | 260 | console.error(data.error); |
560 | daniel-mar | 261 | } else if (data.status >= 0) { |
262 | data.id = id; |
||
107 | daniel-mar | 263 | |
560 | daniel-mar | 264 | var state = { |
265 | "node_id":id, |
||
266 | "titleHTML":(data.icon ? '<img src="'+data.icon+'" width="48" height="48" alt="'+data.title.htmlentities()+'"> ' : '') + data.title.htmlentities(), |
||
267 | "textHTML":data.text, |
||
268 | "staticlinkHREF":"index.php?goto="+encodeURIComponent(id), |
||
269 | }; |
||
270 | if (current_node != id) { |
||
271 | window.history.pushState(state, data.title, "?goto="+encodeURIComponent(id)); |
||
272 | } else { |
||
273 | window.history.replaceState(state, data.title, "?goto="+encodeURIComponent(id)); |
||
274 | } |
||
2 | daniel-mar | 275 | |
560 | daniel-mar | 276 | document.title = combine_systemtitle_and_pagetitle(getOidPlusSystemTitle(), data.title); |
2 | daniel-mar | 277 | |
560 | daniel-mar | 278 | if (data.icon) { |
279 | $('#real_title').html('<img src="'+data.icon+'" width="48" height="48" alt="'+data.title.htmlentities()+'"> ' + data.title.htmlentities()); |
||
280 | } else { |
||
281 | $('#real_title').html(data.title.htmlentities()); |
||
282 | } |
||
283 | $('#real_content').html(data.text); |
||
284 | document.title = combine_systemtitle_and_pagetitle(getOidPlusSystemTitle(), data.title); |
||
285 | current_node = id; |
||
405 | daniel-mar | 286 | |
560 | daniel-mar | 287 | if (anchor != '') { |
288 | jumpToAnchor(anchor); |
||
289 | } |
||
32 | daniel-mar | 290 | } else { |
560 | daniel-mar | 291 | alert(_L("Failed to load content: %1",data.status)); |
292 | console.error(data); |
||
32 | daniel-mar | 293 | } |
560 | daniel-mar | 294 | } |
2 | daniel-mar | 295 | }); |
399 | daniel-mar | 296 | |
297 | return true; |
||
2 | daniel-mar | 298 | } |
299 | |||
107 | daniel-mar | 300 | // This function opens the "parentID" node, and then selects the "childID" node (which should be beneath the parent node) |
2 | daniel-mar | 301 | function openAndSelectNode(childID, parentID) { |
302 | if ($('#oidtree').jstree(true).get_node(parentID)) { |
||
107 | daniel-mar | 303 | $('#oidtree').jstree('open_node', parentID, function(e, data) { // open parent node |
2 | daniel-mar | 304 | if ($('#oidtree').jstree(true).get_node(childID)) { // is the child there? |
107 | daniel-mar | 305 | $('#oidtree').jstree('deselect_all').jstree('select_node', childID); // select it |
2 | daniel-mar | 306 | } else { |
307 | // This can happen if the content page contains brand new items which are not in the treeview yet |
||
183 | daniel-mar | 308 | $("#gotoedit").val(childID); |
154 | daniel-mar | 309 | window.location.href = "?goto="+encodeURIComponent(childID); |
2 | daniel-mar | 310 | } |
311 | }, true); |
||
312 | } else { |
||
313 | // This should usually not happen |
||
183 | daniel-mar | 314 | $("#gotoedit").val(childID); |
154 | daniel-mar | 315 | window.location.href = "?goto="+encodeURIComponent(childID); |
2 | daniel-mar | 316 | } |
317 | } |
||
318 | |||
319 | $(window).on("popstate", function(e) { |
||
399 | daniel-mar | 320 | if (!performCloseQueryCB()) { |
321 | // TODO: does not work!!! The "back/forward" action will be cancelled, but the browser still thinks it was successful, |
||
322 | // so if you do it again, you will then jump 2 pages back, etc! |
||
323 | // This does also not help: |
||
324 | //window.history.pushState(e.originalEvent.state, e.originalEvent.title, e.originalEvent.url); |
||
325 | //window.history.forward(); |
||
326 | return; |
||
327 | } |
||
328 | |||
2 | daniel-mar | 329 | popstate_running = true; |
330 | try { |
||
331 | var data = e.originalEvent.state; |
||
332 | |||
333 | current_node = data.node_id; |
||
327 | daniel-mar | 334 | $("#gotoedit").val(current_node); |
107 | daniel-mar | 335 | $('#oidtree').jstree('deselect_all').jstree('select_node', data.node_id); |
2 | daniel-mar | 336 | $('#real_title').html(data.titleHTML); |
337 | $('#real_content').html(data.textHTML); |
||
338 | $('#static_link').attr("href", data.staticlinkHREF); |
||
112 | daniel-mar | 339 | document.title = combine_systemtitle_and_pagetitle(getOidPlusSystemTitle(), data.titleHTML.html_entity_decode()); |
2 | daniel-mar | 340 | } catch (err) { |
341 | popstate_running = false; |
||
342 | } finally { |
||
343 | popstate_running = false; |
||
344 | } |
||
345 | }); |
||
346 | |||
347 | $(document).ready(function () { |
||
399 | daniel-mar | 348 | /* |
349 | window.onbeforeunload = function(e) { |
||
350 | // TODO: This won't be called because TinyMCE overrides it?? |
||
351 | // TODO: when the user accepted the query in performCloseQueryCB(), then the message will be shown again by the browser! |
||
352 | if (!performCloseQueryCB()) { |
||
353 | // Cancel the event |
||
354 | e.preventDefault(); // If you prevent default behavior in Mozilla Firefox prompt will always be shown |
||
355 | // Chrome requires returnValue to be set |
||
356 | e.returnValue = ''; |
||
357 | } else { |
||
358 | // the absence of a returnValue property on the event will guarantee the browser unload happens |
||
359 | delete e['returnValue']; |
||
360 | } |
||
361 | }; |
||
362 | */ |
||
214 | daniel-mar | 363 | |
2 | daniel-mar | 364 | // --- JsTree |
365 | |||
366 | $('#oidtree') |
||
367 | .jstree({ |
||
368 | plugins: ['massload','search','conditionalselect'], |
||
369 | 'core' : { |
||
370 | 'data' : { |
||
371 | "url" : getTreeLoadURL(), |
||
372 | "data" : function (node) { |
||
373 | return { "id" : node.id }; |
||
374 | } |
||
375 | }, |
||
376 | "multiple": false |
||
377 | }, |
||
378 | 'conditionalselect' : function (node) { |
||
68 | daniel-mar | 379 | if (node.original.conditionalselect !== undefined) { |
380 | return eval(node.original.conditionalselect); |
||
2 | daniel-mar | 381 | } else { |
399 | daniel-mar | 382 | return performCloseQueryCB(); |
2 | daniel-mar | 383 | } |
384 | }, |
||
385 | }) |
||
386 | .on('ready.jstree', function (e, data) { |
||
387 | var url = new URL(window.location.href); |
||
388 | var goto = url.searchParams.get("goto"); |
||
389 | if (goto == null) goto = "oidplus:system"; // the page was not called with ?goto=... |
||
183 | daniel-mar | 390 | $("#gotoedit").val(goto); |
2 | daniel-mar | 391 | |
107 | daniel-mar | 392 | // By setting current_node, select_node() will not cause ajax.php?action=get_description to load (since we already loaded the first static content via PHP, for search engines mainly) |
2 | daniel-mar | 393 | // But then we need to set the history state manually |
394 | current_node = goto; |
||
100 | daniel-mar | 395 | window.history.replaceState({ |
107 | daniel-mar | 396 | "node_id":goto, |
100 | daniel-mar | 397 | "titleHTML":$('#real_title').html(), |
398 | "textHTML":$('#real_content').html(), |
||
108 | daniel-mar | 399 | "staticlinkHREF":"index.php?goto="+encodeURIComponent(goto), |
113 | daniel-mar | 400 | }, $('#real_title').html(), "?goto="+encodeURIComponent(goto)); |
2 | daniel-mar | 401 | |
402 | if (goto != null) data.instance.select_node([goto]); |
||
128 | daniel-mar | 403 | |
643 | daniel-mar | 404 | setTimeout(glayoutWorkaroundAC, 100); |
137 | daniel-mar | 405 | setTimeout(glayoutWorkaroundB, 100); |
2 | daniel-mar | 406 | }) |
407 | .on('select_node.jstree', function (node, selected, event) { |
||
120 | daniel-mar | 408 | mobileNavClose(); |
95 | daniel-mar | 409 | |
9 | daniel-mar | 410 | var id = selected.node.id; |
114 | daniel-mar | 411 | if ((!popstate_running) && (current_node != id)) { |
399 | daniel-mar | 412 | // 4th argument: we force the reload (because in the |
413 | // conditional select above, we already asked if |
||
414 | // tinyMCE needs to be saved) |
||
415 | openOidInPanel(id, false, '', true); |
||
2 | daniel-mar | 416 | } |
417 | }); |
||
418 | |||
419 | // --- Layout |
||
420 | |||
561 | daniel-mar | 421 | $("#system_title_menu")[0].style.display = "block"; |
120 | daniel-mar | 422 | |
355 | daniel-mar | 423 | var tmpObjectTree = _L("OBJECT TREE").replace(/(.{1})/g,"$1<br>"); |
424 | tmpObjectTree = tmpObjectTree.substring(0, tmpObjectTree.length-"<br>".length); |
||
425 | |||
120 | daniel-mar | 426 | $('#oidtree').addClass('ui-layout-west'); |
427 | $('#content_window').addClass('ui-layout-center'); |
||
428 | $('#system_title_bar').addClass('ui-layout-north'); |
||
128 | daniel-mar | 429 | glayout = $('#frames').layout({ |
120 | daniel-mar | 430 | north__size: 40, |
431 | north__slidable: false, |
||
432 | north__closable: false, |
||
433 | north__resizable: false, |
||
434 | west__size: 450, |
||
435 | west__spacing_closed: 20, |
||
436 | west__togglerLength_closed: 230, |
||
695 | daniel-mar | 437 | west__togglerAlign_closed: "center", // TODO: does not work! The text "OBJECT TREE" is still at the top and nearly cut off by the title bar!!! |
355 | daniel-mar | 438 | west__togglerContent_closed: tmpObjectTree, |
439 | west__togglerTip_closed: _L("Open & Pin Menu"), |
||
440 | west__sliderTip: _L("Slide Open Menu"), |
||
120 | daniel-mar | 441 | west__slideTrigger_open: "mouseover", |
442 | center__maskContents: true // IMPORTANT - enable iframe masking |
||
443 | }); |
||
183 | daniel-mar | 444 | |
185 | daniel-mar | 445 | $("#gotobox").addClass("mobilehidden"); |
355 | daniel-mar | 446 | $("#languageBox").addClass("mobilehidden"); |
561 | daniel-mar | 447 | $("#gotobox")[0].style.display = "block"; |
183 | daniel-mar | 448 | $('#gotoedit').keypress(function(event) { |
449 | var keycode = (event.keyCode ? event.keyCode : event.which); |
||
450 | if (keycode == '13') { |
||
451 | gotoButtonClicked(); |
||
452 | } |
||
453 | }); |
||
376 | daniel-mar | 454 | }); |
2 | daniel-mar | 455 | |
643 | daniel-mar | 456 | function glayoutWorkaroundAC() { |
211 | daniel-mar | 457 | // "Bug A": Sometimes, the design is completely destroyed after reloading the page. It does not help when glayout.resizeAll() |
137 | daniel-mar | 458 | // is called at the beginning (e.g. during the ready function), and it does not help if we wait 500ms. |
459 | // So we do it all the time. It has probably something to do with slow loading times, since the error |
||
460 | // does only appear when the page is "blank" for a short while while it is loading. |
||
461 | glayout.resizeAll(); |
||
287 | daniel-mar | 462 | |
463 | // "Bug C": With Firefox (And sometimes with Chrome), there is a gap between the content-window (including scroll bars) |
||
464 | // and the right corner of the screen. Removing the explicit width solves this problem. |
||
561 | daniel-mar | 465 | $("#content_window")[0].style.removeProperty("width"); |
643 | daniel-mar | 466 | |
467 | setTimeout(glayoutWorkaroundAC, 100); |
||
137 | daniel-mar | 468 | } |
469 | |||
470 | function glayoutWorkaroundB() { |
||
471 | // "Bug B": Sometimes, after reload, weird space between oidtree and content window, because oidtree has size of 438px |
||
561 | daniel-mar | 472 | $("#oidtree")[0].style.width = "450px"; |
137 | daniel-mar | 473 | } |
474 | |||
120 | daniel-mar | 475 | function mobileNavClose() { |
476 | if ($("#system_title_menu").is(":hidden")) { |
||
477 | return; |
||
478 | } |
||
479 | |||
480 | $("#oidtree").slideUp("medium").promise().done(function() { |
||
481 | $("#oidtree").addClass("ui-layout-west"); |
||
482 | $("#oidtree").show(); |
||
185 | daniel-mar | 483 | // $("#gotobox").hide(); |
355 | daniel-mar | 484 | // $("#languageBox").hide(); |
185 | daniel-mar | 485 | $("#gotobox").addClass("mobilehidden"); |
355 | daniel-mar | 486 | $("#languageBox").addClass("mobilehidden"); |
120 | daniel-mar | 487 | }); |
488 | $("#system_title_menu").removeClass("active"); |
||
95 | daniel-mar | 489 | } |
490 | |||
120 | daniel-mar | 491 | function mobileNavOpen() { |
492 | $("#oidtree").hide(); |
||
493 | $("#oidtree").removeClass("ui-layout-west"); |
||
494 | $("#oidtree").slideDown("medium"); |
||
185 | daniel-mar | 495 | // $("#gotobox").show(); |
355 | daniel-mar | 496 | // $("#languageBox").show(); |
185 | daniel-mar | 497 | $("#gotobox").removeClass("mobilehidden"); |
355 | daniel-mar | 498 | $("#languageBox").removeClass("mobilehidden"); |
120 | daniel-mar | 499 | $("#system_title_menu").addClass("active"); |
500 | } |
||
501 | |||
105 | daniel-mar | 502 | function mobileNavButtonClick(sender) { |
120 | daniel-mar | 503 | if ($("#oidtree").hasClass("ui-layout-west")) { |
504 | mobileNavOpen(); |
||
103 | daniel-mar | 505 | } else { |
120 | daniel-mar | 506 | mobileNavClose(); |
103 | daniel-mar | 507 | } |
508 | } |
||
105 | daniel-mar | 509 | |
510 | function mobileNavButtonHover(sender) { |
||
511 | sender.classList.toggle("hover"); |
||
512 | } |
||
183 | daniel-mar | 513 | |
514 | function gotoButtonClicked() { |
||
704 | daniel-mar | 515 | openOidInPanel($("#gotoedit").val(), true); |
183 | daniel-mar | 516 | } |
199 | daniel-mar | 517 | |
219 | daniel-mar | 518 | function jumpToAnchor(anchor) { |
519 | window.location.href = "#" + anchor; |
||
520 | } |
||
521 | |||
355 | daniel-mar | 522 | function getCookie(cname) { |
523 | // Source: https://www.w3schools.com/js/js_cookies.asp |
||
524 | var name = cname + "="; |
||
525 | var decodedCookie = decodeURIComponent(document.cookie); |
||
526 | var ca = decodedCookie.split(';'); |
||
527 | for(var i = 0; i <ca.length; i++) { |
||
528 | var c = ca[i]; |
||
529 | while (c.charAt(0) == ' ') { |
||
530 | c = c.substring(1); |
||
531 | } |
||
532 | if (c.indexOf(name) == 0) { |
||
533 | return c.substring(name.length, c.length); |
||
534 | } |
||
535 | } |
||
536 | return undefined; |
||
537 | } |
||
538 | |||
356 | daniel-mar | 539 | function setCookie(cname, cvalue, exdays, path) { |
540 | var d = new Date(); |
||
541 | d.setTime(d.getTime() + (exdays*24*60*60*1000)); |
||
542 | var expires = exdays == 0 ? "" : "; expires="+d.toUTCString(); |
||
561 | daniel-mar | 543 | document.cookie = cname + "=" + cvalue + expires + ";path=" + path + ";SameSite=" + samesite_policy; |
356 | daniel-mar | 544 | } |
545 | |||
355 | daniel-mar | 546 | function setLanguage(lngid) { |
356 | daniel-mar | 547 | setCookie('LANGUAGE', lngid, 0/*Until browser closes*/, location.pathname); |
548 | |||
549 | $(".lng_flag").each(function(){ |
||
550 | $(this).addClass("picture_ghost"); |
||
355 | daniel-mar | 551 | }); |
675 | daniel-mar | 552 | $("#lng_flag_"+$.escapeSelector(lngid)).removeClass("picture_ghost"); |
356 | daniel-mar | 553 | |
554 | if (isInternetExplorer()) { |
||
555 | // Internet Explorer has problems with sending new cookies to new AJAX requests, so we reload the page completely |
||
556 | window.location.reload(); |
||
557 | } else { |
||
561 | daniel-mar | 558 | // TODO: Small detail: The "Go" button also needs to be re-translated |
360 | daniel-mar | 559 | reloadContent(); |
356 | daniel-mar | 560 | mobileNavClose(); |
561 | } |
||
355 | daniel-mar | 562 | } |
563 | |||
564 | function getCurrentLang() { |
||
360 | daniel-mar | 565 | // Note: If the argument "?lang=" is used, PHP will automatically set a Cookie, so it is OK when we only check for the cookie |
699 | daniel-mar | 566 | var lang = getCookie('LANGUAGE'); // do not translate |
567 | return (typeof lang != 'undefined') ? lang : DEFAULT_LANGUAGE; // do not translate |
||
355 | daniel-mar | 568 | } |
569 | |||
360 | daniel-mar | 570 | function _L() { |
571 | var args = Array.prototype.slice.call(arguments); |
||
506 | daniel-mar | 572 | var str = args.shift().trim(); |
360 | daniel-mar | 573 | |
574 | var tmp = ""; |
||
699 | daniel-mar | 575 | if (typeof language_messages[getCurrentLang()] == 'undefined') { // do not translate |
360 | daniel-mar | 576 | tmp = str; |
577 | } else { |
||
578 | var msg = language_messages[getCurrentLang()][str]; |
||
699 | daniel-mar | 579 | if (typeof msg != 'undefined') { // do not translate |
360 | daniel-mar | 580 | tmp = msg; |
581 | } else { |
||
582 | tmp = str; |
||
583 | } |
||
584 | } |
||
585 | |||
586 | tmp = tmp.replace('###', language_tblprefix); |
||
587 | |||
588 | var n = 1; |
||
589 | while (args.length > 0) { |
||
590 | var val = args.shift(); |
||
591 | tmp = tmp.replace("%"+n, val); |
||
592 | n++; |
||
593 | } |
||
594 | |||
370 | daniel-mar | 595 | tmp = tmp.replace("%%", "%"); |
596 | |||
360 | daniel-mar | 597 | return tmp; |
355 | daniel-mar | 598 | } |
532 | daniel-mar | 599 | |
600 | function show_waiting_anim() { |
||
601 | $("#loading").show(); |
||
602 | } |
||
603 | |||
604 | function hide_waiting_anim() { |
||
605 | $("#loading").hide(); |
||
606 | } |
||
544 | daniel-mar | 607 | |
608 | /* Mini-framework to abort all AJAX requests if a new request is made */ |
||
609 | |||
610 | $.xhrPool = []; |
||
611 | $.xhrPool.add = function(jqXHR) { |
||
612 | $.xhrPool.push(jqXHR); |
||
613 | } |
||
614 | $.xhrPool.remove = function(jqXHR) { |
||
615 | var index = $.xhrPool.indexOf(jqXHR); |
||
616 | if (index > -1) { |
||
617 | $.xhrPool.splice(index, 1); |
||
618 | } |
||
619 | }; |
||
620 | $.xhrPool.abortAll = function() { |
||
621 | var calls = Array.from($.xhrPool); |
||
622 | $.each(calls, function(key, value) { |
||
623 | value.abort(); |
||
624 | }); |
||
625 | } |