diff --git a/js/Button.js b/js/Button.js index 9c161b7..70c2914 100644 --- a/js/Button.js +++ b/js/Button.js @@ -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}); diff --git a/js/SettingsWindow.js b/js/SettingsWindow.js index 4214c09..013dc8d 100644 --- a/js/SettingsWindow.js +++ b/js/SettingsWindow.js @@ -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); diff --git a/js/buttonbehaviors.js b/js/buttonbehaviors.js index 511d955..9aa875f 100644 --- a/js/buttonbehaviors.js +++ b/js/buttonbehaviors.js @@ -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; } diff --git a/js/main.js b/js/main.js index 757a3da..9051cd1 100644 --- a/js/main.js +++ b/js/main.js @@ -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) { diff --git a/js/sketches.js b/js/sketches.js index 38cdcfe..f8944f4 100644 --- a/js/sketches.js +++ b/js/sketches.js @@ -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);