Subversion Repositories oidplus

Rev

Rev 532 | Rev 560 | 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
512 daniel-mar 208
        fetch("ajax.php?csrf_token="+encodeURIComponent(csrf_token)+"&action=get_description&id="+encodeURIComponent(id))
2 daniel-mar 209
        .then(function(response) {
210
                response.json()
211
                .then(function(data) {
107 daniel-mar 212
                        if ("error" in data) {
360 daniel-mar 213
                                alert(_L("Failed to load content: %1",data.error));
107 daniel-mar 214
                                console.error(data.error);
215
                                return;
216
                        }
217
 
2 daniel-mar 218
                        data.id = id;
219
 
220
                        var state = {
107 daniel-mar 221
                                "node_id":id,
108 daniel-mar 222
                                "titleHTML":(data.icon ? '<img src="'+data.icon+'" width="48" height="48" alt="'+data.title.htmlentities()+'"> ' : '') + data.title.htmlentities(),
2 daniel-mar 223
                                "textHTML":data.text,
108 daniel-mar 224
                                "staticlinkHREF":"index.php?goto="+encodeURIComponent(id),
2 daniel-mar 225
                        };
226
                        if (current_node != id) {
104 daniel-mar 227
                                window.history.pushState(state, data.title, "?goto="+encodeURIComponent(id));
2 daniel-mar 228
                        } else {
104 daniel-mar 229
                                window.history.replaceState(state, data.title, "?goto="+encodeURIComponent(id));
2 daniel-mar 230
                        }
231
 
405 daniel-mar 232
                        document.title = combine_systemtitle_and_pagetitle(getOidPlusSystemTitle(), data.title);
233
 
32 daniel-mar 234
                        if (data.icon) {
235
                                $('#real_title').html('<img src="'+data.icon+'" width="48" height="48" alt="'+data.title.htmlentities()+'"> ' + data.title.htmlentities());
236
                        } else {
237
                                $('#real_title').html(data.title.htmlentities());
238
                        }
2 daniel-mar 239
                        $('#real_content').html(data.text);
112 daniel-mar 240
                        document.title = combine_systemtitle_and_pagetitle(getOidPlusSystemTitle(), data.title);
2 daniel-mar 241
                        current_node = id;
219 daniel-mar 242
 
243
                        if (anchor != '') {
244
                                jumpToAnchor(anchor);
245
                        }
2 daniel-mar 246
                })
247
                .catch(function(error) {
360 daniel-mar 248
                        alert(_L("Failed to load content: %1",error));
2 daniel-mar 249
                        console.error(error);
250
                });
251
        })
252
        .catch(function(error) {
360 daniel-mar 253
                alert(_L("Failed to load content: %1",error));
2 daniel-mar 254
                console.error(error);
255
        });
399 daniel-mar 256
 
257
        return true;
2 daniel-mar 258
}
259
 
107 daniel-mar 260
// This function opens the "parentID" node, and then selects the "childID" node (which should be beneath the parent node)
2 daniel-mar 261
function openAndSelectNode(childID, parentID) {
262
        if ($('#oidtree').jstree(true).get_node(parentID)) {
107 daniel-mar 263
                $('#oidtree').jstree('open_node', parentID, function(e, data) { // open parent node
2 daniel-mar 264
                        if ($('#oidtree').jstree(true).get_node(childID)) { // is the child there?
107 daniel-mar 265
                                $('#oidtree').jstree('deselect_all').jstree('select_node', childID); // select it
2 daniel-mar 266
                        } else {
267
                                // This can happen if the content page contains brand new items which are not in the treeview yet
183 daniel-mar 268
                                $("#gotoedit").val(childID);
154 daniel-mar 269
                                window.location.href = "?goto="+encodeURIComponent(childID);
2 daniel-mar 270
                        }
271
                }, true);
272
        } else {
273
                // This should usually not happen
183 daniel-mar 274
                $("#gotoedit").val(childID);
154 daniel-mar 275
                window.location.href = "?goto="+encodeURIComponent(childID);
2 daniel-mar 276
        }
277
}
278
 
279
$(window).on("popstate", function(e) {
399 daniel-mar 280
        if (!performCloseQueryCB()) {
281
                // TODO: does not work!!! The "back/forward" action will be cancelled, but the browser still thinks it was successful,
282
                // so if you do it again, you will then jump 2 pages back, etc!
283
                // This does also not help:
284
                //window.history.pushState(e.originalEvent.state, e.originalEvent.title, e.originalEvent.url);
285
                //window.history.forward();
286
                return;
287
        }
288
 
2 daniel-mar 289
        popstate_running = true;
290
        try {
291
                var data = e.originalEvent.state;
292
 
293
                current_node = data.node_id;
327 daniel-mar 294
                $("#gotoedit").val(current_node);
107 daniel-mar 295
                $('#oidtree').jstree('deselect_all').jstree('select_node', data.node_id);
2 daniel-mar 296
                $('#real_title').html(data.titleHTML);
297
                $('#real_content').html(data.textHTML);
298
                $('#static_link').attr("href", data.staticlinkHREF);
112 daniel-mar 299
                document.title = combine_systemtitle_and_pagetitle(getOidPlusSystemTitle(), data.titleHTML.html_entity_decode());
2 daniel-mar 300
        } catch (err) {
301
                popstate_running = false;
302
        } finally {
303
                popstate_running = false;
304
        }
305
});
306
 
307
$(document).ready(function () {
399 daniel-mar 308
        /*
309
        window.onbeforeunload = function(e) {
310
                // TODO: This won't be called because TinyMCE overrides it??
311
                // TODO: when the user accepted the query in performCloseQueryCB(), then the message will be shown again by the browser!
312
                if (!performCloseQueryCB()) {
313
                        // Cancel the event
314
                        e.preventDefault(); // If you prevent default behavior in Mozilla Firefox prompt will always be shown
315
                        // Chrome requires returnValue to be set
316
                        e.returnValue = '';
317
                } else {
318
                        // the absence of a returnValue property on the event will guarantee the browser unload happens
319
                        delete e['returnValue'];
320
                }
321
        };
322
        */
214 daniel-mar 323
 
2 daniel-mar 324
        // --- JsTree
325
 
326
        $('#oidtree')
327
        .jstree({
328
                plugins: ['massload','search','conditionalselect'],
329
                'core' : {
330
                        'data' : {
331
                                "url" : getTreeLoadURL(),
332
                                "data" : function (node) {
333
                                        return { "id" : node.id };
334
                                }
335
                        },
336
                        "multiple": false
337
                },
338
                'conditionalselect' : function (node) {
68 daniel-mar 339
                        if (node.original.conditionalselect !== undefined) {
340
                                return eval(node.original.conditionalselect);
2 daniel-mar 341
                        } else {
399 daniel-mar 342
                                return performCloseQueryCB();
2 daniel-mar 343
                        }
344
                },
345
        })
346
        .on('ready.jstree', function (e, data) {
347
                var url = new URL(window.location.href);
348
                var goto = url.searchParams.get("goto");
349
                if (goto == null) goto = "oidplus:system"; // the page was not called with ?goto=...
183 daniel-mar 350
                $("#gotoedit").val(goto);
2 daniel-mar 351
 
107 daniel-mar 352
                // 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 353
                // But then we need to set the history state manually
354
                current_node = goto;
100 daniel-mar 355
                window.history.replaceState({
107 daniel-mar 356
                        "node_id":goto,
100 daniel-mar 357
                        "titleHTML":$('#real_title').html(),
358
                        "textHTML":$('#real_content').html(),
108 daniel-mar 359
                        "staticlinkHREF":"index.php?goto="+encodeURIComponent(goto),
113 daniel-mar 360
                }, $('#real_title').html(), "?goto="+encodeURIComponent(goto));
2 daniel-mar 361
 
362
                if (goto != null) data.instance.select_node([goto]);
128 daniel-mar 363
 
137 daniel-mar 364
                setTimeout(glayoutWorkaroundA, 100);
365
                setTimeout(glayoutWorkaroundB, 100);
2 daniel-mar 366
        })
367
        .on('select_node.jstree', function (node, selected, event) {
120 daniel-mar 368
                mobileNavClose();
95 daniel-mar 369
 
9 daniel-mar 370
                var id = selected.node.id;
114 daniel-mar 371
                if ((!popstate_running) && (current_node != id)) {
399 daniel-mar 372
                        // 4th argument: we force the reload (because in the
373
                        // conditional select above, we already asked if
374
                        // tinyMCE needs to be saved)
375
                        openOidInPanel(id, false, '', true);
2 daniel-mar 376
                }
377
        });
378
 
379
        // --- Layout
380
 
122 daniel-mar 381
        document.getElementById('system_title_menu').style.display = "block";
120 daniel-mar 382
 
355 daniel-mar 383
        var tmpObjectTree = _L("OBJECT TREE").replace(/(.{1})/g,"$1<br>");
384
        tmpObjectTree = tmpObjectTree.substring(0, tmpObjectTree.length-"<br>".length);
385
 
120 daniel-mar 386
        $('#oidtree').addClass('ui-layout-west');
387
        $('#content_window').addClass('ui-layout-center');
388
        $('#system_title_bar').addClass('ui-layout-north');
128 daniel-mar 389
        glayout = $('#frames').layout({
120 daniel-mar 390
                north__size:                  40,
391
                north__slidable:              false,
392
                north__closable:              false,
393
                north__resizable:             false,
394
                west__size:                   450,
395
                west__spacing_closed:         20,
396
                west__togglerLength_closed:   230,
397
                west__togglerAlign_closed:    "top",
355 daniel-mar 398
                west__togglerContent_closed:  tmpObjectTree,
399
                west__togglerTip_closed:      _L("Open & Pin Menu"),
400
                west__sliderTip:              _L("Slide Open Menu"),
120 daniel-mar 401
                west__slideTrigger_open:      "mouseover",
402
                center__maskContents:         true // IMPORTANT - enable iframe masking
403
        });
183 daniel-mar 404
 
185 daniel-mar 405
        $("#gotobox").addClass("mobilehidden");
355 daniel-mar 406
        $("#languageBox").addClass("mobilehidden");
183 daniel-mar 407
        document.getElementById('gotobox').style.display = "block";
408
        $('#gotoedit').keypress(function(event) {
409
                var keycode = (event.keyCode ? event.keyCode : event.which);
410
                if (keycode == '13') {
411
                        gotoButtonClicked();
412
                }
413
        });
376 daniel-mar 414
});
2 daniel-mar 415
 
