From 17e9cf71da7c144efb657d8414f5496d9501b845 Mon Sep 17 00:00:00 2001 From: elijah Date: Sat, 4 Feb 2012 15:22:25 -0800 Subject: [PATCH 01/25] use english spelling: replace costumStart with customStart. --- static/custom/js.template | 4 ++-- static/index.html | 4 ++-- static/js/pad.js | 4 ++-- static/js/timeslider.js | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/static/custom/js.template b/static/custom/js.template index e857a8bfe..152c3d5d7 100644 --- a/static/custom/js.template +++ b/static/custom/js.template @@ -1,6 +1,6 @@ -function costumStart() +function customStart() { //define your javascript here - //jquery is avaiable - except index.js + //jquery is available - except index.js //you can load extra scripts with $.getScript http://api.jquery.com/jQuery.getScript/ } diff --git a/static/index.html b/static/index.html index fe38318b7..97736d1ef 100644 --- a/static/index.html +++ b/static/index.html @@ -148,8 +148,8 @@ return randomstring; } - //start the costum js - if(typeof costumStart == "function") costumStart(); + // start the custom js + if (typeof customStart == "function") customStart(); diff --git a/static/js/pad.js b/static/js/pad.js index 7eb744a12..85d42f0b9 100644 --- a/static/js/pad.js +++ b/static/js/pad.js @@ -414,8 +414,8 @@ var pad = { $(document).ready(function() { - //start the costum js - if(typeof costumStart == "function") costumStart(); + // start the custom js + if (typeof customStart == "function") customStart(); getParams(); handshake(); }); diff --git a/static/js/timeslider.js b/static/js/timeslider.js index a36bd628a..d2fce8fd7 100644 --- a/static/js/timeslider.js +++ b/static/js/timeslider.js @@ -65,8 +65,8 @@ var socket, token, padId, export_links; function init() { $(document).ready(function () { - //start the costum js - if(typeof costumStart == "function") costumStart(); + // start the custom js + if (typeof customStart == "function") customStart(); //get the padId out of the url var urlParts= document.location.pathname.split("/"); From 200346ee5de6b8df6004008fb2c68b74417aa123 Mon Sep 17 00:00:00 2001 From: John McLear Date: Sun, 5 Feb 2012 14:23:01 +0000 Subject: [PATCH 02/25] Allow parameter to be passed to always show cha ton side of screen --- static/js/pad.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/static/js/pad.js b/static/js/pad.js index 7eb744a12..4ed359ecf 100644 --- a/static/js/pad.js +++ b/static/js/pad.js @@ -99,6 +99,7 @@ function getParams() var IsnoColors = params["noColors"]; var hideQRCode = params["hideQRCode"]; var rtl = params["rtl"]; + var alwaysShowChat = params["alwaysShowChat"]; if(IsnoColors) { @@ -153,6 +154,13 @@ function getParams() settings.rtlIsTrue = true } } + if(alwaysShowChat) + { + if(alwaysShowChat == "true") + { + chat.stickToScreen(); + } + } } function getUrlVars() From 7a03405bb01921b5f3488ac51ee90d8596677513 Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Sun, 5 Feb 2012 13:27:27 -0800 Subject: [PATCH 03/25] Fix version check for jQuery 1.7.1 download. This corrects 3d108d6dceaac78e2e8395620d80b10f88b766d5, which caused jQuery's version to mismatch and installDeps to download a new version every run. --- bin/installDeps.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/installDeps.sh b/bin/installDeps.sh index 2a505f826..b11c09ac5 100755 --- a/bin/installDeps.sh +++ b/bin/installDeps.sh @@ -56,7 +56,7 @@ echo "Ensure jQuery is downloaded and up to date..." DOWNLOAD_JQUERY="true" NEEDED_VERSION="1.7.1" if [ -f "static/js/jquery.js" ]; then - VERSION=$(cat static/js/jquery.js | head -n 3 | grep -o "v[0-9].[0-9]"); + VERSION=$(cat static/js/jquery.js | head -n 3 | grep -o "v[0-9].[0-9].[0-9]"); if [ ${VERSION#v} = $NEEDED_VERSION ]; then DOWNLOAD_JQUERY="false" From 3fb62956b9c004ebf412382d933b2c78e87fd545 Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Sun, 5 Feb 2012 11:13:43 -0800 Subject: [PATCH 04/25] Plugins are injected and no longer exist in the global scope. --- static/js/ace.js | 9 +++++++++ static/js/contentcollector.js | 17 ++--------------- static/js/domline.js | 17 ++--------------- static/js/domline_client.js | 17 ++--------------- static/js/linestylefilter.js | 27 +++------------------------ static/js/linestylefilter_client.js | 27 +++------------------------ static/js/plugins.js | 2 +- 7 files changed, 22 insertions(+), 94 deletions(-) diff --git a/static/js/ace.js b/static/js/ace.js index 6854b1142..9efb5d74a 100644 --- a/static/js/ace.js +++ b/static/js/ace.js @@ -337,6 +337,15 @@ function Ace2Editor() $$INCLUDE_JS("../static/js/domline.js"); $$INCLUDE_JS("../static/js/ace2_inner.js"); pushRequireScriptTo(iframeHTML); + // Inject my plugins into my child. + iframeHTML.push('\ +\ +'); pushScriptTagsFor(iframeHTML, includedJS); iframeHTML.push(''); diff --git a/static/js/contentcollector.js b/static/js/contentcollector.js index fd90a07be..0437ccd7b 100644 --- a/static/js/contentcollector.js +++ b/static/js/contentcollector.js @@ -26,12 +26,7 @@ var _MAX_LIST_LEVEL = 8; var Changeset = require('/easysync2').Changeset -var plugins = undefined; -try { - plugins = require('/plugins').plugins; -} catch (e) { - // silence -} +var plugins = require('/plugins').plugins; function sanitizeUnicode(s) { @@ -42,15 +37,7 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class { browser = browser || {}; - var plugins_; - if (typeof(plugins) != 'undefined') - { - plugins_ = plugins; - } - else - { - plugins_ = parent.parent.plugins; - } + var plugins_ = plugins; var dom = domInterface || { isNodeText: function(n) diff --git a/static/js/domline.js b/static/js/domline.js index 5de33c5aa..d89eeb464 100644 --- a/static/js/domline.js +++ b/static/js/domline.js @@ -26,12 +26,7 @@ // requires: plugins // requires: undefined -var plugins = undefined; -try { - plugins = require('/plugins').plugins; -} catch (e) { - // silence -} +var plugins = require('/plugins').plugins; var domline = {}; domline.noop = function() @@ -148,15 +143,7 @@ domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument) var extraOpenTags = ""; var extraCloseTags = ""; - var plugins_; - if (typeof(plugins) != 'undefined') - { - plugins_ = plugins; - } - else - { - plugins_ = parent.parent.plugins; - } + var plugins_ = plugins; plugins_.callHook("aceCreateDomLine", { domline: domline, diff --git a/static/js/domline_client.js b/static/js/domline_client.js index b999e3589..095307141 100644 --- a/static/js/domline_client.js +++ b/static/js/domline_client.js @@ -25,12 +25,7 @@ // requires: plugins // requires: undefined -var plugins = undefined; -try { - plugins = require('/plugins').plugins; -} catch (e) { - // silence -} +var plugins = require('/plugins').plugins; var domline = {}; domline.noop = function() @@ -147,15 +142,7 @@ domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument) var extraOpenTags = ""; var extraCloseTags = ""; - var plugins_; - if (typeof(plugins) != 'undefined') - { - plugins_ = plugins; - } - else - { - plugins_ = parent.parent.plugins; - } + var plugins_ = plugins; plugins_.callHook("aceCreateDomLine", { domline: domline, diff --git a/static/js/linestylefilter.js b/static/js/linestylefilter.js index fa1b40dee..6bb09f07b 100644 --- a/static/js/linestylefilter.js +++ b/static/js/linestylefilter.js @@ -29,12 +29,7 @@ // requires: undefined var Changeset = require('/easysync2').Changeset -var plugins = undefined; -try { - plugins = require('/plugins').plugins; -} catch (e) { - // silence -} +var plugins = require('/plugins').plugins; var linestylefilter = {}; @@ -59,15 +54,7 @@ linestylefilter.getAuthorClassName = function(author) linestylefilter.getLineStyleFilter = function(lineLength, aline, textAndClassFunc, apool) { - var plugins_; - if (typeof(plugins) != 'undefined') - { - plugins_ = plugins; - } - else - { - plugins_ = parent.parent.plugins; - } + var plugins_ = plugins; if (lineLength == 0) return textAndClassFunc; @@ -312,15 +299,7 @@ linestylefilter.getFilterStack = function(lineText, textAndClassFunc, browser) { var func = linestylefilter.getURLFilter(lineText, textAndClassFunc); - var plugins_; - if (typeof(plugins) != 'undefined') - { - plugins_ = plugins; - } - else - { - plugins_ = parent.parent.plugins; - } + var plugins_ = plugins; var hookFilters = plugins_.callHook("aceGetFilterStack", { linestylefilter: linestylefilter, diff --git a/static/js/linestylefilter_client.js b/static/js/linestylefilter_client.js index 7ff5bef41..8f1a6bafd 100644 --- a/static/js/linestylefilter_client.js +++ b/static/js/linestylefilter_client.js @@ -27,12 +27,7 @@ // requires: undefined var Changeset = require('/easysync2_client').Changeset -var plugins = undefined; -try { - plugins = require('/plugins').plugins; -} catch (e) { - // silence -} +var plugins = require('/plugins').plugins; var linestylefilter = {}; @@ -57,15 +52,7 @@ linestylefilter.getAuthorClassName = function(author) linestylefilter.getLineStyleFilter = function(lineLength, aline, textAndClassFunc, apool) { - var plugins_; - if (typeof(plugins) != 'undefined') - { - plugins_ = plugins; - } - else - { - plugins_ = parent.parent.plugins; - } + var plugins_ = plugins; if (lineLength == 0) return textAndClassFunc; @@ -310,15 +297,7 @@ linestylefilter.getFilterStack = function(lineText, textAndClassFunc, browser) { var func = linestylefilter.getURLFilter(lineText, textAndClassFunc); - var plugins_; - if (typeof(plugins) != 'undefined') - { - plugins_ = plugins; - } - else - { - plugins_ = parent.parent.plugins; - } + var plugins_ = plugins; var hookFilters = plugins_.callHook("aceGetFilterStack", { linestylefilter: linestylefilter, diff --git a/static/js/plugins.js b/static/js/plugins.js index ce3ec9bd7..963f055cf 100644 --- a/static/js/plugins.js +++ b/static/js/plugins.js @@ -4,7 +4,7 @@ * TL;DR COMMENTS ON THIS FILE ARE HIGHLY APPRECIATED */ -plugins = { +var plugins = { callHook: function(hookName, args) { var global = (function () {return this}()); From b1d871d0fddbd08e627ffdfc0d559eb6d370d90f Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Sat, 28 Jan 2012 17:05:29 -0800 Subject: [PATCH 05/25] Defer socket setup until initialization and on document ready. Code at the top level of a module should be related to definition only. Things that execute code should be inside of initialization methods. All evidence suggests that the binding to `window.onload` was arbitrary, and that this can be done as soon as the document is ready with no ill-effects. --- static/js/collab_client.js | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/static/js/collab_client.js b/static/js/collab_client.js index b697d4853..ec575fe0a 100644 --- a/static/js/collab_client.js +++ b/static/js/collab_client.js @@ -20,11 +20,6 @@ * limitations under the License. */ -$(window).bind("load", function() -{ - getCollabClient.windowLoaded = true; -}); - var chat = require('/chat').chat; // Dependency fill on init. This exists for `pad.socket` only. @@ -268,19 +263,6 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad) }*/ } - function setUpSocketWhenWindowLoaded() - { - if (getCollabClient.windowLoaded) - { - setUpSocket(); - } - else - { - setTimeout(setUpSocketWhenWindowLoaded, 200); - } - } - setTimeout(setUpSocketWhenWindowLoaded, 0); - var hiccupCount = 0; function handleCometHiccup(params) @@ -654,8 +636,7 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad) }, 0); } - var self; - return (self = { + var self = { setOnUserJoin: function(cb) { callbacks.onUserJoin = cb; @@ -698,7 +679,10 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad) callWhenNotCommitting: callWhenNotCommitting, addHistoricalAuthors: tellAceAboutHistoricalAuthors, setChannelState: setChannelState - }); + }; + + $(document).ready(setUpSocket); + return self; } function selectElementContents(elem) From f010f3ae9d2ff12be4ff666a1d44756dbe521268 Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Sun, 22 Jan 2012 16:42:07 -0800 Subject: [PATCH 06/25] Remove redundant line. --- node/server.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/node/server.js b/node/server.js index 68b7ab6ab..a6a57497a 100644 --- a/node/server.js +++ b/node/server.js @@ -141,9 +141,6 @@ async.waterfall([ gracefulShutdown(); }); - //serve minified files - app.get('/minified/:filename', minify.minifyJS); - //serve static files app.get('/static/js/require-kernel.js', function (req, res, next) { res.header("Content-Type","application/javascript; charset: utf-8"); From 3678625c7c5f944edccacb0f5b7f63eb164c649f Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Tue, 31 Jan 2012 21:20:33 -0800 Subject: [PATCH 07/25] Remove dependencies on native `map`. --- static/js/ace.js | 13 ------------- static/js/domline.js | 5 +++-- static/js/domline_client.js | 5 +++-- static/js/linestylefilter.js | 3 ++- static/js/linestylefilter_client.js | 3 ++- static/js/plugins.js | 10 ++++++---- 6 files changed, 16 insertions(+), 23 deletions(-) diff --git a/static/js/ace.js b/static/js/ace.js index 9efb5d74a..4cad6b4f7 100644 --- a/static/js/ace.js +++ b/static/js/ace.js @@ -371,19 +371,6 @@ function Ace2Editor() // (throbs busy while typing) outerHTML.push('', '\x3cscript>\n', outerScript.replace(/<\//g, '<\\/'), '\n\x3c/script>', '
x
'); - if (!Array.prototype.map) Array.prototype.map = function(fun) - { //needed for IE - if (typeof fun != "function") throw new TypeError(); - var len = this.length; - var res = new Array(len); - var thisp = arguments[1]; - for (var i = 0; i < len; i++) - { - if (i in this) res[i] = fun.call(thisp, this[i], i, this); - } - return res; - }; - var outerFrame = document.createElement("IFRAME"); outerFrame.frameBorder = 0; // for IE info.frame = outerFrame; diff --git a/static/js/domline.js b/static/js/domline.js index d89eeb464..8d8c2ea9e 100644 --- a/static/js/domline.js +++ b/static/js/domline.js @@ -27,6 +27,7 @@ // requires: undefined var plugins = require('/plugins').plugins; +var map = require('/ace2_common').map; var domline = {}; domline.noop = function() @@ -145,10 +146,10 @@ domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument) var plugins_ = plugins; - plugins_.callHook("aceCreateDomLine", { + map(plugins_.callHook("aceCreateDomLine", { domline: domline, cls: cls - }).map(function(modifier) + }), function(modifier) { cls = modifier.cls; extraOpenTags = extraOpenTags + modifier.extraOpenTags; diff --git a/static/js/domline_client.js b/static/js/domline_client.js index 095307141..87b6ed558 100644 --- a/static/js/domline_client.js +++ b/static/js/domline_client.js @@ -26,6 +26,7 @@ // requires: undefined var plugins = require('/plugins').plugins; +var map = require('/ace2_common').map; var domline = {}; domline.noop = function() @@ -144,10 +145,10 @@ domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument) var plugins_ = plugins; - plugins_.callHook("aceCreateDomLine", { + map(plugins_.callHook("aceCreateDomLine", { domline: domline, cls: cls - }).map(function(modifier) + }), function(modifier) { cls = modifier.cls; extraOpenTags = extraOpenTags + modifier.extraOpenTags; diff --git a/static/js/linestylefilter.js b/static/js/linestylefilter.js index 6bb09f07b..d0b5bc6e8 100644 --- a/static/js/linestylefilter.js +++ b/static/js/linestylefilter.js @@ -30,6 +30,7 @@ var Changeset = require('/easysync2').Changeset var plugins = require('/plugins').plugins; +var map = require('/ace2_common').map; var linestylefilter = {}; @@ -305,7 +306,7 @@ linestylefilter.getFilterStack = function(lineText, textAndClassFunc, browser) linestylefilter: linestylefilter, browser: browser }); - hookFilters.map(function(hookFilter) + map(hookFilters, function(hookFilter) { func = hookFilter(lineText, func); }); diff --git a/static/js/linestylefilter_client.js b/static/js/linestylefilter_client.js index 8f1a6bafd..f057e21a2 100644 --- a/static/js/linestylefilter_client.js +++ b/static/js/linestylefilter_client.js @@ -28,6 +28,7 @@ var Changeset = require('/easysync2_client').Changeset var plugins = require('/plugins').plugins; +var map = require('/ace2_common').map; var linestylefilter = {}; @@ -303,7 +304,7 @@ linestylefilter.getFilterStack = function(lineText, textAndClassFunc, browser) linestylefilter: linestylefilter, browser: browser }); - hookFilters.map(function(hookFilter) + map(hookFilters, function(hookFilter) { func = hookFilter(lineText, func); }); diff --git a/static/js/plugins.js b/static/js/plugins.js index 963f055cf..3e226eba1 100644 --- a/static/js/plugins.js +++ b/static/js/plugins.js @@ -25,10 +25,12 @@ var plugins = { if (sep == undefined) sep = ''; if (pre == undefined) pre = ''; if (post == undefined) post = ''; - return plugins.callHook(hookName, args).map(function(x) - { - return pre + x + post - }).join(sep || ""); + var newCallhooks = []; + var callhooks = plugins.callHook(hookName, args); + for (var i = 0, ii = callhooks.length; i < ii; i++) { + newCallhooks[i] = pre + callhooks[i] + post; + } + return newCallhooks.join(sep || ""); } }; From e68413d9986f099ff855c9790d1eda2412e169ff Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Sun, 22 Jan 2012 18:29:00 -0800 Subject: [PATCH 08/25] Extract Ace.js file generation. --- node/utils/Minify.js | 135 ++++++++++++++++++++++--------------------- 1 file changed, 68 insertions(+), 67 deletions(-) diff --git a/node/utils/Minify.js b/node/utils/Minify.js index 98774d195..44ae88c08 100644 --- a/node/utils/Minify.js +++ b/node/utils/Minify.js @@ -74,7 +74,6 @@ function _handle(req, res, jsFilename, jsFiles) { if(settings.minify) { var fileValues = {}; - var embeds = {}; var latestModification = 0; async.series([ @@ -145,77 +144,20 @@ function _handle(req, res, jsFilename, jsFiles) { { async.forEach(jsFiles, function (item, callback) { - fs.readFile(JS_DIR + item, "utf-8", function(err, data) - { + if (item == 'ace.js') { + getAceFile(handleFile); + } else { + fs.readFile(JS_DIR + item, "utf-8", handleFile); + } + + function handleFile(err, data) + { if(ERR(err, callback)) return; fileValues[item] = data; callback(); - }); + } }, callback); }, - //find all includes in ace.js and embed them - function(callback) - { - //if this is not the creation of pad.js, skip this part - if(jsFilename != "pad.js") - { - callback(); - return; - } - - var founds = fileValues["ace.js"].match(/\$\$INCLUDE_[a-zA-Z_]+\([a-zA-Z0-9.\/_"-]+\)/gi); - - //go trough all includes - async.forEach(founds, function (item, callback) - { - var filename = item.match(/"[^"]*"/g)[0].substr(1); - filename = filename.substr(0,filename.length-1); - - var type = item.match(/INCLUDE_[A-Z]+/g)[0].substr("INCLUDE_".length); - - //read the included file - var shortFilename = filename.replace(/^..\/static\/js\//, ''); - if (shortFilename == 'require-kernel.js') { - // the kernel isn’t actually on the file system. - handleEmbed(null, requireDefinition()); - } else { - fs.readFile(ROOT_DIR + filename, "utf-8", handleEmbed); - } - function handleEmbed(err, data) - { - if(ERR(err, callback)) return; - - if(type == "JS") - { - if (shortFilename == 'require-kernel.js') { - embeds[filename] = compressJS([data]); - } else { - embeds[filename] = compressJS([isolateJS(data, shortFilename)]); - } - } - else - { - embeds[filename] = compressCSS([data]); - } - callback(); - } - }, function(err) - { - if(ERR(err, callback)) return; - - fileValues["ace.js"] += ';\n' - fileValues["ace.js"] += - 'Ace2Editor.EMBEDED = Ace2Editor.EMBED || {};\n' - for (var filename in embeds) - { - fileValues["ace.js"] += - 'Ace2Editor.EMBEDED[' + JSON.stringify(filename) + '] = ' - + JSON.stringify(embeds[filename]) + ';\n'; - } - - callback(); - }); - }, //put all together and write it into a file function(callback) { @@ -295,6 +237,65 @@ function _handle(req, res, jsFilename, jsFiles) { } } +// find all includes in ace.js and embed them. +function getAceFile(callback) { + fs.readFile(JS_DIR + 'ace.js', "utf8", function(err, data) { + if(ERR(err, callback)) return; + + // Find all includes in ace.js and embed them + var founds = data.match(/\$\$INCLUDE_[a-zA-Z_]+\([a-zA-Z0-9.\/_"-]+\)/gi); + if (!settings.minify) { + founds = []; + } + + data += ';\n'; + data += 'Ace2Editor.EMBEDED = Ace2Editor.EMBEDED || {};\n'; + + //go trough all includes + async.forEach(founds, function (item, callback) { + var filename = item.match(/"([^"]*)"/)[1]; + var type = item.match(/INCLUDE_([A-Z]+)/)[1]; + var shortFilename = (filename.match(/^..\/static\/js\/(.*)$/, '')||[])[1]; + + //read the included files + if (shortFilename) { + if (shortFilename == 'require-kernel.js') { + // the kernel isn’t actually on the file system. + handleEmbed(null, requireDefinition()); + } else { + fs.readFile(ROOT_DIR + filename, "utf8", function (error, data) { + handleEmbed(error, isolateJS(data, shortFilename)); + }); + } + } else { + fs.readFile(ROOT_DIR + filename, "utf8", handleEmbed); + } + + function handleEmbed(error, data_) { + if (error) { + return; // Don't bother to include it. + } + if (settings.minify) { + if (type == "JS") { + try { + data_ = compressJS([data_]); + } catch (e) { + // Ignore, include uncompresseed, which will break in browser. + } + } else { + data_ = compressCSS([data_]); + } + } + data += 'Ace2Editor.EMBEDED[' + JSON.stringify(filename) + '] = ' + + JSON.stringify(data_) + ';\n'; + callback(); + } + }, function(error) { + callback(error, data); + }); + }); +} + exports.requireDefinition = requireDefinition; function requireDefinition() { return 'var require = ' + RequireKernel.kernelSource + ';\n'; From ebb5055ce81bd3d279100a5af230728687f92a10 Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Sat, 28 Jan 2012 16:24:11 -0800 Subject: [PATCH 09/25] Extract file retrieval. --- node/utils/Minify.js | 77 +++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 44 deletions(-) diff --git a/node/utils/Minify.js b/node/utils/Minify.js index 44ae88c08..5deaa1330 100644 --- a/node/utils/Minify.js +++ b/node/utils/Minify.js @@ -73,7 +73,7 @@ function _handle(req, res, jsFilename, jsFiles) { //minifying is enabled if(settings.minify) { - var fileValues = {}; + var result = undefined; var latestModification = 0; async.series([ @@ -142,30 +142,20 @@ function _handle(req, res, jsFilename, jsFiles) { //load all js files function (callback) { - async.forEach(jsFiles, function (item, callback) - { - if (item == 'ace.js') { - getAceFile(handleFile); - } else { - fs.readFile(JS_DIR + item, "utf-8", handleFile); - } + var values = []; + tarCode( + jsFiles + , function (content) {values.push(content)} + , function (err) { + if(ERR(err)) return; - function handleFile(err, data) - { - if(ERR(err, callback)) return; - fileValues[item] = data; - callback(); - } - }, callback); + result = values.join(''); + callback(); + }); }, //put all together and write it into a file function(callback) { - //minify all javascript files to one - var values = []; - tarCode(jsFiles, fileValues, function (content) {values.push(content)}); - var result = compressJS(values); - async.parallel([ //write the results plain in a file function(callback) @@ -213,25 +203,11 @@ function _handle(req, res, jsFilename, jsFiles) { //minifying is disabled, so put the files together in one file else { - var fileValues = {}; - - //read all js files - async.forEach(jsFiles, function (item, callback) - { - fs.readFile(JS_DIR + item, "utf-8", function(err, data) - { - if(ERR(err, callback)) return; - fileValues[item] = data; - callback(); - }); - }, - //send all files together - function(err) - { + tarCode( + jsFiles + , function (content) {res.write(content)} + , function (err) { if(ERR(err)) return; - - tarCode(jsFiles, fileValues, function (content) {res.write(content)}); - res.end(); }); } @@ -301,12 +277,25 @@ function requireDefinition() { return 'var require = ' + RequireKernel.kernelSource + ';\n'; } -function tarCode(filesInOrder, files, write) { - for(var i = 0, ii = filesInOrder.length; i < filesInOrder.length; i++) { - var filename = filesInOrder[i]; - write("\n\n\n/*** File: static/js/" + filename + " ***/\n\n\n"); - write(isolateJS(files[filename], filename)); - } +function tarCode(jsFiles, write, callback) { + async.forEach(jsFiles, function (item, callback){ + if (item == 'ace.js') { + getAceFile(handleFile); + } else { + fs.readFile(JS_DIR + item, "utf8", handleFile); + } + + function handleFile(err, data) { + if(ERR(err, callback)) return; + write("\n\n\n/*** File: static/js/" + item + " ***/\n\n\n"); + if (settings.minify) { + write(compressJS([isolateJS(data, item)]) + ';\n'); + } else { + write(isolateJS(data, item)); + } + callback(); + } + }, callback); } // Wrap the following code in a self executing function and assign exports to From ddc74cd0f13afd99d1276a942d0afdd221dba4d9 Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Tue, 31 Jan 2012 14:03:10 -0800 Subject: [PATCH 10/25] Make the comment a part of the module. --- node/utils/Minify.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/utils/Minify.js b/node/utils/Minify.js index 5deaa1330..e025e927e 100644 --- a/node/utils/Minify.js +++ b/node/utils/Minify.js @@ -287,7 +287,7 @@ function tarCode(jsFiles, write, callback) { function handleFile(err, data) { if(ERR(err, callback)) return; - write("\n\n\n/*** File: static/js/" + item + " ***/\n\n\n"); + data = ("\n\n\n/*** File: static/js/" + item + " ***/\n\n\n") + data; if (settings.minify) { write(compressJS([isolateJS(data, item)]) + ';\n'); } else { From 458b5a4f03b081a8abac68f04999f65c4cf442d3 Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Tue, 31 Jan 2012 14:29:48 -0800 Subject: [PATCH 11/25] Combine tar and isolate, so that everything is done in one definition. --- node/utils/Minify.js | 46 ++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/node/utils/Minify.js b/node/utils/Minify.js index e025e927e..b2c98d528 100644 --- a/node/utils/Minify.js +++ b/node/utils/Minify.js @@ -278,37 +278,41 @@ function requireDefinition() { } function tarCode(jsFiles, write, callback) { - async.forEach(jsFiles, function (item, callback){ - if (item == 'ace.js') { + write('require.define({'); + var initialEntry = true; + async.forEach(jsFiles, function (filename, callback){ + if (filename == 'ace.js') { getAceFile(handleFile); } else { - fs.readFile(JS_DIR + item, "utf8", handleFile); + fs.readFile(JS_DIR + filename, "utf8", handleFile); } function handleFile(err, data) { if(ERR(err, callback)) return; - data = ("\n\n\n/*** File: static/js/" + item + " ***/\n\n\n") + data; - if (settings.minify) { - write(compressJS([isolateJS(data, item)]) + ';\n'); + var srcPath = JSON.stringify('/' + filename); + var srcPathAbbv = JSON.stringify('/' + filename.replace(/\.js$/, '')); + if (!initialEntry) { + write('\n,'); } else { - write(isolateJS(data, item)); + initialEntry = false; } + write(srcPath + ': ') + data = '(function (require, exports, module) {' + data + '})'; + if (settings.minify) { + write(compressJS([data])); + } else { + write(data); + } + if (srcPath != srcPathAbbv) { + write('\n,' + srcPathAbbv + ': null'); + } + callback(); } - }, callback); -} - -// Wrap the following code in a self executing function and assign exports to -// global. This is a first step towards removing symbols from the global scope. -// exports is global and require is a function that returns global. -function isolateJS(code, filename) { - var srcPath = JSON.stringify('/' + filename); - var srcPathAbbv = JSON.stringify('/' + filename.replace(/\.js$/, '')); - return 'require.define({' - + srcPath + ': ' - + 'function (require, exports, module) {' + code + '}' - + (srcPath != srcPathAbbv ? '\n,' + srcPathAbbv + ': null' : '') - + '});\n'; + }, function () { + write('});\n'); + callback(); + }); } function compressJS(values) From 348e7ef1d5e1eb38ab76523cbd6e5fdc1b36adca Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Tue, 31 Jan 2012 00:12:10 -0800 Subject: [PATCH 12/25] Define packaging for iframe JS in the same way as pad.js and timeslider.js. --- node/utils/Minify.js | 12 ++++++++--- node/utils/tar.json | 14 +++++++++++++ static/js/ace.js | 48 ++++++++++++++------------------------------ 3 files changed, 38 insertions(+), 36 deletions(-) diff --git a/node/utils/Minify.js b/node/utils/Minify.js index b2c98d528..c078c5c66 100644 --- a/node/utils/Minify.js +++ b/node/utils/Minify.js @@ -239,9 +239,15 @@ function getAceFile(callback) { // the kernel isn’t actually on the file system. handleEmbed(null, requireDefinition()); } else { - fs.readFile(ROOT_DIR + filename, "utf8", function (error, data) { - handleEmbed(error, isolateJS(data, shortFilename)); - }); + var contents = ''; + tarCode(tar[shortFilename] || shortFilename + , function (content) { + contents += content; + } + , function () { + handleEmbed(null, contents); + } + ); } } else { fs.readFile(ROOT_DIR + filename, "utf8", handleEmbed); diff --git a/node/utils/tar.json b/node/utils/tar.json index aeafe23fb..b319791cf 100644 --- a/node/utils/tar.json +++ b/node/utils/tar.json @@ -48,4 +48,18 @@ , "broadcast_revisions.js" , "timeslider.js" ] +, "ace2_inner.js": [ + "ace2_common.js" + , "skiplist.js" + , "virtual_lines.js" + , "easysync2.js" + , "cssmanager.js" + , "colorutils.js" + , "undomodule.js" + , "contentcollector.js" + , "changesettracker.js" + , "linestylefilter.js" + , "domline.js" + , "ace2_inner.js" + ] } diff --git a/static/js/ace.js b/static/js/ace.js index 4cad6b4f7..4a3137276 100644 --- a/static/js/ace.js +++ b/static/js/ace.js @@ -228,29 +228,23 @@ function Ace2Editor() buffer.push('\ '); - pushScriptTagsFor(iframeHTML, includedJS); + pushScriptsTo(iframeHTML); iframeHTML.push(''); iframeHTML.push(' '); From 4bf9b0c8054504b9560cb0b24fcf061f6fa05d6d Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Mon, 30 Jan 2012 21:37:39 -0800 Subject: [PATCH 13/25] Always include the require kernel. --- node/utils/Minify.js | 1 + static/js/ace.js | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/node/utils/Minify.js b/node/utils/Minify.js index c078c5c66..859ee07ae 100644 --- a/node/utils/Minify.js +++ b/node/utils/Minify.js @@ -223,6 +223,7 @@ function getAceFile(callback) { if (!settings.minify) { founds = []; } + founds.push('$$INCLUDE_JS("../static/js/require-kernel.js")'); data += ';\n'; data += 'Ace2Editor.EMBEDED = Ace2Editor.EMBEDED || {};\n'; diff --git a/static/js/ace.js b/static/js/ace.js index 4a3137276..3fdfa05ec 100644 --- a/static/js/ace.js +++ b/static/js/ace.js @@ -217,15 +217,11 @@ function Ace2Editor() return {embeded: embededFiles, remote: remoteFiles}; } function pushRequireScriptTo(buffer) { - /* Folling is for packaging regular expression. */ - /* $$INCLUDE_JS("../static/js/require-kernel.js"); */ var KERNEL_SOURCE = '../static/js/require-kernel.js'; if (Ace2Editor.EMBEDED && Ace2Editor.EMBEDED[KERNEL_SOURCE]) { buffer.push(' @@ -297,14 +294,15 @@ diff --git a/static/timeslider.html b/static/timeslider.html index cbcb3e366..fc8e2d4e3 100644 --- a/static/timeslider.html +++ b/static/timeslider.html @@ -205,13 +205,12 @@ From 762d39f009859f276d7683ad1113fc7032319160 Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Tue, 31 Jan 2012 22:32:46 -0800 Subject: [PATCH 15/25] Move scripts to the bottom of the page. --- static/pad.html | 11 +++++------ static/timeslider.html | 14 ++++++-------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/static/pad.html b/static/pad.html index b8d48028d..48892e0f4 100644 --- a/static/pad.html +++ b/static/pad.html @@ -11,11 +11,6 @@ - - - - -
- + + + + - - - - - @@ -203,7 +197,11 @@ - + + + +