diff --git a/assets/js/countUp.js b/assets/js/countUp.js index bb7e9f8..36e41d3 100644 --- a/assets/js/countUp.js +++ b/assets/js/countUp.js @@ -19,51 +19,29 @@ import { CountUp } from 'countup.js'; countUpItems[el.id] = new CountUp(el.id, el.dataset.endval, options); }); - function destroyCountUp(elID) - { - delete countUpItems.elID; - } - - var latestKnownScrollY = 0; - var ticking = false; - - function onScroll() - { - latestKnownScrollY = window.scrollY; - requestTick(); - } - - function requestTick() - { - if (!ticking) { - requestAnimationFrame(update); - } - ticking = true; - } - - function update() - { - ticking = false; - - Array.prototype.forEach.call(elements, function (el,i) { - if (true === isInViewport(el)) { - countUpItems[el.id].start(destroyCountUp(el.id)); + let options = { + root: null, + rootMargin: '0px', + threshold: 1.0 + }; + + const callback = function (entries, observer) { + entries.forEach(entry => { + if (entry.isIntersecting) { + countUpItems[entry.target.id].start(destroyCountUp(entry.target)); } }); - } + }; - requestAnimationFrame(update); - window.addEventListener('scroll', onScroll, false); + let observer = new IntersectionObserver(callback, options); - function isInViewport(el) - { - const rect = el.getBoundingClientRect(); - return ( - rect.top >= 0 && - rect.left >= 0 && - rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && - rect.right <= (window.innerWidth || document.documentElement.clientWidth) + Array.prototype.forEach.call(elements, function (el,i) { + observer.observe(el); + }); - ); + function destroyCountUp(el) + { + delete countUpItems[el.id]; + observer.unobserve(el); } })(); \ No newline at end of file diff --git a/src/Plenta/ContaoCountUpBundle/Resources/public/countup.4c790889.js b/src/Plenta/ContaoCountUpBundle/Resources/public/countup.4c790889.js new file mode 100644 index 0000000..54a8192 --- /dev/null +++ b/src/Plenta/ContaoCountUpBundle/Resources/public/countup.4c790889.js @@ -0,0 +1 @@ +!function(t){var a={};function i(e){if(a[e])return a[e].exports;var n=a[e]={i:e,l:!1,exports:{}};return t[e].call(n.exports,n,n.exports,i),n.l=!0,n.exports}i.m=t,i.c=a,i.d=function(t,a,e){i.o(t,a)||Object.defineProperty(t,a,{enumerable:!0,get:e})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,a){if(1&a&&(t=i(t)),8&a)return t;if(4&a&&"object"==typeof t&&t&&t.__esModule)return t;var e=Object.create(null);if(i.r(e),Object.defineProperty(e,"default",{enumerable:!0,value:t}),2&a&&"string"!=typeof t)for(var n in t)i.d(e,n,function(a){return t[a]}.bind(null,n));return e},i.n=function(t){var a=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(a,"a",a),a},i.o=function(t,a){return Object.prototype.hasOwnProperty.call(t,a)},i.p="/bundles/contaocountup/",i(i.s="vVf2")}({vVf2:function(t,a,i){"use strict";i.r(a);var e=function(){return(e=Object.assign||function(t){for(var a,i=1,e=arguments.length;in.endVal?n.endVal:n.frameVal,n.frameVal=Number(n.frameVal.toFixed(n.options.decimalPlaces)),n.printValue(n.frameVal),a1?n.options.decimal+o[1]:"",n.options.useGrouping){s="";for(var l=0,u=i.length;lt;var a=t-this.startVal;if(Math.abs(a)>this.options.smartEasingThreshold){this.finalEndVal=t;var i=this.countDown?1:-1;this.endVal=t+i*this.options.smartEasingAmount,this.duration=this.duration/2}else this.endVal=t,this.finalEndVal=null;this.finalEndVal?this.useEasing=!1:this.useEasing=this.options.useEasing},t.prototype.start=function(t){this.error||(this.callback=t,this.duration>0?(this.determineDirectionAndSmartEasing(),this.paused=!1,this.rAF=requestAnimationFrame(this.count)):this.printValue(this.endVal))},t.prototype.pauseResume=function(){this.paused?(this.startTime=null,this.duration=this.remaining,this.startVal=this.frameVal,this.determineDirectionAndSmartEasing(),this.rAF=requestAnimationFrame(this.count)):cancelAnimationFrame(this.rAF),this.paused=!this.paused},t.prototype.reset=function(){cancelAnimationFrame(this.rAF),this.paused=!0,this.resetDuration(),this.startVal=this.validateValue(this.options.startVal),this.frameVal=this.startVal,this.printValue(this.startVal)},t.prototype.update=function(t){cancelAnimationFrame(this.rAF),this.startTime=null,this.endVal=this.validateValue(t),this.endVal!==this.frameVal&&(this.startVal=this.frameVal,this.finalEndVal||this.resetDuration(),this.finalEndVal=null,this.determineDirectionAndSmartEasing(),this.rAF=requestAnimationFrame(this.count))},t.prototype.printValue=function(t){var a=this.formattingFn(t);"INPUT"===this.el.tagName?this.el.value=a:"text"===this.el.tagName||"tspan"===this.el.tagName?this.el.textContent=a:this.el.innerHTML=a},t.prototype.ensureNumber=function(t){return"number"==typeof t&&!isNaN(t)},t.prototype.validateValue=function(t){var a=Number(t);return this.ensureNumber(a)?a:(this.error="[CountUp] invalid start or end value: "+t,null)},t.prototype.resetDuration=function(){this.startTime=null,this.duration=1e3*Number(this.options.duration),this.remaining=this.duration},t}();!function(){var t=document.querySelectorAll(".ce_plenta_countup .countUpValue"),a={};Array.prototype.forEach.call(t,(function(t,i){var e={duration:t.dataset.duration,startVal:t.dataset.startval,decimalPlaces:t.dataset.decimalplaces,decimal:t.dataset.decimal,separator:t.dataset.separator,useGrouping:"true"===t.dataset.usegrouping};a[t.id]=new n(t.id,t.dataset.endval,e)}));var i=new IntersectionObserver((function(t,i){t.forEach((function(t){t.isIntersecting&&a[t.target.id].start(e(t.target))}))}),{root:null,rootMargin:"0px",threshold:1});function e(t){delete a[t.id],i.unobserve(t)}Array.prototype.forEach.call(t,(function(t,a){i.observe(t)}))}()}}); \ No newline at end of file diff --git a/src/Plenta/ContaoCountUpBundle/Resources/public/countup.67ac75d9.js b/src/Plenta/ContaoCountUpBundle/Resources/public/countup.67ac75d9.js deleted file mode 100644 index 430d6be..0000000 --- a/src/Plenta/ContaoCountUpBundle/Resources/public/countup.67ac75d9.js +++ /dev/null @@ -1 +0,0 @@ -!function(t){var i={};function a(n){if(i[n])return i[n].exports;var e=i[n]={i:n,l:!1,exports:{}};return t[n].call(e.exports,e,e.exports,a),e.l=!0,e.exports}a.m=t,a.c=i,a.d=function(t,i,n){a.o(t,i)||Object.defineProperty(t,i,{enumerable:!0,get:n})},a.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},a.t=function(t,i){if(1&i&&(t=a(t)),8&i)return t;if(4&i&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(a.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&i&&"string"!=typeof t)for(var e in t)a.d(n,e,function(i){return t[i]}.bind(null,e));return n},a.n=function(t){var i=t&&t.__esModule?function(){return t.default}:function(){return t};return a.d(i,"a",i),i},a.o=function(t,i){return Object.prototype.hasOwnProperty.call(t,i)},a.p="/bundles/contaocountup/",a(a.s="vVf2")}({vVf2:function(t,i,a){"use strict";a.r(i);var n=function(){return(n=Object.assign||function(t){for(var i,a=1,n=arguments.length;ae.endVal?e.endVal:e.frameVal,e.frameVal=Number(e.frameVal.toFixed(e.options.decimalPlaces)),e.printValue(e.frameVal),i1?e.options.decimal+o[1]:"",e.options.useGrouping){s="";for(var l=0,u=a.length;lt;var i=t-this.startVal;if(Math.abs(i)>this.options.smartEasingThreshold){this.finalEndVal=t;var a=this.countDown?1:-1;this.endVal=t+a*this.options.smartEasingAmount,this.duration=this.duration/2}else this.endVal=t,this.finalEndVal=null;this.finalEndVal?this.useEasing=!1:this.useEasing=this.options.useEasing},t.prototype.start=function(t){this.error||(this.callback=t,this.duration>0?(this.determineDirectionAndSmartEasing(),this.paused=!1,this.rAF=requestAnimationFrame(this.count)):this.printValue(this.endVal))},t.prototype.pauseResume=function(){this.paused?(this.startTime=null,this.duration=this.remaining,this.startVal=this.frameVal,this.determineDirectionAndSmartEasing(),this.rAF=requestAnimationFrame(this.count)):cancelAnimationFrame(this.rAF),this.paused=!this.paused},t.prototype.reset=function(){cancelAnimationFrame(this.rAF),this.paused=!0,this.resetDuration(),this.startVal=this.validateValue(this.options.startVal),this.frameVal=this.startVal,this.printValue(this.startVal)},t.prototype.update=function(t){cancelAnimationFrame(this.rAF),this.startTime=null,this.endVal=this.validateValue(t),this.endVal!==this.frameVal&&(this.startVal=this.frameVal,this.finalEndVal||this.resetDuration(),this.finalEndVal=null,this.determineDirectionAndSmartEasing(),this.rAF=requestAnimationFrame(this.count))},t.prototype.printValue=function(t){var i=this.formattingFn(t);"INPUT"===this.el.tagName?this.el.value=i:"text"===this.el.tagName||"tspan"===this.el.tagName?this.el.textContent=i:this.el.innerHTML=i},t.prototype.ensureNumber=function(t){return"number"==typeof t&&!isNaN(t)},t.prototype.validateValue=function(t){var i=Number(t);return this.ensureNumber(i)?i:(this.error="[CountUp] invalid start or end value: "+t,null)},t.prototype.resetDuration=function(){this.startTime=null,this.duration=1e3*Number(this.options.duration),this.remaining=this.duration},t}();!function(){var t=document.querySelectorAll(".ce_plenta_countup .countUpValue"),i={};Array.prototype.forEach.call(t,(function(t,a){var n={duration:t.dataset.duration,startVal:t.dataset.startval,decimalPlaces:t.dataset.decimalplaces,decimal:t.dataset.decimal,separator:t.dataset.separator,useGrouping:"true"===t.dataset.usegrouping};i[t.id]=new e(t.id,t.dataset.endval,n)}));var a=!1;function n(){a=!1,Array.prototype.forEach.call(t,(function(t,a){!0===function(t){var i=t.getBoundingClientRect();return i.top>=0&&i.left>=0&&i.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&i.right<=(window.innerWidth||document.documentElement.clientWidth)}(t)&&i[t.id].start((t.id,void delete i.elID))}))}requestAnimationFrame(n),window.addEventListener("scroll",(function(){window.scrollY,function(){a||requestAnimationFrame(n);a=!0}()}),!1)}()}}); \ No newline at end of file diff --git a/src/Plenta/ContaoCountUpBundle/Resources/public/entrypoints.json b/src/Plenta/ContaoCountUpBundle/Resources/public/entrypoints.json index b23c582..ea4637b 100644 --- a/src/Plenta/ContaoCountUpBundle/Resources/public/entrypoints.json +++ b/src/Plenta/ContaoCountUpBundle/Resources/public/entrypoints.json @@ -2,7 +2,7 @@ "entrypoints": { "countup": { "js": [ - "/bundles/contaocountup/countup.67ac75d9.js" + "/bundles/contaocountup/countup.4c790889.js" ] } } diff --git a/src/Plenta/ContaoCountUpBundle/Resources/public/manifest.json b/src/Plenta/ContaoCountUpBundle/Resources/public/manifest.json index 5529c20..7640aa0 100644 --- a/src/Plenta/ContaoCountUpBundle/Resources/public/manifest.json +++ b/src/Plenta/ContaoCountUpBundle/Resources/public/manifest.json @@ -1,3 +1,3 @@ { - "contaocountup/countup.js": "/bundles/contaocountup/countup.67ac75d9.js" + "contaocountup/countup.js": "/bundles/contaocountup/countup.4c790889.js" } \ No newline at end of file