0
0
mirror of https://github.com/Doodle3D/doodle3d-client.git synced 2024-11-22 01:07:56 +01:00

Implementing enable disable in Button.js

Removing global enableButton and disableButton
This commit is contained in:
peteruithoven 2014-01-30 17:49:15 +01:00
parent 8ec5772f77
commit fcf966b2e3
5 changed files with 45 additions and 45 deletions

View File

@ -1,3 +1,11 @@
/*
* This file is part of the Doodle3D project (http://doodle3d.com).
*
* Copyright (c) 2013, Doodle3D
* This software is licensed under the terms of the GNU GPL v2 or later.
* See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
*/
// prototype inheritance // prototype inheritance
// http://robertnyman.com/2008/10/06/javascript-inheritance-how-and-why/ // http://robertnyman.com/2008/10/06/javascript-inheritance-how-and-why/
Button.prototype = new jQuery; Button.prototype = new jQuery;
@ -71,6 +79,7 @@ function Button() {
// _y = undefined; // _y = undefined;
} }
function onDownTimerInterval() { function onDownTimerInterval() {
if(!_self.enabled) return;
if (_x!=undefined && _y!=undefined) { if (_x!=undefined && _y!=undefined) {
_self.trigger("onButtonHold",{x:_x,y:_y}); _self.trigger("onButtonHold",{x:_x,y:_y});
} else { } else {
@ -83,6 +92,7 @@ function Button() {
stopDownTimer(); stopDownTimer();
}); });
this.on("touchstart", function(e) { this.on("touchstart", function(e) {
if(!_self.enabled) return;
_clickEnabled = false; _clickEnabled = false;
updateCursor(e); updateCursor(e);
startDownTimer(); startDownTimer();
@ -94,10 +104,12 @@ function Button() {
stopDownTimer(); stopDownTimer();
}); });
this.on("touchmove", function(e) { this.on("touchmove", function(e) {
if(!_self.enabled) return;
updateCursor(e); updateCursor(e);
startDownTimer(); startDownTimer();
}); });
this.mousedown(function(e) { this.mousedown(function(e) {
if(!_self.enabled) return;
updateCursor(e); updateCursor(e);
startDownTimer(); startDownTimer();
}); });
@ -106,6 +118,7 @@ function Button() {
stopDownTimer(); stopDownTimer();
}); });
this.mousemove(function(e) { this.mousemove(function(e) {
if(!_self.enabled) return;
updateCursor(e); updateCursor(e);
//if (_isDown) mousedrag(e); //if (_isDown) mousedrag(e);
}); });
@ -116,7 +129,7 @@ function Button() {
e.preventDefault(); e.preventDefault();
}); });
this.click(function(e) { this.click(function(e) {
if(!_clickEnabled) return; if(!_self.enabled || !_clickEnabled) return;
updateCursor(e); updateCursor(e);
stopDownTimer(); stopDownTimer();
_self.trigger("onButtonClick",{x:_x,y:_y}); _self.trigger("onButtonClick",{x:_x,y:_y});

View File

@ -94,7 +94,7 @@ function SettingsWindow() {
settingsPopup.setEnterEnabled(false); settingsPopup.setEnterEnabled(false);
settingsPopup.setAutoCloseEnabled(false); settingsPopup.setAutoCloseEnabled(false);
enableButton(this.btnOK,settingsPopup.commit); this.btnOK.on('touchstart mousedown',settingsPopup.commit);
$("#popupSettings").bind("onPopupCancel", function() { settingsPopup.close(); } ); $("#popupSettings").bind("onPopupCancel", function() { settingsPopup.close(); } );
$("#popupSettings").bind("onPopupCommit", self.submitwindow); $("#popupSettings").bind("onPopupCommit", self.submitwindow);
@ -164,7 +164,7 @@ function SettingsWindow() {
// }; // };
this.submitwindow = function(e) { this.submitwindow = function(e) {
disableButton(self.btnOK,settingsPopup.commit); self.btnOK.attr("disabled",true);
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
self.saveSettings(self.readForm(),function(success){ self.saveSettings(self.readForm(),function(success){
@ -172,7 +172,7 @@ function SettingsWindow() {
settingsPopup.close(); settingsPopup.close();
self.signin(); self.signin();
} }
enableButton(self.btnOK,settingsPopup.commit); self.btnOK.removeAttr("disabled");
}); });
clearTimeout(self.retryRetrieveNetworkStatusDelay); clearTimeout(self.retryRetrieveNetworkStatusDelay);
@ -278,7 +278,6 @@ function SettingsWindow() {
this.resetSettings = function() { this.resetSettings = function() {
console.log("resetSettings"); console.log("resetSettings");
//$("#restoreSettings").addClass("disabled");
self.btnRestoreSettings.attr("disabled", true); self.btnRestoreSettings.attr("disabled", true);
clearTimeout(self.restoredStateHideDelay); clearTimeout(self.restoredStateHideDelay);

View File

@ -63,6 +63,10 @@ function initButtonBehavior() {
btnWordArt.on("onButtonClick", onBtnWordArt); btnWordArt.on("onButtonClick", onBtnWordArt);
btnShape.on("onButtonClick", onBtnShape); btnShape.on("onButtonClick", onBtnShape);
btnPrint.on("onButtonClick", print); btnPrint.on("onButtonClick", print);
btnStop.on("onButtonClick", stopPrint);
btnSave.on("onButtonClick", saveSketch);
btnPrevious.on("onButtonClick", prevDoodle);
btnNext.on("onButtonClick", nextDoodle);
btnOops.on("onButtonHold", onBtnOops); btnOops.on("onButtonHold", onBtnOops);
// vertical shape buttons // vertical shape buttons
btnToggleVerticalShapes.on("onButtonClick", onBtnToggleVerticalShapes); btnToggleVerticalShapes.on("onButtonClick", onBtnToggleVerticalShapes);
@ -179,17 +183,15 @@ function initButtonBehavior() {
buttonGroupAdd.fadeOut(); buttonGroupAdd.fadeOut();
} }
enableButton(btnSettings, openSettingsWindow); btnSettings.on("onButtonClick", openSettingsWindow);
// 29-okt-2013 - we're not doing help for smartphones at the moment // 29-okt-2013 - we're not doing help for smartphones at the moment
if (clientInfo.isSmartphone) { if (clientInfo.isSmartphone) {
btnInfo.addClass("disabled"); btnInfo.disable();
} else { } else {
function onBtnInfo(e) { btnInfo.on("onButtonClick", function(e) {
helpTours.startTour(helpTours.WELCOMETOUR); helpTours.startTour(helpTours.WELCOMETOUR);
} });
enableButton(btnInfo, onBtnInfo);
} }
} }
@ -350,17 +352,17 @@ function setState(newState,newHasControl) {
// print button // print button
var printEnabled = (newState == Printer.IDLE_STATE && newHasControl); var printEnabled = (newState == Printer.IDLE_STATE && newHasControl);
if(printEnabled) { if(printEnabled) {
enableButton(btnPrint,print); btnPrint.enable();
} else { } else {
disableButton(btnPrint); btnPrint.disable();
} }
// stop button // stop button
var stopEnabled = ((newState == Printer.PRINTING_STATE || newState == Printer.BUFFERING_STATE) && newHasControl); var stopEnabled = ((newState == Printer.PRINTING_STATE || newState == Printer.BUFFERING_STATE) && newHasControl);
if(stopEnabled) { if(stopEnabled) {
enableButton(btnStop,stopPrint); btnStop.enable();
} else { } else {
disableButton(btnStop); btnStop.disable();
} }
// thermometer // thermometer
@ -389,29 +391,29 @@ function setState(newState,newHasControl) {
/* settings button */ /* settings button */
switch(newState) { switch(newState) {
case Printer.IDLE_STATE: case Printer.IDLE_STATE:
enableButton(btnSettings, openSettingsWindow); btnSettings.enable();
break; break;
case Printer.WIFIBOX_DISCONNECTED_STATE: /* fall-through */ case Printer.WIFIBOX_DISCONNECTED_STATE: /* fall-through */
case Printer.BUFFERING_STATE: /* fall-through */ case Printer.BUFFERING_STATE: /* fall-through */
case Printer.PRINTING_STATE: /* fall-through */ case Printer.PRINTING_STATE: /* fall-through */
case Printer.STOPPING_STATE: case Printer.STOPPING_STATE:
disableButton(btnSettings); btnSettings.disable();
break; break;
default: default:
enableButton(btnSettings, openSettingsWindow); btnSettings.enable();
break; break;
} }
/* save, next and prev buttons */ /* save, next and prev buttons */
switch(newState) { switch(newState) {
case Printer.WIFIBOX_DISCONNECTED_STATE: case Printer.WIFIBOX_DISCONNECTED_STATE:
disableButton(btnPrevious); btnPrevious.disable();
disableButton(btnNext); btnNext.disable()
disableButton(btnSave); btnSave.disable();
break; break;
default: default:
updatePrevNextButtonState(); updatePrevNextButtonState();
if (isModified) enableButton(btnSave, saveSketch); if (isModified) btnSave.enable();
break; break;
} }

View File

@ -136,19 +136,6 @@ function disableDragging() {
}); });
} }
function enableButton(elem, handler) {
//var elem = $('#'+domId);
elem.removeClass("disabled");
elem.unbind('onButtonClick');
elem.bind('onButtonClick', handler);
}
function disableButton(elem) {
//var elem = $('#'+domId);
elem.addClass("disabled");
elem.unbind('onButtonClick');
}
function showOrHideThermo() { function showOrHideThermo() {
console.log("f:showOrHideThermo()"); console.log("f:showOrHideThermo()");
if (showOrHide) { if (showOrHide) {

View File

@ -35,8 +35,8 @@ function setSketchModified(_isModified, doNotClearCurrent) {
// alert("isModified: " + isModified); // alert("isModified: " + isModified);
//console.log("setModified: " + isModified + (typeof(doNotClearCurrent) !== 'undefined' ? " (doNotClearCurrent: "+doNotClearCurrent+")" : "")); //TEMP //console.log("setModified: " + isModified + (typeof(doNotClearCurrent) !== 'undefined' ? " (doNotClearCurrent: "+doNotClearCurrent+")" : "")); //TEMP
if (isModified) enableButton(btnSave, saveSketch); if (isModified) btnSave.enable();
else disableButton(btnSave); else btnSave.disable();
//if (typeof(doNotClearCurrent) !== 'undefined' && !doNotClearCurrent) setCurrentSketchId(-1); //if (typeof(doNotClearCurrent) !== 'undefined' && !doNotClearCurrent) setCurrentSketchId(-1);
@ -62,26 +62,26 @@ function setCurrentSketchId(sId) {
} }
function updatePrevNextButtonStateOnClear() { function updatePrevNextButtonStateOnClear() {
if (numSavedSketches > 0) enableButton(btnPrevious, prevDoodle); if (numSavedSketches > 0) btnPrevious.enable();
disableButton(btnNext); btnNext.disable();
currentSketchId = numSavedSketches+1; //after the end of the list currentSketchId = numSavedSketches+1; //after the end of the list
disableButton(btnSave); btnSave.disable();
} }
function updatePrevNextButtonState() { function updatePrevNextButtonState() {
//btnPrevious state //btnPrevious state
if (numSavedSketches==0 || currentSketchId < 2) { if (numSavedSketches==0 || currentSketchId < 2) {
disableButton(btnPrevious); btnPrevious.disable();
} else { } else {
enableButton(btnPrevious, prevDoodle); btnPrevious.enable();
} }
//btnNext state //btnNext state
if (numSavedSketches==0 || currentSketchId >= numSavedSketches) { if (numSavedSketches==0 || currentSketchId >= numSavedSketches) {
disableButton(btnNext); btnNext.disable();
} else { } else {
enableButton(btnNext, nextDoodle); btnNext.enable();
} }
} }
@ -109,7 +109,6 @@ function loadSketch(sketchId) {
}); });
} }
//btnSave.mouseup(saveSketch);
function saveSketch() { function saveSketch() {
svg = saveToSvg(); svg = saveToSvg();
console.log("generated SVG [" + _points.length + " points, " + svg.length + " bytes]:\n" + svg); console.log("generated SVG [" + _points.length + " points, " + svg.length + " bytes]:\n" + svg);