← Back
Editing: admin-bar.js
(()=>{"use strict";const t={n:e=>{const o=e&&e.__esModule?()=>e.default:()=>e;return t.d(o,{a:o}),o},d:(e,o)=>{if(Array.isArray(o))for(var n=0;n<o.length;){var a=o[n++],c=o[n++];t.o(e,a)?0===c&&n++:0===c?Object.defineProperty(e,a,{enumerable:!0,value:o[n++]}):Object.defineProperty(e,a,{enumerable:!0,get:c})}else for(var a in o)t.o(o,a)&&!t.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:o[a]})},o:(t,e)=>Object.hasOwn(t,e)},e=window.jQuery;var o=t.n(e);const n=window.popupMaker.i18n,a=new Set(["role","name","aria-label","rel","href"]);function c(t,e){let o=a.has(t);o||=t.startsWith("data-")&&p(t);let n=p(e)&&e.length<100;return n||=e.startsWith("#")&&p(e.slice(1)),o&&n}function r(t){return p(t)}function i(t){return p(t)}function s(t){return!0}function l(t,e){if(t.nodeType!==Node.ELEMENT_NODE)throw new Error("Can't generate CSS selector for non-element node type.");if("html"===t.tagName.toLowerCase())return"html";const o={root:document.body,idName:r,className:i,tagName:s,attr:c,timeoutMs:1e3,seedMinLength:3,optimizedMinLength:2,maxNumberOfPathChecks:1/0},n=new Date,a={...o,...e},l=function(t,e){return t.nodeType===Node.DOCUMENT_NODE?t:t===e.root?t.ownerDocument:t}(a.root,o);let p,m=0;for(const e of function*(t,e,o){const n=[];let a=[],c=t,r=0;for(;c&&c!==o;){const t=u(c,e);for(const e of t)e.level=r;if(n.push(t),c=c.parentElement,r++,a.push(...g(n)),r>=e.seedMinLength){a.sort(f);for(const t of a)yield t;a=[]}}a.sort(f);for(const t of a)yield t}(t,a,l)){if((new Date).getTime()-n.getTime()>a.timeoutMs||m>=a.maxNumberOfPathChecks){const e=y(t,l);if(!e)throw new Error(`Timeout: Can't find a unique selector after ${a.timeoutMs}ms`);return d(e)}if(m++,w(e,l)){p=e;break}}if(!p)throw new Error("Selector was not found.");const h=[...C(p,t,a,l,n)];return h.sort(f),h.length>0?d(h[0]):d(p)}function p(t){if(/^[a-z\-]{3,}$/i.test(t)){const e=t.split(/-|[A-Z]/);for(const t of e){if(t.length<=2)return!1;if(/[^aeiou]{4,}/i.test(t))return!1}return!0}return!1}function u(t,e){const o=[],n=t.getAttribute("id");n&&e.idName(n)&&o.push({name:"#"+CSS.escape(n),penalty:0});for(let n=0;n<t.classList.length;n++){const a=t.classList[n];e.className(a)&&o.push({name:"."+CSS.escape(a),penalty:1})}for(let n=0;n<t.attributes.length;n++){const a=t.attributes[n];e.attr(a.name,a.value)&&o.push({name:`[${CSS.escape(a.name)}="${CSS.escape(a.value)}"]`,penalty:2})}const a=t.tagName.toLowerCase();if(e.tagName(a)){o.push({name:a,penalty:5});const e=h(t,a);void 0!==e&&o.push({name:b(a,e),penalty:10})}const c=h(t);return void 0!==c&&o.push({name:k(a,c),penalty:50}),o}function d(t){let e=t[0],o=e.name;for(let n=1;n<t.length;n++){const a=t[n].level||0;o=e.level===a-1?`${t[n].name} > ${o}`:`${t[n].name} ${o}`,e=t[n]}return o}function m(t){return t.map(t=>t.penalty).reduce((t,e)=>t+e,0)}function f(t,e){return m(t)-m(e)}function h(t,e){const o=t.parentNode;if(!o)return;let n=o.firstChild;if(!n)return;let a=0;for(;n&&(n.nodeType!==Node.ELEMENT_NODE||void 0!==e&&n.tagName.toLowerCase()!==e||a++,n!==t);)n=n.nextSibling;return a}function y(t,e){let o=0,n=t;const a=[];for(;n&&n!==e;){const t=n.tagName.toLowerCase(),e=h(n,t);if(void 0===e)return;a.push({name:b(t,e),penalty:NaN,level:o}),n=n.parentElement,o++}if(w(a,e))return a}function k(t,e){return"html"===t?"html":`${t}:nth-child(${e})`}function b(t,e){return"html"===t?"html":`${t}:nth-of-type(${e})`}function*g(t,e=[]){if(t.length>0)for(let o of t[0])yield*g(t.slice(1,t.length),e.concat(o));else yield e}function w(t,e){const o=d(t);switch(e.querySelectorAll(o).length){case 0:throw new Error(`Can't select any node with this selector: ${o}`);case 1:return!0;default:return!1}}function*C(t,e,o,n,a){if(t.length>2&&t.length>o.optimizedMinLength)for(let c=1;c<t.length-1;c++){if((new Date).getTime()-a.getTime()>o.timeoutMs)return;const r=[...t];r.splice(c,1),w(r,n)&&n.querySelector(d(r))===e&&(yield r,yield*C(r,e,o,n,a))}}function v(t){const e=document.createElement("div"),a=t.actions?`\n\t\t<div class="pum-modal-actions">\n\t\t\t${t.actions.primary?`\n\t\t\t\t<button class="button button-primary pum-modal-proceed">\n\t\t\t\t\t${t.actions.primary.text}\n\t\t\t\t</button>\n\t\t\t`:""}\n\t\t\t${t.actions.secondary?`\n\t\t\t\t<button class="button button-secondary pum-modal-cancel">\n\t\t\t\t\t${t.actions.secondary.text}\n\t\t\t\t</button>\n\t\t\t`:""}\n\t\t</div>\n\t`:"";e.innerHTML=`<div class="pum-modal pum-modal-overlay">\n\t\t<div class="pum-modal-content">\n\t\t\t<div class="pum-modal-header">\n\t\t\t\t<div class="pum-logo"></div>\n\t\t\t\t<h4>${t.title}</h4>\n\t\t\t\t<button class="pum-modal-close">\n\t\t\t\t\t<span class="dashicons dashicons-no-alt"></span>\n\t\t\t\t\t<span class="screen-reader-text">${t.closeText||(0,n.__)("Close","popup-maker")}</span>\n\t\t\t\t</button>\n\t\t\t</div>\n\t\t\t<div class="pum-modal-body">\n\t\t\t\t${t.content}\n\t\t\t\t${a}\n\t\t\t</div>\n\t\t</div>\n\t</div>`,document.body.appendChild(e);const c=()=>{o()(document).off("keydown",r),o()(document).off("mousedown",i),o()(".pum-modal-close, .pum-modal-cancel",e).off("click",c),o()(".pum-modal-proceed",e).off("click",s),o()(".pum-modal-cancel",e).off("click",l),o()(e).fadeOut(200,()=>{e.remove()})},r=t=>{"Escape"===t.key&&c()},i=t=>{o()(t.target).hasClass("pum-modal-overlay")&&c()},s=()=>{t.actions?.primary?.onClick&&t.actions.primary.onClick(),c()},l=()=>{t.actions?.secondary?.onClick&&t.actions.secondary.onClick(),c()};return o()(document).on("keydown",r),o()(document).on("mousedown",i),o()(".pum-modal-close, .pum-modal-cancel",e).on("click",c),t.actions?.primary&&o()(".pum-modal-proceed",e).on("click",s),t.actions?.secondary&&o()(".pum-modal-cancel",e).on("click",l),e}class _{defaultText={instructions:(0,n.__)("After clicking ok, click the element you want a selector for.","popup-maker"),results:(0,n.__)("Selector","popup-maker"),copy:(0,n.__)("Copy","popup-maker"),close:(0,n.__)("Close","popup-maker"),copied:(0,n.__)("Copied to clipboard","popup-maker")};constructor(){this.text=popupMakerAdminBar?.i18n||this.defaultText,this.initialize()}async copyToClipboard(t){try{return navigator.clipboard&&window.isSecureContext?(await navigator.clipboard.writeText(t),!0):this.fallbackCopyToClipboard(t)}catch(e){return console.error("Failed to copy text:",e),this.fallbackCopyToClipboard(t)}}fallbackCopyToClipboard(t){const e=document.createElement("textarea");try{return e.value=t,e.style.position="fixed",e.style.opacity="0",document.body.appendChild(e),e.select(),document.execCommand("copy")}catch(t){return console.error("Fallback copy failed:",t),!1}finally{document.body.removeChild(e)}}showCopiedNotice(t){const e=document.createElement("div");e.classList.add("notice","notice-success"),e.innerHTML=`<p>${this.text.copied}</p>`,t.append(e),setTimeout(()=>{o()(e).fadeOut(200,()=>{o()(e).remove()})},3e3)}handleSelectorClick=async t=>{t.preventDefault(),t.stopPropagation();const e=l(t.target,{seedMinLength:3}),n=v({title:this.text.results,content:`\n\t\t\t\t<div class="pum-modal-copy">\n\t\t\t\t\t<p>${a=e,String(a).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}</p>\n\t\t\t\t\t<button class="copy-clipboard button button-secondary">\n\t\t\t\t\t\t<span class="dashicons dashicons-clipboard"></span>\n\t\t\t\t\t\t<span class="screen-reader-text">${this.text.copy}</span>\n\t\t\t\t\t</button>\n\t\t\t\t</div>\n\t\t\t`,closeText:this.text.close});var a;o()(".copy-clipboard",n).on("click",async()=>{await this.copyToClipboard(e)&&this.showCopiedNotice(o()(".pum-modal-body",n))})};initialize(){const{PUM:t}=window;o()(document).on("click","#wp-admin-bar-pum-get-selector",t=>{t.preventDefault(),t.stopPropagation(),v({title:(0,n.__)("Get Element Selector","popup-maker"),content:this.text.instructions,closeText:this.text.close,actions:{primary:{text:(0,n.__)("Start Selection","popup-maker"),onClick:()=>{setTimeout(()=>{o()(document).one("click",this.handleSelectorClick)},250)}},secondary:{text:(0,n.__)("Cancel","popup-maker"),onClick:()=>{}}}})}),o()("#wpadminbar").on("click",".pum-toolbar-action",e=>{e.preventDefault(),e.stopPropagation();const a=o()(e.currentTarget),c=a.is("a")?a.attr("href"):a.children("a.ab-item").first().attr("href");if(!c)return;const r=c.match(/^#pum-toolbar-action__(open|close|check-conditions|reset-cookies)--(\d+)$/);if(!r)return;const[,i,s]=r;switch(i){case"open":t.open(s);break;case"close":t.close(s);break;case"check-conditions":v({title:(0,n.__)("Conditions Check","popup-maker"),content:t.checkConditions(s)?(0,n.__)("The conditions were met.","popup-maker"):(0,n.__)("The conditions were not met.","popup-maker")});break;case"reset-cookies":t.clearCookies(s),v({title:(0,n.__)("Cookies Reset","popup-maker"),content:(0,n.__)("The cookies were reset successfully.","popup-maker")})}})}}o()(()=>{new _}),(window.popupMaker=window.popupMaker||{}).adminBar={}})();
Save File
Cancel