wp_back/wp-content/plugins/visual-portfolio/build/assets/js/main.js
2024-05-20 15:37:46 +03:00

1 line
12 KiB
JavaScript

!function(){"use strict";var t={n:function(e){var i=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(i,{a:i}),i},d:function(e,i){for(var o in i)t.o(i,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:i[o]})},o:function(t,e){return Object.prototype.hasOwnProperty.call(t,e)}},e=window.jQuery,i=t.n(e);const{VPData:o}=window,{__:__}=o,s=i()(window);function n(){if("function"==typeof window.Event)window.dispatchEvent(new window.Event("resize"));else{const t=window.document.createEvent("UIEvents");t.initUIEvent("resize",!0,!1,window,0),window.dispatchEvent(t)}}const r={};let a=!1,l=!1,d=!1;function p(){if(clearTimeout(l),!a)return;const t=i()(".vp-portfolio__ready");if(t.length){let e=!1;t.each((function(){const{vpf:t}=this;if(!t)return;const i=r[t.uid]||"none";r[t.uid]=null===this.offsetParent?"hidden":"visible","hidden"===i&&"visible"===r[t.uid]&&(e=!0)})),e&&n()}else a=!1;l=setTimeout(p,500)}i()(document).on("inited.vpf",(t=>{"vpf"===t.namespace&&(a=!0,p())})),document.addEventListener("keydown",(function(t){t.metaKey||t.altKey||t.ctrlKey||(d=!0)}),!0),document.addEventListener("mousedown",(()=>{d=!1}),!0),document.addEventListener("pointerdown",(()=>{d=!1}),!0),document.addEventListener("touchstart",(()=>{d=!1}),!0);class v{constructor(t,e){const i=this;i.$item=t;const o=t[0].className.split(/\s+/);for(let t=0;t<o.length;t+=1)o[t]&&/^vp-uid-/.test(o[t])&&(i.uid=o[t].replace(/^vp-uid-/,"")),o[t]&&/^vp-id-/.test(o[t])&&(i.id=o[t].replace(/^vp-id-/,""));i.uid?(i.href=window.location.href,i.$items_wrap=t.find(".vp-portfolio__items"),i.$slider_thumbnails_wrap=t.find(".vp-portfolio__thumbnails"),i.$pagination=t.find(".vp-portfolio__pagination-wrap"),i.$filter=t.find(".vp-portfolio__filter-wrap"),i.$sort=t.find(".vp-portfolio__sort-wrap"),i.id&&(i.$filter=i.$filter.add(`.vp-single-filter.vp-id-${i.id} .vp-portfolio__filter-wrap`)),i.id&&(i.$sort=i.$sort.add(`.vp-single-sort.vp-id-${i.id} .vp-portfolio__sort-wrap`)),i.userOptions=e,i.firstRun=!0,i.init()):console.error(__.couldnt_retrieve_vp)}emitEvent(t,e){e=e?[this].concat(e):[this],this.$item.trigger(`${t}.vpf`,e),this.$item.trigger(`${t}.vpf-uid-${this.uid}`,e)}init(){const t=this;t.firstRun||t.destroy(),t.destroyed=!1,t.$item.addClass("vp-portfolio__ready"),t.initOptions(),t.initEvents(),t.initLayout(),t.initCustomColors(),t.emitEvent("init"),t.id&&(i()(`.vp-single-filter.vp-id-${t.id}`).addClass("vp-single-filter__ready").parent(".vp-portfolio__layout-elements").addClass("vp-portfolio__layout-elements__ready"),i()(`.vp-single-sort.vp-id-${t.id}`).addClass("vp-single-sort__ready").parent(".vp-portfolio__layout-elements").addClass("vp-portfolio__layout-elements__ready")),t.resized(),t.imagesLoaded(),t.emitEvent("inited"),t.firstRun=!1}isPreview(){return!!this.$item.closest("#vp_preview").length}resized(){n(),this.emitEvent("resized")}imagesLoaded(){this.$items_wrap.imagesLoaded&&this.$items_wrap.imagesLoaded().progress((()=>{this.emitEvent("imagesLoaded")}))}destroy(){const t=this;t.$item.removeClass("vp-portfolio__ready"),t.id&&(i()(`.vp-single-filter.vp-id-${t.id}`).removeClass("vp-single-filter__ready").parent(".vp-portfolio__layout-elements").removeClass("vp-portfolio__layout-elements__ready"),i()(`.vp-single-sort.vp-id-${t.id}`).removeClass("vp-single-sort__ready").parent(".vp-portfolio__layout-elements").removeClass("vp-portfolio__layout-elements__ready")),t.destroyEvents(),t.removeStyle(),t.renderStyle(),t.emitEvent("destroy"),t.destroyed=!0}addStyle(t,e,o){o=o||"";const s=this,{uid:n}=s;s.stylesList||(s.stylesList={}),void 0===s.stylesList[n]&&(s.stylesList[n]={}),void 0===s.stylesList[n][o]&&(s.stylesList[n][o]={}),void 0===s.stylesList[n][o][t]&&(s.stylesList[n][o][t]={}),s.stylesList[n][o][t]=i().extend(s.stylesList[n][o][t],e),s.emitEvent("addStyle",[t,e,o,s.stylesList])}removeStyle(t,e,i){i=i||"";const o=this,{uid:s}=o;o.stylesList||(o.stylesList={}),void 0===o.stylesList[s]||t||(o.stylesList[s]={}),void 0!==o.stylesList[s]&&void 0!==o.stylesList[s][i]&&void 0!==o.stylesList[s][i][t]&&t&&delete o.stylesList[s][i][t],o.emitEvent("removeStyle",[t,e,o.stylesList])}renderStyle(){const t=this,{uid:e}=t;let o="";t.stylesList||(t.stylesList={}),void 0!==t.stylesList[e]&&Object.keys(t.stylesList[e]).forEach((i=>{i&&(o+=`@media ${i} {`),Object.keys(t.stylesList[e][i]).forEach((s=>{const n=`.vp-uid-${e}`;let r=`${n} ${s}`;r=r.replace(/, |,/g,`, ${n} `),o+=`${r} {`,Object.keys(t.stylesList[e][i][s]).forEach((n=>{o+=`${n}:${t.stylesList[e][i][s][n]};`})),o+="}"})),i&&(o+="}")}));let s=i()(`#vp-style-${e}`);s.length||(s=i()("<style>").attr("id",`vp-style-${e}`).appendTo("head")),s.html(o),t.emitEvent("renderStyle",[o,t.stylesList,s])}firstToLowerCase(t){return t.substr(0,1).toLowerCase()+t.substr(1)}initOptions(t){const e=this;e.defaults={layout:"tile",itemsGap:0,pagination:"load-more"},t&&(e.userOptions=t);const o=e.$item[0].dataset,s={};Object.keys(o).forEach((t=>{t&&"vp"===t.substring(0,2)&&(s[e.firstToLowerCase(t.substring(2))]=o[t])})),e.options=i().extend({},e.defaults,s,e.userOptions),e.emitEvent("initOptions")}initEvents(){const t=this,e=`.vpf-uid-${t.uid}`;function o(){const e=t.$item[0].getBoundingClientRect(),{left:i}=e,o=window.innerWidth-e.right,s=parseFloat(t.$item.css("margin-left")||0),n=parseFloat(t.$item.css("margin-right")||0);t.$item.css({marginLeft:s-i,marginRight:n-o,maxWidth:"none",width:"auto"})}t.$item.hasClass("vp-portfolio__stretch")&&!t.isPreview()&&(s.on(`load${e} resize${e} orientationchange${e}`,(()=>{o()})),o()),t.$item.on(`focus${e}`,".vp-portfolio__item a",(function(){const t=i()(this).closest(".vp-portfolio__item");t.addClass("vp-portfolio__item-focus"),d&&t.addClass("vp-portfolio__item-focus-visible")})),t.$item.on(`blur${e}`,".vp-portfolio__item a",(function(){i()(this).closest(".vp-portfolio__item").removeClass("vp-portfolio__item-focus vp-portfolio__item-focus-visible")})),t.$filter.on(`click${e}`,".vp-filter .vp-filter__item a",(function(e){e.preventDefault();const o=i()(this);t.loading||o.closest(".vp-filter__item").addClass("vp-filter__item-active").siblings().removeClass("vp-filter__item-active"),t.loadNewItems(o.attr("href"),!0)})),t.$sort.on(`click${e}`,".vp-sort .vp-sort__item a",(function(e){e.preventDefault();const o=i()(this);t.loading||o.closest(".vp-sort__item").addClass("vp-sort__item-active").siblings().removeClass("vp-sort__item-active"),t.loadNewItems(o.attr("href"),!0)})),t.$filter.add(t.$sort).on(`change${e}`,".vp-filter select, .vp-sort select",(function(){const e=i()(this),o=e.val(),s=e.find(`[value="${o}"]`);s.length&&t.loadNewItems(s.attr("data-vp-url"),!0)})),t.$item.on(`click${e}`,".vp-pagination .vp-pagination__item a",(function(e){e.preventDefault();const o=i()(this),s=o.closest(".vp-pagination");if((!s.hasClass("vp-pagination__no-more")||"paged"===t.options.pagination)&&(t.loadNewItems(o.attr("href"),"paged"===t.options.pagination),"paged"===t.options.pagination&&s.hasClass("vp-pagination__scroll-top"))){const e=i()("#wpadminbar"),o=window.pageYOffset||document.documentElement.scrollTop;let{top:n}=t.$item.offset();s.attr("data-vp-pagination-scroll-top")&&(n-=parseInt(s.attr("data-vp-pagination-scroll-top"),10)||0),e.length&&"fixed"===e.css("position")&&(n-=e.outerHeight()),n=Math.max(0,n),o>n&&window.scrollTo({top:n,behavior:"smooth"})}})),t.$item.on(`click${e}`,".vp-portfolio__items .vp-portfolio__item-meta-category a",(function(e){e.preventDefault(),e.stopPropagation(),t.loadNewItems(i()(this).attr("href"),!0)})),t.$item.on(`transitionend${e}`,".vp-portfolio__items",(e=>{e.currentTarget===e.target&&t.resized()})),t.emitEvent("initEvents")}destroyEvents(){const t=this,e=`.vpf-uid-${t.uid}`;t.$item.off(e),t.$filter.off(e),t.$sort.off(e),s.off(e),t.emitEvent("destroyEvents")}initLayout(){this.emitEvent("initLayout"),this.renderStyle()}initCustomColors(){const t=this;t.$item.find("[data-vp-bg-color]").each((function(){const e=i()(this).attr("data-vp-bg-color");t.addStyle(`[data-vp-bg-color="${e}"]`,{"background-color":`${e} !important`})})),t.$item.find("[data-vp-text-color]").each((function(){const e=i()(this).attr("data-vp-text-color");t.addStyle(`[data-vp-text-color="${e}"]`,{color:`${e} !important`})})),t.renderStyle(),t.emitEvent("initCustomColors")}addItems(t,e,i){this.emitEvent("addItems",[t,e,i])}removeItems(t){this.emitEvent("removeItems",[t])}loadNewItems(t,e,o){const s=this,{randomSeed:n}=s.options;if(s.loading&&void 0===s.loading.readyState||!t||s.href===t)return;s.loading&&s.loading.readyState&&s.loading.abort&&s.loading.abort();const r={method:"POST",url:t,data:{vpf_ajax_call:!0,vpf_random_seed:void 0!==n&&n},complete({responseText:i}){s.href=t,s.replaceItems(i,e,o)}};s.loading=!0,s.$item.addClass("vp-portfolio__loading"),s.emitEvent("startLoadingNewItems",[t,r]),s.loading=i().ajax(r)}replaceItems(t,e,o){const s=this;if(!t)return;t=t.replace("<body",'<body><div id="vp-ajax-load-body"').replace("</body>","</div></body>");const n=i()(t).filter("#vp-ajax-load-body"),r=n.find(`.vp-portfolio.vp-uid-${s.uid}`);if(r.length){const a=r.find(".vp-portfolio__items").html(),l=r.hasClass("vp-portfolio-not-found");s.$item.find(".vp-notice").remove(),l?(s.$item.find(".vp-portfolio__items-wrap").before(r.find(".vp-notice").clone()),s.$item.addClass("vp-portfolio-not-found")):s.$item.removeClass("vp-portfolio-not-found"),s.$filter.length&&s.$filter.each((function(){const t=i()(this);let e="";e=t.parent().hasClass("vp-single-filter")?n.find(`[class="${t.parent().attr("class").replace(" vp-single-filter__ready","")}"] .vp-portfolio__filter-wrap`).html():r.find(".vp-portfolio__filter-wrap").html(),t.html(e)})),s.$sort.length&&s.$sort.each((function(){const t=i()(this);let e="";e=t.parent().hasClass("vp-single-sort")?n.find(`[class="${t.parent().attr("class").replace(" vp-single-sort__ready","")}"] .vp-portfolio__sort-wrap`).html():r.find(".vp-portfolio__sort-wrap").html(),t.html(e)})),s.$pagination.length&&s.$pagination.html(r.find(".vp-portfolio__pagination-wrap").html()),s.addItems(i()(a),e,r),s.emitEvent("loadedNewItems",[r,e,t]),o&&o()}const a=r.attr("data-vp-next-page-url");s.options.nextPageUrl=a,s.$item.attr("data-vp-next-page-url",a),s.$item.removeClass("vp-portfolio__loading"),s.loading=!1,s.emitEvent("endLoadingNewItems"),s.imagesLoaded(),s.initCustomColors()}}i()(document).trigger("extendClass.vpf",[v]);const f=function(t,...e){let o;return this.each((function(){void 0===o&&("object"==typeof t||void 0===t?this.vpf||(this.vpf=new v(i()(this),t)):this.vpf&&(o=this.vpf[t](...e)))})),void 0!==o?o:this};f.constructor=v;const c=i().fn.vpf;i().fn.vpf=f,i().fn.vpf.noConflict=function(){return i().fn.vpf=c,this},i()((()=>{i()(".vp-portfolio").vpf()}));const m=function(t,e,i){var o,s=i||{},n=s.noTrailing,r=void 0!==n&&n,a=s.noLeading,l=void 0!==a&&a,d=s.debounceMode,p=void 0===d?void 0:d,v=!1,f=0;function c(){o&&clearTimeout(o)}function m(){for(var i=arguments.length,s=new Array(i),n=0;n<i;n++)s[n]=arguments[n];var a=this,d=Date.now()-f;function m(){f=Date.now(),e.apply(a,s)}function u(){o=void 0}v||(l||!p||o||m(),c(),void 0===p&&d>t?l?(f=Date.now(),r||(o=setTimeout(p?u:m,t))):m():!0!==r&&(o=setTimeout(p?u:m,void 0===p?t-d:t)))}return m.cancel=function(t){var e=(t||{}).upcomingOnly,i=void 0!==e&&e;c(),v=!i},m}(200,(u=()=>{i()(".vp-portfolio:not(.vp-portfolio__ready)").vpf()},_=[],h=null,g=function(){for(var t=arguments.length,e=new Array(t),i=0;i<t;i++)e[i]=arguments[i];_=e,h||(h=requestAnimationFrame((function(){h=null,u.apply(void 0,_)})))},g.cancel=function(){h&&(cancelAnimationFrame(h),h=null)},g));var u,_,h,g;window.MutationObserver?new window.MutationObserver(m).observe(document.documentElement,{childList:!0,subtree:!0}):i()(document).on("DOMContentLoaded DOMNodeInserted load",(()=>{m()}))}();