137 daniel-mar 416
function glayoutWorkaroundA() {
211 daniel-mar 417
        // "Bug A": Sometimes, the design is completely destroyed after reloading the page. It does not help when glayout.resizeAll()
137 daniel-mar 418
        //          is called at the beginning (e.g. during the ready function), and it does not help if we wait 500ms.
419
        //          So we do it all the time. It has probably something to do with slow loading times, since the error
420
        //          does only appear when the page is "blank" for a short while while it is loading.
421
        glayout.resizeAll();
422
        setTimeout(glayoutWorkaroundA, 100);
287 daniel-mar 423
 
424
        // "Bug C": With Firefox (And sometimes with Chrome), there is a gap between the content-window (including scroll bars)
425
        //          and the right corner of the screen. Removing the explicit width solves this problem.
426
        document.getElementById("content_window").style.removeProperty("width");
137 daniel-mar 427
}
428
 
429
function glayoutWorkaroundB() {
430
        // "Bug B": Sometimes, after reload, weird space between oidtree and content window, because oidtree has size of 438px
431
        document.getElementById("oidtree").style.width = "450px";
432
}
433
 
120 daniel-mar 434
function mobileNavClose() {
435
        if ($("#system_title_menu").is(":hidden")) {
436
                return;
437
        }
438
 
439
        $("#oidtree").slideUp("medium").promise().done(function() {
440
                $("#oidtree").addClass("ui-layout-west");
441
                $("#oidtree").show();
185 daniel-mar 442
//              $("#gotobox").hide();
355 daniel-mar 443
//              $("#languageBox").hide();
185 daniel-mar 444
                $("#gotobox").addClass("mobilehidden");
355 daniel-mar 445
                $("#languageBox").addClass("mobilehidden");
120 daniel-mar 446
        });
447
        $("#system_title_menu").removeClass("active");
95 daniel-mar 448
}
449
 
120 daniel-mar 450
function mobileNavOpen() {
451
        $("#oidtree").hide();
452
        $("#oidtree").removeClass("ui-layout-west");
453
        $("#oidtree").slideDown("medium");
185 daniel-mar 454
//      $("#gotobox").show();
355 daniel-mar 455
//      $("#languageBox").show();
185 daniel-mar 456
        $("#gotobox").removeClass("mobilehidden");
355 daniel-mar 457
        $("#languageBox").removeClass("mobilehidden");
120 daniel-mar 458
        $("#system_title_menu").addClass("active");
459
}
460
 
105 daniel-mar 461
function mobileNavButtonClick(sender) {
120 daniel-mar 462
        if ($("#oidtree").hasClass("ui-layout-west")) {
463
                mobileNavOpen();
103 daniel-mar 464
        } else {
120 daniel-mar 465
                mobileNavClose();
103 daniel-mar 466
        }
467
}
105 daniel-mar 468
 
