diff --git a/bower.json b/bower.json index 1e08500..9c6ef2a 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "jQuery-SlotMachine", "description": "A simple jQuery plugin to make slot machine animation effect", - "version": "2.3.1", + "version": "3.0.0", "keywords": [ "slots", "gambling", diff --git a/dist/jquery.slotmachine.css b/dist/jquery.slotmachine.css new file mode 100644 index 0000000..4c4ea10 --- /dev/null +++ b/dist/jquery.slotmachine.css @@ -0,0 +1,30 @@ +.slotMachineNoTransition { + -webkit-transition: none !important; + transition: none !important; +} + +.slotMachineBlurFast { + -webkit-filter: blur(5px); + filter: blur(5px); +} + +.slotMachineBlurMedium { + -webkit-filter: blur(3px); + filter: blur(3px); +} + +.slotMachineBlurSlow { + -webkit-filter: blur(2px); + filter: blur(2px); +} + +.slotMachineBlurTurtle { + -webkit-filter: blur(1px); + filter: blur(1px); +} + +.slotMachineGradient { + -webkit-mask-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, rgba(0,0,0,0)), color-stop(25%, rgba(0,0,0,1)), color-stop(75%, rgba(0,0,0,1)), color-stop(100%, rgba(0,0,0,0)) ); + -webkit-mask: url("data:image/svg+xml;utf8,#slotMachineFadeMask"); + mask: url("data:image/svg+xml;utf8,#slotMachineFadeMask"); +} diff --git a/dist/jquery.slotmachine.js b/dist/jquery.slotmachine.js index b10e950..649e31b 100644 --- a/dist/jquery.slotmachine.js +++ b/dist/jquery.slotmachine.js @@ -1,4 +1,4 @@ -/*! SlotMachine - v2.3.1 - 2016-02-09 +/*! SlotMachine - v3.0.0 - 2016-02-23 * https://github.com/josex2r/jQuery-SlotMachine * Copyright (c) 2016 Jose Luis Represa; Licensed MIT */ 'use strict'; @@ -27,45 +27,14 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons stopHidden: true, // Stops animations if the element isnĀ“t visible on the screen direction: 'up' // Animation direction ['up'||'down'] }, + FX_NO_TRANSITION = 'slotMachineNoTransition', FX_FAST = 'slotMachineBlurFast', FX_NORMAL = 'slotMachineBlurMedium', FX_SLOW = 'slotMachineBlurSlow', + FX_TURTLE = 'slotMachineBlurTurtle', FX_GRADIENT = 'slotMachineGradient', FX_STOP = FX_GRADIENT; - // Set required styles, filters and masks - $(document).ready(function documentReady() { - - var slotMachineBlurFilterFastString = '' + '' + '' + '' + '#slotMachineBlurFilterFast'; - - var slotMachineBlurFilterMediumString = '' + '' + '' + '' + '#slotMachineBlurFilterMedium'; - - var slotMachineBlurFilterSlowString = '' + '' + '' + '' + '#slotMachineBlurFilterSlow'; - - var slotMachineFadeMaskString = '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '#slotMachineFadeMask'; - - // CSS classes - $('body').append(''); - }); - - // Required easing functions - if (typeof $.easing.easeOutBounce !== 'function') { - // From jQuery easing, extend jQuery animations functions - $.extend($.easing, { - easeOutBounce: function easeOutBounce(x, t, b, c, d) { - if ((t /= d) < 1 / 2.75) { - return c * (7.5625 * t * t) + b; - } else if (t < 2 / 2.75) { - return c * (7.5625 * (t -= 1.5 / 2.75) * t + 0.75) + b; - } else if (t < 2.5 / 2.75) { - return c * (7.5625 * (t -= 2.25 / 2.75) * t + 0.9375) + b; - } else { - return c * (7.5625 * (t -= 2.625 / 2.75) * t + 0.984375) + b; - } - } - }); - } - var Timer = (function () { function Timer(cb, delay) { _classCallCheck(this, Timer); @@ -182,6 +151,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons // Wrap elements inside $container this.$container = this.$tiles.wrapAll('
').parent(); + this.$container.css('transition', '1s ease-in-out'); // Set max top offset this._maxTop = -this.$container.height(); @@ -196,7 +166,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons this._initDirection(); // Show active element - this._marginTop = this.direction.initial; + this.resetPosition(); // Start auto animation if (this.settings.auto !== false) { @@ -249,13 +219,58 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons */ }, { - key: 'raf', + key: '_changeTransition', + + /** + * @desc PRIVATE - Set css transition property + */ + value: function _changeTransition() { + var delay = this._delay || this.settings.delay, + transition = this._transition || this.settings.transition; + this.$container.css('transition', delay + 's ' + transition); + } + + /** + * @desc PRIVATE - Set container margin + * @param {Number}||String - Active element index + */ + + }, { + key: '_animate', + value: function _animate(margin) { + this.$container.css('transform', 'matrix(1, 0, 0, 1, 0, ' + margin + ')'); + } + + /** + * @desc PRIVATE - Is moving from the first element to the last + * @return {Boolean} + */ + + }, { + key: '_isGoingBackward', + value: function _isGoingBackward() { + return this.futureActive > this.active && this.active === 0 && this.futureActive === this.$tiles.length - 1; + } + + /** + * @desc PRIVATE - Is moving from the last element to the first + * @param {Boolean} + */ + + }, { + key: '_isGoingForward', + value: function _isGoingForward() { + return this.futureActive <= this.active && this.active === this.$tiles.length - 1 && this.futureActive === 0; + } /** * @desc PUBLIC - Custom setTimeout using requestAnimationFrame * @param function cb - Callback * @param {Number} timeout - Timeout delay */ + + }, { + key: 'raf', value: function raf(cb, timeout) { var _raf = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame, startTime = new Date().getTime(), @@ -296,9 +311,13 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons */ }, { - key: '_resetPosition', - value: function _resetPosition() { - this._marginTop = this.direction.initial; + key: 'resetPosition', + value: function resetPosition(margin) { + this.$container.toggleClass(FX_NO_TRANSITION); + this._animate(margin === undefined ? this.direction.initial : margin); + // Force reflow, flushing the CSS changes + this.$container[0].offsetHeight; + this.$container.toggleClass(FX_NO_TRANSITION); } /** @@ -328,7 +347,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons value: function prev() { this.futureActive = this.prevIndex; this.running = true; - this.stop(false); + this.stop(); return this.futureActive; } @@ -343,7 +362,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons value: function next() { this.futureActive = this.nextIndex; this.running = true; - this.stop(false); + this.stop(); return this.futureActive; } @@ -354,63 +373,75 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons * @return {Number} - Returns result index */ + }, { + key: 'getDelayFromSpins', + value: function getDelayFromSpins(spins) { + var delay = this.settings.delay; + this._transition = 'linear'; + + switch (spins) { + case 1: + delay /= 0.5; + this._transition = 'ease-out'; + this._animationFX = FX_TURTLE; + break; + case 2: + delay /= 0.75; + this._animationFX = FX_SLOW; + break; + case 3: + delay /= 1; + this._animationFX = FX_NORMAL; + break; + case 4: + delay /= 1.25; + this._animationFX = FX_NORMAL; + break; + default: + delay /= 1.5; + this._animationFX = FX_FAST; + } + + return delay; + } + + /** + * @desc PUBLIC - Starts shuffling the elements + * @param {Number} repeations - Number of shuffles (undefined to make infinite animation + * @return {Number} - Returns result index + */ + }, { key: 'shuffle', value: function shuffle(spins, onComplete) { - var delay = this.settings.delay; + var _this = this; // Make spins optional if (typeof spins === 'function') { onComplete = spins; } - - if (onComplete) { - this._oncompleteStack[1] = onComplete; - } + this._oncompleteStack.push(onComplete); this.running = true; - this._fade = true; - - // Decreasing spin - if (typeof spins === 'number') { - // Change delay and speed - switch (spins) { - case 1: - case 2: - this._animationFX = FX_SLOW; - break; - case 3: - case 4: - this._animationFX = FX_NORMAL; - delay /= 1.5; - break; - default: - this._animationFX = FX_FAST; - delay /= 2; - } - // Infinite spin - } else { - // Set animation effects - this._animationFX = FX_FAST; - delay /= 2; - } - // Perform animation if (!this.visible && this.settings.stopHidden === true) { this.stop(); } else { - this.$container.animate({ - marginTop: this.direction.to - }, delay, 'linear', (function cb() { - // Reset top position - this._marginTop = this.direction.first; - - if (spins - 1 <= 0) { - this.stop(); - } else { - // Repeat animation - this.shuffle(spins - 1); + var delay = this.getDelayFromSpins(spins); + this.delay = delay; + this._animate(this.direction.to); + this.raf(function () { + if (!_this.stopping && _this.running) { + var left = spins - 1; + + _this.resetPosition(_this.direction.first); + if (left <= 1) { + _this.stop(); + } else { + // Repeat animation + _this.shuffle(left); + } } - }).bind(this)); + }, delay); } return this.futureActive; @@ -423,22 +454,15 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons }, { key: 'stop', - value: function stop(showGradient) { - if (!this.running) { - return; - } else if (this.stopping) { + value: function stop() { + var _this2 = this; + + if (!this.running || this.stopping) { return this.futureActive; } - // Stop animation NOW!!!!!!! - this.$container.clearQueue().stop(true, false); - - this._fade = showGradient === undefined ? true : showGradient; - this._animationFX = FX_SLOW; this.running = true; this.stopping = true; - // Set current active element - this.active = this.visibleTile; if (this.futureActive === null) { // Get random or custom element @@ -446,44 +470,31 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons } // Check direction to prevent jumping - if (this.futureActive > this.active) { - // We are moving to the prev (first to last) - if (this.active === 0 && this.futureActive === this.$tiles.length - 1) { - this._marginTop = this.direction.firstToLast; - } - // We are moving to the next (last to first) - } else if (this.active === this.$tiles.length - 1 && this.futureActive === 0) { - this._marginTop = this.direction.lastToFirst; - } + if (this._isGoingBackward()) { + this.resetPosition(this.direction.firstToLast); + } else if (this._isGoingForward()) { + this.resetPosition(this.direction.lastToFirst); + } // Update last choosen element index this.active = this.futureActive; - // Get delay - var delay = this.settings.delay * 3; - // Perform animation - this.$container.animate({ - marginTop: this.getTileOffset(this.active) - }, delay, 'easeOutBounce', (function cb() { - - this.stopping = false; - this.running = false; - this.futureActive = null; - - if (typeof this._oncompleteStack[0] === 'function') { - this._oncompleteStack[0].apply(this, [this.active]); - } - if (typeof this._oncompleteStack[1] === 'function') { - this._oncompleteStack[1].apply(this, [this.active]); - } - }).bind(this)); - - // Disable blur - this.raf((function cb() { - this._fade = false; - this._animationFX = FX_STOP; - }).bind(this), delay / 1.75); + var delay = this.getDelayFromSpins(1); + this.delay = delay; + this._animationFX = FX_STOP; + this._animate(this.getTileOffset(this.active)); + this.raf(function () { + _this2.stopping = false; + _this2.running = false; + _this2.futureActive = null; + + _this2._oncompleteStack.filter(function (fn) { + return typeof fn === 'function'; + }).forEach(function (fn) { + fn.apply(_this2, [_this2.active]); + }); + }, delay); return this.active; } @@ -495,21 +506,21 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons }, { key: 'auto', value: function auto() { + var _this3 = this; + if (!this.running) { - this._timer = new Timer((function cb() { - if (typeof this.settings.randomize !== 'function') { - this.futureActive = this.next; + this._timer = new Timer(function () { + if (typeof _this3.settings.randomize !== 'function') { + _this3.settings.randomize = function () { + return _this3._nextIndex; + }; } - if (!this.visible && this.settings.stopHidden === true) { - this.raf((function cb2() { - this._timer.reset(); - }).bind(this), 500); + if (!_this3.visible && _this3.settings.stopHidden === true) { + _this3.raf(_this3._timer.reset.bind(_this3._timer), 500); } else { - this.shuffle(this.settings.spins, (function cb2() { - this._timer.reset(); - }).bind(this)); + _this3.shuffle(_this3.settings.spins, _this3._timer.reset.bind(_this3._timer)); } - }).bind(this), this.settings.auto); + }, this.settings.auto); } } @@ -556,8 +567,9 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons key: 'visibleTile', get: function get() { var firstTileHeight = this.$tiles.first().height(), - rawContainerMargin = this.$container.css('margin-top'), - containerMargin = parseInt(rawContainerMargin.replace(/px/, ''), 10); + rawContainerMargin = this.$container.css('transform'), + matrixRegExp = /^matrix\(-?\d+,\s?-?\d+,\s?-?\d+,\s?-?\d+,\s?-?\d+,\s?(-?\d+)\)$/, + containerMargin = parseInt(rawContainerMargin.replace(matrixRegExp, '$1'), 10); return Math.abs(Math.round(containerMargin / firstTileHeight)) - 1; } @@ -652,7 +664,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons }, { key: 'prevIndex', get: function get() { - return this.direction === 'up' ? this._prevIndex : this._nextIndex; + return this.direction === 'up' ? this._nextIndex : this._prevIndex; } /** @@ -663,7 +675,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons }, { key: 'nextIndex', get: function get() { - return this.direction === 'up' ? this._nextIndex : this._prevIndex; + return this.direction === 'up' ? this._prevIndex : this._nextIndex; } /** @@ -685,9 +697,9 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons }, { key: '_fxClass', set: function set(FX_SPEED) { - var classes = [FX_FAST, FX_NORMAL, FX_SLOW].join(' '); + var classes = [FX_FAST, FX_NORMAL, FX_SLOW, FX_TURTLE].join(' '); - this.$tiles.removeClass(classes).addClass(FX_SPEED); + this.$tiles.add(this._$fakeFirstTile).add(this._$fakeLastTile).removeClass(classes).addClass(FX_SPEED); } /** @@ -700,12 +712,12 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons key: '_animationFX', set: function set(FX_SPEED) { var delay = this.settings.delay / 4, - $elements = this.$slot.add(this.$tiles); + $elements = this.$slot.add(this.$tiles).add(this._$fakeFirstTile).add(this._$fakeLastTile); this.raf((function cb() { this._fxClass = FX_SPEED; - if (this.fade !== true || FX_SPEED === FX_STOP) { + if (FX_SPEED === FX_STOP) { $elements.removeClass(FX_GRADIENT); } else { $elements.addClass(FX_GRADIENT); @@ -714,14 +726,29 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons } /** - * @desc PRIVATE - Set container margin - * @param {Number}||String - Active element index + * @desc PRIVATE - Set css transition delay + * @param {Number} - Transition delay in ms + */ + + }, { + key: 'delay', + set: function set(delay) { + delay = delay / 1000; + this._delay = delay; + this._changeTransition(); + } + + /** + * @desc PRIVATE - Set css transition + * @param {String} - Transition type */ }, { - key: '_marginTop', - set: function set(margin) { - this.$container.css('margin-top', margin); + key: 'transition', + set: function set(transition) { + transition = transition || 'ease-in-out'; + this._transition = transition; + this._changeTransition(); } }]); @@ -747,15 +774,15 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons * Chainable instance */ $.fn[pluginName] = function initPlugin(options) { - var _this = this; + var _this4 = this; var instances = void 0; if (this.length === 1) { instances = _getInstance(this, options); } else { (function () { - var $els = _this; - instances = $.map($els, function mapValue(el, index) { + var $els = _this4; + instances = $.map($els, function (el, index) { var $el = $els.eq(index); return _getInstance($el, options); }); diff --git a/dist/jquery.slotmachine.min.css b/dist/jquery.slotmachine.min.css new file mode 100644 index 0000000..542ac19 --- /dev/null +++ b/dist/jquery.slotmachine.min.css @@ -0,0 +1 @@ +.slotMachineNoTransition{-webkit-transition:none!important;transition:none!important}.slotMachineBlurFast{-webkit-filter:blur(5px);filter:blur(5px)}.slotMachineBlurMedium{-webkit-filter:blur(3px);filter:blur(3px)}.slotMachineBlurSlow{-webkit-filter:blur(2px);filter:blur(2px)}.slotMachineBlurTurtle{-webkit-filter:blur(1px);filter:blur(1px)}.slotMachineGradient{-webkit-mask-image:-webkit-gradient(linear,left top,left bottom,color-stop(0,rgba(0,0,0,0)),color-stop(25%,rgba(0,0,0,1)),color-stop(75%,rgba(0,0,0,1)),color-stop(100%,rgba(0,0,0,0)));-webkit-mask:url("data:image/svg+xml;utf8,#slotMachineFadeMask");mask:url("data:image/svg+xml;utf8,#slotMachineFadeMask")} \ No newline at end of file diff --git a/dist/jquery.slotmachine.min.js b/dist/jquery.slotmachine.min.js index cbf946f..6fab1d6 100644 --- a/dist/jquery.slotmachine.min.js +++ b/dist/jquery.slotmachine.min.js @@ -1,4 +1,4 @@ -/*! SlotMachine - v2.3.1 - 2016-02-09 +/*! SlotMachine - v3.0.0 - 2016-02-23 * https://github.com/josex2r/jQuery-SlotMachine * Copyright (c) 2016 Jose Luis Represa; Licensed MIT */ -"use strict";function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function a(a,b){for(var c=0;c"+("."+h+'{-webkit-filter: blur(5px);-moz-filter: blur(5px);-o-filter: blur(5px);-ms-filter: blur(5px);filter: blur(5px);filter: url("data:image/svg+xml;utf8,'+b+'");filter:progid:DXImageTransform.Microsoft.Blur(PixelRadius="5")}')+("."+i+'{-webkit-filter: blur(3px);-moz-filter: blur(3px);-o-filter: blur(3px);-ms-filter: blur(3px);filter: blur(3px);filter: url("data:image/svg+xml;utf8,'+c+'");filter:progid:DXImageTransform.Microsoft.Blur(PixelRadius="3")}')+("."+j+'{-webkit-filter: blur(1px);-moz-filter: blur(1px);-o-filter: blur(1px);-ms-filter: blur(1px);filter: blur(1px);filter: url("data:image/svg+xml;utf8,'+d+'");filter:progid:DXImageTransform.Microsoft.Blur(PixelRadius="1")}')+("."+k+"{")+"-webkit-mask-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, rgba(0,0,0,0)), color-stop(25%, rgba(0,0,0,1)), color-stop(75%, rgba(0,0,0,1)), color-stop(100%, rgba(0,0,0,0)) );"+('mask: url("data:image/svg+xml;utf8,'+e+'");')+"}")}),"function"!=typeof a.easing.easeOutBounce&&a.extend(a.easing,{easeOutBounce:function(a,b,c,d,e){return(b/=e)<1/2.75?d*(7.5625*b*b)+c:2/2.75>b?d*(7.5625*(b-=1.5/2.75)*b+.75)+c:2.5/2.75>b?d*(7.5625*(b-=2.25/2.75)*b+.9375)+c:d*(7.5625*(b-=2.625/2.75)*b+.984375)+c}});var m=function(){function a(b,c){return _classCallCheck(this,a),this.cb=b,this.initialDelay=c,this.delay=c,this.deferred=jQuery.Deferred(),this.startTime=null,this.timer=null,this.running=!1,this.resume(),this}return _createClass(a,[{key:"_start",value:function(){this.timer=setTimeout(function(){this.cb.call(this)}.bind(this),this.delay)}},{key:"cancel",value:function(){this.running=!1,clearTimeout(this.timer)}},{key:"pause",value:function(){this.running&&(this.delay-=(new Date).getTime()-this.startTime,this.cancel())}},{key:"resume",value:function(){this.running||(this.running=!0,this.startTime=(new Date).getTime(),this._start())}},{key:"reset",value:function(){this.cancel(),this.delay=this.initialDelay,this._start()}},{key:"add",value:function(a){this.pause(),this.delay+=a,this.resume()}}]),a}(),n=function(){function c(b,d){_classCallCheck(this,c),this.element=b,this.settings=a.extend({},g,d),this.defaults=g,this.name=f,this.$slot=a(b),this.$tiles=this.$slot.children(),this.$container=null,this._minTop=null,this._maxTop=null,this._$fakeFirstTile=null,this._$fakeLastTile=null,this._timer=null,this._oncompleteStack=[this.settings.complete],this._spinsLeft=null,this.futureActive=null,this.running=!1,this.stopping=!1,this.active=this.settings.active,this.$slot.css("overflow","hidden"),this.$container=this.$tiles.wrapAll('
').parent(),this._maxTop=-this.$container.height(),this._initFakeTiles(),this._minTop=-this._$fakeFirstTile.outerHeight(),this._initDirection(),this._marginTop=this.direction.initial,this.settings.auto!==!1&&(this.settings.auto===!0?this.shuffle():this.auto())}return _createClass(c,[{key:"_initFakeTiles",value:function(){this._$fakeFirstTile=this.$tiles.last().clone(),this._$fakeLastTile=this.$tiles.first().clone(),this.$container.prepend(this._$fakeFirstTile),this.$container.append(this._$fakeLastTile)}},{key:"_initDirection",value:function(){this._direction={selected:"down"===this.settings.direction?"down":"up",up:{key:"up",initial:this.getTileOffset(this.active),first:0,last:this.getTileOffset(this.$tiles.length),to:this._maxTop,firstToLast:this.getTileOffset(this.$tiles.length),lastToFirst:0},down:{key:"down",initial:this.getTileOffset(this.active),first:this.getTileOffset(this.$tiles.length),last:0,to:this._minTop,firstToLast:this.getTileOffset(this.$tiles.length),lastToFirst:0}}}},{key:"raf",value:function(a,c){var d=b.requestAnimationFrame||b.mozRequestAnimationFrame||b.webkitRequestAnimationFrame||b.msRequestAnimationFrame,e=(new Date).getTime(),f=function g(){var b=(new Date).getTime(),f=b-e;c>f?d(g):"function"==typeof a&&a()};d(f)}},{key:"getTileOffset",value:function(a){for(var b=0,c=0;a>c;c++)b+=this.$tiles.eq(c).outerHeight();return this._minTop-b}},{key:"_resetPosition",value:function(){this._marginTop=this.direction.initial}},{key:"setRandomize",value:function(a){this.settings.randomize=a,"number"==typeof a&&(this.settings.randomize=function(){return a})}},{key:"prev",value:function(){return this.futureActive=this.prevIndex,this.running=!0,this.stop(!1),this.futureActive}},{key:"next",value:function(){return this.futureActive=this.nextIndex,this.running=!0,this.stop(!1),this.futureActive}},{key:"shuffle",value:function(a,b){var c=this.settings.delay;if("function"==typeof a&&(b=a),b&&(this._oncompleteStack[1]=b),this.running=!0,this._fade=!0,"number"==typeof a)switch(a){case 1:case 2:this._animationFX=j;break;case 3:case 4:this._animationFX=i,c/=1.5;break;default:this._animationFX=h,c/=2}else this._animationFX=h,c/=2;return this.visible||this.settings.stopHidden!==!0?this.$container.animate({marginTop:this.direction.to},c,"linear",function(){this._marginTop=this.direction.first,0>=a-1?this.stop():this.shuffle(a-1)}.bind(this)):this.stop(),this.futureActive}},{key:"stop",value:function(a){if(this.running){if(this.stopping)return this.futureActive;this.$container.clearQueue().stop(!0,!1),this._fade=a===d?!0:a,this._animationFX=j,this.running=!0,this.stopping=!0,this.active=this.visibleTile,null===this.futureActive&&(this.futureActive=this.custom),this.futureActive>this.active?0===this.active&&this.futureActive===this.$tiles.length-1&&(this._marginTop=this.direction.firstToLast):this.active===this.$tiles.length-1&&0===this.futureActive&&(this._marginTop=this.direction.lastToFirst),this.active=this.futureActive;var b=3*this.settings.delay;return this.$container.animate({marginTop:this.getTileOffset(this.active)},b,"easeOutBounce",function(){this.stopping=!1,this.running=!1,this.futureActive=null,"function"==typeof this._oncompleteStack[0]&&this._oncompleteStack[0].apply(this,[this.active]),"function"==typeof this._oncompleteStack[1]&&this._oncompleteStack[1].apply(this,[this.active])}.bind(this)),this.raf(function(){this._fade=!1,this._animationFX=l}.bind(this),b/1.75),this.active}}},{key:"auto",value:function(){this.running||(this._timer=new m(function(){"function"!=typeof this.settings.randomize&&(this.futureActive=this.next),this.visible||this.settings.stopHidden!==!0?this.shuffle(this.settings.spins,function(){this._timer.reset()}.bind(this)):this.raf(function(){this._timer.reset()}.bind(this),500)}.bind(this),this.settings.auto))}},{key:"destroy",value:function(){this._$fakeFirstTile.remove(),this._$fakeLastTile.remove(),this.$tiles.unwrap(),a.data(this.element[0],"plugin_"+f,null)}},{key:"active",get:function(){return this._active},set:function(a){this._active=a,(0>a||a>=this.$tiles.length)&&(this._active=0)}},{key:"visibleTile",get:function(){var a=this.$tiles.first().height(),b=this.$container.css("margin-top"),c=parseInt(b.replace(/px/,""),10);return Math.abs(Math.round(c/a))-1}},{key:"random",get:function(){return Math.floor(Math.random()*this.$tiles.length)}},{key:"custom",get:function(){var a=void 0;if("function"==typeof this.settings.randomize){var b=this.settings.randomize.call(this,this.active);(0>b||b>=this.$tiles.length)&&(b=0),a=b}else a=this.random;return a}},{key:"direction",get:function(){return this._direction[this._direction.selected]},set:function(a){this.running||(this.direction="down"===a?"down":"up")}},{key:"_prevIndex",get:function(){var a=this.active-1;return 0>a?this.$tiles.length-1:a}},{key:"_nextIndex",get:function(){var a=this.active+1;return ac.scrollTop()+c.height(),e=c.scrollTop()>this.$slot.height()+this.$slot.offset().top;return!d&&!e}},{key:"_fxClass",set:function(a){var b=[h,i,j].join(" ");this.$tiles.removeClass(b).addClass(a)}},{key:"_animationFX",set:function(a){var b=this.settings.delay/4,c=this.$slot.add(this.$tiles);this.raf(function(){this._fxClass=a,this.fade!==!0||a===l?c.removeClass(k):c.addClass(k)}.bind(this),b)}},{key:"_marginTop",set:function(a){this.$container.css("margin-top",a)}}]),c}();a.fn[f]=function(b){var c=this,d=void 0;return 1===this.length?d=e(this,b):!function(){var f=c;d=a.map(f,function(a,c){var d=f.eq(c);return e(d,b)})}(),d}}(jQuery,window,document); \ No newline at end of file +"use strict";function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function a(a,b){for(var c=0;c').parent(),this.$container.css("transition","1s ease-in-out"),this._maxTop=-this.$container.height(),this._initFakeTiles(),this._minTop=-this._$fakeFirstTile.outerHeight(),this._initDirection(),this.resetPosition(),this.settings.auto!==!1&&(this.settings.auto===!0?this.shuffle():this.auto())}return _createClass(c,[{key:"_initFakeTiles",value:function(){this._$fakeFirstTile=this.$tiles.last().clone(),this._$fakeLastTile=this.$tiles.first().clone(),this.$container.prepend(this._$fakeFirstTile),this.$container.append(this._$fakeLastTile)}},{key:"_initDirection",value:function(){this._direction={selected:"down"===this.settings.direction?"down":"up",up:{key:"up",initial:this.getTileOffset(this.active),first:0,last:this.getTileOffset(this.$tiles.length),to:this._maxTop,firstToLast:this.getTileOffset(this.$tiles.length),lastToFirst:0},down:{key:"down",initial:this.getTileOffset(this.active),first:this.getTileOffset(this.$tiles.length),last:0,to:this._minTop,firstToLast:this.getTileOffset(this.$tiles.length),lastToFirst:0}}}},{key:"_changeTransition",value:function(){var a=this._delay||this.settings.delay,b=this._transition||this.settings.transition;this.$container.css("transition",a+"s "+b)}},{key:"_animate",value:function(a){this.$container.css("transform","matrix(1, 0, 0, 1, 0, "+a+")")}},{key:"_isGoingBackward",value:function(){return this.futureActive>this.active&&0===this.active&&this.futureActive===this.$tiles.length-1}},{key:"_isGoingForward",value:function(){return this.futureActive<=this.active&&this.active===this.$tiles.length-1&&0===this.futureActive}},{key:"raf",value:function(a,c){var d=b.requestAnimationFrame||b.mozRequestAnimationFrame||b.webkitRequestAnimationFrame||b.msRequestAnimationFrame,e=(new Date).getTime(),f=function g(){var b=(new Date).getTime(),f=b-e;c>f?d(g):"function"==typeof a&&a()};d(f)}},{key:"getTileOffset",value:function(a){for(var b=0,c=0;a>c;c++)b+=this.$tiles.eq(c).outerHeight();return this._minTop-b}},{key:"resetPosition",value:function(a){this.$container.toggleClass(h),this._animate(a===d?this.direction.initial:a),this.$container[0].offsetHeight,this.$container.toggleClass(h)}},{key:"setRandomize",value:function(a){this.settings.randomize=a,"number"==typeof a&&(this.settings.randomize=function(){return a})}},{key:"prev",value:function(){return this.futureActive=this.prevIndex,this.running=!0,this.stop(),this.futureActive}},{key:"next",value:function(){return this.futureActive=this.nextIndex,this.running=!0,this.stop(),this.futureActive}},{key:"getDelayFromSpins",value:function(a){var b=this.settings.delay;switch(this._transition="linear",a){case 1:b/=.5,this._transition="ease-out",this._animationFX=l;break;case 2:b/=.75,this._animationFX=k;break;case 3:b/=1,this._animationFX=j;break;case 4:b/=1.25,this._animationFX=j;break;default:b/=1.5,this._animationFX=i}return b}},{key:"shuffle",value:function(a,b){var c=this;if("function"==typeof a&&(b=a),this._oncompleteStack.push(b),this.running=!0,this.visible||this.settings.stopHidden!==!0){var d=this.getDelayFromSpins(a);this.delay=d,this._animate(this.direction.to),this.raf(function(){if(!c.stopping&&c.running){var b=a-1;c.resetPosition(c.direction.first),1>=b?c.stop():c.shuffle(b)}},d)}else this.stop();return this.futureActive}},{key:"stop",value:function(){var a=this;if(!this.running||this.stopping)return this.futureActive;this.running=!0,this.stopping=!0,null===this.futureActive&&(this.futureActive=this.custom),this._isGoingBackward()?this.resetPosition(this.direction.firstToLast):this._isGoingForward()&&this.resetPosition(this.direction.lastToFirst),this.active=this.futureActive;var b=this.getDelayFromSpins(1);return this.delay=b,this._animationFX=n,this._animate(this.getTileOffset(this.active)),this.raf(function(){a.stopping=!1,a.running=!1,a.futureActive=null,a._oncompleteStack.filter(function(a){return"function"==typeof a}).forEach(function(b){b.apply(a,[a.active])})},b),this.active}},{key:"auto",value:function(){var a=this;this.running||(this._timer=new o(function(){"function"!=typeof a.settings.randomize&&(a.settings.randomize=function(){return a._nextIndex}),a.visible||a.settings.stopHidden!==!0?a.shuffle(a.settings.spins,a._timer.reset.bind(a._timer)):a.raf(a._timer.reset.bind(a._timer),500)},this.settings.auto))}},{key:"destroy",value:function(){this._$fakeFirstTile.remove(),this._$fakeLastTile.remove(),this.$tiles.unwrap(),a.data(this.element[0],"plugin_"+f,null)}},{key:"active",get:function(){return this._active},set:function(a){this._active=a,(0>a||a>=this.$tiles.length)&&(this._active=0)}},{key:"visibleTile",get:function(){var a=this.$tiles.first().height(),b=this.$container.css("transform"),c=/^matrix\(-?\d+,\s?-?\d+,\s?-?\d+,\s?-?\d+,\s?-?\d+,\s?(-?\d+)\)$/,d=parseInt(b.replace(c,"$1"),10);return Math.abs(Math.round(d/a))-1}},{key:"random",get:function(){return Math.floor(Math.random()*this.$tiles.length)}},{key:"custom",get:function(){var a=void 0;if("function"==typeof this.settings.randomize){var b=this.settings.randomize.call(this,this.active);(0>b||b>=this.$tiles.length)&&(b=0),a=b}else a=this.random;return a}},{key:"direction",get:function(){return this._direction[this._direction.selected]},set:function(a){this.running||(this.direction="down"===a?"down":"up")}},{key:"_prevIndex",get:function(){var a=this.active-1;return 0>a?this.$tiles.length-1:a}},{key:"_nextIndex",get:function(){var a=this.active+1;return ac.scrollTop()+c.height(),e=c.scrollTop()>this.$slot.height()+this.$slot.offset().top;return!d&&!e}},{key:"_fxClass",set:function(a){var b=[i,j,k,l].join(" ");this.$tiles.add(this._$fakeFirstTile).add(this._$fakeLastTile).removeClass(b).addClass(a)}},{key:"_animationFX",set:function(a){var b=this.settings.delay/4,c=this.$slot.add(this.$tiles).add(this._$fakeFirstTile).add(this._$fakeLastTile);this.raf(function(){this._fxClass=a,a===n?c.removeClass(m):c.addClass(m)}.bind(this),b)}},{key:"delay",set:function(a){a/=1e3,this._delay=a,this._changeTransition()}},{key:"transition",set:function(a){a=a||"ease-in-out",this._transition=a,this._changeTransition()}}]),c}();a.fn[f]=function(b){var c=this,d=void 0;return 1===this.length?d=e(this,b):!function(){var f=c;d=a.map(f,function(a,c){var d=f.eq(c);return e(d,b)})}(),d}}(jQuery,window,document); \ No newline at end of file diff --git a/package.json b/package.json index bfdbb19..6536b96 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jquery-slotmachine", - "version": "2.3.1", + "version": "3.0.0", "engines": { "node": ">= 0.8.0" }, diff --git a/slotmachine.jquery.json b/slotmachine.jquery.json index 33bc646..a99385c 100644 --- a/slotmachine.jquery.json +++ b/slotmachine.jquery.json @@ -11,7 +11,7 @@ "winning", "machine" ], - "version": "2.3.1", + "version": "3.0.0", "download": "https://github.com/josex2r/jQuery-SlotMachine", "homepage": "https://github.com/josex2r/jQuery-SlotMachine", "demo": "http://josex2r.github.io/jQuery-SlotMachine/",