From 480abb17ca199f78e1b8d0de2a4f2ca70639b0ae Mon Sep 17 00:00:00 2001 From: Doug Fritz Date: Mon, 18 Apr 2011 17:27:33 -0700 Subject: [PATCH 1/2] updated buildscript barnraiser --- index.html | 3 +- src/DAT/GUI/GUI.js | 8 ++- utils/barnraiser.py | 138 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 145 insertions(+), 4 deletions(-) create mode 100644 utils/barnraiser.py diff --git a/index.html b/index.html index f9f5bbf..be33ef0 100644 --- a/index.html +++ b/index.html @@ -1,4 +1,5 @@ + dat.gui @@ -125,7 +126,7 @@
  • Download the minified source [11kb] + id="buildsize">[22.8kb]
  • diff --git a/src/DAT/GUI/GUI.js b/src/DAT/GUI/GUI.js index aabef94..45a4199 100644 --- a/src/DAT/GUI/GUI.js +++ b/src/DAT/GUI/GUI.js @@ -670,17 +670,19 @@ DAT.GUI.extendController = function(clazz) { 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(' ' + className, 'g'); domElement.className = domElement.className.replace(reg, ''); -} +}; if (DAT.GUI.getVarFromURL('saveString') != null) { DAT.GUI.load(DAT.GUI.getVarFromURL('saveString')); } + +window["DAT.GUI"] = DAT.GUI; \ No newline at end of file diff --git a/utils/barnraiser.py b/utils/barnraiser.py new file mode 100644 index 0000000..dd1b958 --- /dev/null +++ b/utils/barnraiser.py @@ -0,0 +1,138 @@ +#/usr/bin/env python + +from optparse import OptionParser +import httplib, urllib +import os, fnmatch, shutil, re + +usage = """usage: %prog [options] command + +Commands: + build build the script + debug print the header to include js files + clean remove any built files +""" +parser = OptionParser(usage=usage) +parser.add_option('-l', '--level', dest='level', default='ADVANCED_OPTIMIZATIONS', + help='Closure compilation level [WHITESPACE_ONLY, SIMPLE_OPTIMIZATIONS, \ + ADVANCED_OPTIMIZATIONS]') + +UTILS = os.path.dirname(os.path.abspath(__file__)) + +SRC_ROOT= os.path.join(UTILS,'..','src') +BUILD_ROOT = os.path.join(UTILS,'..','build') +INDEX = os.path.join(UTILS,'..','index.html') +BUILD_NAME = 'DAT.GUI' +ALL = ['DAT'] + + +def flatten(l, ltypes=(list, tuple)): + ltype = type(l) + l = list(l) + i = 0 + while i < len(l): + while isinstance(l[i], ltypes): + if not l[i]: + l.pop(i) + i -= 1 + break + else: + l[i:i + 1] = l[i] + i += 1 + return ltype(l) + +def expand(path, globby): + matches = [] + path = path.split('.') + path.insert(0,SRC_ROOT) + path = os.path.join(*path) + for root, dirnames, filenames in os.walk(path): + for filename in fnmatch.filter(filenames, globby): + matches.append(os.path.join(root, filename)) + return matches + +def source_list(src, globby='*.js'): + def expander(f): + return expand(f,globby) + return set(flatten(map(expander, src))) + +def compile(code): + params = urllib.urlencode([ + ('js_code', code), + ('compilation_level', options.level), + ('output_format', 'text'), + ('output_info', 'compiled_code'), + ]) + headers = { 'Content-type': 'application/x-www-form-urlencoded' } + conn = httplib.HTTPConnection('closure-compiler.appspot.com') + conn.request('POST', '/compile', params, headers) + response = conn.getresponse() + data = response.read() + conn.close() + return data + +def bytes_to_kb(b,digits=1): + return round(0.0078125 * b, digits) + +def clean(): + if os.path.exists(BUILD_ROOT): + shutil.rmtree(BUILD_ROOT) + print('DONE. Removed %s'%(BUILD_ROOT,)) + else: + print('DONE. Nothing to clean') + +def build(src): + if not os.path.exists(BUILD_ROOT): + os.makedirs(BUILD_ROOT) + + cssfiles = source_list(src, '*.css') + css = '\n'.join([open(f).read() for f in cssfiles]) + css = re.sub('\W+','',css) + + jsfiles = source_list(src, '*.js') + code = '\n'.join([open(f).read() for f in jsfiles]) + code += """DAT.GUI.inlineCSS = '%s';\n"""%(css,) + + outpath = os.path.join(BUILD_ROOT, BUILD_NAME+'.js') + with open(outpath,'w') as f: + f.write(code) + + compiled = compile(code) + outpath = os.path.join(BUILD_ROOT, BUILD_NAME+'.min.js') + with open(outpath,'w') as f: + f.write(compiled) + + outpath = os.path.join(BUILD_ROOT, BUILD_NAME+'.css') + with open(outpath,'w') as f: + f.write(code) + + size = bytes_to_kb(os.path.getsize(outpath)) + with open(INDEX,'r') as f: + index = f.read() + with open(INDEX,'w') as f: + index = re.sub(r'\[[0-9.]+kb\]','[%skb]'%(size,),index) + f.write(index) + + print('DONE. Built files in %s.'%(BUILD_ROOT,)) + +def debug(src): + files = source_list(src) + scripts = "" + for f in files: + scripts += '\n'%(f,) + print(scripts) + +if __name__ == '__main__': + global options + (options, args) = parser.parse_args() + if len(args) != 1: + print(parser.usage) + exit(0) + command = args[0] + if command == 'build': + build(ALL) + elif command == 'clean': + clean() + elif command == 'debug': + debug(ALL) + + From 944a4ab7d31720f97e9ee441e18c141aee257fec Mon Sep 17 00:00:00 2001 From: Doug Fritz Date: Mon, 18 Apr 2011 17:31:10 -0700 Subject: [PATCH 2/2] buildscript css --- index.html | 2 +- src/DAT/GUI/GUI.js | 47 ++++++++++++++++++--------------------------- utils/barnraiser.py | 2 +- 3 files changed, 21 insertions(+), 30 deletions(-) diff --git a/index.html b/index.html index 773bf6a..1fa3476 100644 --- a/index.html +++ b/index.html @@ -130,7 +130,7 @@
  • Download the minified source [22.8kb] + id="buildsize">[255.9kb]
  • diff --git a/src/DAT/GUI/GUI.js b/src/DAT/GUI/GUI.js index dd0a4dd..a25c3c8 100644 --- a/src/DAT/GUI/GUI.js +++ b/src/DAT/GUI/GUI.js @@ -6,10 +6,6 @@ DAT.GUI = function(parameters) { parameters = {}; } - if (parameters.height == undefined) { - parameters.height = 300; - } - var MIN_WIDTH = 240; var MAX_WIDTH = 500; @@ -23,9 +19,11 @@ DAT.GUI = function(parameters) { // Sum total of heights of controllers in this gui var controllerHeight; + var curControllerContainerHeight = 0; + var _this = this; - var open = true; + var open = false; var width = 280; // Prevents checkForOverflow bug in which loaded gui appearance @@ -47,10 +45,9 @@ DAT.GUI = function(parameters) { this.domElement.setAttribute('class', 'guidat'); this.domElement.style.width = width + 'px'; - var curControllerContainerHeight = parameters.height; var controllerContainer = document.createElement('div'); controllerContainer.setAttribute('class', 'guidat-controllers'); - controllerContainer.style.height = curControllerContainerHeight + 'px'; + controllerContainer.style.height = '0px'; // Firefox hack to prevent horizontal scrolling controllerContainer.addEventListener('DOMMouseScroll', function(e) { @@ -74,10 +71,11 @@ DAT.GUI = function(parameters) { }, false); + var toggleButton = document.createElement('a'); toggleButton.setAttribute('class', 'guidat-toggle'); toggleButton.setAttribute('href', '#'); - toggleButton.innerHTML = open ? closeString : openString; + toggleButton.innerHTML = openString; var toggleDragged = false; var dragDisplacementY = 0; @@ -302,7 +300,7 @@ DAT.GUI = function(parameters) { return; } - var args = [this]; // Set first arg (parent) to this + var args = [this]; // Set first arg (parent) to this for (var j = 0; j < arguments.length; j++) { args.push(arguments[j]); } @@ -359,10 +357,13 @@ DAT.GUI = function(parameters) { 'function': DAT.GUI.ControllerFunction }; + this.reset = function() { // TODO ... Set all values back to their initials. } + // DAT.GUI ... DAT.GUI + this.toggle = function() { open ? this.close() : this.open(); }; @@ -372,7 +373,6 @@ DAT.GUI = function(parameters) { resizeTo = openHeight; clearTimeout(resizeTimeout); beginResize(); - adaptToScrollbar(); open = true; } @@ -381,7 +381,6 @@ DAT.GUI = function(parameters) { resizeTo = 0; clearTimeout(resizeTimeout); beginResize(); - adaptToScrollbar(); open = false; } @@ -397,12 +396,13 @@ DAT.GUI = function(parameters) { var beginResize = function() { - curControllerContainerHeight = controllerContainer.offsetHeight; curControllerContainerHeight += (resizeTo - curControllerContainerHeight) * 0.6; if (Math.abs(curControllerContainerHeight - resizeTo) < 1) { curControllerContainerHeight = resizeTo; + adaptToScrollbar(); + } else { resizeTimeout = setTimeout(beginResize, 1000 / 30); } @@ -413,14 +413,15 @@ DAT.GUI = function(parameters) { } var adaptToScrollbar = function() { - // Clears lingering scrollbar column - _this.domElement.style.width = (width - 1) + 'px'; + // Clears lingering slider column + _this.domElement.style.width = (width + 1) + 'px'; setTimeout(function() { _this.domElement.style.width = width + 'px'; }, 1); }; + // Load saved appearance: if (DAT.GUI.guiIndex < DAT.GUI.savedAppearanceVars.length) { @@ -452,23 +453,13 @@ DAT.GUI = function(parameters) { DAT.GUI.allGuis.push(this); // Add hide listener if this is the first DAT.GUI. - if (DAT.GUI.allGuis.length == 1) { - window.addEventListener('keyup', function(e) { // Hide on 'H' - if (!DAT.GUI.supressHotKeys && e.keyCode == 72) { + if (e.keyCode == 72) { DAT.GUI.toggleHide(); } }, false); - - if (DAT.GUI.inlineCSS) { - var styleSheet = document.createElement('style'); - styleSheet.setAttribute('type', 'text/css'); - styleSheet.innerHTML = DAT.GUI.inlineCSS; - document.head.appendChild(styleSheet); - } - } }; @@ -483,7 +474,6 @@ DAT.GUI.autoPlaceContainer = null; DAT.GUI.allControllers = []; DAT.GUI.allGuis = []; -DAT.GUI.supressHotKeys = false; DAT.GUI.toggleHide = function() { if (DAT.GUI.hidden) { @@ -534,7 +524,8 @@ DAT.GUI.savedAppearanceVars = []; DAT.GUI.getSaveString = function() { - var vals = [], i; + var vals = [], + i; vals.push(DAT.GUI.allGuis.length); vals.push(document.body.scrollTop); @@ -694,4 +685,4 @@ if (DAT.GUI.getVarFromURL('saveString') != null) { DAT.GUI.load(DAT.GUI.getVarFromURL('saveString')); } -window["DAT.GUI"] = DAT.GUI; +window["DAT.GUI"] = DAT.GUI; \ No newline at end of file diff --git a/utils/barnraiser.py b/utils/barnraiser.py index dd1b958..81e9ad9 100644 --- a/utils/barnraiser.py +++ b/utils/barnraiser.py @@ -86,7 +86,7 @@ def build(src): cssfiles = source_list(src, '*.css') css = '\n'.join([open(f).read() for f in cssfiles]) - css = re.sub('\W+','',css) + css = re.sub(r'[ \t\n\r]+',' ',css) jsfiles = source_list(src, '*.js') code = '\n'.join([open(f).read() for f in jsfiles])