Repository navigation
Expand file tree
/
Copy pathlazyload-preview.js
More file actions
2 lines (2 loc) · 11.7 KB
/
Copy pathlazyload-preview.js
File metadata and controls
2 lines (2 loc) · 11.7 KB
1
2
(()=>{"use strict";var e,t,r,n;e={"(":9,"!":8,"*":7,"/":7,"%":7,"+":6,"-":6,"<":5,"<=":5,">":5,">=":5,"==":4,"!=":4,"&&":3,"||":2,"?":1,"?:":1},t=["(","?"],r={")":["("],":":["?","?:"]},n=/<=|>=|==|!=|&&|\|\||\?:|\(|!|\*|\/|%|\+|-|<|>|\?|\)|:/;var i={"!":function(e){return!e},"*":function(e,t){return e*t},"/":function(e,t){return e/t},"%":function(e,t){return e%t},"+":function(e,t){return e+t},"-":function(e,t){return e-t},"<":function(e,t){return e<t},"<=":function(e,t){return e<=t},">":function(e,t){return e>t},">=":function(e,t){return e>=t},"==":function(e,t){return e===t},"!=":function(e,t){return e!==t},"&&":function(e,t){return e&&t},"||":function(e,t){return e||t},"?:":function(e,t,r){if(e)throw t;return r}};function o(o){var s=function(i){for(var o,s,l,a,c=[],d=[];o=i.match(n);){for(s=o[0],(l=i.substr(0,o.index).trim())&&c.push(l);a=d.pop();){if(r[s]){if(r[s][0]===a){s=r[s][1]||s;break}}else if(t.indexOf(a)>=0||e[a]<e[s]){d.push(a);break}c.push(a)}r[s]||d.push(s),i=i.substr(o.index+s.length)}return(i=i.trim())&&c.push(i),c.concat(d.reverse())}(o);return function(e){return function(e,t){var r,n,o,s,l,a,c=[];for(r=0;r<e.length;r++){if(l=e[r],s=i[l]){for(n=s.length,o=Array(n);n--;)o[n]=c.pop();try{a=s.apply(null,o)}catch(e){return e}}else a=t.hasOwnProperty(l)?t[l]:+l;c.push(a)}return c[0]}(s,e)}}var s={contextDelimiter:"",onMissingKey:null};function l(e,t){var r;for(r in this.data=e,this.pluralForms={},this.options={},s)this.options[r]=void 0!==t&&r in t?t[r]:s[r]}l.prototype.getPluralForm=function(e,t){var r,n,i,s=this.pluralForms[e];return s||("function"!=typeof(i=(r=this.data[e][""])["Plural-Forms"]||r["plural-forms"]||r.plural_forms)&&(n=function(e){var t,r,n;for(t=e.split(";"),r=0;r<t.length;r++)if(0===(n=t[r].trim()).indexOf("plural="))return n.substr(7)}(r["Plural-Forms"]||r["plural-forms"]||r.plural_forms),i=function(e){var t=o(e);return function(e){return+t({n:e})}}(n)),s=this.pluralForms[e]=i),s(t)},l.prototype.dcnpgettext=function(e,t,r,n,i){var o,s,l;return o=void 0===i?0:this.getPluralForm(e,i),s=r,t&&(s=t+this.options.contextDelimiter+r),(l=this.data[e][s])&&l[o]?l[o]:(this.options.onMissingKey&&this.options.onMissingKey(r,e),0===o?r:n)};var a={plural_forms:e=>1===e?0:1},c=/^i18n\.(n?gettext|has_translation)(_|$)/;var d=function(e){return"string"!=typeof e||""===e?(console.error("The namespace must be a non-empty string."),!1):!!/^[a-zA-Z][a-zA-Z0-9_.\-\/]*$/.test(e)||(console.error("The namespace can only contain numbers, letters, dashes, periods, underscores and slashes."),!1)};var h=function(e){return"string"!=typeof e||""===e?(console.error("The hook name must be a non-empty string."),!1):/^__/.test(e)?(console.error("The hook name cannot begin with `__`."),!1):!!/^[a-zA-Z][a-zA-Z0-9_.-]*$/.test(e)||(console.error("The hook name can only contain numbers, letters, dashes, periods and underscores."),!1)};var u=function(e,t){return function(r,n,i,o=10){const s=e[t];if(!h(r))return;if(!d(n))return;if("function"!=typeof i)return void console.error("The hook callback must be a function.");if("number"!=typeof o)return void console.error("If specified, the hook priority must be a number.");const l={callback:i,priority:o,namespace:n};if(s[r]){const e=s[r].handlers;let t;for(t=e.length;t>0&&!(o>=e[t-1].priority);t--);t===e.length?e[t]=l:e.splice(t,0,l),s.__current.forEach(e=>{e.name===r&&e.currentIndex>=t&&e.currentIndex++})}else s[r]={handlers:[l],runs:0};"hookAdded"!==r&&e.doAction("hookAdded",r,n,i,o)}};var p=function(e,t,r=!1){return function(n,i){const o=e[t];if(!h(n))return;if(!r&&!d(i))return;if(!o[n])return 0;let s=0;if(r)s=o[n].handlers.length,o[n]={runs:o[n].runs,handlers:[]};else{const e=o[n].handlers;for(let t=e.length-1;t>=0;t--)e[t].namespace===i&&(e.splice(t,1),s++,o.__current.forEach(e=>{e.name===n&&e.currentIndex>=t&&e.currentIndex--}))}return"hookRemoved"!==n&&e.doAction("hookRemoved",n,i),s}};var m=function(e,t){return function(r,n){const i=e[t];return void 0!==n?r in i&&i[r].handlers.some(e=>e.namespace===n):r in i}};var y=function(e,t,r,n){return function(i,...o){const s=e[t];s[i]||(s[i]={handlers:[],runs:0}),s[i].runs++;const l=s[i].handlers;if(!l||!l.length)return r?o[0]:void 0;const a={name:i,currentIndex:0};return(n?async function(){try{s.__current.add(a);let e=r?o[0]:void 0;for(;a.currentIndex<l.length;){const t=l[a.currentIndex];e=await t.callback.apply(null,o),r&&(o[0]=e),a.currentIndex++}return r?e:void 0}finally{s.__current.delete(a)}}:function(){try{s.__current.add(a);let e=r?o[0]:void 0;for(;a.currentIndex<l.length;){e=l[a.currentIndex].callback.apply(null,o),r&&(o[0]=e),a.currentIndex++}return r?e:void 0}finally{s.__current.delete(a)}})()}};var f=function(e,t){return function(){const r=e[t],n=Array.from(r.__current);return n.at(-1)?.name??null}};var g=function(e,t){return function(r){const n=e[t];return void 0===r?n.__current.size>0:Array.from(n.__current).some(e=>e.name===r)}};var v=function(e,t){return function(r){const n=e[t];if(h(r))return n[r]&&n[r].runs?n[r].runs:0}},_=class{actions;filters;addAction;addFilter;removeAction;removeFilter;hasAction;hasFilter;removeAllActions;removeAllFilters;doAction;doActionAsync;applyFilters;applyFiltersAsync;currentAction;currentFilter;doingAction;doingFilter;didAction;didFilter;constructor(){this.actions=Object.create(null),this.actions.__current=new Set,this.filters=Object.create(null),this.filters.__current=new Set,this.addAction=u(this,"actions"),this.addFilter=u(this,"filters"),this.removeAction=p(this,"actions"),this.removeFilter=p(this,"filters"),this.hasAction=m(this,"actions"),this.hasFilter=m(this,"filters"),this.removeAllActions=p(this,"actions",!0),this.removeAllFilters=p(this,"filters",!0),this.doAction=y(this,"actions",!1,!1),this.doActionAsync=y(this,"actions",!1,!0),this.applyFilters=y(this,"filters",!0,!1),this.applyFiltersAsync=y(this,"filters",!0,!0),this.currentAction=f(this,"actions"),this.currentFilter=f(this,"filters"),this.doingAction=g(this,"actions"),this.doingFilter=g(this,"filters"),this.didAction=v(this,"actions"),this.didFilter=v(this,"filters")}};var b=function(){return new _}(),{addAction:A,addFilter:F,removeAction:x,removeFilter:w,hasAction:P,hasFilter:T,removeAllActions:N,removeAllFilters:I,doAction:k,doActionAsync:E,applyFilters:z,applyFiltersAsync:L,currentAction:S,currentFilter:B,doingAction:D,doingFilter:C,didAction:R,didFilter:O,actions:j,filters:Z}=b,G=((e,t,r)=>{const n=new l({}),i=new Set,o=()=>{i.forEach(e=>e())},s=(e,t="default")=>{n.data[t]={...n.data[t],...e},n.data[t][""]={...a,...n.data[t]?.[""]},delete n.pluralForms[t]},d=(e,t)=>{s(e,t),o()},h=(e="default",t,r,i,o)=>(n.data[e]||s(void 0,e),n.dcnpgettext(e,t,r,i,o)),u=e=>e||"default",p=(e,t,n)=>{let i=h(n,t,e);return r?(i=r.applyFilters("i18n.gettext_with_context",i,e,t,n),r.applyFilters("i18n.gettext_with_context_"+u(n),i,e,t,n)):i};if(e&&d(e,t),r){const e=e=>{c.test(e)&&o()};r.addAction("hookAdded","core/i18n",e),r.addAction("hookRemoved","core/i18n",e)}return{getLocaleData:(e="default")=>n.data[e],setLocaleData:d,addLocaleData:(e,t="default")=>{n.data[t]={...n.data[t],...e,"":{...a,...n.data[t]?.[""],...e?.[""]}},delete n.pluralForms[t],o()},resetLocaleData:(e,t)=>{n.data={},n.pluralForms={},d(e,t)},subscribe:e=>(i.add(e),()=>i.delete(e)),__:(e,t)=>{let n=h(t,void 0,e);return r?(n=r.applyFilters("i18n.gettext",n,e,t),r.applyFilters("i18n.gettext_"+u(t),n,e,t)):n},_x:p,_n:(e,t,n,i)=>{let o=h(i,void 0,e,t,n);return r?(o=r.applyFilters("i18n.ngettext",o,e,t,n,i),r.applyFilters("i18n.ngettext_"+u(i),o,e,t,n,i)):o},_nx:(e,t,n,i,o)=>{let s=h(o,i,e,t,n);return r?(s=r.applyFilters("i18n.ngettext_with_context",s,e,t,n,i,o),r.applyFilters("i18n.ngettext_with_context_"+u(o),s,e,t,n,i,o)):s},isRTL:()=>"rtl"===p("ltr","text direction"),hasTranslation:(e,t,i)=>{const o=t?t+""+e:e;let s=!!n.data?.[i??"default"]?.[o];return r&&(s=r.applyFilters("i18n.has_translation",s,e,t,i),s=r.applyFilters("i18n.has_translation_"+u(i),s,e,t,i)),s}}})(void 0,void 0,b);G.getLocaleData.bind(G),G.setLocaleData.bind(G),G.resetLocaleData.bind(G),G.subscribe.bind(G),G.__.bind(G),G._x.bind(G),G._n.bind(G),G._nx.bind(G),G.isRTL.bind(G),G.hasTranslation.bind(G);const H={cycleTime:2e3,animate:document.getElementById("lazy_loading.lazy_animate"),image:document.getElementById("lazyload-image"),placeHolders:document.querySelectorAll('[name="lazy_loading[lazy_placeholder]"]'),preloader:document.getElementById("preloader-image"),color:document.getElementById("lazy_loading.lazy_custom_color"),previewCycle:document.getElementById("preview-cycle"),progress:document.getElementById("progress-bar"),threshold:document.getElementById("lazy_loading.lazy_threshold"),currentPlaceholder:null,svg:null,running:!1,init(){this.svg=this.image.dataset.svg,this.currentPlaceholder=document.getElementById("placeholder-"+this.getPlaceholder()),[...this.placeHolders].forEach(e=>{e.addEventListener("change",()=>this.changePlaceholder(e.value))}),this.color.addEventListener("input",()=>this.changePreloader()),this.animate.addEventListener("change",()=>this.changePreloader()),this.previewCycle.addEventListener("click",()=>this.startCycle())},getPlaceholder:()=>document.querySelector('[name="lazy_loading[lazy_placeholder]"]:checked').value,changePreloader(){this.preloader.src=this.getSVG()},changePlaceholder(e){const t=document.getElementById("placeholder-"+e);this.currentPlaceholder&&(this.currentPlaceholder.style.display="none",this.currentPlaceholder.style.width="85%",this.currentPlaceholder.style.boxShadow="",this.currentPlaceholder.style.bottom="0"),t&&(t.style.display=""),this.currentPlaceholder=t},getThreshold(){return parseInt(this.threshold.value)+this.image.parentNode.parentNode.offsetHeight},startCycle(){this.running?this.endCycle():(this.changePlaceholder("none"),this.image.parentNode.parentNode.style.overflowY="scroll",this.image.parentNode.style.visibility="hidden",this.image.parentNode.style.width="100%",this.image.parentNode.style.boxShadow="none",this.progress.style.width="100%",this.preloader.parentNode.style.visibility="hidden",this.running=setTimeout(()=>{this.progress.style.visibility="hidden",this.progress.style.width="0%",this.preloader.parentNode.style.visibility="",setTimeout(()=>{const e=this.getThreshold();this.image.parentNode.style.visibility="",this.preloader.parentNode.style.bottom="-"+e+"px",setTimeout(()=>{setTimeout(()=>{this.image.parentNode.parentNode.scrollTo({top:e,behavior:"smooth"}),this.showPlaceholder()},this.cycleTime/3)},this.cycleTime/2)},this.cycleTime/2)},this.cycleTime/2))},showPlaceholder(){const e=this.getPlaceholder(),t=this.getThreshold();"off"!==e&&(this.changePlaceholder(e),this.currentPlaceholder&&(this.currentPlaceholder.style.width="100%",this.currentPlaceholder.style.boxShadow="none",this.currentPlaceholder.style.bottom="-"+t+"px")),setTimeout(()=>{this.showImage()},this.cycleTime/2)},showImage(){const e=this.getThreshold();this.changePlaceholder("none"),this.image.parentNode.style.bottom="-"+e+"px",this.image.parentNode.style.visibility="",setTimeout(()=>{this.endCycle()},this.cycleTime)},endCycle(){clearTimeout(this.running),this.running=!1,this.changePlaceholder(this.getPlaceholder()),this.image.parentNode.style.visibility="",this.image.parentNode.style.bottom="0",this.image.parentNode.style.width="65%",this.image.parentNode.style.boxShadow="",this.preloader.parentNode.style.bottom="0",this.image.parentNode.parentNode.style.overflowY="",this.progress.style.visibility=""},getSVG(){const e=this.color.value,t=[e];if(this.animate.checked){const r=[...e.matchAll(new RegExp(/[\d+\.*]+/g))];r[3]=.1,t.push("rgba("+r.join(",")+")"),t.push(e)}return this.svg.replace("-color-",t.join(";"))},showLoader(){this.image.parentNode.style.opacity=1,this.image.parentNode.src=this.getSVG(),setTimeout(()=>{this.showPlaceholder(this.image.parentNode.dataset.placeholder)},this.cycleTime)}};window.addEventListener("load",()=>H.init())})();
//# sourceMappingURL=lazyload-preview.js.map