From 38e7d9b0297a62e57bb381777d3da307b75c2ae4 Mon Sep 17 00:00:00 2001 From: George Michael Brower Date: Mon, 18 Apr 2011 13:51:15 -0700 Subject: [PATCH] moved src into internal dat folder --- index.html | 17 ++-- src/{ => dat}/controllers/boolean.js | 0 src/{ => dat}/controllers/controller.js | 0 src/{ => dat}/controllers/function.js | 0 src/{ => dat}/controllers/number.js | 17 ++-- src/{ => dat}/controllers/slider.js | 0 src/{ => dat}/controllers/string.js | 0 src/{ => dat}/gui.css | 0 src/{ => dat}/gui.js | 120 ++++++++++++++---------- 9 files changed, 93 insertions(+), 61 deletions(-) rename src/{ => dat}/controllers/boolean.js (100%) rename src/{ => dat}/controllers/controller.js (100%) rename src/{ => dat}/controllers/function.js (100%) rename src/{ => dat}/controllers/number.js (92%) rename src/{ => dat}/controllers/slider.js (100%) rename src/{ => dat}/controllers/string.js (100%) rename src/{ => dat}/gui.css (100%) rename src/{ => dat}/gui.js (81%) diff --git a/index.html b/index.html index 6798fe4..f7897e9 100644 --- a/index.html +++ b/index.html @@ -5,14 +5,15 @@ - - - - - - - - + + + + + + + + diff --git a/src/controllers/boolean.js b/src/dat/controllers/boolean.js similarity index 100% rename from src/controllers/boolean.js rename to src/dat/controllers/boolean.js diff --git a/src/controllers/controller.js b/src/dat/controllers/controller.js similarity index 100% rename from src/controllers/controller.js rename to src/dat/controllers/controller.js diff --git a/src/controllers/function.js b/src/dat/controllers/function.js similarity index 100% rename from src/controllers/function.js rename to src/dat/controllers/function.js diff --git a/src/controllers/number.js b/src/dat/controllers/number.js similarity index 92% rename from src/controllers/number.js rename to src/dat/controllers/number.js index a5b7720..dc23514 100644 --- a/src/controllers/number.js +++ b/src/dat/controllers/number.js @@ -42,13 +42,18 @@ DAT.GUI.NumberController = function() { this.domElement.appendChild(slider.domElement); } - numberField.addEventListener('blur', function(e) { + numberField.addEventListener('blur', function() { var val = parseFloat(this.value); + if (slider) { + DAT.GUI.removeClass(slider.domElement, 'active'); + console.log(slider.domElement.className); + } if (!isNaN(val)) { _this.setValue(val); } }, false); + numberField.addEventListener('mousewheel', function(e) { e.preventDefault(); _this.setValue(_this.getValue() + Math.abs(e.wheelDeltaY) / e.wheelDeltaY * step); @@ -58,6 +63,11 @@ DAT.GUI.NumberController = function() { numberField.addEventListener('mousedown', function(e) { py = y = e.pageY; clickedNumberField = true; + if (slider) { + DAT.GUI.addClass(slider.domElement, 'active'); + + console.log(slider.domElement.className); + } document.addEventListener('mousemove', dragNumberField, false); document.addEventListener('mouseup', mouseup, false); }, false); @@ -84,12 +94,10 @@ DAT.GUI.NumberController = function() { var mouseup = function(e) { document.removeEventListener('mousemove', dragNumberField, false); DAT.GUI.makeSelectable(_this.parent.domElement); - DAT.GUI.makeSelectable(numberField); if (clickedNumberField && !draggedNumberField) { numberField.focus(); numberField.select(); } - if (slider) slider.domElement.className = slider.domElement.className.replace(' active', ''); draggedNumberField = false; clickedNumberField = false; if (_this.finishChangeFunction != null) { @@ -108,9 +116,6 @@ DAT.GUI.NumberController = function() { // TODO: Make makeUselectable go through each element and child element. DAT.GUI.makeUnselectable(_this.parent.domElement); - DAT.GUI.makeUnselectable(numberField); - - if (slider) slider.domElement.className += ' active'; py = y; y = e.pageY; diff --git a/src/controllers/slider.js b/src/dat/controllers/slider.js similarity index 100% rename from src/controllers/slider.js rename to src/dat/controllers/slider.js diff --git a/src/controllers/string.js b/src/dat/controllers/string.js similarity index 100% rename from src/controllers/string.js rename to src/dat/controllers/string.js diff --git a/src/gui.css b/src/dat/gui.css similarity index 100% rename from src/gui.css rename to src/dat/gui.css diff --git a/src/gui.js b/src/dat/gui.js similarity index 81% rename from src/gui.js rename to src/dat/gui.js index d27ffbd..83ac8df 100644 --- a/src/gui.js +++ b/src/dat/gui.js @@ -71,7 +71,7 @@ DAT.GUI = function(parameters) { var toggleButton = document.createElement('a'); toggleButton.setAttribute('class', 'guidat-toggle'); toggleButton.setAttribute('href', '#'); - toggleButton.innerHTML = "Show Controls"; + toggleButton.innerHTML = 'Show Controls'; var toggleDragged = false; var dragDisplacementY = 0; @@ -91,7 +91,7 @@ DAT.GUI = function(parameters) { if (dmy > 0) { open = true; curControllerContainerHeight = openHeight = 1; - toggleButton.innerHTML = name || "Hide Controls"; + toggleButton.innerHTML = name || 'Hide Controls'; } else { return; } @@ -102,7 +102,8 @@ DAT.GUI = function(parameters) { if (dmy > 0 && curControllerContainerHeight > controllerHeight) { - var d = DAT.GUI.map(curControllerContainerHeight, controllerHeight, controllerHeight + 100, 1, 0); + var d = DAT.GUI.map(curControllerContainerHeight, controllerHeight, + controllerHeight + 100, 1, 0); dmy *= d; } @@ -155,9 +156,11 @@ DAT.GUI = function(parameters) { } else if (controllerContainer.children.length >= 1) { - var singleControllerHeight = controllerContainer.children[0].offsetHeight; + var singleControllerHeight = controllerContainer.children[0]. + offsetHeight; clearTimeout(resizeTimeout); - var target = Math.round(curControllerContainerHeight / singleControllerHeight) * singleControllerHeight - 1; + var target = Math.round(curControllerContainerHeight / + singleControllerHeight) * singleControllerHeight - 1; resizeTo = target; if (resizeTo <= 0) { _this.hide(); @@ -186,7 +189,7 @@ DAT.GUI = function(parameters) { } else if (DAT.GUI.autoPlace) { if (DAT.GUI.autoPlaceContainer == null) { DAT.GUI.autoPlaceContainer = document.createElement('div'); - DAT.GUI.autoPlaceContainer.setAttribute("id", "guidat"); + DAT.GUI.autoPlaceContainer.setAttribute('id', 'guidat'); document.body.appendChild(DAT.GUI.autoPlaceContainer); } @@ -201,7 +204,7 @@ DAT.GUI = function(parameters) { }, this.autoListenIntervalTime); }; - this.__defineSetter__("autoListen", function(v) { + this.__defineSetter__('autoListen', function(v) { autoListen = v; if (!autoListen) { clearInterval(listenInterval); @@ -210,7 +213,7 @@ DAT.GUI = function(parameters) { } }); - this.__defineGetter__("autoListen", function(v) { + this.__defineGetter__('autoListen', function(v) { return autoListen; }); @@ -271,7 +274,7 @@ DAT.GUI = function(parameters) { // Have we already added this? if (alreadyControlled(object, propertyName)) { - // DAT.GUI.error("Controller for \"" + propertyName+"\" already added."); + // DAT.GUI.error('Controller for \'' + propertyName+'\' already added.'); // return; } @@ -279,7 +282,8 @@ DAT.GUI = function(parameters) { // Does this value exist? Is it accessible? if (value == undefined) { - DAT.GUI.error(object + " either has no property \"" + propertyName + "\", or the property is inaccessible."); + DAT.GUI.error(object + ' either has no property \'' + propertyName + + '\', or the property is inaccessible.'); return; } @@ -288,7 +292,7 @@ DAT.GUI = function(parameters) { // Do we know how to deal with this data type? if (handler == undefined) { - DAT.GUI.error("Cannot create controller for data type \"" + type + "\""); + DAT.GUI.error('Cannot create controller for data type \'' + type + '\''); return; } @@ -301,7 +305,7 @@ DAT.GUI = function(parameters) { // Were we able to make the controller? if (!controllerObject) { - DAT.GUI.error("Error creating controller for \"" + propertyName + "\"."); + DAT.GUI.error('Error creating controller for \'' + propertyName + '\'.'); return; } @@ -311,7 +315,7 @@ DAT.GUI = function(parameters) { DAT.GUI.allControllers.push(controllerObject); // Do we have a saved value for this controller? - if (type != "function" && + if (type != 'function' && DAT.GUI.saveIndex < DAT.GUI.savedValues.length) { controllerObject.setValue(DAT.GUI.savedValues[DAT.GUI.saveIndex]); DAT.GUI.saveIndex++; @@ -336,17 +340,17 @@ DAT.GUI = function(parameters) { controllerHeight += controllers[i].domElement.offsetHeight; } if (controllerHeight - 1 > openHeight) { - controllerContainer.style.overflowY = "auto"; + controllerContainer.style.overflowY = 'auto'; } else { - controllerContainer.style.overflowY = "hidden"; + controllerContainer.style.overflowY = 'hidden'; } }; var handlerTypes = { - "number": DAT.GUI.NumberController, - "string": DAT.GUI.StringController, - "boolean": DAT.GUI.BooleanController, - "function": DAT.GUI.FunctionController + 'number': DAT.GUI.NumberController, + 'string': DAT.GUI.StringController, + 'boolean': DAT.GUI.BooleanController, + 'function': DAT.GUI.FunctionController }; @@ -361,7 +365,7 @@ DAT.GUI = function(parameters) { }; this.show = function() { - toggleButton.innerHTML = name || "Hide Controls"; + toggleButton.innerHTML = name || 'Hide Controls'; resizeTo = openHeight; clearTimeout(resizeTimeout); beginResize(); @@ -369,7 +373,7 @@ DAT.GUI = function(parameters) { } this.hide = function() { - toggleButton.innerHTML = name || "Show Controls"; + toggleButton.innerHTML = name || 'Show Controls'; resizeTo = 0; clearTimeout(resizeTimeout); beginResize(); @@ -387,17 +391,21 @@ DAT.GUI = function(parameters) { } var beginResize = function() { - //console.log("Resizing from " + curControllerContainerHeight + " to " + resizeTo); - curControllerContainerHeight += (resizeTo - curControllerContainerHeight) * 0.6; - if (Math.abs(curControllerContainerHeight - resizeTo) < 1) { + + curControllerContainerHeight += (resizeTo - curControllerContainerHeight) + * 0.6; + + if (Math.abs(curControllerContainerHeight - resizeTo) < 1) { curControllerContainerHeight = resizeTo; adaptToScrollbar(); } else { resizeTimeout = setTimeout(beginResize, 1000 / 30); } - controllerContainer.style.height = Math.round(curControllerContainerHeight) + 'px'; + controllerContainer.style.height = Math.round(curControllerContainerHeight) + + 'px'; checkForOverflow(); + } var adaptToScrollbar = function() { @@ -413,7 +421,7 @@ DAT.GUI = function(parameters) { if (DAT.GUI.guiIndex < DAT.GUI.savedAppearanceVars.length) { width = parseInt(DAT.GUI.savedAppearanceVars[DAT.GUI.guiIndex][1]); - _this.domElement.style.width = width + "px"; + _this.domElement.style.width = width + 'px'; openHeight = parseInt(DAT.GUI.savedAppearanceVars[DAT.GUI.guiIndex][2]); explicitOpenHeight = true; @@ -441,7 +449,7 @@ DAT.GUI = function(parameters) { // Add hide listener if this is the first DAT.GUI. if (DAT.GUI.allGuis.length == 1) { window.addEventListener('keyup', function(e) { - // Hide on "H" + // Hide on 'H' if (e.keyCode == 72) { DAT.GUI.toggleHide(); } @@ -472,19 +480,19 @@ DAT.GUI.toggleHide = function() { DAT.GUI.show = function() { DAT.GUI.hidden = false; for (var i in DAT.GUI.allGuis) { - DAT.GUI.allGuis[i].domElement.style.display = "block"; + DAT.GUI.allGuis[i].domElement.style.display = 'block'; } } DAT.GUI.hide = function() { DAT.GUI.hidden = true; for (var i in DAT.GUI.allGuis) { - DAT.GUI.allGuis[i].domElement.style.display = "none"; + DAT.GUI.allGuis[i].domElement.style.display = 'none'; } } DAT.GUI.saveURL = function() { - var url = DAT.GUI.replaceGetVar("saveString", DAT.GUI.getSaveString()); + var url = DAT.GUI.replaceGetVar('saveString', DAT.GUI.getSaveString()); window.location = url; }; @@ -493,7 +501,7 @@ DAT.GUI.scrollTop = -1; DAT.GUI.load = function(saveString) { //DAT.GUI.savedAppearanceVars = []; - var vals = saveString.split(","); + var vals = saveString.split(','); var numGuis = parseInt(vals[0]); DAT.GUI.scrollTop = parseInt(vals[1]); for (var i = 0; i < numGuis; i++) { @@ -527,14 +535,14 @@ DAT.GUI.getSaveString = function() { for (i in DAT.GUI.allControllers) { // We don't save values for functions. - if (DAT.GUI.allControllers[i].type == "function") { + if (DAT.GUI.allControllers[i].type == 'function') { continue; } var v = DAT.GUI.allControllers[i].getValue(); // Round numbers so they don't get enormous - if (DAT.GUI.allControllers[i].type == "number") { + if (DAT.GUI.allControllers[i].type == 'number') { v = DAT.GUI.roundToDecimal(v, 4); } @@ -549,10 +557,11 @@ DAT.GUI.getSaveString = function() { DAT.GUI.getVarFromURL = function(v) { var vars = [], hash; - var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); + 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]; @@ -567,10 +576,11 @@ DAT.GUI.replaceGetVar = function(varName, val) { var vars = [], hash; var loc = window.location.href; - var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); + 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); @@ -578,10 +588,10 @@ DAT.GUI.replaceGetVar = function(varName, val) { } if (window.location.href.indexOf('?') != -1) { - return loc + "&" + varName + "=" + val; + return loc + '&' + varName + '=' + val; } - return loc + "?" + varName + "=" + val; + return loc + '?' + varName + '=' + val; }; @@ -598,17 +608,17 @@ DAT.GUI.makeUnselectable = function(elem) { elem.onselectstart = function() { return false; }; - elem.style.MozUserSelect = "none"; - elem.style.KhtmlUserSelect = "none"; - elem.unselectable = "on"; + elem.style.MozUserSelect = 'none'; + elem.style.KhtmlUserSelect = 'none'; + elem.unselectable = 'on'; }; DAT.GUI.makeSelectable = function(elem) { elem.onselectstart = function() { }; - elem.style.MozUserSelect = "auto"; - elem.style.KhtmlUserSelect = "auto"; - elem.unselectable = "off"; + elem.style.MozUserSelect = 'auto'; + elem.style.KhtmlUserSelect = 'auto'; + elem.unselectable = 'off'; }; DAT.GUI.map = function(v, i1, i2, o1, o2) { @@ -623,7 +633,7 @@ DAT.GUI.constrain = function (v, o1, o2) { DAT.GUI.error = function(str) { if (typeof console.error == 'function') { - console.error("[DAT.GUI ERROR] " + str); + console.error('[DAT.GUI ERROR] ' + str); } }; @@ -637,4 +647,20 @@ DAT.GUI.extendController = function(clazz) { clazz.prototype.constructor = clazz; }; -if (DAT.GUI.getVarFromURL('saveString') != null) DAT.GUI.load(DAT.GUI.getVarFromURL('saveString')); +DAT.GUI.addClass = function(domElement, className) { + if (DAT.GUI.hasClass(domElement, className)) return; + domElement.className += ' ' + className; +} + +DAT.GUI.hasClass = function(domElement, className) { + return domElement.className.indexOf(className) != -1; +} + +DAT.GUI.removeClass = function(domElement, className) { + var reg = new RegExp('(\\s|^)'+className+'(\\s|$)', 'g'); + domElement.className = domElement.className.replace(reg, ''); +} + +if (DAT.GUI.getVarFromURL('saveString') != null) { + DAT.GUI.load(DAT.GUI.getVarFromURL('saveString')); +}