summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2014-12-01 08:56:58 +0900
committerSean Whitton <spwhitton@spwhitton.name>2014-12-01 09:51:44 +0900
commit8853df582333d0838bfe822b2d59dc810569fc00 (patch)
treed6acc9607a442a9f5e236236d3b48aa77c00444a
parentb909c74c5511b9574a7d5d7e11d6d743df59859f (diff)
downloadschoolclock-devel.tar.gz
attempt to make MyFlipClock a jQuery plugindevel
-rw-r--r--js/main.js54
1 files changed, 29 insertions, 25 deletions
diff --git a/js/main.js b/js/main.js
index e5981dd..e1f3433 100644
--- a/js/main.js
+++ b/js/main.js
@@ -149,40 +149,43 @@ $.ionSound({
preload: true
});
-function MyFlipClock (obj, options)
-{
- options.autoStart = false;
- FlipClock.Factory.call(this, obj, 0, options);
- this.go = function (seconds) {
- this.setTime(seconds);
- this.start();
- };
- this.reset = function () {
- this.stop();
- this.setTime(0);
- };
- this.custom = function () {
- var minutes = parseInt(prompt('Number of minutes', '0'));
- var seconds = parseInt(prompt('Number of seconds', '0'));
- this.go(minutes * 60 + seconds);
+(function ($) {
+ MyFlipClock = function(obj, digit, options) {
+ if(digit instanceof Object && digit instanceof Date === false) {
+ options = digit;
+ digit = 0;
+ }
+ return new MyFlipClock.Factory(obj, digit, options);
};
-}
-MyFlipClock.prototype = new FlipClock.Factory;
+ MyFlipClock.Factory = FlipClock.Factory.extend({
+ autoStart:false,
+ go:function (seconds) {
+ this.setTime(seconds);
+ this.start();
+ },
+ reset:function () {
+ this.stop();
+ this.setTime(0);
+ },
+ custom:function () {
+ var minutes = parseInt(prompt('Number of minutes', '0'));
+ var seconds = parseInt(prompt('Number of seconds', '0'));
+ this.go(minutes * 60 + seconds);
+ }
+ });
+}(jQuery));
-var timeWastingClock = new MyFlipClock($('.time-wasting-clock'), {
+var timeWastingClock = new MyFlipClock($('.time-wasting-clock'),{
callbacks:{
interval:function () {
$.ionSound.play("button_tiny");
- if (timeWastingClock)
- var time = timeWastingClock.getTime().time;
- else
- time = 0;
+ var time = timeWastingClock.getTime().time;
$.jStorage.set("time_wasted", time);
}
}
});
-timeWastingClock.setTime($.jStorage.get("time_wasted", 0));
+timeWastingClock.setTime($.jStorage.get("time_wasted", 0));
timeWastingClock.running = false;
timeWastingClock.reset = $.proxy(function () {
if (this.getTime() != 1)
@@ -192,7 +195,7 @@ timeWastingClock.reset = $.proxy(function () {
if (this.running)
{
$('#timeWastingClockGo').html('Start <u>t</u>imer');
- this.stop();
+ timeWastingClock.stop();
this.running = false;
}
$.jStorage.set('time_wasted', 0);
@@ -223,6 +226,7 @@ var activityClock = new MyFlipClock($('.activity-countdown'), {
}
}
});
+activityClock.countdown = true;
$(document).bind('keydown', 't', timeWastingClock.toggle);
$(document).bind('keydown', 'j', timeWastingClock.toggle);