49,61 → 49,6 |
); |
} |
|
function isInternetExplorer() { |
// see also includes/functions.inc.php |
var ua = window.navigator.userAgent; |
return ((ua.indexOf("MSIE ") > 0) || (ua.indexOf("Trident/") > 0)); |
} |
|
String.prototype.explode = function (separator, limit) { |
// https://stackoverflow.com/questions/4514323/javascript-equivalent-to-php-explode |
const array = this.split(separator); |
if (limit !== undefined && array.length >= limit) { |
array.push(array.splice(limit - 1).join(separator)); |
} |
return array; |
}; |
|
String.prototype.htmlentities = function () { |
return this.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');//" |
}; |
|
String.prototype.html_entity_decode = function () { |
return $('<textarea />').html(this).text(); |
}; |
|
if (!String.prototype.replaceAll) { |
/** |
* String.prototype.replaceAll() polyfill |
* https://gomakethings.com/how-to-replace-a-section-of-a-string-with-another-one-with-vanilla-js/ |
* @author Chris Ferdinandi |
* @license MIT |
*/ |
String.prototype.replaceAll = function(str, newStr){ |
// If a regex pattern |
if (Object.prototype.toString.call(str).toLowerCase() === '[object regexp]') { |
return this.replace(str, newStr); |
} |
// If a string |
return this.replace(new RegExp(str, 'g'), newStr); |
}; |
} |
|
if (!String.prototype.startsWith) { |
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith#polyfill |
Object.defineProperty(String.prototype, 'startsWith', { |
value: function(search, rawPos) { |
var pos = rawPos > 0 ? rawPos|0 : 0; |
return this.substring(pos, pos + search.length) === search; |
} |
}); |
} |
|
function getMeta(metaName) { |
const metas = $('meta[name='+metaName+']'); |
return (metas.length == 0) ? '' : metas[0].content; |
} |
|
function getOidPlusSystemTitle() { |
return getMeta('OIDplus-SystemTitle'); // do not translate |
} |
557,34 → 502,6 |
openOidInPanel($("#gotoedit").val(), true); |
} |
|
function jumpToAnchor(anchor) { |
window.location.href = "#" + anchor; |
} |
|
function getCookie(cname) { |
// Source: https://www.w3schools.com/js/js_cookies.asp |
var name = cname + "="; |
var decodedCookie = decodeURIComponent(document.cookie); |
var ca = decodedCookie.split(';'); |
for(var i = 0; i <ca.length; i++) { |
var c = ca[i]; |
while (c.charAt(0) == ' ') { |
c = c.substring(1); |
} |
if (c.indexOf(name) == 0) { |
return c.substring(name.length, c.length); |
} |
} |
return undefined; |
} |
|
function setCookie(cname, cvalue, exdays, path) { |
var d = new Date(); |
d.setTime(d.getTime() + (exdays*24*60*60*1000)); |
var expires = exdays == 0 ? "" : "; expires="+d.toUTCString(); |
document.cookie = cname + "=" + cvalue + expires + ";path=" + path + ";SameSite=" + samesite_policy; |
} |
|
function setLanguage(lngid) { |
setCookie('LANGUAGE', lngid, 0/*Until browser closes*/, location.pathname); |
|
603,42 → 520,6 |
} |
} |
|
function getCurrentLang() { |
// Note: If the argument "?lang=" is used, PHP will automatically set a Cookie, so it is OK when we only check for the cookie |
var lang = getCookie('LANGUAGE'); // do not translate |
return (typeof lang != 'undefined') ? lang : DEFAULT_LANGUAGE; // do not translate |
} |
|
function _L() { |
var args = Array.prototype.slice.call(arguments); |
var str = args.shift().trim(); |
|
var tmp = ""; |
if (typeof language_messages[getCurrentLang()] == 'undefined') { // do not translate |
tmp = str; |
} else { |
var msg = language_messages[getCurrentLang()][str]; |
if (typeof msg != 'undefined') { // do not translate |
tmp = msg; |
} else { |
tmp = str; |
} |
} |
|
tmp = tmp.replace('###', language_tblprefix); |
|
var n = 1; |
while (args.length > 0) { |
var val = args.shift(); |
tmp = tmp.replace("%"+n, val); |
n++; |
} |
|
tmp = tmp.replace("%%", "%"); |
|
return tmp; |
} |
|
function show_waiting_anim() { |
$("#loading").show(); |
} |
666,18 → 547,6 |
}); |
} |
|
/* Misc functions */ |
|
function isNull(val, def) { |
// For compatibility with Internet Explorer, use isNull(a,b) instead of a??b |
if (val == null) { |
// since null==undefined, this also works with undefined |
return def; |
} else { |
return val; |
} |
} |
|
/* Individual alert types */ |
/* 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)? */ |
|
698,57 → 567,3 |
// TODO: as toast? |
alert(txt); |
} |
|
/* Misc functions */ |
|
function copyToClipboard(elem) { |
// Source: https://stackoverflow.com/questions/22581345/click-button-copy-to-clipboard-using-jquery |
|
// create hidden text element, if it doesn't already exist |
var targetId = "_hiddenCopyText_"; |
var isInput = elem.tagName === "INPUT" || elem.tagName === "TEXTAREA"; |
var origSelectionStart, origSelectionEnd; |
if (isInput) { |
// can just use the original source element for the selection and copy |
target = elem; |
origSelectionStart = elem.selectionStart; |
origSelectionEnd = elem.selectionEnd; |
} else { |
// must use a temporary form element for the selection and copy |
target = document.getElementById(targetId); |
if (!target) { |
var target = document.createElement("textarea"); |
target.style.position = "absolute"; |
target.style.left = "-9999px"; |
target.style.top = "0"; |
target.id = targetId; |
document.body.appendChild(target); |
} |
target.textContent = elem.textContent; |
} |
// select the content |
var currentFocus = document.activeElement; |
target.focus(); |
target.setSelectionRange(0, target.value.length); |
|
// copy the selection |
var succeed; |
try { |
succeed = document.execCommand("copy"); |
} catch(e) { |
succeed = false; |
} |
// restore original focus |
if (currentFocus && typeof currentFocus.focus === "function") { |
currentFocus.focus(); |
} |
|
if (isInput) { |
// restore prior selection |
elem.setSelectionRange(origSelectionStart, origSelectionEnd); |
} else { |
// clear temporary content |
target.textContent = ""; |
} |
return succeed; |
} |