Commits

Stefan Scherfke committed a262f6f

Fixed //<<issue 6>> (lets see if bitbucket parses this :))

Comments (0)

Files changed (3)

Tea Timer.wdgt/Info.plist

 	<key>CFBundleName</key>
 	<string>Tea Timer</string>
 	<key>CFBundleVersion</key>
-	<string>1.7</string>
+	<string>1.7.1-RC1</string>
 	<key>MainHTML</key>
 	<string>TeaTimer.html</string>
 	<key>CloseBoxInsetX</key>

Tea Timer.wdgt/Scripts/Front.js

         })
     );
     for (i in buttons) {
+        // Remember to add "i = parseInt(i);" if you’re ever going to add some
+        // calculations with "i"!! :-X
+        
         button = buttons[i];
         $(button[0]).click(button[1]);
         $(button[0]).bind(mouse_events, {button: button[0]}, this.toggleButton);
     }
 
-	elems = Array(
-		'timerTarget', 
-		'readyIn', 
-		'hours', 
-		'minutes', 
-		'seconds'
+	fields = Array(
+		'#timerTarget', 
+		'#readyIn', 
+		'#hours', 
+		'#minutes', 
+		'#seconds'
 	);
-	l = elems.length;
-	for (i in elems) {
-		i = parseInt(i);
-		val = elems[i];
-		$('#' + val).bind('click', {editor: val + 'Input'}, this.showEdit);
-		$('#' + val + 'Input').bind('blur keypress', {display: val}, 
-			this.setText);
-		$('#' + val + 'Input').bind('keypress', 
-			{pre: elems[(i+l-1) % l], nxt: elems[(i+1) % l]}, this.cycleInputs);
-		if (i > 0)
-			$('#' + val + 'Input').keypress(this.raiseOrLowerValue);
+	len = fields.length;
+	for (var i in fields) {
+        // If I don’t do parseInt(i), the expressions "(i + len - 1) % len" 
+        // and "(i + 1) % len" won’t be evaluated each iteration, but be
+        // cached instead. :-X
+        i = parseInt(i);
+        
+	    field = fields[i];
+	    input = field + 'Input';
+        
+	    $(field).bind('click', {editor: input}, this.showEdit);
+		$(input).bind('blur keypress', {display: field}, this.setText);
+		$(input).bind('keypress', {
+		    pre: fields[(i + len - 1) % len], // i - 1 would not always be > 0!
+		    next: fields[(i + 1) % len]}, this.cycleInputs);
+		    
+		if (i > 1)
+			$(input).keypress(this.raiseOrLowerValue);
 	}
 };
 
     front.toggleVisibility('#stop', '#icon');
 };
 
-
 /**
  * Hide one element and show the other.
  *
     $(hide).css('visibility', 'hidden');
     $(show).css('visibility', 'visible');
 };
-
 	
 /**
  * Handles the onMouseDown and onMouseUp events for buttons.
  * @param event: The js event.
  */
 Front.prototype.showEdit = function(event) {
+    // Stop the timer if it is running
 	if (timer.timerInterval)
-		$('#start').click();
+		$('#pause').click();
+		
 	var display = $(event.target);
-	var editor = $('#' + event.data.editor);
+	var editor = $(event.data.editor);
+	
 	editor.attr('value', display.text());
 	editor.css('visibility', 'visible');
 	display.css('visiblity', 'hidden');
 	editor.get(0).focus();
+	
 	if (display.attr('id') != 'readyIn')
 		editor.get(0).select();
 };
 Front.prototype.setText = function(event) {
 	if (event.type == 'keypress' && event.keyCode != 13)
 		return;
+		
 	var editor = $(event.target);
-	var display = $('#' + event.data.display);
+	var display = $(event.data.display);
+	
 	if (editor.css('visibility') == 'visible') {
 		if (timer.timerInterval)
 			clearInterval(timerInterval);
+			
 		if (editor.val().length < 1) {
 			if (editor.attr('id') == 'timerTargetInput')
 				editor.val(getLocalizedString('Something'));
 			else
 				editor.val('00');
 		}
-		if (display.attr('id') == 'timerTarget' || display.attr('id') == 'readyIn')
+		
+		if (display.attr('id') == 'timerTarget' || 
+		        display.attr('id') == 'readyIn')
 			display.text(editor.val());
-		else
-			display.text(front.formatTwoDigits(editor.val()));
+		else {
+		    var val = Math.min(Math.max(editor.val(), 0), 59);
+		    display.text(front.formatTwoDigits(val));
+		}
+			
+			
 		if (display.attr('id') == 'timerTarget' && window.widget)
 			setPrefForKey(editor.val(), widget.identifier, 'timerTarget');
 		if (display.attr('id') == 'readyIn' && window.widget)
 			setPrefForKey(editor.val(), widget.identifier, 'minutes');
 		if (display.attr('id') == 'seconds' && window.widget)
 			setPrefForKey(editor.val(), widget.identifier, 'seconds');
+			
+		timer.isPaused = false; // Timer will read the inputs again.
+			
 		display.css('visibility', 'visible');
 		editor.css('visibility', 'hidden');
 	}
 		return;
 	event.preventDefault();
 	if (event.shiftKey)
-		$('#' + event.data.pre).click();
+		$(event.data.pre).click();
 	else
-		$('#' + event.data.nxt).click()
+		$(event.data.next).click();
 	$(event.target).blur();
 };
 

Tea Timer.wdgt/Scripts/Timer.js

 function Timer() {
 	this._targetTime = null;
 	this._isTargetReached = false;
-	this._isPaused = false;
+	this.isPaused = false;
 	this.hours = -1;
 	this.minutes = -1;
 	this.seconds = -1;
 Timer.prototype.run = function() {
     var h, m, s;
     
-    if (!timer._isPaused) {
+    if (!timer.isPaused) {
 		timer.hours = $('#hours').text()
 		timer.minutes = $('#minutes').text()
 		timer.seconds = $('#seconds').text()
 		s = parseInt(timer.seconds, 10);  
     }
     else {
-        timer._isPaused = false;
+        timer.isPaused = false;
         h = timer.remainingHours;
         m = timer.remainingMinutes;
         s = timer.remainingSeconds;
 Timer.prototype.pause = function() {
 	clearInterval(timer.timerInterval);
 	timer.timerInterval = null;
-	timer._isPaused = true
+	timer.isPaused = true
 };
 
 /**
 	clearInterval(timer.timerInterval);
 	timer.timerInterval = null;
 	timer._isTargetReached = false;
-	timer._isPaused = false;
+	timer.isPaused = false;
 	front.resetDisplayTo(timer.hours, timer.minutes, timer.seconds);
 };
 
 		clearInterval(timer.timerInterval);
 		timer.timerInterval = null;
 		timer._isTargetReached = true;
-		timer._isPaused = false;
+		timer.isPaused = false;
 		front.resetDisplayTo(timer.hours, timer.minutes, timer.seconds);
 		if (alarm.keepAlarming)
 			front.showStopAlarmButton();