toolshed-8.x-1.x-dev/js/toolshed.min.js
js/toolshed.min.js
"use strict";Drupal.Toolshed={isString(e){return"string"==typeof e||e instanceof String},escapeRegex(e){return e.replace(/[\^$+*?[\]{}()\\]/g,"\\$&")},ucFirst(e){return e.charAt(0).toUpperCase()+e.slice(1)},camelCase(e){return e.replace(/(?:[ _-]+)([a-z])/g,(e,t)=>t.toUpperCase())},pascalCase(e){return e.replace(/(?:^|[ _-]+)([a-z])/g,(e,t)=>t.toUpperCase())},getCurrentPath(){if(!this.getCurrentPath.path){if(this.getCurrentPath.path=null,!drupalSettings.path.baseUrl)throw Error("Base path is unavailable. This usually occurs if getCurrentPath() is run before the DOM is loaded.");var e=new RegExp("^"+this.escapeRegex(drupalSettings.path.baseUrl),"i");this.getCurrentPath.path=window.location.pathname.replace(e,"")}return this.getCurrentPath.path},getUrlParams(e){const t={};var[e]=(e||window.location.search).split("#",2),[,e=null]=e.split("?",2);return e&&e.split("&").forEach(e=>{e=/^([^=]+)=(.*)$/.exec(e);e&&(t[decodeURIComponent(e[1])]=decodeURIComponent(e[2]))}),t},buildUrl(e,t){let r=e||"";var n;return/^([a-z]{2,5}:)?\/\//i.test(r)||(e=drupalSettings.path.baseUrl||"/",r=r.replace(/^[/,\s]+|<front>|([/,\s]+$)/g,""),r=""+e+drupalSettings.path.pathPrefix+r),t&&(e=this.isString(t)?t:Object.entries(t).reduce((e,t)=>`${e}&${encodeURIComponent(t[0])}=`+encodeURIComponent(t[1]),"").substring(1)).length&&([t,n]=r.split("#",2),r=t+(-1===t.indexOf("?")?"?":"&")+e+(n?"#"+n:"")),r},createRequester(i,l={}){const p=this,u=(l={method:"GET",format:"json",encoding:"urlencoded",...l},e=>p.isString(e)&&"json"===l.format?JSON.parse(e):e);if("POST"!==l.method&&"PUT"!==l.method)return r=>{const n=new XMLHttpRequest;return{promise:new Promise((e,t)=>{n.open(l.method,p.buildUrl(i,r),!0),n.responseType=l.format,n.onload=()=>{200===n.status?e(u(n.response)):t(new Error(n.status+": "+n.statusText))},n.onerror=()=>t(new Error("Unable to connect")),n.onabort=()=>t(new Error("Cancelled")),n.ontimeout=()=>t(new Error("Timeout")),n.send()}),xhr:n}};{let o,a;return a="json"===l.encoding?(o="application/json",JSON.stringify):(o="application/x-www-form-urlencoded",e=>Object.entries(e).reduce((e,[t,r])=>`${e}&${encodeURIComponent(t)}=`+encodeURIComponent(r),"").substring(1)),(r,n)=>{const s=new XMLHttpRequest;return{promise:new Promise((e,t)=>{s.open(l.method,p.buildUrl(i,n),!0),s.responseType=l.format,s.onreadystatechange=function(){this.readyState===XMLHttpRequest.DONE&&(200===this.status?e(u(this.response)):t(new Error(this.status+": "+this.statusText)))},s.onerror=()=>t(new Error("Unable to connect")),s.onabort=()=>t(new Error("Cancelled")),s.ontimeout=()=>t(new Error("Timeout")),r instanceof FormData?s.send(r):(s.setRequestHeader("Content-Type",o),s.send(p.isString(r)?r:a(r)))}),xhr:s}}}},sendRequest(e,t,r={}){e=this.createRequester(e,r)(t).promise;return e},getObject(e){if(!e||!e.split)return null;const n=(e,t)=>{var r=t.shift();return e[r]?t.length?n(e[r],t):e[r]:null};return n(window,e.split("."))},walkByClass(e,t,r,n=null){e=e.classList&&e.classList.contains(t)?[e]:e.getElementsByClassName(t);this._applyToElements(e,r,n)},walkBySelector(e,t,r,n=null){e=e.matches&&e.matches(t)?[e]:e.querySelectorAll(t);this._applyToElements(e,r,n)},_applyToElements(e,t,r=null){if(r){const n=t;t=e=>{if(!e.classList.contains(r))return e.classList.add(r),n(e)}}Array.prototype.forEach.call(e,t)}};