diff --git a/js/Wallop.min.js b/js/Wallop.min.js index 50e67b3..b141610 100644 --- a/js/Wallop.min.js +++ b/js/Wallop.min.js @@ -1 +1 @@ -!function(t){function e(t,e){if(!t)throw new Error('Selector missing, eg: new Wallop(".selector")');for(var s=0;s0)throw new Error("Selector cannot be an array");this.$selector=t,this.options=n(this.options,e),this.event=null,this.allItemsArray=Array.prototype.slice.call(this.$selector.querySelectorAll(" ."+this.options.itemClass)),this.allItemsArrayLength=this.allItemsArray.length-1,this.currentItemIndex=this.allItemsArray.indexOf(this.$selector.querySelector(" ."+this.options.currentItemClass)),this.buttonPrevious=this.$selector.querySelector(" ."+this.options.buttonPreviousClass),this.buttonNext=this.$selector.querySelector(" ."+this.options.buttonNextClass),this.bindEvents(),this.createCustomEvent(),this.currentItemIndex<0&&(this.currentItemIndex=0,i(this.allItemsArray[this.currentItemIndex],this.options.currentItemClass));var o=this;setTimeout(function(){o.event.detail.currentItemIndex=o.currentItemIndex,o.$selector.dispatchEvent(o.event)},0)}function s(t){return t?document.querySelectorAll("."+t):void 0}function i(t,e){t&&(t.className=t.className.replace(/\s+$/gi,"")+" "+e)}function o(t,e){t&&(t.className=t.className.replace(e,""))}function n(t,e){var s,i={};for(s in t)i[s]=t[s];for(s in e)i[s]=e[s];return i}function r(t,e){e=e||{bubbles:!1,cancelable:!1,detail:void 0};var s=document.createEvent("CustomEvent");return s.initCustomEvent(t,e.bubbles,e.cancelable,e.detail),s}var l=[],u=e.prototype;u.updateButtonStates=function(){(this.buttonPrevious||this.buttonNext)&&(this.currentItemIndex===this.allItemsArrayLength&&this.options.carousel!==!0?this.buttonNext.setAttribute("disabled","disabled"):0===this.currentItemIndex&&this.options.carousel!==!0&&this.buttonPrevious.setAttribute("disabled","disabled"))},u.removeAllHelperSettings=function(){o(this.allItemsArray[this.currentItemIndex],this.options.currentItemClass),o(s(this.options.hidePreviousClass)[0],this.options.hidePreviousClass),o(s(this.options.hideNextClass)[0],this.options.hideNextClass),o(s(this.options.showPreviousClass)[0],this.options.showPreviousClass),o(s(this.options.showNextClass)[0],this.options.showNextClass),(this.buttonPrevious||this.buttonNext)&&(this.buttonPrevious.removeAttribute("disabled"),this.buttonNext.removeAttribute("disabled"))},u.goTo=function(t){if(t!==this.currentItemIndex){if(this.options.carousel&&-1===t)t=this.allItemsArrayLength-1;else if(t>this.allItemsArrayLength||0>t)return;this.removeAllHelperSettings(),i(this.allItemsArray[this.currentItemIndex],t>this.currentItemIndex?this.options.hidePreviousClass:this.options.hideNextClass),i(this.allItemsArray[t],this.options.currentItemClass+" "+(t>this.currentItemIndex?this.options.showNextClass:this.options.showPreviousClass)),this.currentItemIndex=t,this.updateButtonStates(),this.event.detail.currentItemIndex=this.currentItemIndex,this.$selector.dispatchEvent(this.event)}},u.previous=function(){this.options.carousel&&0===this.currentItemIndex?this.goTo(this.allItemsArrayLength):this.goTo(this.currentItemIndex-1)},u.next=function(){this.currentItemIndex>=this.allItemsArrayLength&&this.options.carousel===!0?this.goTo(0):this.goTo(this.currentItemIndex+1)},u.bindEvents=function(){l.push(this.$selector);var t=this;this.buttonPrevious&&this.buttonPrevious.addEventListener("click",function(e){e.preventDefault(),t.previous()}),this.buttonNext&&this.buttonNext.addEventListener("click",function(e){e.preventDefault(),t.next()})},u.on=function(t,e){this.$selector.addEventListener(t,function(t){return e(t)},!1)},u.createCustomEvent=function(){var t=this;this.event=new r("change",{detail:{wallopEl:t.$selector,currentItemIndex:Number(t.currentItemIndex)},bubbles:!0,cancelable:!0})},r.prototype=window.CustomEvent?window.CustomEvent.prototype:{},window.CustomEvent=r,"function"==typeof define&&define.amd?define(function(){return e}):"undefined"!=typeof module&&module.exports?module.exports=e:t.Wallop=e}(this); \ No newline at end of file +!function(t){function e(t,e){if(!t)throw new Error('Selector missing, eg: new Wallop(".selector")');for(var s=0;s0)throw new Error("Selector cannot be an array");this.$selector=t,this.options=o(this.options,e),this.event=null,this.allItemsArray=Array.prototype.slice.call(this.$selector.querySelectorAll(" ."+this.options.itemClass)),this.allItemsArrayLength=this.allItemsArray.length-1,this.currentItemIndex=this.allItemsArray.indexOf(this.$selector.querySelector(" ."+this.options.currentItemClass)),this.buttonPrevious=this.$selector.querySelector(" ."+this.options.buttonPreviousClass),this.buttonNext=this.$selector.querySelector(" ."+this.options.buttonNextClass),this.bindEvents(),this.createCustomEvent(),-1===this.currentItemIndex&&(this.currentItemIndex=0,i(this.allItemsArray[this.currentItemIndex],this.options.currentItemClass)),this.updateButtonStates();var n=this;setTimeout(function(){n.event.detail.currentItemIndex=n.currentItemIndex,n.$selector.dispatchEvent(n.event)},0)}function s(t){return t?document.querySelectorAll("."+t):void 0}function i(t,e){t&&(t.className=(t.className+" "+e).trim())}function n(t,e){t&&(t.className=t.className.replace(e,"").trim())}function o(t,e){var s,i={};for(s in t)i[s]=t[s];for(s in e)i[s]=e[s];return i}function r(t,e){e=e||{bubbles:!1,cancelable:!1,detail:void 0};var s=document.createEvent("CustomEvent");return s.initCustomEvent(t,e.bubbles,e.cancelable,e.detail),s}var l=[],u=e.prototype;u.updateButtonStates=function(){!this.buttonPrevious&&!this.buttonNext||this.options.carousel||(this.currentItemIndex===this.allItemsArrayLength?this.buttonNext.setAttribute("disabled","disabled"):0===this.currentItemIndex&&this.buttonPrevious.setAttribute("disabled","disabled"))},u.removeAllHelperSettings=function(){n(this.allItemsArray[this.currentItemIndex],this.options.currentItemClass),n(s(this.options.hidePreviousClass)[0],this.options.hidePreviousClass),n(s(this.options.hideNextClass)[0],this.options.hideNextClass),n(s(this.options.showPreviousClass)[0],this.options.showPreviousClass),n(s(this.options.showNextClass)[0],this.options.showNextClass),(this.buttonPrevious||this.buttonNext)&&(this.buttonPrevious.removeAttribute("disabled"),this.buttonNext.removeAttribute("disabled"))},u.goTo=function(t){if(t!==this.currentItemIndex){if(this.options.carousel&&-1===t)t=this.allItemsArrayLength-1;else if(t>this.allItemsArrayLength||0>t)return;this.removeAllHelperSettings();var e=(t>this.currentItemIndex||0===t&&this.currentItemIndex===this.allItemsArrayLength)&&!(t===this.allItemsArrayLength&&0===this.currentItemIndex);i(this.allItemsArray[this.currentItemIndex],e?this.options.hidePreviousClass:this.options.hideNextClass),i(this.allItemsArray[t],this.options.currentItemClass+" "+(e?this.options.showNextClass:this.options.showPreviousClass)),this.currentItemIndex=t,this.updateButtonStates(),this.event.detail.currentItemIndex=this.currentItemIndex,this.$selector.dispatchEvent(this.event)}},u.previous=function(){this.options.carousel&&0===this.currentItemIndex?this.goTo(this.allItemsArrayLength):this.goTo(this.currentItemIndex-1)},u.next=function(){this.currentItemIndex>=this.allItemsArrayLength&&this.options.carousel===!0?this.goTo(0):this.goTo(this.currentItemIndex+1)},u.bindEvents=function(){l.push(this.$selector);var t=this;this.buttonPrevious&&this.buttonPrevious.addEventListener("click",function(e){e.preventDefault(),t.previous()}),this.buttonNext&&this.buttonNext.addEventListener("click",function(e){e.preventDefault(),t.next()})},u.on=function(t,e){this.$selector.addEventListener(t,function(t){return e(t)},!1)},u.createCustomEvent=function(){var t=this;this.event=new r("change",{detail:{wallopEl:t.$selector,currentItemIndex:Number(t.currentItemIndex)},bubbles:!0,cancelable:!0})},r.prototype=window.CustomEvent?window.CustomEvent.prototype:{},window.CustomEvent=r,"function"==typeof define&&define.amd?define(function(){return e}):"undefined"!=typeof module&&module.exports?module.exports=e:t.Wallop=e}(this); \ No newline at end of file diff --git a/package.json b/package.json index dca675e..08c668b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wallop", - "version": "2.2.0", + "version": "2.2.1", "description": "wallop is a minimal 4kb library for showing & hiding things", "main": "js/Wallop.js", "scripts": {