469
function mobileNavButtonHover(sender) {
470
        sender.classList.toggle("hover");
471
}
183 daniel-mar 472
 
473
function gotoButtonClicked() {
474
        openOidInPanel($("#gotoedit").val(), 1);
475
}
199 daniel-mar 476
 
219 daniel-mar 477
function jumpToAnchor(anchor) {
478
        window.location.href = "#" + anchor;
479
}
480
 
355 daniel-mar 481
function getCookie(cname) {
482
        // Source: https://www.w3schools.com/js/js_cookies.asp
483
        var name = cname + "=";
484
        var decodedCookie = decodeURIComponent(document.cookie);
485
        var ca = decodedCookie.split(';');
486
        for(var i = 0; i <ca.length; i++) {
487
                var c = ca[i];
488
                while (c.charAt(0) == ' ') {
489
                        c = c.substring(1);
490
                }
491
                if (c.indexOf(name) == 0) {
492
                        return c.substring(name.length, c.length);
493
                }
494
        }
495
        return undefined;
496
}
497
 
356 daniel-mar 498
function setCookie(cname, cvalue, exdays, path) {
499
        var d = new Date();
500
        d.setTime(d.getTime() + (exdays*24*60*60*1000));
501
        var expires = exdays == 0 ? "" : "; expires="+d.toUTCString();
502
        document.cookie = cname + "=" + cvalue + expires + ";path=" + path;
503
}
504
 
355 daniel-mar 505
function setLanguage(lngid) {
356 daniel-mar 506
        setCookie('LANGUAGE', lngid, 0/*Until browser closes*/, location.pathname);
507
 
508
        $(".lng_flag").each(function(){
509
                $(this).addClass("picture_ghost");
355 daniel-mar 510
        });
356 daniel-mar 511
        $("#lng_flag_"+lngid).removeClass("picture_ghost");
512
 
513
        if (isInternetExplorer()) {
514
                // Internet Explorer has problems with sending new cookies to new AJAX requests, so we reload the page completely
515
                window.location.reload();
516
        } else {
360 daniel-mar 517
                reloadContent();
356 daniel-mar 518
                mobileNavClose();
519
        }
355 daniel-mar 520
}
521
 
522
function getCurrentLang() {
360 daniel-mar 523
        // 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 524
        var lang = getCookie('LANGUAGE');
525
        return (typeof lang != "undefined") ? lang : DEFAULT_LANGUAGE;
526
}
527
 
360 daniel-mar 528
function _L() {
529
        var args = Array.prototype.slice.call(arguments);
506 daniel-mar 530
        var str = args.shift().trim();
360 daniel-mar 531
 
532
        var tmp = "";
533
        if (typeof language_messages[getCurrentLang()] == "undefined") {
534
                tmp = str;
535
        } else {
536
                var msg = language_messages[getCurrentLang()][str];
537
                if (typeof msg != "undefined") {
538
                        tmp = msg;
539
                } else {
540
                        tmp = str;
541
                }
542
        }
543
 
544
        tmp = tmp.replace('###', language_tblprefix);
545
 
546
        var n = 1;
547
        while (args.length > 0) {
548
                var val = args.shift();
549
                tmp = tmp.replace("%"+n, val);
550
                n++;
551
        }
552
 
370 daniel-mar 553
        tmp = tmp.replace("%%", "%");
554
 
360 daniel-mar 555
        return tmp;
355 daniel-mar 556
}
532 daniel-mar 557
 
558
function show_waiting_anim() {
559
        $("#loading").show();
560
}
561
 
562
function hide_waiting_anim() {
563
        $("#loading").hide();
564
}
544 daniel-mar 565
 
566
/* Mini-framework to abort all AJAX requests if a new request is made */
567
 
568
$.xhrPool = [];
569
$.xhrPool.add = function(jqXHR) {
570
        $.xhrPool.push(jqXHR);
571
}
572
$.xhrPool.remove = function(jqXHR) {
573
        var index = $.xhrPool.indexOf(jqXHR);
574
        if (index > -1) {
575
                $.xhrPool.splice(index, 1);
576
        }
577
};
578
$.xhrPool.abortAll = function() {
579
        var calls = Array.from($.xhrPool);
580
        $.each(calls, function(key, value) {
581
                value.abort();
582
        });
583
}