Skip to content

Commit

Permalink
Merge pull request #16 from yuezk/master
Browse files Browse the repository at this point in the history
Thanks for solve the issue :)
  • Loading branch information
josex2r committed Feb 9, 2016
2 parents ef48566 + cba330b commit 70cf538
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 35 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
73 changes: 46 additions & 27 deletions dist/jquery.slotmachine.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*! SlotMachine - v2.3.0 - 2015-12-22
/*! SlotMachine - v2.3.0 - 2016-02-02
* 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"); } }

Expand Down Expand Up @@ -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);

Expand All @@ -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',
Expand Down Expand Up @@ -131,7 +131,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
}]);

return Timer;
})();
}();

/**
* @desc Class - Makes Slot Machine animation effect
Expand All @@ -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);

Expand Down Expand Up @@ -359,13 +359,14 @@ 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;
}

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;

Expand Down Expand Up @@ -399,7 +400,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;

Expand All @@ -409,7 +410,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
// Repeat animation
this.shuffle(spins - 1);
}
}).bind(this));
}.bind(this));
}

return this.futureActive;
Expand Down Expand Up @@ -439,6 +440,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)
Expand All @@ -459,7 +465,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;
Expand All @@ -471,13 +477,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;
}
Expand All @@ -490,22 +496,35 @@ 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);
}
}

/**
* @desc PUBLIC - Destroy the machine
*/

}, {
key: 'destroy',
value: function destroy() {
this._$fakeFirstTile.remove();
this._$fakeLastTile.remove();
this.$tiles.unwrap();
$.data(this.element[0], 'plugin_' + pluginName, null);
}
}, {
key: 'active',
get: function get() {
Expand Down Expand Up @@ -683,15 +702,15 @@ 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) {
$elements.removeClass(FX_GRADIENT);
} else {
$elements.addClass(FX_GRADIENT);
}
}).bind(this), delay);
}.bind(this), delay);
}

/**
Expand All @@ -707,7 +726,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
}]);

return SlotMachine;
})();
}();

/*
* Create new plugin instance if needed and return it
Expand Down
Loading

0 comments on commit 70cf538

Please sign in to comment.