Skip to content

Commit 81c84ee

Browse files
committed
Fixed #2
Added setRandomize function to the machines objects. This function accepts a function or and integer as argument ;)
1 parent 96cdab2 commit 81c84ee

File tree

7 files changed

+57
-10
lines changed

7 files changed

+57
-10
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ Check if the machine is running:
4646
machine.isRunning(); //Returns boolean
4747
```
4848

49+
Change spin result, if the returned value is out of bounds, the element will be randomly choosen:
50+
51+
```javascript
52+
machine.setRandomize(foo); //foo must be a function (should return int) or an int
53+
```
54+
4955
## Params
5056

5157
Params must be an object, optionally containing the next parammeters:

dist/jquery.slotmachine.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! SlotMachine - v2.0.1 - 2014-07-09
1+
/*! SlotMachine - v2.0.1 - 2014-07-31
22
* https://github.com/josex2r/jQuery-SlotMachine
33
* Copyright (c) 2014 Jose Luis Represa; Licensed MIT */
44
;(function($, window, document, undefined){
@@ -156,6 +156,21 @@
156156
};
157157
}
158158

159+
/**
160+
* @desc PUBLIC - Changes randomize function
161+
* @param function|int - Set new randomize function
162+
*/
163+
function _setRandomize(rnd){
164+
if( typeof rnd==='number' ){
165+
var _fn = function(){
166+
return rnd;
167+
};
168+
self.settings.randomize = _fn;
169+
}else{
170+
self.settings.randomize = rnd;
171+
}
172+
}
173+
159174
/**
160175
* @desc PRIVATE - Get random element based on the custom randomize function
161176
* @return object - Element index and HTML node
@@ -539,7 +554,13 @@
539554
*/
540555
isRunning : function(){
541556
return _isRunning;
542-
}
557+
},
558+
559+
/**
560+
* @desc PUBLIC - Changes randomize function
561+
* @param function|int - Set new randomize function
562+
*/
563+
setRandomize : _setRandomize
543564
};
544565
}
545566

dist/jquery.slotmachine.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<link rel="stylesheet" href="css/reset.css" type="text/css" media="screen" />
1010
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" />
1111

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

1515
</head>
@@ -181,10 +181,9 @@
181181
$(document).ready(function(){
182182

183183
//Fake machine 1
184-
var machine1 = $("#machineFake1").slotMachine({
184+
window.machine1 = $("#machineFake1").slotMachine({
185185
active: 1,
186186
randomize : function(activeElementIndex){
187-
//This slot machine always shows the element in position '1'
188187
return 1;
189188
}
190189
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jquery-slotmachine",
3-
"version": "2.0.1-ignored",
3+
"version": "2.0.2-ignored",
44
"engines": {
55
"node": ">= 0.8.0"
66
},

slotmachine.jquery.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"winning",
1212
"machine"
1313
],
14-
"version": "2.0.1",
14+
"version": "2.0.2",
1515
"download": "https://github.com/josex2r/jQuery-SlotMachine",
1616
"homepage": "https://github.com/josex2r/jQuery-SlotMachine",
1717
"demo": "http://josex2r.github.io/jQuery-SlotMachine/",

src/jquery.slotmachine.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,21 @@
160160
};
161161
}
162162

163+
/**
164+
* @desc PUBLIC - Changes randomize function
165+
* @param function|int - Set new randomize function
166+
*/
167+
function _setRandomize(rnd){
168+
if( typeof rnd==='number' ){
169+
var _fn = function(){
170+
return rnd;
171+
};
172+
self.settings.randomize = _fn;
173+
}else{
174+
self.settings.randomize = rnd;
175+
}
176+
}
177+
163178
/**
164179
* @desc PRIVATE - Get random element based on the custom randomize function
165180
* @return object - Element index and HTML node
@@ -543,7 +558,13 @@
543558
*/
544559
isRunning : function(){
545560
return _isRunning;
546-
}
561+
},
562+
563+
/**
564+
* @desc PUBLIC - Changes randomize function
565+
* @param function|int - Set new randomize function
566+
*/
567+
setRandomize : _setRandomize
547568
};
548569
}
549570

0 commit comments

Comments
 (0)