From 151879cdffe393eb7bfce9737a4b4bc912a0d31f Mon Sep 17 00:00:00 2001 From: Szymon Nowak Date: Thu, 10 Feb 2011 22:00:01 +0100 Subject: [PATCH] Fixed missing semicolons and implied globals. --- controllers/controller.boolean.js | 2 +- controllers/controller.function.js | 2 +- controllers/controller.js | 19 ++++--- controllers/controller.number.js | 17 +++--- controllers/controller.string.js | 2 +- controllers/slider.js | 14 ++--- gui.js | 88 +++++++++++------------------- 7 files changed, 58 insertions(+), 86 deletions(-) diff --git a/controllers/controller.boolean.js b/controllers/controller.boolean.js index 839564b..2cb68b3 100644 --- a/controllers/controller.boolean.js +++ b/controllers/controller.boolean.js @@ -33,7 +33,7 @@ GUI.BooleanController = function() { } catch (e) {} } return GUI.Controller.prototype.setValue.call(this, val); - } + }; }; GUI.extendController(GUI.BooleanController); diff --git a/controllers/controller.function.js b/controllers/controller.function.js index 63690fa..586c17f 100644 --- a/controllers/controller.function.js +++ b/controllers/controller.function.js @@ -17,7 +17,7 @@ GUI.FunctionController = function() { this.onFire = function(fnc) { fireFunction = fnc; return this; - } + }; this.fire = function() { if (fireFunction != null) { diff --git a/controllers/controller.js b/controllers/controller.js index 6a2916a..c054fa0 100644 --- a/controllers/controller.js +++ b/controllers/controller.js @@ -34,12 +34,12 @@ GUI.Controller.prototype.reset = function() { GUI.Controller.prototype.listen = function() { this.parent.listenTo(this); return this; -} +}; GUI.Controller.prototype.unlisten = function() { this.parent.unlistenTo(this); // <--- hasn't been tested yet return this; -} +}; GUI.Controller.prototype.setValue = function(n) { this.object[this.propertyName] = n; @@ -48,22 +48,23 @@ GUI.Controller.prototype.setValue = function(n) { } this.updateDisplay(); return this; -} +}; GUI.Controller.prototype.getValue = function() { return this.object[this.propertyName]; -} +}; -GUI.Controller.prototype.updateDisplay = function() {} +GUI.Controller.prototype.updateDisplay = function() {}; GUI.Controller.prototype.onChange = function(fnc) { this.changeFunction = fnc; return this; -} +}; + GUI.Controller.prototype.onFinishChange = function(fnc) { this.finishChangeFunction = fnc; return this; -} +}; GUI.Controller.prototype.options = function() { var _this = this; @@ -90,7 +91,7 @@ GUI.Controller.prototype.options = function() { if (_this.finishChangeFunction != null) { _this.finishChangeFunction.call(this, _this.getValue()); } - }); + }, false); _this.domElement.appendChild(select); return this; -} +}; diff --git a/controllers/controller.number.js b/controllers/controller.number.js index 8ffb01f..eae0a2b 100644 --- a/controllers/controller.number.js +++ b/controllers/controller.number.js @@ -12,7 +12,7 @@ GUI.NumberController = function() { var clickedNumberField = false; - var y = py = 0; + var y = 0, py = 0; var min = arguments[3]; var max = arguments[4]; @@ -65,13 +65,14 @@ GUI.NumberController = function() { // Handle up arrow and down arrow numberField.addEventListener('keydown', function(e) { + var newVal; switch(e.keyCode) { case 38: // up - var newVal = _this.getValue() + step; + newVal = _this.getValue() + step; _this.setValue(newVal); break; case 40: // down - var newVal = _this.getValue() - step; + newVal = _this.getValue() - step; _this.setValue(newVal); break; } @@ -91,9 +92,7 @@ GUI.NumberController = function() { _this.finishChangeFunction.call(this, _this.getValue()); } document.removeEventListener('mouseup', mouseup, false); - } - - + }; var dragNumberField = function(e) { draggedNumberField = true; @@ -112,7 +111,7 @@ GUI.NumberController = function() { var newVal = _this.getValue() + dy*step; _this.setValue(newVal); return false; - } + }; this.options = function() { _this.noSlider(); @@ -139,12 +138,12 @@ GUI.NumberController = function() { return GUI.Controller.prototype.setValue.call(this, val); - } + }; this.updateDisplay = function() { numberField.value = GUI.roundToDecimal(_this.getValue(), 4); if (slider) slider.value = _this.getValue(); - } + }; }; GUI.extendController(GUI.NumberController); diff --git a/controllers/controller.string.js b/controllers/controller.string.js index bceb44c..1b6fa45 100644 --- a/controllers/controller.string.js +++ b/controllers/controller.string.js @@ -33,7 +33,7 @@ GUI.StringController = function() { this.updateDisplay = function() { input.value = _this.getValue(); - } + }; this.options = function() { _this.domElement.removeChild(input); diff --git a/controllers/slider.js b/controllers/slider.js index fc7c989..83841eb 100644 --- a/controllers/slider.js +++ b/controllers/slider.js @@ -1,9 +1,5 @@ GUI.Slider = function(numberController, min, max, step, initValue) { - var min = min; - var max = max; - var step = step; - var clicked = false; var _this = this; @@ -18,15 +14,15 @@ GUI.Slider = function(numberController, min, max, step, initValue) { this.domElement.appendChild(this.fg); var findPos = function(obj) { - var curleft = curtop = 0; + var curleft = 0, curtop = 0; if (obj.offsetParent) { do { curleft += obj.offsetLeft; curtop += obj.offsetTop; - } while (obj = obj.offsetParent); + } while ((obj = obj.offsetParent)); return [curleft,curtop]; } - } + }; this.__defineSetter__('value', function(e) { var pct = GUI.map(e, min, max, 0, 100); @@ -39,7 +35,7 @@ GUI.Slider = function(numberController, min, max, step, initValue) { var val = GUI.map(e.pageX, pos[0], pos[0] + _this.domElement.offsetWidth, min, max); val = Math.round(val/step)*step; numberController.setValue(val); - } + }; this.domElement.addEventListener('mousedown', function(e) { clicked = true; @@ -66,4 +62,4 @@ GUI.Slider = function(numberController, min, max, step, initValue) { this.value = initValue; -} +}; diff --git a/gui.js b/gui.js index 884ff53..7eeeef6 100644 --- a/gui.js +++ b/gui.js @@ -17,8 +17,6 @@ var GUI = function() { var curControllerContainerHeight = 0; - var _this = this; - var open = false; var width = 280; @@ -68,9 +66,10 @@ var GUI = function() { toggleButton.setAttribute('href', '#'); toggleButton.innerHTML = "Show Controls"; - var toggleDragged = false; - var dragDisplacementY = 0; - var togglePressed = false; + var toggleDragged = false, + dragDisplacementX = 0, + dragDisplacementY = 0, + togglePressed = false; var my, pmy, mx, pmx; @@ -177,12 +176,8 @@ var GUI = function() { beginResize(); } } - - - } - document.removeEventListener('mousemove', resize, false); e.preventDefault(); toggleDragged = false; @@ -211,7 +206,7 @@ var GUI = function() { listenInterval = setInterval(function() { _this.listen(); }, this.autoListenIntervalTime); - } + }; this.__defineSetter__("autoListen", function(v) { autoListen = v; @@ -253,7 +248,7 @@ var GUI = function() { this.listenAll = function() { this.listen(controllers); - } + }; this.autoListen = true; @@ -340,7 +335,7 @@ var GUI = function() { return controllerObject; - } + }; var checkForOverflow = function() { controllerHeight = 0; @@ -352,7 +347,7 @@ var GUI = function() { } else { controllerContainer.style.overflowY = "hidden"; } - } + }; var handlerTypes = { "number": GUI.NumberController, @@ -361,27 +356,9 @@ var GUI = function() { "function": GUI.FunctionController }; - var alreadyControlled = function(object, propertyName) { - for (var i in controllers) { - if (controllers[i].object == object && - controllers[i].propertyName == propertyName) { - return true; - } - } - return false; - }; - - var construct = function(constructor, args) { - function F() { - return constructor.apply(this, args); - } - F.prototype = constructor.prototype; - return new F(); - }; - this.reset = function() { // TODO - } + }; // GUI ... GUI @@ -395,7 +372,7 @@ var GUI = function() { clearTimeout(resizeTimeout); beginResize(); open = true; - } + }; this.hide = function() { toggleButton.innerHTML = name || "Show Controls"; @@ -403,17 +380,17 @@ var GUI = function() { clearTimeout(resizeTimeout); beginResize(); open = false; - } + }; this.name = function(n) { name = n; toggleButton.innerHTML = n; - } + }; // used in saveURL this.appearanceVars = function() { - return [open, width, openHeight, controllerContainer.scrollTop] - } + return [open, width, openHeight, controllerContainer.scrollTop]; + }; var beginResize = function() { //console.log("Resizing from " + curControllerContainerHeight + " to " + resizeTo); @@ -425,7 +402,7 @@ var GUI = function() { } controllerContainer.style.height = Math.round(curControllerContainerHeight)+'px'; checkForOverflow(); - } + }; // Load saved appearance: @@ -439,7 +416,7 @@ var GUI = function() { explicitOpenHeight = true; if (eval(GUI.savedAppearanceVars[GUI.guiIndex][0]) == true) { curControllerContainerHeight = openHeight; - var t = GUI.savedAppearanceVars[GUI.guiIndex][3] + var t = GUI.savedAppearanceVars[GUI.guiIndex][3]; // Hack. setTimeout(function() { @@ -468,8 +445,7 @@ GUI.allControllers = []; GUI.allGuis = []; GUI.saveURL = function() { - title = window.location; - url = GUI.replaceGetVar("saveString", GUI.getSaveString()); + var url = GUI.replaceGetVar("saveString", GUI.getSaveString()); window.location = url; }; @@ -495,20 +471,21 @@ GUI.savedAppearanceVars = []; GUI.getSaveString = function() { - var vals = []; + var vals = [], + i; vals.push(GUI.allGuis.length); vals.push(document.body.scrollTop); - for (var i in GUI.allGuis) { + for (i in GUI.allGuis) { var av = GUI.allGuis[i].appearanceVars(); for (var j = 0; j < av.length; j++) { vals.push(av[j]); } } - for (var i in GUI.allControllers) { + for (i in GUI.allControllers) { // We don't save values for functions. if (GUI.allControllers[i].type == "function") { @@ -528,7 +505,7 @@ GUI.getSaveString = function() { return vals.join(','); -} +}; GUI.getVarFromURL = function(v) { @@ -536,7 +513,7 @@ GUI.getVarFromURL = function(v) { var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); for (var i = 0; i < hashes.length; i++) { - hash = hashes[i].split("=") + hash = hashes[i].split("="); if (hash == undefined) continue; if (hash[0] == v) { return hash[1]; @@ -554,7 +531,7 @@ GUI.replaceGetVar = function(varName, val) { var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); for (var i = 0; i < hashes.length; i++) { - hash = hashes[i].split("=") + hash = hashes[i].split("="); if (hash == undefined) continue; if (hash[0] == varName) { return loc.replace(hash[1], val); @@ -574,7 +551,7 @@ GUI.guiIndex = 0; GUI.showSaveString = function() { alert(GUI.getSaveString()); -} +}; // Util functions @@ -583,25 +560,24 @@ GUI.makeUnselectable = function(elem) { elem.style.MozUserSelect = "none"; elem.style.KhtmlUserSelect = "none"; elem.unselectable = "on"; -} +}; GUI.makeSelectable = function(elem) { elem.onselectstart = function() { }; elem.style.MozUserSelect = "auto"; elem.style.KhtmlUserSelect = "auto"; elem.unselectable = "off"; -} +}; GUI.map = function(v, i1, i2, o1, o2) { - var v = o1 + (o2 - o1) * ((v - i1) / (i2 - i1)); - return v; -} + return o1 + (o2 - o1) * ((v - i1) / (i2 - i1)); +}; GUI.constrain = function (v, o1, o2) { if (v < o1) v = o1; else if (v > o2) v = o2; return v; -} +}; GUI.error = function(str) { if (typeof console.error == 'function') { @@ -612,11 +588,11 @@ GUI.error = function(str) { GUI.roundToDecimal = function(n, decimals) { var t = Math.pow(10, decimals); return Math.round(n*t)/t; -} +}; GUI.extendController = function(clazz) { clazz.prototype = new GUI.Controller(); clazz.prototype.constructor = clazz; -} +}; if (GUI.getVarFromURL('saveString') != null) GUI.load(GUI.getVarFromURL('saveString'));