{"version":3,"file":"script.min.js","sources":["../../../../block-editor/blocks/media-text-slider/script.js"],"sourcesContent":["class MediaSlider {\n\n\tstatic instances = [];\n\n\tconstructor( node, opts = {} ) {\n\t\tif ( ! node ) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.node = node;\n\t\tthis.opts = {\n\t\t\titems : '.media-text-slider__items',\n\t\t\tnext : '.media-text-slider__next',\n\t\t\tprev : '.media-text-slider__prev',\n\t\t\tpagination : '.media-text-slider__pagination',\n\t\t\tautoplay: false,\n\t\t\tinterval: 5000,\n\t\t};\n\n\t\tObject.keys( this.opts ).forEach( key => {\n\t\t\tif ( typeof opts[ key ] !== 'undefined' ) {\n\t\t\t\tthis.opts[ key ] = opts[ key ];\n\t\t\t} else if ( typeof this.node.dataset[ key ] !== 'undefined' ) {\n\t\t\t\tthis.opts[ key ] = this.node.dataset[ key ];\n\t\t\t}\n\t\t} );\n\n\t\tthis.items = node.querySelector( this.opts.items );\n\t\tthis.prev = node.querySelector( this.opts.prev );\n\t\tthis.next = node.querySelector( this.opts.next );\n\t\tthis.allImages = this.items.querySelectorAll('[loading=\"lazy\"]');\n\t\t//this.pagination = node.querySelector( this.opts.pagination );\n\n\t\tif ( this.opts.autoplay ) {\n\t\t\tthis.interval = setInterval( () => {\n\t\t\t\tif ( this.getCurrentScrollIndex() >= items.children.length - 1 ) {\n\t\t\t\t\treturn this.setScrollIndex(0);\n\t\t\t\t}\n\n\t\t\t\treturn this.scrollNext();\n\t\t\t}, parseInt( this.opts.interval, 10 ) );\n\t\t}\n\n\t\tif ( this.prev ) {\n\t\t\tthis.prev.addEventListener( 'click', () => {\n\t\t\t\tthis.scrollPrev();\n\n\t\t\t\tif ( this.interval ) {\n\t\t\t\t\tclearInterval( this.interval );\n\t\t\t\t}\n\t\t\t} );\n\t\t}\n\n\t\tif ( this.next ) {\n\t\t\tthis.next.addEventListener( 'click', () => {\n\t\t\t\tthis.scrollNext();\n\n\t\t\t\tif ( this.interval ) {\n\t\t\t\t\tclearInterval( this.interval );\n\t\t\t\t}\n\t\t\t} );\n\t\t}\n\n\t\t// if ( this.pagination ) {\n\t\t// \tthis.pagination.addEventListener( 'click', (e) => {\n\t\t// \t\tconsole.log(e.target);\n\t\t// \t\tlet clickedDot = e.target;\n\t\t// \t\tconst dotIndex = [...clickedDot.parentElement.children].indexOf(clickedDot);\n\t\t// \t\tthis.setScrollIndex(dotIndex);\n\t\t// \t} );\n\t\t// }\n\n\t\t//switch to Eager loading due to image loading issues\n\t\tthis.allImages.forEach((img)=>{\n\t\t\timg.setAttribute('loading', 'eager');\n\t\t});\n\t\tthis.items.addEventListener( 'scroll', this.setState.bind( this ) );\n\t\tthis.setScrollIndex(0);\n\t\tthis.setState();\n\n\n\n\t\t//Testimonials.instances.push(this);\n\t}\n\n\tscrollPrev() {\n\t\tthis.setScrollIndex( Math.round( Math.max( this.getCurrentScrollIndex() - 1, 0 ) ) );\n\t}\n\n\tscrollNext() {\n\t\tthis.setScrollIndex( Math.round( Math.min( this.getCurrentScrollIndex() + 1, this.items.children.length - 1 ) ) );\n\t}\n\n\tsetScrollIndex( index, behavior = 'smooth' ) {\n\t\tthis.items.scrollTo( {\n\t\t\tleft: index * this.items.offsetWidth,\n\t\t\ttop: 0,\n\t\t\tbehavior: behavior || this.opts.scrollBehavior\n\t\t} );\n\t};\n\n\tgetCurrentScrollIndex() {\n\t\treturn Math.round( this.items.scrollLeft / this.items.offsetWidth );\n\t}\n\n\tsetState() {\n\t\tconst index = this.getCurrentScrollIndex();\n\n\t\tif ( index >= this.items.children.length - 1 ) {\n\t\t\tif ( this.next ) {\n\t\t\t\tthis.next.disabled = true;\n\t\t\t}\n\n\t\t\tif ( this.prev ) {\n\t\t\t\tthis.prev.removeAttribute('disabled');\n\t\t\t}\n\t\t} else if ( index <= 0 ) {\n\t\t\tif ( this.next ) {\n\t\t\t\tthis.next.removeAttribute('disabled');\n\t\t\t}\n\n\t\t\tif ( this.prev ) {\n\t\t\t\tthis.prev.disabled = true;\n\t\t\t}\n\t\t} else {\n\t\t\tif ( this.next ) {\n\t\t\t\tthis.next.removeAttribute('disabled');\n\t\t\t}\n\n\t\t\tif ( this.prev ) {\n\t\t\t\tthis.prev.removeAttribute('disabled');\n\t\t\t}\n\t\t}\n\n\t\t// let prevActiveDot = this.pagination.querySelector('[disabled]');\n\t\t// if( prevActiveDot ) {\n\t\t// \tprevActiveDot.removeAttribute('disabled');\n\t\t// }\n\t\t// this.pagination.children[index].disabled = true;\n\t}\n}\n\ndocument.addEventListener( 'DOMContentLoaded', () => {\n\tdocument.querySelectorAll( '.media-text-slider' ).forEach( node => {\n\t\tnew MediaSlider( node )\n\t} );\n} );\n\nexport default MediaSlider;\n"],"names":["MediaSlider","static","constructor","node","opts","this","items","next","prev","pagination","autoplay","interval","Object","keys","forEach","key","dataset","querySelector","allImages","querySelectorAll","setInterval","getCurrentScrollIndex","children","length","setScrollIndex","scrollNext","parseInt","addEventListener","scrollPrev","clearInterval","img","setAttribute","setState","bind","Math","round","max","min","index","behavior","scrollTo","left","offsetWidth","top","scrollBehavior","scrollLeft","disabled","removeAttribute","document"],"mappings":"kHAAA,MAAMA,EAELC,iBAAmB,GAEnBC,WAAAA,CAAaC,EAAMC,EAAO,IAClBD,IAIPE,KAAKF,KAAOA,EACZE,KAAKD,KAAO,CACXE,MAAa,4BACbC,KAAa,2BACbC,KAAa,2BACbC,WAAa,iCACbC,UAAU,EACVC,SAAU,KAGXC,OAAOC,KAAMR,KAAKD,MAAOU,SAASC,SACL,IAAhBX,EAAMW,GACjBV,KAAKD,KAAMW,GAAQX,EAAMW,QACsB,IAA7BV,KAAKF,KAAKa,QAASD,KACrCV,KAAKD,KAAMW,GAAQV,KAAKF,KAAKa,QAASD,GACvC,IAGDV,KAAKC,MAAQH,EAAKc,cAAeZ,KAAKD,KAAKE,OAC3CD,KAAKG,KAAQL,EAAKc,cAAeZ,KAAKD,KAAKI,MAC3CH,KAAKE,KAAQJ,EAAKc,cAAeZ,KAAKD,KAAKG,MAC3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