/*\ title: $:/core/modules/utils/deprecated.js type: application/javascript module-type: utils Deprecated util functions. These preserve the pre-5.4.0 signatures and behaviour for backwards compatibility with plugins and external scripts. Prefer modern alternatives in new code (Array.prototype methods, classList, Math.sign, String.prototype.repeat, etc.). \*/ exports.logTable = (data) => console.table(data); /* Repeats a string */ exports.repeat = function(str,count) { var result = ""; for(var t=0;t array.some((element) => $tw.utils.hop(object,element)); exports.sign = Math.sign; exports.strEndsWith = (str,ending,position) => str.endsWith(ending,position); exports.stringifyNumber = function(num) { return num + ""; }; // Returns the fully escaped CSS selector for a tag, e.g. // "$:/tags/Stylesheet" -> "tc-tagged-\%24\%3A\%2Ftags\%2FStylesheet" exports.tagToCssSelector = function(tagName) { return "tc-tagged-" + encodeURIComponent(tagName).replace(/[!"#$%&'()*+,\-./:;<=>?@[\\\]^`{\|}~,]/mg,function(c) { return "\\" + c; }); }; /* Determines whether element 'a' contains element 'b'. Returns false when a === b (matches the original John Resig semantics). */ exports.domContains = function(a,b) { return a !== b && a.contains(b); }; exports.domMatchesSelector = (node,selector) => node.matches(selector); exports.hasClass = function(el,className) { return !!(el && el.classList && el.classList.contains(className)); }; // addClass/removeClass/toggleClass split on whitespace to preserve the // original setAttribute("class", ...) acceptance of "foo bar" as two // classes. Regressed in #9251. function splitClasses(className) { return (typeof className === "string" && className.match(/\S+/g)) || []; } exports.addClass = function(el,className) { if(!el.classList) return; splitClasses(className).forEach(function(c) { el.classList.add(c); }); }; exports.removeClass = function(el,className) { if(!el.classList) return; splitClasses(className).forEach(function(c) { el.classList.remove(c); }); }; exports.toggleClass = function(el,className,status) { if(!el.classList) return; splitClasses(className).forEach(function(c) { el.classList.toggle(c,status); }); }; exports.getLocationPath = function() { return window.location.toString().split("#")[0]; };