PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.14.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.14.0
2.14.0 2.13.0 2.13.1 2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 All 81 releases
← All changes | assets/build/blocks/counter/view.js +3 -0 1.0 → 2.14.0 View file →
@@ -1,0 +1,3 @@
1 +(()=>{"use strict";const t=class{constructor(t){if(this.ablocksCounter=t,!this.ablocksCounter)return;const e=t;this.startValue=Number(e?.getAttribute("data-start"))||0,this.endValue=Number(e?.getAttribute("data-end"))||0,this.totalNumber=Number(e?.getAttribute("data-total"))||0,this.duration=Number(e?.getAttribute("data-duration")),this.separator=e?.getAttribute("data-separator"),this.decimalPlaces=Number(e?.getAttribute("data-decimalPlaces"))||0,this.circleSize=Number(e?.getAttribute("data-circleSize"))||220;const r=e?.getAttribute("data-layout");this.animationRepeat=e?.getAttribute("data-animationRepeat"),this.layout=r,r?("number"!==r&&this.endValue>=this.totalNumber&&(this.endValue=this.totalNumber),new window.IntersectionObserver(this.IOCallback.bind(this),{root:null,rootMargin:"0px",threshold:.5}).observe(this.ablocksCounter)):console.error(`Missing 'data-layout' attribute for '${e}'.`)}init=()=>{
2 +"number"===this.layout?this.numberCounter():"circle"===this.layout?this.circleCounter():"bar"===this.layout?this.bar():console.error(`Unsupported layout '${this.layout}' for '${this.countElement}'.`)};playOnce=!1;IOCallback(t){t.forEach(t=>{t.isIntersecting&&("false"!==this.animationRepeat||this.playOnce||(this.playOnce=!0,this.init()),"true"===this.animationRepeat&&this.init())})}numberCounter(){const t=this.ablocksCounter?.querySelector(".ablocks-counter__content-number");if(!t)return void console.error("'.ablocks-counter__content-number' element not found.");const{startValue:e,endValue:r,duration:o,separator:a,decimalPlaces:i}=this;let n=null;const s=r-e,u=r=>{n||(n=r);const l=r-n,c=0===o?1:Math.min(l/o,1),b=e+c*s;t.innerHTML=this.formatNumberWithSeparator(b,a,i),l<o&&window.requestAnimationFrame(u)};window.requestAnimationFrame(u)}circleCounter(){this.numberCounter();const t=this.ablocksCounter?.querySelector(".ablocks-circle-counter__progress")
3 +;if(!t)return void console.error("'.ablocks-circle-counter__progress' element not found.");const{startValue:e,endValue:r,totalNumber:o,duration:a,circleSize:i}=this,n=i/2,s=2*Math.PI*n,u=[{strokeDashoffset:s-e/o*100/100*s},{strokeDashoffset:s-r/o*100/100*s}],l={duration:a,fill:"forwards"};t.animate(u,l)}bar(){this.numberCounter();const t=this.ablocksCounter?.querySelector(".ablocks-bar-counter__progress");if(!t)return void console.error("'.ablocks-bar-counter__progress' element not found.");const{startValue:e,endValue:r,totalNumber:o,duration:a}=this,i=[{width:e/o*100+"%"},{width:r/o*100+"%"}],n={duration:a,fill:"forwards"};t.animate(i,n)}formatNumberWithSeparator(t,e,r){const o={minimumFractionDigits:r,maximumFractionDigits:r};return t.toLocaleString("en-US",o).replace(/,/g,e)}};document.addEventListener("DOMContentLoaded",()=>{document.querySelectorAll(".ablocks-block--counter").forEach(e=>{new t(e)})})})();