From b909c74c5511b9574a7d5d7e11d6d743df59859f Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Mon, 1 Dec 2014 07:56:21 +0900 Subject: attempt to make a proper derived class from FlipClock.Factory. Options don't seem to get passed --- js/main.js | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/js/main.js b/js/main.js index ee03828..e5981dd 100644 --- a/js/main.js +++ b/js/main.js @@ -149,36 +149,34 @@ $.ionSound({ preload: true }); -// function to make a FlipClock with a few additional features. Not -// as neat a constructor as I would like because I don't fully -// understand how jQuery works -function MyFlipClock (jq, obj) +function MyFlipClock (obj, options) { - var thisClock = new FlipClock(jq, obj); - - thisClock.go = $.proxy(function (seconds) { + options.autoStart = false; + FlipClock.Factory.call(this, obj, 0, options); + this.go = function (seconds) { this.setTime(seconds); this.start(); - }, thisClock); - thisClock.reset = $.proxy(function () { - thisClock.stop(); - thisClock.setTime(0); - }, thisClock); - thisClock.custom = $.proxy(function () { + }; + 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')); - thisClock.go(minutes * 60 + seconds); - }, thisClock); - - return thisClock; + this.go(minutes * 60 + seconds); + }; } +MyFlipClock.prototype = new FlipClock.Factory; -var timeWastingClock = MyFlipClock($('.time-wasting-clock'), { - autoStart:false, +var timeWastingClock = new MyFlipClock($('.time-wasting-clock'), { callbacks:{ interval:function () { $.ionSound.play("button_tiny"); - var time = timeWastingClock.getTime().time; + if (timeWastingClock) + var time = timeWastingClock.getTime().time; + else + time = 0; $.jStorage.set("time_wasted", time); } } @@ -217,8 +215,7 @@ timeWastingClock.toggle = $.proxy(function () { } }, timeWastingClock); -var activityClock = MyFlipClock($('.activity-countdown'), { - autoStart:false, +var activityClock = new MyFlipClock($('.activity-countdown'), { countdown:true, callbacks:{ stop:function () { -- cgit v1.2.3