Rev 876 | Rev 1018 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 876 | Rev 982 | ||
---|---|---|---|
Line 47... | Line 47... | ||
47 | if (typeof fel == 'function') fel(); |
47 | if (typeof fel == 'function') fel(); |
48 | } |
48 | } |
49 | ); |
49 | ); |
50 | } |
50 | } |
51 | 51 | ||
52 | function isInternetExplorer() { |
- | |
53 | // see also includes/functions.inc.php |
- | |
54 | var ua = window.navigator.userAgent; |
- | |
55 | return ((ua.indexOf("MSIE ") > 0) || (ua.indexOf("Trident/") > 0)); |
- | |
56 | } |
- | |
57 | - | ||
58 | String.prototype.explode = function (separator, limit) { |
- | |
59 | // https://stackoverflow.com/questions/4514323/javascript-equivalent-to-php-explode |
- | |
60 | const array = this.split(separator); |
- | |
61 | if (limit !== undefined && array.length >= limit) { |
- | |
62 | array.push(array.splice(limit - 1).join(separator)); |
- | |
63 | } |
- | |
64 | return array; |
- | |
65 | }; |
- | |
66 | - | ||
67 | String.prototype.htmlentities = function () { |
- | |
68 | return this.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');//" |
- | |
69 | }; |
- | |
70 | - | ||
71 | String.prototype.html_entity_decode = function () { |
- | |
72 | return $('<textarea />').html(this).text(); |
- | |
73 | }; |
- | |
74 | - | ||
75 | if (!String.prototype.replaceAll) { |
- | |
76 | /** |
- | |
77 | * String.prototype.replaceAll() polyfill |
- | |
78 | * https://gomakethings.com/how-to-replace-a-section-of-a-string-with-another-one-with-vanilla-js/ |
- | |
79 | * @author Chris Ferdinandi |
- | |
80 | * @license MIT |
- | |
81 | */ |
- | |
82 | String.prototype.replaceAll = function(str, newStr){ |
- | |
83 | // If a regex pattern |
- | |
84 | if (Object.prototype.toString.call(str).toLowerCase() === '[object regexp]') { |
- | |
85 | return this.replace(str, newStr); |
- | |
86 | } |
- | |
87 | // If a string |
- | |
88 | return this.replace(new RegExp(str, 'g'), newStr); |
- | |
89 | }; |
- | |
90 | } |
- | |
91 | - | ||
92 | if (!String.prototype.startsWith) { |
- | |
93 | // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith#polyfill |
- | |
94 | Object.defineProperty(String.prototype, 'startsWith', { |
- | |
95 | value: function(search, rawPos) { |
- | |
96 | var pos = rawPos > 0 ? rawPos|0 : 0; |
- | |
97 | return this.substring(pos, pos + search.length) === search; |
- | |
98 | } |
- | |
99 | }); |
- | |
100 | } |
- | |
101 | - | ||
102 | function getMeta(metaName) { |
- | |
103 | const metas = $('meta[name='+metaName+']'); |
- | |
104 | return (metas.length == 0) ? '' : metas[0].content; |
- | |
105 | } |
- | |
106 | - | ||
107 | function getOidPlusSystemTitle() { |
52 | function getOidPlusSystemTitle() { |
108 | return getMeta('OIDplus-SystemTitle'); // do not translate |
53 | return getMeta('OIDplus-SystemTitle'); // do not translate |
109 | } |
54 | } |
110 | 55 | ||
111 | function combine_systemtitle_and_pagetitle(systemtitle, pagetitle) { |
56 | function combine_systemtitle_and_pagetitle(systemtitle, pagetitle) { |
Line 555... | Line 500... | ||
555 | 500 | ||
556 | function gotoButtonClicked() { |
501 | function gotoButtonClicked() { |
557 | openOidInPanel($("#gotoedit").val(), true); |
502 | openOidInPanel($("#gotoedit").val(), true); |
558 | } |
503 | } |
559 | 504 | ||
560 | function jumpToAnchor(anchor) { |
- | |
561 | window.location.href = "#" + anchor; |
- | |
562 | } |
- | |
563 | - | ||
564 | function getCookie(cname) { |
- | |
565 | // Source: https://www.w3schools.com/js/js_cookies.asp |
- | |
566 | var name = cname + "="; |
- | |
567 | var decodedCookie = decodeURIComponent(document.cookie); |
- | |
568 | var ca = decodedCookie.split(';'); |
- | |
569 | for(var i = 0; i <ca.length; i++) { |
- | |
570 | var c = ca[i]; |
- | |
571 | while (c.charAt(0) == ' ') { |
- | |
572 | c = c.substring(1); |
- | |
573 | } |
- | |
574 | if (c.indexOf(name) == 0) { |
- | |
575 | return c.substring(name.length, c.length); |
- | |
576 | } |
- | |
577 | } |
- | |
578 | return undefined; |
- | |
579 | } |
- | |
580 | - | ||
581 | function setCookie(cname, cvalue, exdays, path) { |
- | |
582 | var d = new Date(); |
- | |
583 | d.setTime(d.getTime() + (exdays*24*60*60*1000)); |
- | |
584 | var expires = exdays == 0 ? "" : "; expires="+d.toUTCString(); |
- | |
585 | document.cookie = cname + "=" + cvalue + expires + ";path=" + path + ";SameSite=" + samesite_policy; |
- | |
586 | } |
- | |
587 | - | ||
588 | function setLanguage(lngid) { |
505 | function setLanguage(lngid) { |
589 | setCookie('LANGUAGE', lngid, 0/*Until browser closes*/, location.pathname); |
506 | setCookie('LANGUAGE', lngid, 0/*Until browser closes*/, location.pathname); |
590 | 507 | ||
591 | $(".lng_flag").each(function(){ |
508 | $(".lng_flag").each(function(){ |
592 | $(this).addClass("picture_ghost"); |
509 | $(this).addClass("picture_ghost"); |
Line 601... | Line 518... | ||
601 | reloadContent(); |
518 | reloadContent(); |
602 | mobileNavClose(); |
519 | mobileNavClose(); |
603 | } |
520 | } |
604 | } |
521 | } |
605 | 522 | ||
606 | function getCurrentLang() { |
- | |
607 | // Note: If the argument "?lang=" is used, PHP will automatically set a Cookie, so it is OK when we only check for the cookie |
- | |
608 | var lang = getCookie('LANGUAGE'); // do not translate |
- | |
609 | return (typeof lang != 'undefined') ? lang : DEFAULT_LANGUAGE; // do not translate |
- | |
610 | } |
- | |
611 | - | ||
612 | function _L() { |
- | |
613 | var args = Array.prototype.slice.call(arguments); |
- | |
614 | var str = args.shift().trim(); |
- | |
615 | - | ||
616 | var tmp = ""; |
- | |
617 | if (typeof language_messages[getCurrentLang()] == 'undefined') { // do not translate |
- | |
618 | tmp = str; |
- | |
619 | } else { |
- | |
620 | var msg = language_messages[getCurrentLang()][str]; |
- | |
621 | if (typeof msg != 'undefined') { // do not translate |
- | |
622 | tmp = msg; |
- | |
623 | } else { |
- | |
624 | tmp = str; |
- | |
625 | } |
- | |
626 | } |
- | |
627 | - | ||
628 | tmp = tmp.replace('###', language_tblprefix); |
- | |
629 | - | ||
630 | var n = 1; |
- | |
631 | while (args.length > 0) { |
- | |
632 | var val = args.shift(); |
- | |
633 | tmp = tmp.replace("%"+n, val); |
- | |
634 | n++; |
- | |
635 | } |
- | |
636 | - | ||
637 | tmp = tmp.replace("%%", "%"); |
- | |
638 | - | ||
639 | return tmp; |
- | |
640 | } |
- | |
641 | - | ||
642 | function show_waiting_anim() { |
523 | function show_waiting_anim() { |
643 | $("#loading").show(); |
524 | $("#loading").show(); |
644 | } |
525 | } |
645 | 526 | ||
646 | function hide_waiting_anim() { |
527 | function hide_waiting_anim() { |
Line 664... | Line 545... | ||
664 | $.each(calls, function(key, value) { |
545 | $.each(calls, function(key, value) { |
665 | value.abort(); |
546 | value.abort(); |
666 | }); |
547 | }); |
667 | } |
548 | } |
668 | 549 | ||
669 | /* Misc functions */ |
- | |
670 | - | ||
671 | function isNull(val, def) { |
- | |
672 | // For compatibility with Internet Explorer, use isNull(a,b) instead of a??b |
- | |
673 | if (val == null) { |
- | |
674 | // since null==undefined, this also works with undefined |
- | |
675 | return def; |
- | |
676 | } else { |
- | |
677 | return val; |
- | |
678 | } |
- | |
679 | } |
- | |
680 | - | ||
681 | /* Individual alert types */ |
550 | /* Individual alert types */ |
682 | /* TODO: alert() blocks program flow, but alertSuccess() not! Will the mass change have negative effects (e.g. a redirect without the user seeing the toast)? */ |
551 | /* TODO: alert() blocks program flow, but alertSuccess() not! Will the mass change have negative effects (e.g. a redirect without the user seeing the toast)? */ |
683 | 552 | ||
684 | function alertSuccess(txt) { |
553 | function alertSuccess(txt) { |
685 | if (typeof bs5Utils !== "undefined") { |
554 | if (typeof bs5Utils !== "undefined") { |
Line 696... | Line 565... | ||
696 | 565 | ||
697 | function alertError(txt) { |
566 | function alertError(txt) { |
698 | // TODO: as toast? |
567 | // TODO: as toast? |
699 | alert(txt); |
568 | alert(txt); |
700 | } |
569 | } |
701 | - | ||
702 | /* Misc functions */ |
- | |
703 | - | ||
704 | function copyToClipboard(elem) { |
- | |
705 | // Source: https://stackoverflow.com/questions/22581345/click-button-copy-to-clipboard-using-jquery |
- | |
706 | - | ||
707 | // create hidden text element, if it doesn't already exist |
- | |
708 | var targetId = "_hiddenCopyText_"; |
- | |
709 | var isInput = elem.tagName === "INPUT" || elem.tagName === "TEXTAREA"; |
- | |
710 | var origSelectionStart, origSelectionEnd; |
- | |
711 | if (isInput) { |
- | |
712 | // can just use the original source element for the selection and copy |
- | |
713 | target = elem; |
- | |
714 | origSelectionStart = elem.selectionStart; |
- | |
715 | origSelectionEnd = elem.selectionEnd; |
- | |
716 | } else { |
- | |
717 | // must use a temporary form element for the selection and copy |
- | |
718 | target = document.getElementById(targetId); |
- | |
719 | if (!target) { |
- | |
720 | var target = document.createElement("textarea"); |
- | |
721 | target.style.position = "absolute"; |
- | |
722 | target.style.left = "-9999px"; |
- | |
723 | target.style.top = "0"; |
- | |
724 | target.id = targetId; |
- | |
725 | document.body.appendChild(target); |
- | |
726 | } |
- | |
727 | target.textContent = elem.textContent; |
- | |
728 | } |
- | |
729 | // select the content |
- | |
730 | var currentFocus = document.activeElement; |
- | |
731 | target.focus(); |
- | |
732 | target.setSelectionRange(0, target.value.length); |
- | |
733 | - | ||
734 | // copy the selection |
- | |
735 | var succeed; |
- | |
736 | try { |
- | |
737 | succeed = document.execCommand("copy"); |
- | |
738 | } catch(e) { |
- | |
739 | succeed = false; |
- | |
740 | } |
- | |
741 | // restore original focus |
- | |
742 | if (currentFocus && typeof currentFocus.focus === "function") { |
- | |
743 | currentFocus.focus(); |
- | |
744 | } |
- | |
745 | - | ||
746 | if (isInput) { |
- | |
747 | // restore prior selection |
- | |
748 | elem.setSelectionRange(origSelectionStart, origSelectionEnd); |
- | |
749 | } else { |
- | |
750 | // clear temporary content |
- | |
751 | target.textContent = ""; |
- | |
752 | } |
- | |
753 | return succeed; |
- | |
754 | } |
- |