Subversion Repositories oidplus

Rev

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