From f3d8d75a4ff0c64ec48c2cbf55ecbf33a52a7bf9 Mon Sep 17 00:00:00 2001 From: dev Date: Sun, 9 Apr 2023 17:07:28 +0000 Subject: [PATCH] v2.1.3 - Refactoring. --- dist/trig.js | 2 +- package.json | 2 +- src/trig.js | 32 +++++++++++++++++++------------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/dist/trig.js b/dist/trig.js index 5fee5dc..04f9e77 100755 --- a/dist/trig.js +++ b/dist/trig.js @@ -1 +1 @@ -class Trig{trigs=[];thePos=[];height=0;pos=0;scrollDir=["trig-scroll-down","trig-scroll-up"];observer;trigInit(){trig.observer=new IntersectionObserver(trig.trigObserver),trig.trigs=document.querySelectorAll("body,.enable-trig,[data-trig]"),trig.height=innerHeight,trig.trigScroll()}trigScroll(){trig.trigs&&trig.trigs.forEach(function(t,r){t.index=r,trig.observer.observe(t)})}trigEntries(t){t.forEach(function(t){trig.trigIntersecting(t),0==t.target.index&&trig.trigDirection(t),trig.trigPos(t),trig.updatePos(t.target)})}trigDirection(t){var r=t.boundingClientRect.y;trig.scrollPos&&(trig.scrollPosr+1&&(trig.scrollDir=["trig-scroll-up","trig-scroll-down"])),trig.scrollPos=r}trigObserver(t){trig.trigEntries(t),trig.observer.disconnect()}trigIntersecting(t){document.body!=t.target&&(t.isIntersecting?t.target.classList.add("trig"):t.target.classList.remove("trig"))}trigPos(t){var r={offset:0,height:0,min:-100,max:100};Object.keys(r).forEach(function(i){r[i]=trig.trigAttributes(t,r,i)});var i=t.boundingClientRect.top,e=t.boundingClientRect.height;if(trig.height>e&&(e=trig.height),document.body==t.target)var g=0-i,s=g/(e-trig.height)*100;else var g=0-(i-(trig.height/2+r.offset)),s=g/(e+r.height)*100;trig.trigSetPos(s,r.min,r.max,t.target)}trigAttributes(t,r,i){var e=t.target.getAttribute("data-trig-"+i);return e?null!=e.match(/^[0-9]+$/)?parseInt(e):e:r[i]}trigSetPos(t,r,i,e){t>=r&&t<=i?trig.thePos[e.index]=t:t<=r?trig.thePos[e.index]=r:t>=i&&(trig.thePos[e.index]=i)}trigSetBody(t){var r=t.classList;r.contains(trig.scrollDir[0])&&r.replace(trig.scrollDir[0],trig.scrollDir[1]),r.contains(trig.scrollDir[0])||r.contains(trig.scrollDir[1])||r.add("trig-scroll-up");var i=[0,25,50,75,100];for(let e=0;e=t?i.add("trig-scroll-"+e):trig.thePos[r]r+1&&(trig.scrollDir=["trig-scroll-up","trig-scroll-down"])),trig.scrollPos=r}trigObserver(t){trig.trigEntries(t),trig.observer.disconnect()}trigIntersecting(t){document.body!=t.target&&(t.isIntersecting?t.target.classList.add("trig"):t.target.classList.remove("trig"))}trigPos(t){var r={offset:0,height:0,min:-100,max:100};Object.keys(r).forEach(function(i){r[i]=trig.trigAttributes(t,r,i)});var i=t.boundingClientRect.top,e=t.boundingClientRect.height;if(trig.height>e&&(e=trig.height),document.body==t.target)var g=0-i,s=g/(e-trig.height)*100;else var g=0-(i-(trig.height/2+r.offset)),s=g/(e+r.height)*100;trig.trigSetPos(s,r.min,r.max,t.target)}trigAttributes(t,r,i){var e=t.target.getAttribute("data-trig-"+i);return e?null!=e.match(/^[0-9]+$/)?parseInt(e):e:r[i]}trigSetPos(t,r,i,e){t>=r&&t<=i?trig.thePos[e.index]=t:t<=r?trig.thePos[e.index]=r:t>=i&&(trig.thePos[e.index]=i)}trigSetBody(t){var r=t.classList;r.contains(trig.scrollDir[0])&&r.replace(trig.scrollDir[0],trig.scrollDir[1]),r.contains(trig.scrollDir[0])||r.contains(trig.scrollDir[1])||r.add("trig-scroll-up");var i=[0,25,50,75,100];for(let e=0;e=r?i.add("trig-scroll-"+t):trig.thePos[e]= split){ - cl.add("trig-scroll-"+name); - } else if(trig.thePos[index] < split) { - cl.remove("trig-scroll-"+name); - } + if(trig.thePos[index] == split){ + cl.add("trig-scroll-"+name); + } else { + cl.remove("trig-scroll-"+name); + } + } + trigSplitMoreThan(name,split,cl,index){ + if(trig.thePos[index] >= split){ + cl.add("trig-scroll-"+name); + } else if(trig.thePos[index] < split) { + cl.remove("trig-scroll-"+name); } } updatePos(element) {