diff --git a/src/jquery.slotmachine.js b/src/jquery.slotmachine.js
index f163202..81d37a3 100644
--- a/src/jquery.slotmachine.js
+++ b/src/jquery.slotmachine.js
@@ -5,7 +5,7 @@
* Copyright 2014 Jose Luis Represa
* Released under the MIT license
*/
-(function($) {
+;(function($, window, document, undefined){
//Set required styles, filters and masks
@@ -94,7 +94,8 @@
var defaults = {
active : 0, //Active element [int]
delay : 200, //Animation time [int]
- repeat : false //Repeat delay [false||int]
+ repeat : false, //Repeat delay [false||int]
+ randomize : null //Randomize function, must return an integer with the selected position
};
settings = $.extend(defaults, settings); //Plugin settings
@@ -145,21 +146,24 @@
}
/**
- * @desc PRIVATE - Get currently active element
- * @return object elWithIndex - Element index and HTML node
- */
- function _getActive(){
- //Update last choosen element index
- return _active;
- }
-
- /**
- * @desc PRIVATE - Set currently showing element and makes active
- * @param object elWithIndex - Element index and HTML node
- */
- function _setActive( elWithIndex ){
- //Update last choosen element index
- _active = elWithIndex;
+ * @desc PRIVATE - Get the randomize setting function element
+ * @return int - Element index and HTML node
+ */
+ function _getCustom(){
+ var choosen = {};
+ if( settings.randomize!==null && typeof settings.randomize==='function' ){
+ var index = settings.randomize(_active.index);
+ if( index<0 || index>=$titles.length ){
+ index = 0;
+ }
+ choosen = {
+ index : index,
+ el : $titles.get( index )
+ };
+ }else{
+ choosen = _getRandom();
+ }
+ return choosen;
}
/**
@@ -188,6 +192,24 @@
return nextObj;
}
+ /**
+ * @desc PRIVATE - Get currently active element
+ * @return object elWithIndex - Element index and HTML node
+ */
+ function _getActive(){
+ //Update last choosen element index
+ return _active;
+ }
+
+ /**
+ * @desc PRIVATE - Set currently showing element and makes active
+ * @param object elWithIndex - Element index and HTML node
+ */
+ function _setActive( elWithIndex ){
+ //Update last choosen element index
+ _active = elWithIndex;
+ }
+
/**
* @desc PRIVATE - Set CSS classes to make speed effect
* @param string speed - Element speed [fast||medium||slow]
@@ -369,11 +391,14 @@
rnd = getElementFn();
}else{
- if( settings.repeat ){
+ if( settings.randomize!==null && typeof settings.randomize==='function' ){
+ rnd = _getCustom();
+ }else if( settings.repeat ){
rnd = _getNext();
}else{
rnd = _getRandom();
}
+
}
//Stop animation NOW!!!!!!!
@@ -445,7 +470,7 @@
if( _forceStop===false ){
- delay = delay===undefined ? 1 : settings.repeat + 1725;
+ delay = delay===undefined ? 1 : settings.repeat + 1000;
_timer = setTimeout(function(){
@@ -561,4 +586,4 @@
};
-})(jQuery);
+})( jQuery, window, document );
\ No newline at end of file