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