site/includes/modules.js
/**
 * Adds event listeners to the track
 * @param el The track element
 * @param loop Whether to loop the scrolling
 */
Adds event listeners to the track
@param el The track element
@param loop Whether to loop the scrolling
Adds event listeners to the track @param el The track element @param loop Whether to loop the scrolling
function initTrack(el, loop) {
  let loopInterval;
  function startLoop() {
    if (!loop) return;
    if (loopInterval) clearInterval(loopInterval);
    loopInterval = setInterval(function() {
      scrollTrack(el, 1, loop);
    }, loop);
  }
  startLoop();
  scrollTrack(el, 0, loop);
  el.find(".trackButtonLeft").each(function(){
    this.addEventListener("click",function(){
      scrollTrack(el, -1, loop);
      startLoop();
    },{passive:true});
  });
  el.find(".trackButtonRight").each(function(){
    this.addEventListener("click",function(){
      scrollTrack(el, 1, loop);
      startLoop();
    },{passive:true});
  });
  function clientX(e) {
    return (e.changedTouches ? e.changedTouches[0] : e).clientX;
  }
  let x0 = null;
  function start(e) {
    x0 = clientX(e);
    el.removeClass("transitioning");
    if (loopInterval) clearInterval(loopInterval);
  }
  function move(e) {
    if (x0 !== null) {
      const partial = Math.round(x0 - clientX(e));
      el.get(0).style.setProperty("--partial-offset", `${partial}px`);
    }
  }
  function end(e) {
    if(x0 !== null) {
      let dx = x0 - clientX(e);
      scrollTrack(el, Math.sign(dx), loop, dx);
      x0 = null;
    }
    startLoop();
    el.get(0).style.removeProperty("--partial-offset");
  }
  el.get(0).addEventListener("touchstart", start, {capture:false,passive:true});
  el.get(0).addEventListener("touchmove", move, {capture:false,passive:true});
  el.get(0).addEventListener("touchend", end, {capture:false,passive:true});
  el.get(0).addEventListener("touchcancel", end, {capture:false,passive:true});
}
function initTrack ( el , loop ) { let loopInterval ; function startLoop ( ) { if ( ! loop ) return ; if ( loopInterval ) clearInterval ( loopInterval ) ; loopInterval = setInterval ( function ( ) { scrollTrack ( el , 1 , loop ) ; } , loop ) ; } startLoop ( ) ; scrollTrack ( el , 0 , loop ) ; el . find ( ".trackButtonLeft" ) . each ( function ( ) { this . addEventListener ( "click" , function ( ) { scrollTrack ( el , - 1 , loop ) ; startLoop ( ) ; } , { passive : true } ) ; } ) ; el . find ( ".trackButtonRight" ) . each ( function ( ) { this . addEventListener ( "click" , function ( ) { scrollTrack ( el , 1 , loop ) ; startLoop ( ) ; } , { passive : true } ) ; } ) ; function clientX ( e ) { return ( e . changedTouches ? e . changedTouches [ 0 ] : e ) . clientX ; } let x0 = null ; function start ( e ) { x0 = clientX ( e ) ; el . removeClass ( "transitioning" ) ; if ( loopInterval ) clearInterval ( loopInterval ) ; } function move ( e ) { if ( x0 !== null ) { const partial = Math . round ( x0 - clientX ( e ) ) ; el . get ( 0 ) . style . setProperty ( "--partial-offset" , ` ${ partial } ` ) ; } } function end ( e ) { if ( x0 !== null ) { let dx = x0 - clientX ( e ) ; scrollTrack ( el , Math . sign ( dx ) , loop , dx ) ; x0 = null ; } startLoop ( ) ; el . get ( 0 ) . style . removeProperty ( "--partial-offset" ) ; } el . get ( 0 ) . addEventListener ( "touchstart" , start , { capture : false , passive : true } ) ; el . get ( 0 ) . addEventListener ( "touchmove" , move , { capture : false , passive : true } ) ; el . get ( 0 ) . addEventListener ( "touchend" , end , { capture : false , passive : true } ) ; el . get ( 0 ) . addEventListener ( "touchcancel" , end , { capture : false , passive : true } ) ; }
Adds event listeners to the track
 @param el The track element
 @param loop Whether to loop the scrolling
Adds event listeners to the track @param el The track element @param loop Whether to loop the scrolling