Skip to content

Commit

Permalink
Enabled 'stopHidden' attribute. Fixed #6
Browse files Browse the repository at this point in the history
  • Loading branch information
josex2r committed Apr 21, 2015
1 parent fb8800d commit 25296b4
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 51 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Pass an int as miliseconds to make the machine auto rotate

repeat: false

### stopHidden (currently disabled)
### stopHidden

Stop animation if the element is above or below the screen

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jQuery-SlotMachine",
"description": "A simple jQuery plugin to make slot machine animation effect",
"version": "2.0.8",
"version": "2.0.9",
"keywords": [
"slots",
"gambling",
Expand Down
53 changes: 30 additions & 23 deletions dist/jquery.slotmachine.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! SlotMachine - v2.0.8 - 2015-01-28
/*! SlotMachine - v2.0.9 - 2015-04-21
* https://github.com/josex2r/jQuery-SlotMachine
* Copyright (c) 2015 Jose Luis Represa; Licensed MIT */
;(function($, window, document, undefined){
Expand All @@ -10,7 +10,7 @@
auto : false, //Repeat delay [false||int]
randomize : null, //Randomize function, must return an integer with the selected position
complete : null, //Callback function(result)
//stopHidden : true //Stops animations if the element isn´t visible on the screen
stopHidden : true //Stops animations if the element isn´t visible on the screen
};

var FX_FAST = 'slotMachineBlurFast',
Expand Down Expand Up @@ -363,11 +363,7 @@
*/
SlotMachine.prototype.shuffle = function( spins, onComplete ){
var self = this;
/*
if(!this.isVisible() && this.settings.stopHidden === true){
return this.stop();
}
*/

if(onComplete !== undefined){
//this._oncompleteStack.push(onComplete);
this._oncompleteStack[1] = onComplete;
Expand Down Expand Up @@ -409,19 +405,24 @@
}

//Perform animation
this.$container.animate({
marginTop : this._maxTop
}, delay, 'linear', function(){
//Reset top position
self.$container.css('margin-top', 0);

if(spins - 1 <= 0){
self.stop();
}else{
//Repeat animation
self.shuffle(spins - 1);
}
});
if(!this.isVisible() && this.settings.stopHidden === true){
spins = 0;
self.stop();
}else{
this.$container.animate({
marginTop : this._maxTop
}, delay, 'linear', function(){
//Reset top position
self.$container.css('margin-top', 0);

if(spins - 1 <= 0){
self.stop();
}else{
//Repeat animation
self.shuffle(spins - 1);
}
});
}

return this.futureActive;
};
Expand Down Expand Up @@ -511,9 +512,15 @@
self.futureActive = self.getNext();
}
self.isRunning = true;
self.shuffle(5, function(){
self._timer.reset();
});
if(!self.isVisible() && self.settings.stopHidden === true){
setTimeout(function(){
self._timer.reset();
}, 500);
}else{
self.shuffle(5, function(){
self._timer.reset();
});
}

}, this.settings.auto);
};
Expand Down
4 changes: 2 additions & 2 deletions dist/jquery.slotmachine.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jquery-slotmachine",
"version": "2.0.8",
"version": "2.0.9",
"engines": {
"node": ">= 0.8.0"
},
Expand Down
2 changes: 1 addition & 1 deletion slotmachine.jquery.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"winning",
"machine"
],
"version": "2.0.8",
"version": "2.0.9",
"download": "https://github.com/josex2r/jQuery-SlotMachine",
"homepage": "https://github.com/josex2r/jQuery-SlotMachine",
"demo": "http://josex2r.github.io/jQuery-SlotMachine/",
Expand Down
Loading

0 comments on commit 25296b4

Please sign in to comment.