From b2ddf5b7031e4064d2b99d26f93d09cc7d22720f Mon Sep 17 00:00:00 2001 From: Kevin Yue Date: Mon, 1 Feb 2016 23:53:35 +0800 Subject: [PATCH 1/4] =?UTF-8?q?Added=20`destroy`=20method=EF=BC=8CFixed=20?= =?UTF-8?q?josex2r/jQuery-SlotMachine/#13=EF=BC=8Cmake=20`shuffle`=20spins?= =?UTF-8?q?=20argument=20optional?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/jquery.slotmachine.js | 67 ++++++++++++++++++++-------------- dist/jquery.slotmachine.min.js | 6 +-- src/jquery.slotmachine.js | 20 ++++++++-- 3 files changed, 59 insertions(+), 34 deletions(-) diff --git a/dist/jquery.slotmachine.js b/dist/jquery.slotmachine.js index fa0f3aa..933463b 100644 --- a/dist/jquery.slotmachine.js +++ b/dist/jquery.slotmachine.js @@ -1,9 +1,9 @@ -/*! SlotMachine - v2.3.0 - 2015-12-22 +/*! SlotMachine - v2.3.0 - 2016-02-01 * https://github.com/josex2r/jQuery-SlotMachine -* Copyright (c) 2015 Jose Luis Represa; Licensed MIT */ +* Copyright (c) 2016 Jose Luis Represa; Licensed MIT */ 'use strict'; -var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -66,7 +66,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons }); } - var Timer = (function () { + var Timer = function () { function Timer(cb, delay) { _classCallCheck(this, Timer); @@ -86,9 +86,9 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons _createClass(Timer, [{ key: '_start', value: function _start() { - this.timer = setTimeout((function cb() { + this.timer = setTimeout(function cb() { this.cb.call(this); - }).bind(this), this.delay); + }.bind(this), this.delay); } }, { key: 'cancel', @@ -131,7 +131,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons }]); return Timer; - })(); + }(); /** * @desc Class - Makes Slot Machine animation effect @@ -140,7 +140,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons * @return jQuery node - Returns jQuery selector with some new functions (shuffle, stop, next, auto, active) */ - var SlotMachine = (function () { + var SlotMachine = function () { function SlotMachine(element, options) { _classCallCheck(this, SlotMachine); @@ -359,13 +359,13 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons value: function shuffle(spins, onComplete) { var delay = this.settings.delay; + if (typeof spins === 'function') { + onComplete = spins; + } + if (onComplete) { this._oncompleteStack[1] = onComplete; } - if (this.futureActive === null) { - // Get random or custom element - this.futureActive = this.custom; - } this.running = true; this._fade = true; @@ -399,7 +399,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons } else { this.$container.animate({ marginTop: this.direction.to - }, delay, 'linear', (function cb() { + }, delay, 'linear', function cb() { // Reset top position this._marginTop = this.direction.first; @@ -409,7 +409,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons // Repeat animation this.shuffle(spins - 1); } - }).bind(this)); + }.bind(this)); } return this.futureActive; @@ -439,6 +439,11 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons // Set current active element this.active = this.visibleTile; + if (this.futureActive === null) { + // Get random or custom element + this.futureActive = this.custom; + } + // Check direction to prevent jumping if (this.futureActive > this.active) { // We are moving to the prev (first to last) @@ -459,7 +464,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons // Perform animation this.$container.animate({ marginTop: this.getTileOffset(this.active) - }, delay, 'easeOutBounce', (function cb() { + }, delay, 'easeOutBounce', function cb() { this.stopping = false; this.running = false; @@ -471,13 +476,13 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons if (typeof this._oncompleteStack[1] === 'function') { this._oncompleteStack[1].apply(this, [this.active]); } - }).bind(this)); + }.bind(this)); // Disable blur - this.raf((function cb() { + this.raf(function cb() { this._fade = false; this._animationFX = FX_STOP; - }).bind(this), delay / 1.75); + }.bind(this), delay / 1.75); return this.active; } @@ -490,22 +495,30 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons key: 'auto', value: function auto() { if (!this.running) { - this._timer = new Timer((function cb() { + this._timer = new Timer(function cb() { if (typeof this.settings.randomize !== 'function') { this.futureActive = this.next; } if (!this.visible && this.settings.stopHidden === true) { - this.raf((function cb2() { + this.raf(function cb2() { this._timer.reset(); - }).bind(this), 500); + }.bind(this), 500); } else { - this.shuffle(this.settings.spins, (function cb2() { + this.shuffle(this.settings.spins, function cb2() { this._timer.reset(); - }).bind(this)); + }.bind(this)); } - }).bind(this), this.settings.auto); + }.bind(this), this.settings.auto); } } + }, { + key: 'destroy', + value: function destroy() { + this._$fakeFirstTile.remove(); + this._$fakeLastTile.remove(); + this.$tiles.unwrap(); + $.data(this.element, 'plugin_' + pluginName, null); + } }, { key: 'active', get: function get() { @@ -683,7 +696,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons var delay = this.settings.delay / 4, $elements = this.$slot.add(this.$tiles); - this.raf((function cb() { + this.raf(function cb() { this._fxClass = FX_SPEED; if (this.fade !== true || FX_SPEED === FX_STOP) { @@ -691,7 +704,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons } else { $elements.addClass(FX_GRADIENT); } - }).bind(this), delay); + }.bind(this), delay); } /** @@ -707,7 +720,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons }]); return SlotMachine; - })(); + }(); /* * Create new plugin instance if needed and return it diff --git a/dist/jquery.slotmachine.min.js b/dist/jquery.slotmachine.min.js index c98df63..5c79176 100644 --- a/dist/jquery.slotmachine.min.js +++ b/dist/jquery.slotmachine.min.js @@ -1,4 +1,4 @@ -/*! SlotMachine - v2.3.0 - 2015-12-22 +/*! SlotMachine - v2.3.0 - 2016-02-01 * https://github.com/josex2r/jQuery-SlotMachine -* Copyright (c) 2015 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(b&&(this._oncompleteStack[1]=b),null===this.futureActive&&(this.futureActive=this.custom),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,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:"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 +* 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,"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 diff --git a/src/jquery.slotmachine.js b/src/jquery.slotmachine.js index 25e701f..7d64d40 100644 --- a/src/jquery.slotmachine.js +++ b/src/jquery.slotmachine.js @@ -499,13 +499,13 @@ class SlotMachine { shuffle (spins, onComplete) { let delay = this.settings.delay; + if (typeof spins === 'function') { + onComplete = spins; + } + if (onComplete) { this._oncompleteStack[1] = onComplete; } - if (this.futureActive === null) { - // Get random or custom element - this.futureActive = this.custom; - } this.running = true; this._fade = true; @@ -576,6 +576,11 @@ class SlotMachine { // Set current active element this.active = this.visibleTile; + if (this.futureActive === null) { + // Get random or custom element + this.futureActive = this.custom; + } + // Check direction to prevent jumping if (this.futureActive > this.active) { // We are moving to the prev (first to last) @@ -640,6 +645,13 @@ class SlotMachine { }.bind(this), this.settings.auto); } } + + destroy () { + this._$fakeFirstTile.remove(); + this._$fakeLastTile.remove(); + this.$tiles.unwrap(); + $.data(this.element, 'plugin_' + pluginName, null); + } } /* From 36228b77f78146abb308c5ef16c922d659a189db Mon Sep 17 00:00:00 2001 From: Kevin Yue Date: Tue, 2 Feb 2016 09:38:11 +0800 Subject: [PATCH 2/4] Fixed destroy method --- dist/jquery.slotmachine.js | 4 ++-- dist/jquery.slotmachine.min.js | 4 ++-- src/jquery.slotmachine.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dist/jquery.slotmachine.js b/dist/jquery.slotmachine.js index 933463b..6ccfdc7 100644 --- a/dist/jquery.slotmachine.js +++ b/dist/jquery.slotmachine.js @@ -1,4 +1,4 @@ -/*! SlotMachine - v2.3.0 - 2016-02-01 +/*! SlotMachine - v2.3.0 - 2016-02-02 * https://github.com/josex2r/jQuery-SlotMachine * Copyright (c) 2016 Jose Luis Represa; Licensed MIT */ 'use strict'; @@ -517,7 +517,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons this._$fakeFirstTile.remove(); this._$fakeLastTile.remove(); this.$tiles.unwrap(); - $.data(this.element, 'plugin_' + pluginName, null); + $.data(this.element[0], 'plugin_' + pluginName, null); } }, { key: 'active', diff --git a/dist/jquery.slotmachine.min.js b/dist/jquery.slotmachine.min.js index 5c79176..fe2b924 100644 --- a/dist/jquery.slotmachine.min.js +++ b/dist/jquery.slotmachine.min.js @@ -1,4 +1,4 @@ -/*! SlotMachine - v2.3.0 - 2016-02-01 +/*! SlotMachine - v2.3.0 - 2016-02-02 * 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,"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"+("."+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 diff --git a/src/jquery.slotmachine.js b/src/jquery.slotmachine.js index 7d64d40..3812533 100644 --- a/src/jquery.slotmachine.js +++ b/src/jquery.slotmachine.js @@ -650,7 +650,7 @@ class SlotMachine { this._$fakeFirstTile.remove(); this._$fakeLastTile.remove(); this.$tiles.unwrap(); - $.data(this.element, 'plugin_' + pluginName, null); + $.data(this.element[0], 'plugin_' + pluginName, null); } } From 2bbcac4a6569a9fe7d3930096647b752b2f6ae60 Mon Sep 17 00:00:00 2001 From: Kevin Yue Date: Tue, 2 Feb 2016 10:47:47 +0800 Subject: [PATCH 3/4] Added some comments --- dist/jquery.slotmachine.js | 6 ++++++ src/jquery.slotmachine.js | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/dist/jquery.slotmachine.js b/dist/jquery.slotmachine.js index 6ccfdc7..63c2d3b 100644 --- a/dist/jquery.slotmachine.js +++ b/dist/jquery.slotmachine.js @@ -359,6 +359,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons value: function shuffle(spins, onComplete) { var delay = this.settings.delay; + // Make spins optional if (typeof spins === 'function') { onComplete = spins; } @@ -511,6 +512,11 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons }.bind(this), this.settings.auto); } } + + /** + * @desc PUBLIC - Destroy the machine + */ + }, { key: 'destroy', value: function destroy() { diff --git a/src/jquery.slotmachine.js b/src/jquery.slotmachine.js index 3812533..5199584 100644 --- a/src/jquery.slotmachine.js +++ b/src/jquery.slotmachine.js @@ -499,6 +499,7 @@ class SlotMachine { shuffle (spins, onComplete) { let delay = this.settings.delay; + // Make spins optional if (typeof spins === 'function') { onComplete = spins; } @@ -646,6 +647,9 @@ class SlotMachine { } } + /** + * @desc PUBLIC - Destroy the machine + */ destroy () { this._$fakeFirstTile.remove(); this._$fakeLastTile.remove(); From cba330be2f66effa9f131dbe744c7100097bfe80 Mon Sep 17 00:00:00 2001 From: Kevin Yue Date: Tue, 2 Feb 2016 11:02:33 +0800 Subject: [PATCH 4/4] Update README.md --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4d83df3..682994a 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ var machine = $(foo).slotMachine(); Shuffle: ```javascript -machine.shuffle( repeat, onStopCallback ); //No args to make rotate infinitely +machine.shuffle( repeat, onStopCallback ); //No args to make rotate infinitely, `repeat` is optional ``` Change the selected element: @@ -94,6 +94,12 @@ Change spin direction, machine must not be running: machine.direction = direction; //direction must be a String ('up' || 'down') ``` +Destroy the machine. It will be useful when you want to reuse DOM: + +```javascript +machine.destroy(); +``` + ## Params Params must be an object, optionally containing the next parammeters: