0
0
mirror of https://github.com/Doodle3D/doodle3d-client.git synced 2024-12-22 13:13:48 +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
// http://robertnyman.com/2008/10/06/javascript-inheritance-how-and-why/
Button.prototype = new jQuery;
@ -71,6 +79,7 @@ function Button() {
// _y = undefined;
}
function onDownTimerInterval() {
if(!_self.enabled) return;
if (_x!=undefined && _y!=undefined) {
_self.trigger("onButtonHold",{x:_x,y:_y});
} else {
@ -83,6 +92,7 @@ function Button() {
stopDownTimer();
});
this.on("touchstart", function(e) {
if(!_self.enabled) return;
_clickEnabled = false;
updateCursor(e);
startDownTimer();
@ -94,10 +104,12 @@ function Button() {
stopDownTimer();
});
this.on("touchmove", function(e) {
if(!_self.enabled) return;
updateCursor(e);
startDownTimer();
});
this.mousedown(function(e) {
if(!_self.enabled) return;
updateCursor(e);
startDownTimer();
});
@ -106,6 +118,7 @@ function Button() {
stopDownTimer();
});
this.mousemove(function(e) {
if(!_self.enabled) return;
updateCursor(e);
//if (_isDown) mousedrag(e);
});
@ -116,7 +129,7 @@ function Button() {
e.preventDefault();
});
this.click(function(e) {
if(!_clickEnabled) return;
if(!_self.enabled || !_clickEnabled) return;
updateCursor(e);
stopDownTimer();
_self.trigger("onButtonClick",{x:_x,y:_y});

View File

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

View File

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

View File

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