-
Notifications
You must be signed in to change notification settings - Fork 13
/
twcsl-min.js
1 lines (1 loc) · 7.57 KB
/
twcsl-min.js
1
const twcsl=($=>{"use strict";const t={hasTouchScreen:!1},e=Static.SQUARESPACE_CONTEXT.templateVersion;let r="";try{r=Static.SQUARESPACE_CONTEXT.collection.fullUrl}catch(t){}const o="7"==e,a="7.1"==e,s=t=>{let e=new URLSearchParams(location.search).get(t);return null===e&&(e=""),e},l=()=>0!=$('body[id^="item-"]').length,i=()=>0!=$('body[id^="collection-"]').length,n=t=>{let e;switch(!0){case o:let r=s(t);if(!r)return"";r=encodeURIComponent(r).replaceAll("%20","+"),e=r?`${t}=${r}`:"";break;case a:if(e=location.pathname.split("/").slice(-2),e[0]!=t)return"";e=e.join("/")}return e},c=()=>{const t=p.blog,e=['body[class~="collection-type-blog"]','body[class*="collection-type-blog-"]'].join(", ");if(t.is=Boolean($(e).length),!t.is)return;t.urlSlug=r;(()=>{const e=t.list;if(e.is=i(),!e.is)return;(()=>{const t=n("category");e.categoryUrlSlug=t})(),e.hasCategory=Boolean(e.categoryUrlSlug),(()=>{if(!e.hasCategory)return;const t=$("title").text().split(" — ")[0];e.category=t})(),(()=>{const t=n("tag");e.tagUrlSlug=t})(),e.hasTag=Boolean(e.tagUrlSlug),(()=>{if(!e.hasTag)return;let t=$('link[ rel="canonical" ]').attr("href").split("/").splice(-1);t=decodeURIComponent(t).replaceAll("+"," "),e.tag=t})()})(),(()=>{const e=t.post;if(e.is=l(),!e.is)return;const r=[".blog-item-category",".Blog-meta-item-category",".categories a",".meta-above-title .entry-category a"].join(", "),o=[".blog-item-tag",".Blog-meta-item-tag",".tags a",".entry-tags a"].join(", ");(()=>{const t=$(r).map((function(){return $(this).text().trim()})).toArray();e.categories=t})(),(()=>{const t=$(r).map((function(){return $(this).attr("href").replace(e.urlSlug+"/category","")})).toArray();e.categoryUrlSlugs=t})(),(()=>{const t=$(o).map((function(){return $(this).text().trim()})).toArray();e.tags=t})(),(()=>{const t=$(o).map((function(){return $(this).attr("href").replace(e.urlSlug+"/tag","")})).toArray();e.tagUrlSlugs=t})()})()},g=()=>{const t=p.events;if(t.is=Boolean($('body[class~="collection-type-events"], body[class*="collection-type-events-"]').length),!t.is)return;t.urlSlug=r;(()=>{const e=t.event;if(e.is=l(),!e.is)return;(()=>{const t=$(".eventitem-meta-cats a").map((function(){return $(this).text().trim()})).toArray();e.categories=t})(),(()=>{const t=$(".eventitem-meta-tags a").map((function(){return $(this).text().trim()})).toArray();e.tags=t})()})(),(()=>{const e=t.list;if(e.is=i(),!e.is)return;const r=()=>$(".eventlist-filter").text().split(": ")[1].replace(/(?:“)(.+)(?:”)/,"$1").trim();(()=>{const t=n("category");e.categoryUrlSlug=t})(),e.hasCategory=Boolean(e.categoryUrlSlug),(()=>{if(!e.hasCategory)return;const t=r();e.category=t})(),(()=>{const t=n("tag");e.tagUrlSlug=t})(),e.hasTag=Boolean(e.tagUrlSlug),(()=>{if(!e.hasTag)return;const t=r();e.tag=t})()})()},u=()=>{const t=p.store;if(t.is=$("body").hasClass("collection-type-products"),!t.is)return;t.urlSlug=r;(()=>{const e=t.detail;if(e.is=l(),!e.is)return;const r=()=>{const t=Static.SQUARESPACE_CONTEXT.product.variants;let e,r;if(1==t.length)r=t[0];else{if(r=$(".product-variants:visible").attr("data-selected-variant"),void 0===r)return;r=JSON.parse(r),r=r.id,r=t.filter((t=>t.id==r))[0]}return e=r.stock,e=e.unlimited?1/0:e.quantity,e};(()=>{if(a)return;const t=[".ProductItem",".productWrapper","#productWrapper"].join(", "),r=$(t).attr("class").split(" ").filter((t=>t.startsWith("category-"))).map((t=>t=t.slice(9)));e.classCategories=r})(),(()=>{const t=[".pdp-layout",".ProductItem",".productWrapper","#productWrapper"].join(", "),r=$(t).attr("class").split(" ").filter((t=>t.startsWith("tag-"))).map((t=>t.slice(4)));e.classTags=r})(),e.get.stockQuantity=r})(),(()=>{const e=t.list;if(e.is=i(),!e.is)return;const r=s("tag");let l="";e.hasTag=Boolean(r),(()=>{if(o)return;const t=$(".category-link.activeParent, .category-link.active").map((function(){return $(this).text()})).toArray().join(" > ");e.categories=t})(),(()=>{switch(!0){case o:l=s("category");break;case a:const e=t.urlSlug.length+1;l=location.pathname.slice(e)}})(),e.hasCategory=Boolean(l),(()=>{if(!l)return;const t=[".filter-by-category",".nested-category-title","#categoryNav ul li.active-link:not(.all) a",".ProductList-filter-list-item--active"].join(", "),r=$(t).eq(0).text().trim();e.category=r})(),(()=>{if(!l)return;let t="";switch(!0){case o:t=n("category");break;case a:t=location.pathname.replace(twcsl.page.store.urlSlug,"")}e.categoryUrlSlug=t})(),(()=>{if(!r)return;const t=decodeURIComponent(r);e.tag=t})(),(()=>{if(!r)return;const t=n("tag");e.tagUrlSlug=t})()})()},p={album:{is:!1,urlSlug:""},blog:{is:!1,list:{category:"",categoryUrlSlug:"",hasCategory:!1,hasTag:!1,is:!1,tag:"",tagUrlSlug:""},post:{categories:[],categoryUrlSlugs:[],tags:[],tagUrlSlugs:[],is:!1},urlSlug:""},cart:{is:"/cart"==location.pathname},cover:{is:!1,urlSlug:""},events:{event:{categories:[],is:!1,tags:[]},is:!1,list:{category:"",categoryUrlSlug:"",hasCategory:!1,hasTag:!1,is:!1,tag:"",tagUrlSlug:""},urlSlug:""},gallery:{is:!1,urlSlug:""},index:{is:!1,urlSlug:""},portfolio:{is:!1,list:{is:!1},subPage:{is:!1},urlSlug:""},search:{is:"/search"==location.pathname},store:{detail:{classCategories:[],classTags:[],get:{},is:!1},is:!1,list:{categories:"",category:"",categoryUrlSlug:"",hasCategory:!1,hasTag:!1,is:!1,tag:"",tagUrlSlug:""},urlSlug:""},videos:{is:!1,urlSlug:""}},h={is70:o,is71:a,version:e},y="0.3.3",f=t=>{const e=document.createElement("a");return e.href=t,e},m=t=>{switch(!0){case a:$(t);break;case o:Squarespace.onInitialize(Y,t)}};return(()=>{const t=`Tom's Web Consulting Squarespace Library v${y}, License < https://tinyurl.com/s872fb68 >, Tom's Web Consulting < http://www.tomsWeb.consulting >`;console.log(t);m((()=>{(()=>{if(a)return;const t=p.album;t.is=$("body").hasClass("collection-type-album"),t.is&&(t.urlSlug=r)})(),c(),(()=>{if(a)return;if(!$('.sqs-slide-wrapper[data-slide-type="cover-page"]').length)return;const t=p.cover;t.is=!0,t.urlSlug=r})(),g(),(()=>{if(a)return;if(!$("body.collection-type-gallery").length)return;const t=p.gallery;t.is=!0,t.urlSlug=r})(),(()=>{if(a)return;if(!$("body.collection-type-index").length)return;const t=p.index;t.is=!0,t.urlSlug=r})(),(()=>{if(o)return;let t='.page-section[class*="collection-type-portfolio-"]',e=$(t);e=Boolean(e.length),t='.item-pagination[data-collection-type^="portfolio"]';let a=$(t);if(a=Boolean(a.length),!e&&!a)return;const s=p.portfolio;s.is=!0,s.list.is=e,s.subPage.is=a,s.urlSlug=r})(),u(),(()=>{if(o)return;let t=$(".lessons-list-section").length;if(t=Boolean(t),!t)return;const e=p.videos;e.is=t,e.urlSlug=r})()}))})(),{version:y,getFormFieldLabel:t=>$(".title",t).clone().children().remove().end().text().trim(),getFormNth:(t=1)=>{const e=$(`.sqs-block-form:eq( ${--t} )`);if(e.length)return $("form",e)},getPageSectionNth:(t=1)=>{let e=$("x-twc-empty");return a&&t&&(e=$(":not( #footer-sections ) > .page-section"),t>0&&(t-=1),e=e.eq(t)),e.length||(e=void 0),e},getUrlParser:f,go:m,isElementInPage:t=>{const e=t.outerHeight(),r=$("#header").outerHeight(),o=$(window).height()-r,{top:a,bottom:s}=t.get(0).getBoundingClientRect();return a>=r&&s<=window.innerHeight||e>o&&a<=r},isElementInViewport:t=>{const{top:e,bottom:r}=t.get(0).getBoundingClientRect();return e>=0&&r<=window.innerHeight},scrollEffect:(t,e="linear",r=!1)=>{if("function"!=typeof t)return;$(window).scroll((function(){const o=$(document).height()-$(window).height(),a=((t,e,r,o)=>{let a=t/e;switch(r){case"inCircle":a=1-Math.sqrt(1-Math.pow(a,2));break;case"inOutQuadratic":a=a<.5?2*a*a:1-Math.pow(-2*a+2,2)/2;break;case"outCircle":a=Math.sqrt(1-Math.pow(a-1,2))}return o&&(a=1-a),a})(scrollY,o,e,r);t(a)}))},urlToCssClassName:t=>(t=(t=f(t)).pathname).split("/").slice(-1)[0].replace(/^([\d-_]{1})/,"x-$1"),navigator:t,page:p,ss:h}})(jQuery);