function EZSlots(id, useroptions) {
var that = this; //keep reference to function for use in callbacks
//set some variables from the options, or with defaults.
var options = useroptions ? useroptions : {};
this.reelCount = options.reelCount ? options.reelCount : 3; //how many reels, assume 3
this.symbols = options.symbols ? options.symbols : ['A', 'B', 'C'];
this.sameSymbolsEachSlot = true;
this.startingSet = options.startingSet;
this.winningSet = options.winningSet;
this.width = options.width ? options.width : 200;
this.height = options.width ? options.height : 200;
this.time = options.time ? (options.time * 1000) : 5000; //time in millis for a spin to take
this.howManySymbolsToAppend = Math.round(this.time / 250); //how many symbols each spin adds
this.endingLocation = 7; //location for selected symbol... needs to be a few smaller than howManySymbolsToAppend
this.jqo = $("#" + id); //jquery object reference to main wrapper
this.jqoSliders = []; //jquery object reference to strips sliding up and down
this.callback = options.callback; //callback function to be called once slots animation is finished
//to initialize we construct the correct number of slot windows
//and then populate each strip once
this.init = function () {
this.jqo.addClass("ezslots"); //to get the css goodness
//figure out if we are using the same of symbols for each window - assume if the first
//entry of the symbols is not a string we have an array of arrays
if (typeof this.symbols[0] != 'string') {
this.sameSymbolsEachSlot = false;
}
//make each slot window
for (var i = 0; i < this.reelCount; i++) {
var jqoSlider = $('
');
var jqoSlot = $('');
var jqoWindow = $('');
this.scaleJqo(jqoWindow).append(jqoSlider); //make window right size and put slider in it
this.jqo.append(jqoWindow); //add window to main div
this.jqoSliders.push(jqoSlider); //keep reference to jqo of slider
this.addSymbolsToStrip(jqoSlider, i, false, true); //and add the initial set
}
};
//convenience function since we need to apply width and height to multiple parts
this.scaleJqo = function (jqo) {
const vw = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
const vh = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
// console.log(vw + " x " + vh);
this.height = 126;
this.width = 92;
if (vw < 700 || vh < 700) { //middle
this.height = 90;
this.width = 65;
}
if (vw < 430 || vh < 490) {
this.height = 77;
this.width = 56;
}
jqo.css("height", this.height + "px").css("width", this.width + "px");
return jqo;
}
//add the various symbols - but take care to possibly add the "winner" as the symbol chosen
this.addSymbolsToStrip = function (jqoSlider, whichReel, shouldWin, isInitialCall) {
var symbolsToUse = that.sameSymbolsEachSlot ? that.symbols : that.symbols[whichReel];
var chosen = shouldWin ? that.winningSet[whichReel] : Math.floor(Math.random() * symbolsToUse.length);
for (var i = 0; i < that.howManySymbolsToAppend; i++) {
var ctr = (i == that.endingLocation) ? chosen : Math.floor(Math.random() * symbolsToUse.length);
if (i == 0 && isInitialCall && that.startingSet) {
ctr = that.startingSet[whichReel];
}
//we nest "content" inside of "symbol" so we can do vertical and horizontal centering more easily
var jqoContent = $("" + symbolsToUse[ctr] + "
");
that.scaleJqo(jqoContent);
var jqoSymbol = $("");
that.scaleJqo(jqoSymbol);
jqoSymbol.append(jqoContent);
jqoSlider.append(jqoSymbol);
}
return chosen;
}
//to spin, we add symbols to a strip, and then bounce it down
this.spinOne = function (jqoSlider, whichReel, shouldWin) {
var heightBefore = parseInt(jqoSlider.css("height"), 10);
var chosen = that.addSymbolsToStrip(jqoSlider, whichReel, shouldWin);
// console.log(chosen);
var marginTop = -(heightBefore + ((that.endingLocation) * that.height));
jqoSlider.stop(true, true).animate(
{"margin-top": marginTop + "px"},
{'duration': that.time + Math.round(Math.random() * 1000), 'easing': "easeOutElastic"});
return chosen;
}
this.setWidth = function (width) {
this.options.width = width;
}
this.setHeight = function (height) {
this.options.height = height;
}
this.spinAll = function (shouldWin) {
var results = [];
for (var i = 0; i < that.reelCount; i++) {
results.push(that.spinOne(that.jqoSliders[i], i, shouldWin));
}
if (that.callback) {
setTimeout(function () {
that.callback(results);
}, that.time - 3000);
}
return results;
}
this.init();
return {
spin: function () {
return that.spinAll();
},
win: function () {
return that.spinAll(true);
}
}
}
/*
JQUERY: STOPWATCH & COUNTDOWN
This is a basic stopwatch & countdown plugin to run with jquery. Start timer, pause it, stop it or reset it. Same behaviour with the countdown besides you need to input the countdown value in seconds first. At the end of the countdown a callback function is invoked.
Any questions, suggestions? marc.fuehnen(at)gmail.com
*/
$(window).load(function () {
$('#page-preloader').fadeOut('slow');
});
$(document).ready(function () {
(function ($) {
$.extend({
APP: {
formatTimer: function (a) {
if (a < 10) {
a = '0' + a;
}
return a;
},
startTimer: function (dir) {
var a;
// save type
$.APP.dir = dir;
// get current date
$.APP.d1 = new Date();
switch ($.APP.state) {
case 'pause' :
// resume timer
// get current timestamp (for calculations) and
// substract time difference between pause and now
$.APP.t1 = $.APP.d1.getTime() - $.APP.td;
break;
default :
// get current timestamp (for calculations)
$.APP.t1 = $.APP.d1.getTime();
// if countdown add ms based on seconds in textfield
if ($.APP.dir === 'cd') {
$.APP.t1 += parseInt($('#cd_seconds').val()) * 1000;
}
break;
}
// reset state
$.APP.state = 'alive';
$('#' + $.APP.dir + '_status').html('Running');
// start loop
$.APP.loopTimer();
},
pauseTimer: function () {
// save timestamp of pause
$.APP.dp = new Date();
$.APP.tp = $.APP.dp.getTime();
// save elapsed time (until pause)
$.APP.td = $.APP.tp - $.APP.t1;
// change button value
$('#' + $.APP.dir + '_start').val('Resume');
// set state
$.APP.state = 'pause';
$('#' + $.APP.dir + '_status').html('Paused');
},
stopTimer: function () {
// change button value
$('#' + $.APP.dir + '_start').val('start');
// set state
$.APP.state = 'stop';
$('#' + $.APP.dir + '_status').html('Stopped');
},
resetTimer: function () {
// reset display
$('#' + $.APP.dir + '_ms,#' + $.APP.dir + '_s,#' + $.APP.dir + '_m,#' + $.APP.dir + '_h').html('00');
// change button value
$('#' + $.APP.dir + '_start').val('Start');
// set state
$.APP.state = 'reset';
$('#' + $.APP.dir + '_status').html('Reset & Idle again');
},
endTimer: function (callback) {
// change button value
$('#' + $.APP.dir + '_start').val('start');
// set state
$.APP.state = 'end';
// invoke callback
if (typeof callback === 'function') {
callback();
}
},
loopTimer: function () {
var td;
var d2, t2;
var ms = 0;
var s = 0;
var m = 0;
var h = 0;
if ($.APP.state === 'alive') {
// get current date and convert it into
// timestamp for calculations
d2 = new Date();
t2 = d2.getTime();
// calculate time difference between
// initial and current timestamp
if ($.APP.dir === 'sw') {
td = t2 - $.APP.t1;
// reversed if countdown
} else {
td = $.APP.t1 - t2;
if (td <= 0) {
// if time difference is 0 end countdown
$.APP.endTimer(function () {
$.APP.resetTimer();
$('#' + $.APP.dir + '_status').html('Ended & Reset');
});
}
}
// calculate milliseconds
ms = td % 1000;
if (ms < 1) {
ms = 0;
} else {
// calculate seconds
s = (td - ms) / 1000;
if (s < 1) {
s = 0;
} else {
// calculate minutes
var m = (s - (s % 60)) / 60;
if (m < 1) {
m = 0;
} else {
// calculate hours
var h = (m - (m % 60)) / 60;
if (h < 1) {
h = 0;
}
}
}
}
// substract elapsed minutes & hours
ms = Math.round(ms / 100);
s = s - (m * 60);
m = m - (h * 60);
// update display
$('#' + $.APP.dir + '_ms').html($.APP.formatTimer(ms));
$('#' + $.APP.dir + '_s').html($.APP.formatTimer(s));
$('#' + $.APP.dir + '_m').html($.APP.formatTimer(m));
$('#' + $.APP.dir + '_h').html($.APP.formatTimer(h));
// loop
$.APP.t = setTimeout($.APP.loopTimer, 1);
} else {
// kill loop
clearTimeout($.APP.t);
return true;
}
}
}
});
$('#sw_start').click(function () {
$.APP.startTimer('sw');
$(".time").addClass("running");
});
$('#cd_start').click(function () {
$.APP.startTimer('cd');
$(".time").addClass("running");
});
$('#sw_stop,#cd_stop').click(function () {
$.APP.stopTimer();
$(".time").removeClass("running");
});
$('#sw_reset,#cd_reset').click(function () {
$.APP.resetTimer();
$(".time").removeClass("running");
});
$('#sw_pause,#cd_pause').click(function () {
$.APP.pauseTimer();
});
$("#page-preloader").click(function () {
$(this).hide();
});
})(jQuery);
})
;