Skip to content

Commit

Permalink
Fixed #2
Browse files Browse the repository at this point in the history
Added setRandomize function to the machines objects. This function accepts a function or and integer as argument ;)
  • Loading branch information
josex2r committed Jul 31, 2014
1 parent 96cdab2 commit 81c84ee
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 10 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ Check if the machine is running:
machine.isRunning(); //Returns boolean
```

Change spin result, if the returned value is out of bounds, the element will be randomly choosen:

```javascript
machine.setRandomize(foo); //foo must be a function (should return int) or an int
```

## Params

Params must be an object, optionally containing the next parammeters:
Expand Down
25 changes: 23 additions & 2 deletions dist/jquery.slotmachine.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! SlotMachine - v2.0.1 - 2014-07-09
/*! SlotMachine - v2.0.1 - 2014-07-31
* https://github.com/josex2r/jQuery-SlotMachine
* Copyright (c) 2014 Jose Luis Represa; Licensed MIT */
;(function($, window, document, undefined){
Expand Down Expand Up @@ -156,6 +156,21 @@
};
}

/**
* @desc PUBLIC - Changes randomize function
* @param function|int - Set new randomize function
*/
function _setRandomize(rnd){
if( typeof rnd==='number' ){
var _fn = function(){
return rnd;
};
self.settings.randomize = _fn;
}else{
self.settings.randomize = rnd;
}
}

/**
* @desc PRIVATE - Get random element based on the custom randomize function
* @return object - Element index and HTML node
Expand Down Expand Up @@ -539,7 +554,13 @@
*/
isRunning : function(){
return _isRunning;
}
},

/**
* @desc PUBLIC - Changes randomize function
* @param function|int - Set new randomize function
*/
setRandomize : _setRandomize
};
}

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.

5 changes: 2 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<link rel="stylesheet" href="css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" />

<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="//code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="dist/jquery.slotmachine.min.js"></script>

</head>
Expand Down Expand Up @@ -181,10 +181,9 @@
$(document).ready(function(){

//Fake machine 1
var machine1 = $("#machineFake1").slotMachine({
window.machine1 = $("#machineFake1").slotMachine({
active: 1,
randomize : function(activeElementIndex){
//This slot machine always shows the element in position '1'
return 1;
}
});
Expand Down
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.1-ignored",
"version": "2.0.2-ignored",
"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.1",
"version": "2.0.2",
"download": "https://github.com/josex2r/jQuery-SlotMachine",
"homepage": "https://github.com/josex2r/jQuery-SlotMachine",
"demo": "http://josex2r.github.io/jQuery-SlotMachine/",
Expand Down
23 changes: 22 additions & 1 deletion src/jquery.slotmachine.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,21 @@
};
}

/**
* @desc PUBLIC - Changes randomize function
* @param function|int - Set new randomize function
*/
function _setRandomize(rnd){
if( typeof rnd==='number' ){
var _fn = function(){
return rnd;
};
self.settings.randomize = _fn;
}else{
self.settings.randomize = rnd;
}
}

/**
* @desc PRIVATE - Get random element based on the custom randomize function
* @return object - Element index and HTML node
Expand Down Expand Up @@ -543,7 +558,13 @@
*/
isRunning : function(){
return _isRunning;
}
},

/**
* @desc PUBLIC - Changes randomize function
* @param function|int - Set new randomize function
*/
setRandomize : _setRandomize
};
}

Expand Down

0 comments on commit 81c84ee

Please sign in to comment.