{"version":3,"file":"slideshow.min.js","sources":["scripts/slideshow.min.js"],"sourcesContent":["/**************************************************************************\r\nName: slideshow.js\r\nDescription: Scripting for slideshows.\r\nDate Created: 2022-06-23 by Owen Haggerty\r\nModified: \r\n**************************************************************************/\r\nconst defaultOptions = {\r\n\tloopSlides: true,\r\n\tprevSelector: \"\",\t//CSS selector for the previous slide button\r\n\tnextSelector: \"\",\t//CSS selector for the next slide button\r\n\tindicatorSelector: \"\",\t//CSS selector for the indicator wrapper\r\n\ttouchThreshhold: 50,\t//The minimum number of pixels a slide needs to be dragged to transition to another slide\r\n\twrapperHeight: \"none\"\t//The height of the slide wrapper\r\n};\r\n\r\nfunction initSlideshow(slideshow, passedOptions={}){\r\n\tlet wrapper = jQuery(slideshow);\t//Get a jQuery instance of the slideshow wrapper\r\n\t//Set any undefined options to the defaults\r\n\tlet options = {};\r\n\tObject.assign(options, defaultOptions, passedOptions);\r\n\r\n\t//Define the next and previous slide functions\r\n\tlet prevSlide = function(){transitionToSlide(getCurSlideNum() - 1)};\r\n\tlet nextSlide = function(){transitionToSlide(getCurSlideNum() + 1)};\r\n\r\n\tlet init = function(){\r\n\t\t/*Initializes a slideshow*/\r\n\t\tinitSlides();\t//Initialize the slides\r\n\t\tpopulateIndicator();\t//Adds the slideshow indicators\r\n\t\tinitArrows();\t//Initialize the next slide and previous slide buttons\r\n\t\tinitTouch();\t//Initialize the touch handlers\r\n\t}\r\n\r\n\tlet populateIndicator = function(){\r\n\t\t/*Populates the slide indicator*/\r\n\t\tif(options.indicatorSelector === \"\") return;\r\n\t\tlet numSlides = wrapper.find(\".slide\").length;\r\n\t\tlet indicatorWrapper = wrapper.find(options.indicatorSelector).first();\r\n\r\n\t\t//Add new indicators to the wrapper\r\n\t\tfor(let i=0; i\").addClass(\"slideIndicator\");\r\n\t\t\tnewIndicator.attr(\"data-num\",i);\t//Set the associated slide number\r\n\t\t\tnewIndicator.attr(\"title\", \"Switch to slide \" + String(i+1));\r\n\t\t\tif(i === 0) newIndicator.addClass(\"active\");\r\n\t\t\tnewIndicator.on(\"click\",()=>{transitionToSlide(i)});\t//Set click listener\r\n\t\t\tindicatorWrapper.append(newIndicator);\r\n\t\t}\r\n\t}\r\n\r\n\tlet initSlides = function(){\r\n\t\t/*Initializes the slides in the slideshow*/\r\n\t\tlet i = 0;\t//Slide index counter\r\n\t\twrapper.find(\".slide\").each(function(i, el){\r\n\t\t\t//Set the active class and dataset values\r\n\t\t\tlet elem = jQuery(el);\r\n\t\t\telem.attr(\"data-num\",i);\r\n\t\t\tif(i === 0)\r\n\t\t\t\telem.addClass(\"active\");\r\n\t\t\telse\r\n\t\t\t\telem.attr(\"aria-hidden\",\"true\");\r\n\t\t});\r\n\t\tif(options.wrapperHeight != \"none\"){\r\n\t\t\tlet slideWrapper = wrapper.find(\".slide\").first().parent();\r\n\t\t\tswitch(options.wrapperHeight){\r\n\t\t\t\tcase \"maxSlide\":\t//Set the height to the maximum slide height\r\n\t\t\t\trecalculateSlideWrapperHeight();\r\n\t\t\t\t\tlet timeout = null;\t//Window timeout object\r\n\t\t\t\t\tjQuery(window).on(\"resize orientationchange\",function(){\r\n\t\t\t\t\t\t//Window resize listener\r\n\t\t\t\t\t\tif(timeout !== null)\r\n\t\t\t\t\t\t\twindow.clearTimeout(timeout);\r\n\t\t\t\t\t\ttimeout = window.setTimeout(function(){\r\n\t\t\t\t\t\t\trecalculateSlideWrapperHeight();\r\n\t\t\t\t\t\t\ttimeout = null;\t//Clear the timeout\r\n\t\t\t\t\t\t},100);\r\n\t\t\t\t\t});\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tlet initArrows = function(){\r\n\t\t/*Sets the click listeners on the next and previous buttons*/\r\n\t\tif(options.prevSelector !== \"\"){\r\n\t\t\twrapper.find(options.prevSelector).on(\"click\", prevSlide);\r\n\t\t\tif(!options.loopSlides)\r\n\t\t\t\twrapper.find(options.prevSelector).prop(\"disabled\",true);\r\n\t\t}\r\n\t\tif(options.nextSelector !== \"\"){\r\n\t\t\twrapper.find(options.nextSelector).on(\"click\", nextSlide);\r\n\t\t}\r\n\t}\r\n\r\n\tlet initTouch = function(){\r\n\t\t/* Initializes the touch handlers */\r\n\t\tlet startX = null;\r\n\t\tlet deltaX = 0;\r\n\t\t//Handler for the start of the event\r\n\t\twrapper.on(\"touchstart\", (event)=>{\r\n\t\t\tif(event.touches.length > 1) return;\r\n\t\t\tstartX = event.touches[0].screenX;\r\n\t\t\twrapper.addClass(\"dragging\");\r\n\t\t});\r\n\t\t//Handler for touch drag events\r\n\t\twrapper.on(\"touchmove\", (event)=>{\r\n\t\t\tif(event.touches.length > 1) return;\r\n\t\t\tif(startX === null) return;\r\n\t\t\t//Calculate the total amount moved since the start of the touch\r\n\t\t\tdeltaX = event.touches[0].screenX - startX;\r\n\t\t\t//Get the current slide\r\n\t\t\tlet curSlideNum = getCurSlideNum();\r\n\t\t\tlet activeSlide = wrapper.find(\".slide[data-num='\" + curSlideNum + \"']\");\r\n\t\t\tif(Math.abs(deltaX) < options.touchThreshhold){\r\n\t\t\t\tif(!activeSlide.attr(\"style\")) return;\t//Return if the slide is not yet being dragged\r\n\t\t\t}\r\n\t\t\t//Determine which slide should be revealed behind the current one\r\n\t\t\tlet nextSlideNum;\r\n\t\t\tif(deltaX < 0) nextSlideNum = curSlideNum + 1;\r\n\t\t\telse nextSlideNum = curSlideNum - 1;\r\n\t\t\tif(!options.loopSlides){\r\n\t\t\t\t//Check that there is a slide to show\r\n\t\t\t\tlet numSlides = wrapper.find(\".slide\").length;\r\n\t\t\t\tif(nextSlideNum < 0 || nextSlideNum >= numSlides) return;\r\n\t\t\t}\r\n\t\t\t//Style the slide being dragged\r\n\t\t\tlet opacity = 1 - Math.abs(deltaX / activeSlide.width());\r\n\t\t\tactiveSlide.css({\r\n\t\t\t\topacity: opacity.toFixed(2),\r\n\t\t\t\tleft: String(deltaX) + \"px\",\r\n\t\t\t\tzIndex: 1\r\n\t\t\t});\r\n\t\t\t//Style the slide being revealed\r\n\t\t\tlet newSlide = wrapper.find(\".slide[data-num='\" + nextSlideNum + \"']\");\r\n\t\t\tnewSlide.css({\r\n\t\t\t\topacity: (1 - opacity).toFixed(2),\r\n\t\t\t\tzIndex: 0\r\n\t\t\t});\r\n\t\t});\r\n\t\t//Handler for the end of the event\r\n\t\twrapper.on(\"touchend\", (event)=>{\r\n\t\t\t//Remove the dragging class from the slideshow\r\n\t\t\twrapper.removeClass(\"dragging\");\r\n\t\t\t//Remove inline styles from the slides\r\n\t\t\twindow.setTimeout(()=>{\r\n\t\t\t\twrapper.find(\".slide\").each(function(){\r\n\t\t\t\t\tjQuery(this).removeAttr(\"style\");\r\n\t\t\t\t});\r\n\t\t\t},10);\r\n\t\t\t//Check if the slide was moved enough to trigger a transition\r\n\t\t\tif(event.touches.length > 0 ||\r\n\t\t\tMath.abs(deltaX) < options.touchThreshhold){\r\n\t\t\t\t//Reset the touch event variables\r\n\t\t\t\tstartX = null;\r\n\t\t\t\tdeltaX = 0;\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\t//Transition to the new slide\r\n\t\t\tif(deltaX < 0) transitionToSlide(getCurSlideNum() + 1);\r\n\t\t\telse transitionToSlide(getCurSlideNum() - 1);\r\n\t\t\t//Reset the touch event variables\r\n\t\t\tstartX = null;\r\n\t\t\tdeltaX = 0;\r\n\t\t});\r\n\t}\r\n\r\n\tlet getCurSlideNum = function(){\r\n\t\tlet curSlide = wrapper.find(\".slide.active\").first();\r\n\t\tif(curSlide.length === 0)\r\n\t\t\treturn 0;\r\n\t\tlet num = parseInt(curSlide.attr(\"data-num\"));\r\n\t\treturn (num === NaN)? 0 : num;\r\n\t}\r\n\r\n\tlet transitionToSlide = function(newSlideNum){\r\n\t\t/*Transitions to the slide with the given index*/\r\n\t\tlet numSlides = wrapper.find(\".slide\").length;\r\n\t\tlet oldSlideNum = getCurSlideNum();\r\n\t\t//Calculate whether the slide is to the left of the current slide\r\n\t\tlet isDirLeft = newSlideNum < oldSlideNum;\r\n\t\t//Ensure the new slide number is valid\r\n\t\tif(options.loopSlides)\r\n\t\t\tnewSlideNum = newSlideNum % numSlides;\r\n\t\telse{\r\n\t\t\tif(newSlideNum < 0)\r\n\t\t\t\tnewSlideNum = 0;\r\n\t\t\telse if(newSlideNum >= numSlides)\r\n\t\t\t\tnewSlideNum = numSlides - 1;\r\n\t\t}\r\n\t\tif(newSlideNum === oldSlideNum) return;\r\n\t\t//Set the new slide as active and mark the old one as inactive\r\n\t\tlet oldSlide = wrapper.find(\".slide[data-num=\"+String(oldSlideNum)+\"]\");\r\n\t\toldSlide.attr(\"aria-hidden\",\"true\");\r\n\t\tlet newSlide =\twrapper.find(\".slide[data-num=\"+String(newSlideNum)+\"]\");\r\n\t\tnewSlide.addClass(\"active\").removeAttr(\"aria-hidden\");\r\n\t\toldSlide.removeClass(\"active\");\r\n\t\tif(isDirLeft)\r\n\t\t\toldSlide.addClass(\"transRight\");\r\n\t\telse\r\n\t\t\toldSlide.addClass(\"transLeft\");\r\n\t\twindow.setTimeout(()=>{\r\n\t\t\toldSlide.removeClass(\"transLeft\").removeClass(\"transRight\");\t//Clear the class after the transition\r\n\t\t}, 800);\r\n\t\t//Update the slide indicators\r\n\t\twrapper.find(\".slideIndicator[data-num=\"+String(oldSlideNum)+\"]\").removeClass(\"active\");\r\n\t\twrapper.find(\".slideIndicator[data-num=\"+String(newSlideNum)+\"]\").addClass(\"active\");\r\n\t\t//Update the navigation arrows\r\n\t\tif(!options.loopSlides){\r\n\t\t\tif(options.prevSelector !== \"\"){\r\n\t\t\t\t//Set the previous selector\r\n\t\t\t\tif(newSlideNum === 0)\r\n\t\t\t\t\twrapper.find(options.prevSelector).prop(\"disabled\",true);\r\n\t\t\t\telse\r\n\t\t\t\t\twrapper.find(options.prevSelector).prop(\"disabled\",false);\r\n\t\t\t}\r\n\t\t\tif(options.nextSelector !== \"\"){\r\n\t\t\t\t//Set the next selector\r\n\t\t\t\tif(newSlideNum === numSlides-1)\r\n\t\t\t\t\twrapper.find(options.nextSelector).prop(\"disabled\",true);\r\n\t\t\t\telse\r\n\t\t\t\t\twrapper.find(options.nextSelector).prop(\"disabled\",false);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tlet recalculateSlideWrapperHeight = function(){\r\n\t\t//Update the slide wrapper height\r\n\t\tlet slideWrapper = wrapper.find(\".slide\").first().parent();\r\n\t\tslideWrapper.css(\"height\",\"\");\t//Clear the wrapper height\r\n\t\tlet maxHeight = 0;\r\n\t\twrapper.find(\".slide\").each((i, el)=>{\r\n\t\t\tif(jQuery(el).height() > maxHeight)\r\n\t\t\t\tmaxHeight = Math.ceil(jQuery(el).height());\r\n\t\t});\r\n\t\t//Set the new height\r\n\t\tslideWrapper.height(String(maxHeight) + \"px\");\r\n\t}\r\n\r\n\t//Call the initialization function\r\n\tinit();\r\n}\r\n"],"names":["defaultOptions","loopSlides","prevSelector","nextSelector","indicatorSelector","touchThreshhold","wrapperHeight","initSlideshow","slideshow","passedOptions","let","wrapper","jQuery","options","prevSlide","Object","assign","transitionToSlide","getCurSlideNum","nextSlide","curSlide","find","first","length","NaN","num","parseInt","attr","newSlideNum","numSlides","oldSlideNum","isDirLeft","oldSlide","String","addClass","removeAttr","removeClass","window","setTimeout","prop","recalculateSlideWrapperHeight","slideWrapper","parent","css","maxHeight","each","i","el","height","Math","ceil","elem","timeout","on","clearTimeout","indicatorWrapper","newIndicator","append","initTouch","startX","deltaX","event","touches","screenX","curSlideNum","activeSlide","abs","nextSlideNum","opacity","width","toFixed","left","zIndex","this"],"mappings":"AAMA,MAAMA,eAAiB,CACtBC,WAAY,CAAA,EACZC,aAAc,GACdC,aAAc,GACdC,kBAAmB,GACnBC,gBAAiB,GACjBC,cAAe,MAChB,EAEA,SAASC,cAAcC,EAAWC,EAAc,IAC/CC,IAAIC,EAAUC,OAAOJ,CAAS,EAE1BK,EAAU,GAIVC,GAHJC,OAAOC,OAAOH,EAASb,eAAgBS,CAAa,EAGpC,WAAWQ,EAAkBC,EAAe,EA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