From 1c0a74d7c60ae51937325be331af94c6b7327abc Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Tue, 17 Jan 2012 01:42:06 -0800 Subject: [PATCH 01/24] Use middleware to specify Server name in header. --- node/server.js | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/node/server.js b/node/server.js index 50f486337c9..f4f3a371d4c 100644 --- a/node/server.js +++ b/node/server.js @@ -78,7 +78,12 @@ async.waterfall([ { //create server var app = express.createServer(); - + + app.use(function (req, res, next) { + res.header("Server", serverName); + next(); + }); + //load modules that needs a initalized db readOnlyManager = require("./db/ReadOnlyManager"); exporthtml = require("./utils/ExportHtml"); @@ -112,7 +117,6 @@ async.waterfall([ //serve static files app.get('/static/*', function(req, res) { - res.header("Server", serverName); var filePath = path.normalize(__dirname + "/.." + req.url.replace(/\.\./g, '').split("?")[0]); res.sendfile(filePath, { maxAge: exports.maxAge }); @@ -121,8 +125,6 @@ async.waterfall([ //serve minified files app.get('/minified/:id', function(req, res, next) { - res.header("Server", serverName); - var id = req.params.id; if(id == "pad.js" || id == "timeslider.js") @@ -178,8 +180,6 @@ async.waterfall([ //serve read only pad app.get('/ro/:id', function(req, res) { - res.header("Server", serverName); - var html; var padId; var pad; @@ -264,7 +264,6 @@ async.waterfall([ app.get('/p/:pad', function(req, res, next) { goToPad(req, res, function() { - res.header("Server", serverName); var filePath = path.normalize(__dirname + "/../static/pad.html"); res.sendfile(filePath, { maxAge: exports.maxAge }); }); @@ -274,7 +273,6 @@ async.waterfall([ app.get('/p/:pad/timeslider', function(req, res, next) { goToPad(req, res, function() { - res.header("Server", serverName); var filePath = path.normalize(__dirname + "/../static/timeslider.html"); res.sendfile(filePath, { maxAge: exports.maxAge }); }); @@ -301,7 +299,6 @@ async.waterfall([ } res.header("Access-Control-Allow-Origin", "*"); - res.header("Server", serverName); hasPadAccess(req, res, function() { @@ -321,8 +318,6 @@ async.waterfall([ return; } - res.header("Server", serverName); - hasPadAccess(req, res, function() { importHandler.doImport(req, res, req.params.pad); @@ -335,7 +330,6 @@ async.waterfall([ //This is for making an api call, collecting all post information and passing it to the apiHandler var apiCaller = function(req, res, fields) { - res.header("Server", serverName); res.header("Content-Type", "application/json; charset=utf-8"); apiLogger.info("REQUEST, " + req.params.func + ", " + JSON.stringify(fields)); @@ -396,7 +390,6 @@ async.waterfall([ //serve index.html under / app.get('/', function(req, res) { - res.header("Server", serverName); var filePath = path.normalize(__dirname + "/../static/index.html"); res.sendfile(filePath, { maxAge: exports.maxAge }); }); @@ -404,7 +397,6 @@ async.waterfall([ //serve robots.txt app.get('/robots.txt', function(req, res) { - res.header("Server", serverName); var filePath = path.normalize(__dirname + "/../static/robots.txt"); res.sendfile(filePath, { maxAge: exports.maxAge }); }); @@ -412,7 +404,6 @@ async.waterfall([ //serve favicon.ico app.get('/favicon.ico', function(req, res) { - res.header("Server", serverName); var filePath = path.normalize(__dirname + "/../static/custom/favicon.ico"); res.sendfile(filePath, { maxAge: exports.maxAge }, function(err) { From c3acdbe32939c1741717f6c60dfefeb8dc566476 Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Tue, 17 Jan 2012 00:57:59 -0800 Subject: [PATCH 02/24] Minify uses the stardard middleware interface. --- node/server.js | 14 +------------- node/utils/Minify.js | 8 +++++--- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/node/server.js b/node/server.js index f4f3a371d4c..422bbe12086 100644 --- a/node/server.js +++ b/node/server.js @@ -123,19 +123,7 @@ async.waterfall([ }); //serve minified files - app.get('/minified/:id', function(req, res, next) - { - var id = req.params.id; - - if(id == "pad.js" || id == "timeslider.js") - { - minify.minifyJS(req,res,id); - } - else - { - next(); - } - }); + app.get('/minified/:filename', minify.minifyJS); //checks for padAccess function hasPadAccess(req, res, callback) diff --git a/node/utils/Minify.js b/node/utils/Minify.js index 3477cd01078..da047bb2054 100644 --- a/node/utils/Minify.js +++ b/node/utils/Minify.js @@ -40,20 +40,22 @@ var tar = JSON.parse(fs.readFileSync(TAR_PATH, 'utf8')); * @param req the Express request * @param res the Express response */ -exports.minifyJS = function(req, res, jsFilename) +exports.minifyJS = function(req, res, next) { - res.header("Content-Type","text/javascript"); + var jsFilename = req.params['filename']; //choose the js files we need var jsFiles = undefined; if (Object.prototype.hasOwnProperty.call(tar, jsFilename)) { jsFiles = tar[jsFilename]; } else { - throw new Error("there is no profile for creating " + name); + return next(); } var rootPath = path.normalize(__dirname + "/../../" ); + res.header("Content-Type","text/javascript"); + //minifying is enabled if(settings.minify) { From 53549b7422b9e61ed9685f95d36d33031fcf6910 Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Tue, 17 Jan 2012 02:16:25 -0800 Subject: [PATCH 03/24] Use constants and CWD-independent paths for resource directories. --- node/utils/Minify.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/node/utils/Minify.js b/node/utils/Minify.js index da047bb2054..1a214fb928b 100644 --- a/node/utils/Minify.js +++ b/node/utils/Minify.js @@ -32,6 +32,10 @@ var gzip = require('gzip'); var server = require('../server'); var os = require('os'); +var ROOT_DIR = path.normalize(__dirname + "/../" ); +var JS_DIR = ROOT_DIR + '../static/js/'; +var CSS_DIR = ROOT_DIR + '../static/css/'; +var CACHE_DIR = ROOT_DIR + '../var/'; var TAR_PATH = path.join(__dirname, 'tar.json'); var tar = JSON.parse(fs.readFileSync(TAR_PATH, 'utf8')); @@ -52,8 +56,6 @@ exports.minifyJS = function(req, res, next) return next(); } - var rootPath = path.normalize(__dirname + "/../../" ); - res.header("Content-Type","text/javascript"); //minifying is enabled @@ -67,7 +69,7 @@ exports.minifyJS = function(req, res, next) //find out the highest modification date function(callback) { - var folders2check = [rootPath + "static/css", rootPath + "static/js"]; + var folders2check = [CSS_DIR, JS_DIR]; //go trough this two folders async.forEach(folders2check, function(path, callback) @@ -106,7 +108,7 @@ exports.minifyJS = function(req, res, next) function(callback) { //check the modification time of the minified js - fs.stat(rootPath + "var/minified_" + jsFilename, function(err, stats) + fs.stat(CACHE_DIR + "/minified_" + jsFilename, function(err, stats) { if(err && err.code != "ENOENT") { @@ -131,7 +133,7 @@ exports.minifyJS = function(req, res, next) { async.forEach(jsFiles, function (item, callback) { - fs.readFile(rootPath + "static/js/" + item, "utf-8", function(err, data) + fs.readFile(JS_DIR + item, "utf-8", function(err, data) { if(ERR(err, callback)) return; fileValues[item] = data; @@ -160,7 +162,7 @@ exports.minifyJS = function(req, res, next) var type = item.match(/INCLUDE_[A-Z]+/g)[0].substr("INCLUDE_".length); //read the included file - fs.readFile(filename, "utf-8", function(err, data) + fs.readFile(ROOT_DIR + filename, "utf-8", function(err, data) { if(ERR(err, callback)) return; @@ -209,7 +211,7 @@ exports.minifyJS = function(req, res, next) //write the results plain in a file function(callback) { - fs.writeFile(rootPath + "var/minified_" + jsFilename, result, "utf8", callback); + fs.writeFile(CACHE_DIR + "minified_" + jsFilename, result, "utf8", callback); }, //write the results compressed in a file function(callback) @@ -223,7 +225,7 @@ exports.minifyJS = function(req, res, next) if(ERR(err, callback)) return; - fs.writeFile(rootPath + "var/minified_" + jsFilename + ".gz", compressedResult, callback); + fs.writeFile(CACHE_DIR + "minified_" + jsFilename + ".gz", compressedResult, callback); }); } //skip this step on windows @@ -247,12 +249,12 @@ exports.minifyJS = function(req, res, next) var pathStr; if(gzipSupport && os.type().indexOf("Windows") == -1) { - pathStr = path.normalize(rootPath + "var/minified_" + jsFilename + ".gz"); + pathStr = path.normalize(CACHE_DIR + "minified_" + jsFilename + ".gz"); res.header('Content-Encoding', 'gzip'); } else { - pathStr = path.normalize(rootPath + "var/minified_" + jsFilename ); + pathStr = path.normalize(CACHE_DIR + "minified_" + jsFilename ); } res.sendfile(pathStr, { maxAge: server.maxAge }); @@ -266,7 +268,7 @@ exports.minifyJS = function(req, res, next) //read all js files async.forEach(jsFiles, function (item, callback) { - fs.readFile(rootPath + "static/js/" + item, "utf-8", function(err, data) + fs.readFile(JS_DIR + item, "utf-8", function(err, data) { if(ERR(err, callback)) return; fileValues[item] = data; From b175ad562a20f71e713ba70d7b51a46675585dad Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Sun, 15 Jan 2012 17:33:53 -0800 Subject: [PATCH 04/24] Use uncompressed jQuery. The jQuery library does not need to be compressed; it is compressed as a consequence of being included in `pad.js`. --- .gitignore | 2 +- bin/installDeps.sh | 6 +++--- node/utils/tar.json | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 50cd6e21206..32f9ea7d761 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ node_modules settings.json -static/js/jquery.min.js +static/js/jquery.js APIKEY.txt bin/abiword.exe bin/node.exe diff --git a/bin/installDeps.sh b/bin/installDeps.sh index 0533caf2d85..a3f767a2481 100755 --- a/bin/installDeps.sh +++ b/bin/installDeps.sh @@ -48,8 +48,8 @@ npm install || { echo "Ensure jQuery is downloaded and up to date..." DOWNLOAD_JQUERY="true" NEEDED_VERSION="1.7" -if [ -f "static/js/jquery.min.js" ]; then - VERSION=$(cat static/js/jquery.min.js | head -n 3 | grep -o "v[0-9].[0-9]"); +if [ -f "static/js/jquery.js" ]; then + VERSION=$(cat static/js/jquery.js | head -n 3 | grep -o "v[0-9].[0-9]"); if [ ${VERSION#v} = $NEEDED_VERSION ]; then DOWNLOAD_JQUERY="false" @@ -57,7 +57,7 @@ if [ -f "static/js/jquery.min.js" ]; then fi if [ $DOWNLOAD_JQUERY = "true" ]; then - curl -lo static/js/jquery.min.js http://code.jquery.com/jquery-$NEEDED_VERSION.min.js || exit 1 + curl -lo static/js/jquery.js http://code.jquery.com/jquery-$NEEDED_VERSION.js || exit 1 fi #Remove all minified data to force node creating it new diff --git a/node/utils/tar.json b/node/utils/tar.json index 7cb60694314..3b1ba63ca46 100644 --- a/node/utils/tar.json +++ b/node/utils/tar.json @@ -1,6 +1,6 @@ { "pad.js": [ - "jquery.min.js" + "jquery.js" , "pad_utils.js" , "plugins.js" , "undo-xpopup.js" @@ -23,7 +23,7 @@ , "farbtastic.js" ] , "timeslider.js": [ - "jquery.min.js" + "jquery.js" , "plugins.js" , "undo-xpopup.js" , "json2.js" From 548c527aaf1ae58fb16c89695d42e78b146ba839 Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Mon, 16 Jan 2012 00:31:28 -0800 Subject: [PATCH 05/24] Move exposure of `Ace2Editor` closer to the code that requires it. --- static/js/ace.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/static/js/ace.js b/static/js/ace.js index 2bcf1241945..ffe00b07837 100644 --- a/static/js/ace.js +++ b/static/js/ace.js @@ -30,7 +30,6 @@ Ace2Editor.registry = { function Ace2Editor() { - var thisFunctionsName = "Ace2Editor"; var ace2 = Ace2Editor; var editor = {}; @@ -323,6 +322,10 @@ function Ace2Editor() iframeHTML.push(''); iframeHTML.push(' '); + // Expose myself to global for my child frame. + var thisFunctionsName = "ChildAccessibleAce2Editor"; + (function () {return this}())[thisFunctionsName] = Ace2Editor; + var outerScript = 'editorId = "' + info.id + '"; editorInfo = parent.' + thisFunctionsName + '.registry[editorId]; ' + 'window.onload = function() ' + '{ window.onload = null; setTimeout' + '(function() ' + '{ var iframe = document.createElement("IFRAME"); ' + 'iframe.scrolling = "no"; var outerdocbody = document.getElementById("outerdocbody"); ' + 'iframe.frameBorder = 0; iframe.allowTransparency = true; ' + // for IE 'outerdocbody.insertBefore(iframe, outerdocbody.firstChild); ' + 'iframe.ace_outerWin = window; ' + 'readyFunc = function() { editorInfo.onEditorReady(); readyFunc = null; editorInfo = null; }; ' + 'var doc = iframe.contentWindow.document; doc.open(); var text = (' + JSON.stringify(iframeHTML.join('\n')) + ');doc.write(text); doc.close(); ' + '}, 0); }'; From 50d304022dd0d068a8e29bd33f47b86df3fd52ce Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Sun, 15 Jan 2012 19:03:03 -0800 Subject: [PATCH 06/24] Change calculation of `userAgent`. Default to 'node-js' only if no user agent can be found the normal way. --- static/js/ace2_common.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/static/js/ace2_common.js b/static/js/ace2_common.js index 4561b919203..1414f855ab2 100644 --- a/static/js/ace2_common.js +++ b/static/js/ace2_common.js @@ -80,14 +80,8 @@ function isArray(testObject) return testObject && typeof testObject === 'object' && !(testObject.propertyIsEnumerable('length')) && typeof testObject.length === 'number'; } -if (typeof exports !== "undefined") -{ - userAgent = "node-js"; -} -else -{ - userAgent = navigator.userAgent.toLowerCase(); -} +var userAgent = (((function () {return this;})().navigator || {}).userAgent || 'node-js').toLowerCase(); + // Figure out what browser is being used (stolen from jquery 1.2.1) var browser = { version: (userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [])[1], From 0f7e6feda11a4c4c4ba0b9cca1a6bb895a6d3889 Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Sun, 15 Jan 2012 18:22:28 -0800 Subject: [PATCH 07/24] Remove individual settings in `pad2.js` from global. --- static/js/pad2.js | 40 +++++++++++++++++++++------------------- static/js/pad_editor.js | 6 +++--- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/static/js/pad2.js b/static/js/pad2.js index bbb385b3b9a..ca4ef53fcc5 100644 --- a/static/js/pad2.js +++ b/static/js/pad2.js @@ -23,12 +23,14 @@ /* global $, window */ var socket; -var LineNumbersDisabled = false; -var noColors = false; -var useMonospaceFontGlobal = false; -var globalUserName = false; -var hideQRCode = false; -var rtlIsTrue = false; + +var settings = {}; +settings.LineNumbersDisabled = false; +settings.noColors = false; +settings.useMonospaceFontGlobal = false; +settings.globalUserName = false; +settings.hideQRCode = false; +settings.rtlIsTrue = false; $(document).ready(function() { @@ -101,7 +103,7 @@ function getParams() { if(IsnoColors == "true") { - noColors = true; + settings.noColors = true; $('#clearAuthorship').hide(); } } @@ -124,20 +126,20 @@ function getParams() { if(showLineNumbers == "false") { - LineNumbersDisabled = true; + settings.LineNumbersDisabled = true; } } if(useMonospaceFont) { if(useMonospaceFont == "true") { - useMonospaceFontGlobal = true; + settings.useMonospaceFontGlobal = true; } } if(userName) { // If the username is set as a parameter we should set a global value that we can call once we have initiated the pad. - globalUserName = unescape(userName); + settings.globalUserName = unescape(userName); } if(hideQRCode) { @@ -147,7 +149,7 @@ function getParams() { if(rtl == "true") { - rtlIsTrue = true + settings.rtlIsTrue = true } } } @@ -298,33 +300,33 @@ function handshake() initalized = true; // If the LineNumbersDisabled value is set to true then we need to hide the Line Numbers - if (LineNumbersDisabled == true) + if (settings.LineNumbersDisabled == true) { pad.changeViewOption('showLineNumbers', false); } // If the noColors value is set to true then we need to hide the backround colors on the ace spans - if (noColors == true) + if (settings.noColors == true) { pad.changeViewOption('noColors', true); } - if (rtlIsTrue == true) + if (settings.rtlIsTrue == true) { pad.changeViewOption('rtl', true); } // If the Monospacefont value is set to true then change it to monospace. - if (useMonospaceFontGlobal == true) + if (settings.useMonospaceFontGlobal == true) { pad.changeViewOption('useMonospaceFont', true); } // if the globalUserName value is set we need to tell the server and the client about the new authorname - if (globalUserName !== false) + if (settings.globalUserName !== false) { - pad.notifyChangeName(globalUserName); // Notifies the server - pad.myUserInfo.name = globalUserName; - $('#myusernameedit').attr({"value":globalUserName}); // Updates the current users UI + pad.notifyChangeName(settings.globalUserName); // Notifies the server + pad.myUserInfo.name = settings.globalUserName; + $('#myusernameedit').attr({"value":settings.globalUserName}); // Updates the current users UI } } //This handles every Message after the clientVars diff --git a/static/js/pad_editor.js b/static/js/pad_editor.js index 183de948df0..6daf5e7de90 100644 --- a/static/js/pad_editor.js +++ b/static/js/pad_editor.js @@ -68,7 +68,7 @@ var padeditor = (function() pad.changeViewOption('useMonospaceFont', $("#viewfontmenu").val() == 'monospace'); }); - noColors = !noColors; // Inversed so we can pass it to showauthorcolors + settings.noColors = !settings.noColors; // Inversed so we can pass it to showauthorcolors }, setViewOptions: function(newOptions) { @@ -93,9 +93,9 @@ var padeditor = (function() self.ace.setProperty("textface", (v ? "monospace" : "Arial, sans-serif")); $("#viewfontmenu").val(v ? "monospace" : "normal"); - self.ace.setProperty("showsauthorcolors", noColors); + self.ace.setProperty("showsauthorcolors", settings.noColors); - self.ace.setProperty("rtlIsTrue", rtlIsTrue); + self.ace.setProperty("rtlIsTrue", settings.rtlIsTrue); }, initViewZoom: function() { From 6bbc32a19f7127b84e2383b151f4c963cc055117 Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Wed, 18 Jan 2012 00:28:55 -0800 Subject: [PATCH 08/24] Default plugin should not fail if clientVars is not defined. In the case that it is not defined, the configuration is `undefined`. --- static/js/plugins.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/static/js/plugins.js b/static/js/plugins.js index b29d01d4d6b..741934620c9 100644 --- a/static/js/plugins.js +++ b/static/js/plugins.js @@ -7,7 +7,8 @@ plugins = { callHook: function(hookName, args) { - var hook = clientVars.hooks[hookName]; + var global = (function () {return this}()); + var hook = ((global.clientVars || {}).hooks || {})[hookName]; if (hook === undefined) return []; var res = []; for (var i = 0, N = hook.length; i < N; i++) From 003c2a59aaecbcc6a0da3da6d956648496d6b41d Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Tue, 17 Jan 2012 00:43:11 -0800 Subject: [PATCH 09/24] Remove dependency on a global socket and address `pad.socket` instead. --- static/js/collab_client.js | 20 ++++++++++++++------ static/js/pad2.js | 4 ++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/static/js/collab_client.js b/static/js/collab_client.js index fafe0fd2f98..bb2351fc3cd 100644 --- a/static/js/collab_client.js +++ b/static/js/collab_client.js @@ -25,12 +25,20 @@ $(window).bind("load", function() getCollabClient.windowLoaded = true; }); +// Dependency fill on init. This exists for `pad.socket` only. +// TODO: bind directly to the socket. +var pad = undefined; +function getSocket() { + return pad && pad.socket; +} + /** Call this when the document is ready, and a new Ace2Editor() has been created and inited. ACE's ready callback does not need to have fired yet. "serverVars" are from calling doc.getCollabClientVars() on the server. */ -function getCollabClient(ace2editor, serverVars, initialUserInfo, options) +function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad) { var editor = ace2editor; + pad = _pad; // Inject pad to avoid a circular dependency. var rev = serverVars.rev; var padId = serverVars.padId; @@ -81,7 +89,7 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options) $(window).bind("unload", function() { - if (socket) + if (getSocket()) { setChannelState("DISCONNECTED", "unload"); } @@ -111,7 +119,7 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options) function handleUserChanges() { - if ((!socket) || channelState == "CONNECTING") + if ((!getSocket()) || channelState == "CONNECTING") { if (channelState == "CONNECTING" && (((+new Date()) - initialStartConnectTime) > 20000)) { @@ -295,7 +303,7 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options) function sendMessage(msg) { - socket.json.send( + getSocket().json.send( { type: "COLLABROOM", component: "pad", @@ -337,7 +345,7 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options) { if (window.console) console.log(evt); - if (!socket) return; + if (!getSocket()) return; if (!evt.data) return; var wrapper = evt; if (wrapper.type != "COLLABROOM") return; @@ -442,7 +450,7 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options) userInfo.userId = userId; userSet[userId] = userInfo; tellAceActiveAuthorInfo(userInfo); - if (!socket) return; + if (!getSocket()) return; sendMessage( { type: "USERINFO_UPDATE", diff --git a/static/js/pad2.js b/static/js/pad2.js index ca4ef53fcc5..5872b7a1122 100644 --- a/static/js/pad2.js +++ b/static/js/pad2.js @@ -185,7 +185,7 @@ function handshake() //find out in which subfolder we are var resource = loc.pathname.substr(1, loc.pathname.indexOf("/p/")) + "socket.io"; //connect - socket = io.connect(url, { + socket = pad.socket = io.connect(url, { resource: resource, 'max reconnection attempts': 3 }); @@ -474,7 +474,7 @@ var pad = { pad.collabClient = getCollabClient(padeditor.ace, clientVars.collab_client_vars, pad.myUserInfo, { colorPalette: pad.getColorPalette() - }); + }, pad); pad.collabClient.setOnUserJoin(pad.handleUserJoin); pad.collabClient.setOnUpdateUserInfo(pad.handleUserUpdate); pad.collabClient.setOnUserLeave(pad.handleUserLeave); From 2b5d7a0048c1b5718b9870eed059f77a9c513136 Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Sun, 15 Jan 2012 17:23:48 -0800 Subject: [PATCH 10/24] All files export their public interface if `exports` is available. --- static/js/ace.js | 4 ++++ static/js/ace2_common.js | 18 +++++++++++++++--- static/js/ace2_inner.js | 4 ++++ static/js/broadcast.js | 4 ++++ static/js/broadcast_revisions.js | 4 ++++ static/js/broadcast_slider.js | 4 ++++ static/js/changesettracker.js | 4 ++++ static/js/chat.js | 4 ++++ static/js/collab_client.js | 5 +++++ static/js/colorutils.js | 4 ++++ static/js/contentcollector.js | 5 +++++ static/js/cssmanager.js | 4 ++++ static/js/cssmanager_client.js | 4 ++++ static/js/domline.js | 4 ++++ static/js/domline_client.js | 4 ++++ static/js/draggable.js | 4 ++++ static/js/easysync2.js | 5 +++++ static/js/easysync2_client.js | 5 +++++ static/js/linestylefilter.js | 4 ++++ static/js/linestylefilter_client.js | 4 ++++ static/js/pad2.js | 13 +++++++++++++ static/js/pad_connectionstatus.js | 4 ++++ static/js/pad_cookie.js | 4 ++++ static/js/pad_docbar.js | 4 ++++ static/js/pad_editbar.js | 4 ++++ static/js/pad_editor.js | 4 ++++ static/js/pad_impexp.js | 4 ++++ static/js/pad_modals.js | 4 ++++ static/js/pad_savedrevs.js | 4 ++++ static/js/pad_userlist.js | 4 ++++ static/js/pad_utils.js | 4 ++++ static/js/plugins.js | 4 ++++ static/js/skiplist.js | 4 ++++ static/js/undomodule.js | 6 +++++- static/js/virtual_lines.js | 4 ++++ 35 files changed, 165 insertions(+), 4 deletions(-) diff --git a/static/js/ace.js b/static/js/ace.js index ffe00b07837..3f52d315f60 100644 --- a/static/js/ace.js +++ b/static/js/ace.js @@ -370,3 +370,7 @@ function Ace2Editor() return editor; } + +if (typeof exports !== 'undefined') { +exports.Ace2Editor = Ace2Editor; +} diff --git a/static/js/ace2_common.js b/static/js/ace2_common.js index 1414f855ab2..0918189c9aa 100644 --- a/static/js/ace2_common.js +++ b/static/js/ace2_common.js @@ -147,7 +147,19 @@ function htmlPrettyEscape(str) }).replace(/\r?\n/g, '\\n'); } -if (typeof exports !== "undefined") -{ - exports.map = map; +if (typeof exports !== 'undefined') { +exports.isNodeText = isNodeText; +exports.object = object; +exports.extend = extend; +exports.forEach = forEach; +exports.map = map; +exports.filter = filter; +exports.isArray = isArray; +exports.browser = browser; +exports.getAssoc = getAssoc; +exports.setAssoc = setAssoc; +exports.binarySearch = binarySearch; +exports.binarySearchInfinite = binarySearchInfinite; +exports.htmlPrettyEscape = htmlPrettyEscape; +exports.map = map; } diff --git a/static/js/ace2_inner.js b/static/js/ace2_inner.js index ec0d5dc45b2..ea6d7cbe2b4 100644 --- a/static/js/ace2_inner.js +++ b/static/js/ace2_inner.js @@ -5858,3 +5858,7 @@ function OUTER(gscope) }; OUTER(this); + +if (typeof exports !== 'undefined') { +exports.OUTER = OUTER; // This is probably unimportant. +} diff --git a/static/js/broadcast.js b/static/js/broadcast.js index 865574abdce..edfeef9c6d5 100644 --- a/static/js/broadcast.js +++ b/static/js/broadcast.js @@ -758,3 +758,7 @@ function loadBroadcastJS() receiveAuthorData(clientVars.historicalAuthorData); } + +if (typeof exports !== 'undefined') { +exports.loadBroadcastJS = loadBroadcastJS; +} diff --git a/static/js/broadcast_revisions.js b/static/js/broadcast_revisions.js index 33a2f9dfa7c..f60e58bb8d1 100644 --- a/static/js/broadcast_revisions.js +++ b/static/js/broadcast_revisions.js @@ -125,3 +125,7 @@ function loadBroadcastRevisionsJS() }; } } + +if (typeof exports !== 'undefined') { +exports.loadBroadcastRevisionsJS = loadBroadcastRevisionsJS; +} diff --git a/static/js/broadcast_slider.js b/static/js/broadcast_slider.js index af5a5041126..1d9f4928eb9 100644 --- a/static/js/broadcast_slider.js +++ b/static/js/broadcast_slider.js @@ -496,3 +496,7 @@ function loadBroadcastSliderJS() $("#viewlatest").html(loc == BroadcastSlider.getSliderLength() ? "Viewing latest content" : "View latest content"); }) } + +if (typeof exports !== 'undefined') { +exports.loadBroadcastSliderJS = loadBroadcastSliderJS; +} diff --git a/static/js/changesettracker.js b/static/js/changesettracker.js index cc7f6462326..60c73d3d53b 100644 --- a/static/js/changesettracker.js +++ b/static/js/changesettracker.js @@ -207,3 +207,7 @@ function makeChangesetTracker(scheduler, apool, aceCallbacksProvider) }; } + +if (typeof exports !== 'undefined') { +exports.makeChangesetTracker = makeChangesetTracker; +} diff --git a/static/js/chat.js b/static/js/chat.js index 71cd0c69d4f..1636ab690e1 100644 --- a/static/js/chat.js +++ b/static/js/chat.js @@ -172,3 +172,7 @@ var chat = (function() return self; }()); + +if (typeof exports !== 'undefined') { +exports.chat = chat; +} diff --git a/static/js/collab_client.js b/static/js/collab_client.js index bb2351fc3cd..3a40fba1746 100644 --- a/static/js/collab_client.js +++ b/static/js/collab_client.js @@ -722,3 +722,8 @@ function selectElementContents(elem) } } } + +if (typeof exports !== 'undefined') { +exports.getCollabClient = getCollabClient; +exports.selectElementContents = selectElementContents; +} diff --git a/static/js/colorutils.js b/static/js/colorutils.js index 92d8da7194c..1fc452b6a43 100644 --- a/static/js/colorutils.js +++ b/static/js/colorutils.js @@ -119,3 +119,7 @@ colorutils.blend = function(c1, c2, t) { return [colorutils.scale(t, c1[0], c2[0]), colorutils.scale(t, c1[1], c2[1]), colorutils.scale(t, c1[2], c2[2])]; } + +if (typeof exports !== 'undefined') { +exports.colorutils = colorutils; +} diff --git a/static/js/contentcollector.js b/static/js/contentcollector.js index 883ca09f0fc..e5a90586c61 100644 --- a/static/js/contentcollector.js +++ b/static/js/contentcollector.js @@ -692,3 +692,8 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class return cc; } + +if (typeof exports !== 'undefined') { +exports.sanitizeUnicode = sanitizeUnicode; +exports.makeContentCollector = makeContentCollector; +} diff --git a/static/js/cssmanager.js b/static/js/cssmanager.js index b8208b83fa7..1d45f302412 100644 --- a/static/js/cssmanager.js +++ b/static/js/cssmanager.js @@ -118,3 +118,7 @@ function makeCSSManager(emptyStylesheetTitle, top) } }; } + +if (typeof exports !== 'undefined') { +exports.makeCSSManager = makeCSSManager; +} diff --git a/static/js/cssmanager_client.js b/static/js/cssmanager_client.js index 60bf9f8c5a9..3db467e31a9 100644 --- a/static/js/cssmanager_client.js +++ b/static/js/cssmanager_client.js @@ -114,3 +114,7 @@ function makeCSSManager(emptyStylesheetTitle) } }; } + +if (typeof exports !== 'undefined') { +exports.makeCSSManager = makeCSSManager; +} diff --git a/static/js/domline.js b/static/js/domline.js index 84aeb4a817e..7ebf5b350c7 100644 --- a/static/js/domline.js +++ b/static/js/domline.js @@ -310,3 +310,7 @@ domline.processSpaces = function(s, doesWrap) } return parts.join(''); }; + +if (typeof exports !== 'undefined') { +exports.domline = domline; +} diff --git a/static/js/domline_client.js b/static/js/domline_client.js index 9f47dae54df..e995140f4fa 100644 --- a/static/js/domline_client.js +++ b/static/js/domline_client.js @@ -309,3 +309,7 @@ domline.processSpaces = function(s, doesWrap) } return parts.join(''); }; + +if (typeof exports !== 'undefined') { +exports.domline = domline; +} diff --git a/static/js/draggable.js b/static/js/draggable.js index 7bf523eb570..1d0ddb4c3f7 100644 --- a/static/js/draggable.js +++ b/static/js/draggable.js @@ -193,3 +193,7 @@ function makeResizableHPane(left, sep, right, minLeft, minRight, sepWidth, sepOf } }); } + +if (typeof exports !== 'undefined') { +exports.makeDraggable = makeDraggable; +} diff --git a/static/js/easysync2.js b/static/js/easysync2.js index 17ab585d983..81a416b2562 100644 --- a/static/js/easysync2.js +++ b/static/js/easysync2.js @@ -2508,3 +2508,8 @@ Changeset.followAttributes = function(att1, att2, pool) } return buf.toString(); }; + +if (typeof exports !== 'undefined') { +exports.Changeset = Changeset; +exports.AttribPool = AttribPool; +} diff --git a/static/js/easysync2_client.js b/static/js/easysync2_client.js index 3611da233f8..5745110e63c 100644 --- a/static/js/easysync2_client.js +++ b/static/js/easysync2_client.js @@ -2269,3 +2269,8 @@ Changeset.inverse = function(cs, lines, alines, pool) return Changeset.checkRep(builder.toString()); }; + +if (typeof exports !== 'undefined') { +exports.Changeset = Changeset; +exports.AttribPool = AttribPool; +} diff --git a/static/js/linestylefilter.js b/static/js/linestylefilter.js index 13a74618606..e990a68bc76 100644 --- a/static/js/linestylefilter.js +++ b/static/js/linestylefilter.js @@ -352,3 +352,7 @@ linestylefilter.populateDomLine = function(textLine, aline, apool, domLineObj) func = linestylefilter.getLineStyleFilter(text.length, aline, func, apool); func(text, ''); }; + +if (typeof exports !== 'undefined') { +exports.linestylefilter = linestylefilter; +} diff --git a/static/js/linestylefilter_client.js b/static/js/linestylefilter_client.js index 9fd2a3f8c8e..a4536490f74 100644 --- a/static/js/linestylefilter_client.js +++ b/static/js/linestylefilter_client.js @@ -350,3 +350,7 @@ linestylefilter.populateDomLine = function(textLine, aline, apool, domLineObj) func = linestylefilter.getLineStyleFilter(text.length, aline, func, apool); func(text, ''); }; + +if (typeof exports !== 'undefined') { +exports.linestylefilter = linestylefilter; +} diff --git a/static/js/pad2.js b/static/js/pad2.js index 5872b7a1122..8a2c33847e7 100644 --- a/static/js/pad2.js +++ b/static/js/pad2.js @@ -953,3 +953,16 @@ var alertBar = (function() }; return self; }()); + +if (typeof exports !== 'undefined') { +exports.settings = settings; +exports.createCookie = createCookie; +exports.readCookie = readCookie; +exports.randomString = randomString; +exports.getParams = getParams; +exports.getUrlVars = getUrlVars; +exports.savePassword = savePassword; +exports.handshake = handshake; +exports.pad = pad; +exports.alertBar = alertBar; +} diff --git a/static/js/pad_connectionstatus.js b/static/js/pad_connectionstatus.js index d35eb02d6a7..bec359c36de 100644 --- a/static/js/pad_connectionstatus.js +++ b/static/js/pad_connectionstatus.js @@ -85,3 +85,7 @@ var padconnectionstatus = (function() }; return self; }()); + +if (typeof exports !== 'undefined') { +exports.padconnectionstatus = padconnectionstatus; +} diff --git a/static/js/pad_cookie.js b/static/js/pad_cookie.js index 64211750d7e..d8eb464c7f5 100644 --- a/static/js/pad_cookie.js +++ b/static/js/pad_cookie.js @@ -126,3 +126,7 @@ var padcookie = (function() }; return self; }()); + +if (typeof exports !== 'undefined') { +exports.padcookie = padcookie; +} diff --git a/static/js/pad_docbar.js b/static/js/pad_docbar.js index c67ca55c44d..09315c7783b 100644 --- a/static/js/pad_docbar.js +++ b/static/js/pad_docbar.js @@ -456,3 +456,7 @@ var paddocbar = (function() }; return self; }()); + +if (typeof exports !== 'undefined') { +exports.paddocbar = paddocbar; +} diff --git a/static/js/pad_editbar.js b/static/js/pad_editbar.js index 6cd5163de73..6754e99c2b4 100644 --- a/static/js/pad_editbar.js +++ b/static/js/pad_editbar.js @@ -230,3 +230,7 @@ var padeditbar = (function() }; return self; }()); + +if (typeof exports !== 'undefined') { +exports.padeditbar = padeditbar; +} diff --git a/static/js/pad_editor.js b/static/js/pad_editor.js index 6daf5e7de90..929112bbf5b 100644 --- a/static/js/pad_editor.js +++ b/static/js/pad_editor.js @@ -150,3 +150,7 @@ var padeditor = (function() }; return self; }()); + +if (typeof exports !== 'undefined') { +exports.padeditor = padeditor; +} diff --git a/static/js/pad_impexp.js b/static/js/pad_impexp.js index 23b7134c049..638991a6450 100644 --- a/static/js/pad_impexp.js +++ b/static/js/pad_impexp.js @@ -325,3 +325,7 @@ var padimpexp = (function() }; return self; }()); + +if (typeof exports !== 'undefined') { +exports.padimpexp = padimpexp; +} diff --git a/static/js/pad_modals.js b/static/js/pad_modals.js index cf9d0435515..d5e7811b94d 100644 --- a/static/js/pad_modals.js +++ b/static/js/pad_modals.js @@ -364,3 +364,7 @@ var padmodals = (function() }; return self; }()); + +if (typeof exports !== 'undefined') { +exports.padmodals = padmodals; +} diff --git a/static/js/pad_savedrevs.js b/static/js/pad_savedrevs.js index 487e85f1a8a..7aadea71e44 100644 --- a/static/js/pad_savedrevs.js +++ b/static/js/pad_savedrevs.js @@ -518,3 +518,7 @@ var padsavedrevs = (function() }; return self; }()); + +if (typeof exports !== 'undefined') { +exports.padsavedrevs = padsavedrevs; +} diff --git a/static/js/pad_userlist.js b/static/js/pad_userlist.js index 748674916fc..96513225834 100644 --- a/static/js/pad_userlist.js +++ b/static/js/pad_userlist.js @@ -805,3 +805,7 @@ function showColorPicker() $($("#colorpickerswatches li")[myUserInfo.colorId]).addClass("picked"); //seems weird } } + +if (typeof exports !== 'undefined') { +exports.paduserlist = paduserlist; +} diff --git a/static/js/pad_utils.js b/static/js/pad_utils.js index 9083fa9b697..3c73aa069aa 100644 --- a/static/js/pad_utils.js +++ b/static/js/pad_utils.js @@ -486,3 +486,7 @@ window.onerror = function test (msg, url, linenumber) return false; }; + +if (typeof exports !== 'undefined') { +exports.padutils = padutils; +} diff --git a/static/js/plugins.js b/static/js/plugins.js index 741934620c9..2cf0e0e261e 100644 --- a/static/js/plugins.js +++ b/static/js/plugins.js @@ -31,3 +31,7 @@ plugins = { }).join(sep || ""); } }; + +if (typeof exports !== 'undefined') { +exports.plugins = plugins; +} diff --git a/static/js/skiplist.js b/static/js/skiplist.js index c9654be4636..995cd6bc75c 100644 --- a/static/js/skiplist.js +++ b/static/js/skiplist.js @@ -488,3 +488,7 @@ that is a string. } return self; } + +if (typeof exports !== 'undefined') { +exports.newSkipList = newSkipList; +} diff --git a/static/js/undomodule.js b/static/js/undomodule.js index 3891629aad3..a0073e19ed2 100644 --- a/static/js/undomodule.js +++ b/static/js/undomodule.js @@ -21,7 +21,7 @@ */ -undoModule = (function() +var undoModule = (function() { var stack = (function() { @@ -329,3 +329,7 @@ undoModule = (function() apool: null }; // apool is filled in by caller })(); + +if (typeof exports !== 'undefined') { +exports.undoModule = undoModule; +} diff --git a/static/js/virtual_lines.js b/static/js/virtual_lines.js index ece96b1498a..32fc588757d 100644 --- a/static/js/virtual_lines.js +++ b/static/js/virtual_lines.js @@ -384,3 +384,7 @@ function makeVirtualLineView(lineNode) } } + +if (typeof exports !== 'undefined') { +exports.makeVirtualLineView = makeVirtualLineView; +} From 9e16b9a575efa51f608f8096f1a8c0b390faece8 Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Tue, 17 Jan 2012 01:22:23 -0800 Subject: [PATCH 11/24] Always use the JS assets processed by Minify. This allows the preprocessing that will restrict scope of files to be done once in Minify. --- node/utils/Minify.js | 13 ++++++++++++- static/js/ace.js | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/node/utils/Minify.js b/node/utils/Minify.js index 1a214fb928b..d3c8831afae 100644 --- a/node/utils/Minify.js +++ b/node/utils/Minify.js @@ -52,10 +52,21 @@ exports.minifyJS = function(req, res, next) var jsFiles = undefined; if (Object.prototype.hasOwnProperty.call(tar, jsFilename)) { jsFiles = tar[jsFilename]; + _handle(req, res, jsFilename, jsFiles) } else { - return next(); + // Not in tar list, but try anyways, if it fails, pass to `next`. + jsFiles = [jsFilename]; + fs.stat(JS_DIR + jsFilename, function (error, stats) { + if (error || !stats.isFile()) { + next(); + } else { + _handle(req, res, jsFilename, jsFiles); + } + }); } +} +function _handle(req, res, jsFilename, jsFiles) { res.header("Content-Type","text/javascript"); //minifying is enabled diff --git a/static/js/ace.js b/static/js/ace.js index 3f52d315f60..4735aaae7d1 100644 --- a/static/js/ace.js +++ b/static/js/ace.js @@ -230,6 +230,7 @@ function Ace2Editor() } for (var i = 0, ii = remoteFiles.length; i < ii; i++) { var file = remoteFiles[i]; + file = file.replace(/^\.\.\/static\/js\//, '../minified/'); buffer.push(' + diff --git a/static/timeslider.html b/static/timeslider.html index c1310cc6cef..71b4443d211 100644 --- a/static/timeslider.html +++ b/static/timeslider.html @@ -19,6 +19,8 @@ // Date: Mon, 16 Jan 2012 00:37:48 -0800 Subject: [PATCH 15/24] Add missing dependency for `timeslider.js`. When dependencies are made explicity `pad_savedrevs.js` will be required by several of the `pad_*.js`. --- node/utils/tar.json | 1 + 1 file changed, 1 insertion(+) diff --git a/node/utils/tar.json b/node/utils/tar.json index 3b1ba63ca46..92883bb743c 100644 --- a/node/utils/tar.json +++ b/node/utils/tar.json @@ -35,6 +35,7 @@ , "pad_editbar.js" , "pad_docbar.js" , "pad_modals.js" + , "pad_savedrevs.js" , "pad_impexp.js" , "easysync2_client.js" , "domline_client.js" From 72d29b1c627d54453fe48a89b063631fec8e6859 Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Sun, 15 Jan 2012 21:05:19 -0800 Subject: [PATCH 16/24] Inject the pad dependency into chat. --- static/js/chat.js | 7 ++++--- static/js/pad2.js | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/static/js/chat.js b/static/js/chat.js index 1636ab690e1..a0d0d9ac265 100644 --- a/static/js/chat.js +++ b/static/js/chat.js @@ -82,13 +82,13 @@ var chat = (function() send: function() { var text = $("#chatinput").val(); - pad.collabClient.sendMessage({"type": "CHAT_MESSAGE", "text": text}); + this._pad.collabClient.sendMessage({"type": "CHAT_MESSAGE", "text": text}); $("#chatinput").val(""); }, addMessage: function(msg, increment) { //correct the time - msg.time += pad.clientTimeOffset; + msg.time += this._pad.clientTimeOffset; //create the time string var minutes = "" + new Date(msg.time).getMinutes(); @@ -150,8 +150,9 @@ var chat = (function() self.scrollDown(); }, - init: function() + init: function(pad) { + this._pad = pad; $("#chatinput").keypress(function(evt) { //if the user typed enter, fire the send diff --git a/static/js/pad2.js b/static/js/pad2.js index 8a2c33847e7..5f454172fbd 100644 --- a/static/js/pad2.js +++ b/static/js/pad2.js @@ -413,7 +413,7 @@ var pad = { pad.clientTimeOffset = new Date().getTime() - clientVars.serverTimestamp; //initialize the chat - chat.init(); + chat.init(this); pad.initTime = +(new Date()); pad.padOptions = clientVars.initialOptions; From 7f98116a435d0204f91100cb24bfb4f1f49f41d3 Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Sun, 15 Jan 2012 20:16:11 -0800 Subject: [PATCH 17/24] Implement `require` for most modules. --- static/js/ace2_inner.js | 29 +++++++++++++++++++++++++++++ static/js/broadcast.js | 6 ++++++ static/js/changesettracker.js | 2 ++ static/js/chat.js | 2 ++ static/js/collab_client.js | 2 ++ static/js/contentcollector.js | 2 ++ static/js/linestylefilter.js | 3 +++ static/js/linestylefilter_client.js | 3 +++ static/js/pad2.js | 3 +++ static/js/pad_editor.js | 1 + static/js/undomodule.js | 2 ++ 11 files changed, 55 insertions(+) diff --git a/static/js/ace2_inner.js b/static/js/ace2_inner.js index ea6d7cbe2b4..455958cd248 100644 --- a/static/js/ace2_inner.js +++ b/static/js/ace2_inner.js @@ -20,6 +20,35 @@ * limitations under the License. */ +var Ace2Common = require('/ace2_common'); +// Extract useful method defined in the other module. +var isNodeText = Ace2Common.isNodeText; +var object = Ace2Common.object; +var extend = Ace2Common.extend; +var forEach = Ace2Common.forEach; +var map = Ace2Common.map; +var filter = Ace2Common.filter; +var isArray = Ace2Common.isArray; +var browser = Ace2Common.browser; +var getAssoc = Ace2Common.getAssoc; +var setAssoc = Ace2Common.setAssoc; +var binarySearch = Ace2Common.binarySearch; +var binarySearchInfinite = Ace2Common.binarySearchInfinite; +var htmlPrettyEscape = Ace2Common.htmlPrettyEscape; +var map = Ace2Common.map; + +var makeChangesetTracker = require('/changesettracker').makeChangesetTracker; +var colorutils = require('/colorutils').colorutils; +var makeContentCollector = require('/contentcollector').makeContentCollector; +var makeCSSManager = require('/cssmanager').makeCSSManager; +var domline = require('/domline').domline; +var AttribPool = require('/easysync2').AttribPool; +var Changeset = require('/easysync2').Changeset; +var linestylefilter = require('/linestylefilter').linestylefilter; +var newSkipList = require('/skiplist').newSkipList; +var undoModule = require('/undomodule').undoModule; +var makeVirtualLineView = require('/virtual_lines').makeVirtualLineView; + function OUTER(gscope) { diff --git a/static/js/broadcast.js b/static/js/broadcast.js index edfeef9c6d5..f2aa048fbe0 100644 --- a/static/js/broadcast.js +++ b/static/js/broadcast.js @@ -22,6 +22,12 @@ var global = this; +var makeCSSManager = require('/cssmanager_client').makeCSSManager; +var domline = require('/domline_client').domline; +var Changeset = require('/easysync2_client').Changeset; +var AttribPool = require('/easysync2_client').AttribPool; +var linestylefilter = require('/linestylefilter_client').linestylefilter; + function loadBroadcastJS() { // just in case... (todo: this must be somewhere else in the client code.) diff --git a/static/js/changesettracker.js b/static/js/changesettracker.js index 60c73d3d53b..db3ab94460f 100644 --- a/static/js/changesettracker.js +++ b/static/js/changesettracker.js @@ -20,6 +20,8 @@ * limitations under the License. */ +var Changeset = require('/easysync2').Changeset; +var AttribPool = require('/easysync2').AttribPool; function makeChangesetTracker(scheduler, apool, aceCallbacksProvider) { diff --git a/static/js/chat.js b/static/js/chat.js index a0d0d9ac265..b4d15f4e583 100644 --- a/static/js/chat.js +++ b/static/js/chat.js @@ -20,6 +20,8 @@ * limitations under the License. */ +var padutils = require('/pad_utils').padutils; + var chat = (function() { var bottomMargin = "0px"; diff --git a/static/js/collab_client.js b/static/js/collab_client.js index 3a40fba1746..1f4e21dc88b 100644 --- a/static/js/collab_client.js +++ b/static/js/collab_client.js @@ -25,6 +25,8 @@ $(window).bind("load", function() getCollabClient.windowLoaded = true; }); +var chat = require('/chat').chat; + // Dependency fill on init. This exists for `pad.socket` only. // TODO: bind directly to the socket. var pad = undefined; diff --git a/static/js/contentcollector.js b/static/js/contentcollector.js index e5a90586c61..d69d813d8a0 100644 --- a/static/js/contentcollector.js +++ b/static/js/contentcollector.js @@ -25,6 +25,8 @@ var _MAX_LIST_LEVEL = 8; +var Changeset = require('/easysync2').Changeset + function sanitizeUnicode(s) { return s.replace(/[\uffff\ufffe\ufeff\ufdd0-\ufdef\ud800-\udfff]/g, '?'); diff --git a/static/js/linestylefilter.js b/static/js/linestylefilter.js index e990a68bc76..5d831ae80a1 100644 --- a/static/js/linestylefilter.js +++ b/static/js/linestylefilter.js @@ -27,6 +27,9 @@ // requires: top // requires: plugins // requires: undefined + +var Changeset = require('/easysync2').Changeset + var linestylefilter = {}; linestylefilter.ATTRIB_CLASSES = { diff --git a/static/js/linestylefilter_client.js b/static/js/linestylefilter_client.js index a4536490f74..b9203c9fd6b 100644 --- a/static/js/linestylefilter_client.js +++ b/static/js/linestylefilter_client.js @@ -25,6 +25,9 @@ // requires: top // requires: plugins // requires: undefined + +var Changeset = require('/easysync2_client').Changeset + var linestylefilter = {}; linestylefilter.ATTRIB_CLASSES = { diff --git a/static/js/pad2.js b/static/js/pad2.js index 5f454172fbd..3964dae6bb8 100644 --- a/static/js/pad2.js +++ b/static/js/pad2.js @@ -32,6 +32,9 @@ settings.globalUserName = false; settings.hideQRCode = false; settings.rtlIsTrue = false; +var chat = require('/chat').chat; +var getCollabClient = require('/collab_client').getCollabClient; + $(document).ready(function() { //start the costum js diff --git a/static/js/pad_editor.js b/static/js/pad_editor.js index 929112bbf5b..5fc067cb285 100644 --- a/static/js/pad_editor.js +++ b/static/js/pad_editor.js @@ -20,6 +20,7 @@ * limitations under the License. */ +var Ace2Editor = require('/ace').Ace2Editor; var padeditor = (function() { diff --git a/static/js/undomodule.js b/static/js/undomodule.js index a0073e19ed2..b515180d423 100644 --- a/static/js/undomodule.js +++ b/static/js/undomodule.js @@ -20,6 +20,8 @@ * limitations under the License. */ +var Changeset = require('/easysync2').Changeset; +var extend = require('/ace2_common').extend; var undoModule = (function() { From fa2a6e9ee690eef161b5e286e3d21fb186283f1d Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Sun, 15 Jan 2012 21:37:47 -0800 Subject: [PATCH 18/24] Implement `require` of dependencies for all `pad_*` modules. Create a lazily-defined local reference for pad on initialization in each pad module in order to avoid circular dependency. At some point in the future this dependency should instead be injected into each module on initialization. --- static/js/pad2.js | 14 ++++++++++++-- static/js/pad_connectionstatus.js | 2 ++ static/js/pad_cookie.js | 3 +++ static/js/pad_docbar.js | 6 ++++++ static/js/pad_editbar.js | 4 ++++ static/js/pad_editor.js | 9 ++++++++- static/js/pad_impexp.js | 8 ++++++++ static/js/pad_modals.js | 6 ++++++ static/js/pad_savedrevs.js | 6 +++++- static/js/pad_userlist.js | 7 ++++++- static/js/pad_utils.js | 2 ++ 11 files changed, 62 insertions(+), 5 deletions(-) diff --git a/static/js/pad2.js b/static/js/pad2.js index 3964dae6bb8..5369d422a4e 100644 --- a/static/js/pad2.js +++ b/static/js/pad2.js @@ -34,6 +34,16 @@ settings.rtlIsTrue = false; var chat = require('/chat').chat; var getCollabClient = require('/collab_client').getCollabClient; +var padconnectionstatus = require('/pad_connectionstatus').padconnectionstatus; +var padcookie = require('/pad_cookie').padcookie; +var paddocbar = require('/pad_docbar').paddocbar; +var padeditbar = require('/pad_editbar').padeditbar; +var padeditor = require('/pad_editor').padeditor; +var padimpexp = require('/pad_impexp').padimpexp; +var padmodals = require('/pad_modals').padmodals; +var padsavedrevs = require('/pad_savedrevs').padsavedrevs; +var paduserlist = require('/pad_userlist').paduserlist; +var padutils = require('/pad_utils').padutils; $(document).ready(function() { @@ -275,13 +285,13 @@ function handshake() { $("#editorloadingbox").html("You need a password to access this pad
" + ""+ - ""); + ""); } else if(obj.accessStatus == "wrongPassword") { $("#editorloadingbox").html("You're password was wrong
" + ""+ - ""); + ""); } } diff --git a/static/js/pad_connectionstatus.js b/static/js/pad_connectionstatus.js index bec359c36de..d3a7648cb29 100644 --- a/static/js/pad_connectionstatus.js +++ b/static/js/pad_connectionstatus.js @@ -20,6 +20,8 @@ * limitations under the License. */ +var padmodals = require('/pad_modals').padmodals; + var padconnectionstatus = (function() { diff --git a/static/js/pad_cookie.js b/static/js/pad_cookie.js index d8eb464c7f5..00dc28f39b3 100644 --- a/static/js/pad_cookie.js +++ b/static/js/pad_cookie.js @@ -85,9 +85,12 @@ var padcookie = (function() var alreadyWarnedAboutNoCookies = false; var inited = false; + var pad = undefined; var self = { init: function(prefsToSet) { + pad = require('/pad2').pad; // Sidestep circular dependency (should be injected). + var rawCookie = getRawCookie(); if (rawCookie) { diff --git a/static/js/pad_docbar.js b/static/js/pad_docbar.js index 09315c7783b..2bf1a1da07d 100644 --- a/static/js/pad_docbar.js +++ b/static/js/pad_docbar.js @@ -20,6 +20,7 @@ * limitations under the License. */ +var padutils = require('/pad_utils').padutils; var paddocbar = (function() { @@ -113,11 +114,14 @@ var paddocbar = (function() self.renderPassword(); } + var pad = undefined; var self = { title: null, password: null, init: function(opts) { + pad = require('/pad2').pad; // Sidestep circular dependency (should be injected). + panels = { impexp: { animator: getPanelOpenCloseAnimator("impexp", 160) @@ -444,6 +448,8 @@ var paddocbar = (function() }, handleResizePage: function() { + // Side-step circular reference. This should be injected. + var padsavedrevs = require('/pad_savedrevs').padsavedrevs; padsavedrevs.handleResizePage(); }, hideLaterIfNoOtherInteraction: function() diff --git a/static/js/pad_editbar.js b/static/js/pad_editbar.js index 6754e99c2b4..77420894084 100644 --- a/static/js/pad_editbar.js +++ b/static/js/pad_editbar.js @@ -20,6 +20,10 @@ * limitations under the License. */ +var padutils = require('/pad_utils').padutils; +var padeditor = require('/pad_editor').padeditor; +var padsavedrevs = require('/pad_savedrevs').padsavedrevs; + var padeditbar = (function() { diff --git a/static/js/pad_editor.js b/static/js/pad_editor.js index 5fc067cb285..45a90f00695 100644 --- a/static/js/pad_editor.js +++ b/static/js/pad_editor.js @@ -20,16 +20,23 @@ * limitations under the License. */ -var Ace2Editor = require('/ace').Ace2Editor; +var padcookie = require('/pad_cookie').padcookie; +var padutils = require('/pad_utils').padutils; var padeditor = (function() { + var Ace2Editor = undefined; + var pad = undefined; + var settings = undefined; var self = { ace: null, // this is accessed directly from other files viewZoom: 100, init: function(readyFunc, initialViewOptions) { + Ace2Editor = require('/ace').Ace2Editor; + pad = require('/pad2').pad; // Sidestep circular dependency (should be injected). + settings = require('/pad2').settings; function aceReady() { diff --git a/static/js/pad_impexp.js b/static/js/pad_impexp.js index 638991a6450..8f187a5cb57 100644 --- a/static/js/pad_impexp.js +++ b/static/js/pad_impexp.js @@ -20,6 +20,7 @@ * limitations under the License. */ +var paddocbar = require('/pad_docbar').paddocbar; var padimpexp = (function() { @@ -233,9 +234,16 @@ var padimpexp = (function() } ///// + var pad = undefined; var self = { init: function() { + try { + pad = require('/pad2').pad; // Sidestep circular dependency (should be injected). + } catch (e) { + // skip (doesn't require pad when required by timeslider) + } + //get /p/padname var pad_root_path = new RegExp(/.*\/p\/[^\/]+/).exec(document.location.pathname) //get http://example.com/p/padname diff --git a/static/js/pad_modals.js b/static/js/pad_modals.js index d5e7811b94d..9d24c5f1a48 100644 --- a/static/js/pad_modals.js +++ b/static/js/pad_modals.js @@ -20,6 +20,9 @@ * limitations under the License. */ +var padutils = require('/pad_utils').padutils; +var paddocbar = require('/pad_docbar').paddocbar; + var padmodals = (function() { @@ -70,9 +73,12 @@ var padmodals = (function() clearShareBoxTo(); } + var pad = undefined; var self = { init: function() { + pad = require('/pad2').pad; // Sidestep circular dependency (should be injected). + self.initFeedback(); self.initShareBox(); }, diff --git a/static/js/pad_savedrevs.js b/static/js/pad_savedrevs.js index 7aadea71e44..964c83386b0 100644 --- a/static/js/pad_savedrevs.js +++ b/static/js/pad_savedrevs.js @@ -20,6 +20,8 @@ * limitations under the License. */ +var padutils = require('/pad_utils').padutils; +var paddocbar = require('/pad_docbar').paddocbar; var padsavedrevs = (function() { @@ -39,7 +41,7 @@ var padsavedrevs = (function() box.find(".srauthor").html("by " + padutils.escapeHtml(revisionInfo.savedBy)); var viewLink = '/ep/pad/view/' + pad.getPadId() + '/' + revisionInfo.id; box.find(".srview").attr('href', viewLink); - var restoreLink = 'javascript:void padsavedrevs.restoreRevision(' + rnum + ');'; + var restoreLink = 'javascript:void(require('+JSON.stringify(module.id)+').padsavedrevs.restoreRevision(' + JSON.stringify(rnum) + ');'; box.find(".srrestore").attr('href', restoreLink); box.find(".srname").click(function(evt) { @@ -345,9 +347,11 @@ var padsavedrevs = (function() $(document).unbind('mouseup', clearScrollRepeatTimer); } + var pad = undefined; var self = { init: function(initialRevisions) { + pad = require('/pad2').pad; // Sidestep circular dependency (should be injected). self.newRevisionList(initialRevisions, true); $("#savedrevs-savenow").click(function() diff --git a/static/js/pad_userlist.js b/static/js/pad_userlist.js index 96513225834..b9d08932e51 100644 --- a/static/js/pad_userlist.js +++ b/static/js/pad_userlist.js @@ -20,6 +20,8 @@ * limitations under the License. */ +var padutils = require('/pad_utils').padutils; + var myUserInfo = {}; var colorPickerOpen = false; @@ -460,9 +462,12 @@ var paduserlist = (function() return true; }, 1000); + var pad = undefined; var self = { init: function(myInitialUserInfo) { + pad = require('/pad2').pad; // Sidestep circular dependency (should be injected). + self.setMyUserInfo(myInitialUserInfo); $("#otheruserstable tr").remove(); @@ -652,7 +657,7 @@ var paduserlist = (function() if (box.length == 0) { // make guest prompt box - box = $('
Guest: ' + padutils.escapeHtml(displayName) + '
'); + box = $('
Guest: ' + padutils.escapeHtml(displayName) + '
'); $("#guestprompts").append(box); } else diff --git a/static/js/pad_utils.js b/static/js/pad_utils.js index 3c73aa069aa..30ff308c01c 100644 --- a/static/js/pad_utils.js +++ b/static/js/pad_utils.js @@ -34,6 +34,7 @@ var padutils = { }, uniqueId: function() { + var pad = require('/pad2').pad; // Sidestep circular dependency function encodeNum(n, width) { // returns string that is exactly 'width' chars, padding with zeros @@ -226,6 +227,7 @@ var padutils = { }, timediff: function(d) { + var pad = require('/pad2').pad; // Sidestep circular dependency function format(n, word) { n = Math.round(n); From 86f31c752d60957768bff7a684c156277d74e2cf Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Sun, 15 Jan 2012 21:52:03 -0800 Subject: [PATCH 19/24] Implement `require` for for plugin module. --- static/js/ace.js | 2 ++ static/js/contentcollector.js | 6 ++++++ static/js/domline.js | 8 ++++++++ static/js/domline_client.js | 8 ++++++++ static/js/linestylefilter.js | 6 ++++++ static/js/linestylefilter_client.js | 6 ++++++ 6 files changed, 36 insertions(+) diff --git a/static/js/ace.js b/static/js/ace.js index 4735aaae7d1..78a79d7ecdf 100644 --- a/static/js/ace.js +++ b/static/js/ace.js @@ -28,6 +28,8 @@ Ace2Editor.registry = { nextId: 1 }; +var plugins = require('/plugins').plugins; + function Ace2Editor() { var ace2 = Ace2Editor; diff --git a/static/js/contentcollector.js b/static/js/contentcollector.js index d69d813d8a0..5f78a3f249c 100644 --- a/static/js/contentcollector.js +++ b/static/js/contentcollector.js @@ -26,6 +26,12 @@ var _MAX_LIST_LEVEL = 8; var Changeset = require('/easysync2').Changeset +var plugins = undefined; +try { + plugins = require('/plugins').plugins; +} catch (e) { + // silence +} function sanitizeUnicode(s) { diff --git a/static/js/domline.js b/static/js/domline.js index 7ebf5b350c7..2d891392876 100644 --- a/static/js/domline.js +++ b/static/js/domline.js @@ -25,6 +25,14 @@ // requires: top // requires: plugins // requires: undefined + +var plugins = undefined; +try { + plugins = require('/plugins').plugins; +} catch (e) { + // silence +} + var domline = {}; domline.noop = function() {}; diff --git a/static/js/domline_client.js b/static/js/domline_client.js index e995140f4fa..6a09a1723e1 100644 --- a/static/js/domline_client.js +++ b/static/js/domline_client.js @@ -24,6 +24,14 @@ // requires: top // requires: plugins // requires: undefined + +var plugins = undefined; +try { + plugins = require('/plugins').plugins; +} catch (e) { + // silence +} + var domline = {}; domline.noop = function() {}; diff --git a/static/js/linestylefilter.js b/static/js/linestylefilter.js index 5d831ae80a1..9558ed71bd8 100644 --- a/static/js/linestylefilter.js +++ b/static/js/linestylefilter.js @@ -29,6 +29,12 @@ // requires: undefined var Changeset = require('/easysync2').Changeset +var plugins = undefined; +try { + plugins = require('/plugins').plugins; +} catch (e) { + // silence +} var linestylefilter = {}; diff --git a/static/js/linestylefilter_client.js b/static/js/linestylefilter_client.js index b9203c9fd6b..9b1cb83dcaa 100644 --- a/static/js/linestylefilter_client.js +++ b/static/js/linestylefilter_client.js @@ -27,6 +27,12 @@ // requires: undefined var Changeset = require('/easysync2_client').Changeset +var plugins = undefined; +try { + plugins = require('/plugins').plugins; +} catch (e) { + // silence +} var linestylefilter = {}; From 1b89e7e2903877487ee72b8df39f07b4ed1d8a36 Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Mon, 16 Jan 2012 02:10:34 -0800 Subject: [PATCH 20/24] Implement `require` in HTML pages. --- static/pad.html | 8 ++++++++ static/timeslider.html | 10 +++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/static/pad.html b/static/pad.html index 33df2d4f3eb..fba52b782c0 100644 --- a/static/pad.html +++ b/static/pad.html @@ -340,5 +340,13 @@

No Authorization.

+ + diff --git a/static/timeslider.html b/static/timeslider.html index 71b4443d211..a416562e8c0 100644 --- a/static/timeslider.html +++ b/static/timeslider.html @@ -21,6 +21,10 @@ var require = (function (path) {return (function () {return this}())}); + /* TODO: These globals shouldn't exist. */ + padeditbar = require('/pad_editbar').padeditbar; + padimpexp = require('/pad_impexp').padimpexp; + function createCookie(name,value,days) { if (days) { @@ -143,9 +147,9 @@ clientVars = message.data; //load all script that doesn't work without the clientVars - loadBroadcastSliderJS(); - loadBroadcastRevisionsJS(); - loadBroadcastJS(); + require('/broadcast_slider').loadBroadcastSliderJS(); + require('/broadcast_revisions').loadBroadcastRevisionsJS(); + require('/broadcast').loadBroadcastJS(); //initialize export ui padimpexp.init(); From 8bf0e7c2aaa457b991955650e1e32e1f0e5357bc Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Sun, 15 Jan 2012 22:53:44 -0800 Subject: [PATCH 21/24] Allow dashes in included file names. --- 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 12efc547aa0..8b198f3e1dc 100644 --- a/node/utils/Minify.js +++ b/node/utils/Minify.js @@ -162,7 +162,7 @@ function _handle(req, res, jsFilename, jsFiles) { return; } - var founds = fileValues["ace.js"].match(/\$\$INCLUDE_[a-zA-Z_]+\([a-zA-Z0-9.\/_"]+\)/gi); + 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) From 71dfced06de716dcc24cdc933ee02bdb4e75d535 Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Sun, 15 Jan 2012 22:56:41 -0800 Subject: [PATCH 22/24] Provide filename to isolation function. --- node/utils/Minify.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/node/utils/Minify.js b/node/utils/Minify.js index 8b198f3e1dc..016739b1adb 100644 --- a/node/utils/Minify.js +++ b/node/utils/Minify.js @@ -179,7 +179,8 @@ function _handle(req, res, jsFilename, jsFiles) { if(type == "JS") { - embeds[filename] = compressJS([isolateJS(data)]); + var shortFilename = filename.replace(/^..\/static\/js\//, ''); + embeds[filename] = compressJS([isolateJS(data, shortFilename)]); } else { @@ -297,14 +298,14 @@ 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])); + write(isolateJS(files[filename], filename)); } } // 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) { +function isolateJS(code, filename) { return '(function (exports, require) {' + code + '\n' + '}(function () {return this}(), (function (path) {return (function () {return this}())})));\n'; From 62e0a8f26c3dea9d46818dd5ae9599cf375ad91e Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Sun, 15 Jan 2012 22:07:45 -0800 Subject: [PATCH 23/24] Use require-kernel for require functionality. --- node/server.js | 8 ++++++++ node/utils/Minify.js | 40 ++++++++++++++++++++++++++++++++-------- package.json | 1 + static/js/ace.js | 35 ++++++++++++++++++++++++++--------- static/pad.html | 4 +--- static/timeslider.html | 3 +-- 6 files changed, 69 insertions(+), 22 deletions(-) diff --git a/node/server.js b/node/server.js index 422bbe12086..c0d6ce6ad8c 100644 --- a/node/server.js +++ b/node/server.js @@ -114,7 +114,15 @@ 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"); + res.write(minify.requireDefinition()); + res.end(); + }); app.get('/static/*', function(req, res) { var filePath = path.normalize(__dirname + "/.." + diff --git a/node/utils/Minify.js b/node/utils/Minify.js index 016739b1adb..348f25373cf 100644 --- a/node/utils/Minify.js +++ b/node/utils/Minify.js @@ -29,6 +29,7 @@ var pro = require("uglify-js").uglify; var path = require('path'); var Buffer = require('buffer').Buffer; var gzip = require('gzip'); +var RequireKernel = require('require-kernel'); var server = require('../server'); var os = require('os'); @@ -173,22 +174,31 @@ function _handle(req, res, jsFilename, jsFiles) { var type = item.match(/INCLUDE_[A-Z]+/g)[0].substr("INCLUDE_".length); //read the included file - fs.readFile(ROOT_DIR + filename, "utf-8", function(err, data) + 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") { - var shortFilename = filename.replace(/^..\/static\/js\//, ''); - embeds[filename] = compressJS([isolateJS(data, shortFilename)]); + 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; @@ -294,21 +304,35 @@ function _handle(req, res, jsFilename, jsFiles) { } } +exports.requireDefinition = requireDefinition; +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)); } + + for(var i = 0, ii = filesInOrder.length; i < filesInOrder.length; i++) { + var filename = filesInOrder[i]; + write('require(' + JSON.stringify('/' + filename.replace(/^\/+/, '')) + ');\n'); + } } // 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) { - return '(function (exports, require) {' - + code + '\n' - + '}(function () {return this}(), (function (path) {return (function () {return this}())})));\n'; + 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 compressJS(values) diff --git a/package.json b/package.json index efc89fd7a3f..6567e5324d4 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "name": "Robin Buse" } ], "dependencies" : { + "require-kernel" : "1.0.0", "socket.io" : "0.8.7", "ueberDB" : "0.1.3", "async" : "0.1.15", diff --git a/static/js/ace.js b/static/js/ace.js index 78a79d7ecdf..8ecfbc0cb68 100644 --- a/static/js/ace.js +++ b/static/js/ace.js @@ -216,25 +216,41 @@ 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(' + - diff --git a/static/timeslider.html b/static/timeslider.html index a416562e8c0..4e85047e3b4 100644 --- a/static/timeslider.html +++ b/static/timeslider.html @@ -9,6 +9,7 @@ + @@ -19,8 +20,6 @@ // Date: Mon, 16 Jan 2012 00:47:10 -0800 Subject: [PATCH 24/24] Remove guards surrounding export steps. --- static/js/ace.js | 2 -- static/js/ace2_common.js | 2 -- static/js/ace2_inner.js | 2 -- static/js/broadcast.js | 2 -- static/js/broadcast_revisions.js | 2 -- static/js/broadcast_slider.js | 2 -- static/js/changesettracker.js | 2 -- static/js/chat.js | 2 -- static/js/collab_client.js | 2 -- static/js/colorutils.js | 2 -- static/js/contentcollector.js | 2 -- static/js/cssmanager.js | 2 -- static/js/cssmanager_client.js | 2 -- static/js/domline.js | 2 -- static/js/domline_client.js | 2 -- static/js/draggable.js | 2 -- static/js/easysync2.js | 2 -- static/js/easysync2_client.js | 2 -- static/js/linestylefilter.js | 2 -- static/js/linestylefilter_client.js | 2 -- static/js/pad2.js | 2 -- static/js/pad_connectionstatus.js | 2 -- static/js/pad_cookie.js | 2 -- static/js/pad_docbar.js | 2 -- static/js/pad_editbar.js | 2 -- static/js/pad_editor.js | 2 -- static/js/pad_impexp.js | 2 -- static/js/pad_modals.js | 2 -- static/js/pad_savedrevs.js | 2 -- static/js/pad_userlist.js | 2 -- static/js/pad_utils.js | 2 -- static/js/plugins.js | 2 -- static/js/skiplist.js | 2 -- static/js/undomodule.js | 2 -- static/js/virtual_lines.js | 2 -- 35 files changed, 70 deletions(-) diff --git a/static/js/ace.js b/static/js/ace.js index 8ecfbc0cb68..6854b114275 100644 --- a/static/js/ace.js +++ b/static/js/ace.js @@ -391,6 +391,4 @@ function Ace2Editor() return editor; } -if (typeof exports !== 'undefined') { exports.Ace2Editor = Ace2Editor; -} diff --git a/static/js/ace2_common.js b/static/js/ace2_common.js index 0918189c9aa..1ce7810aa72 100644 --- a/static/js/ace2_common.js +++ b/static/js/ace2_common.js @@ -147,7 +147,6 @@ function htmlPrettyEscape(str) }).replace(/\r?\n/g, '\\n'); } -if (typeof exports !== 'undefined') { exports.isNodeText = isNodeText; exports.object = object; exports.extend = extend; @@ -162,4 +161,3 @@ exports.binarySearch = binarySearch; exports.binarySearchInfinite = binarySearchInfinite; exports.htmlPrettyEscape = htmlPrettyEscape; exports.map = map; -} diff --git a/static/js/ace2_inner.js b/static/js/ace2_inner.js index 455958cd248..e97847721ef 100644 --- a/static/js/ace2_inner.js +++ b/static/js/ace2_inner.js @@ -5888,6 +5888,4 @@ function OUTER(gscope) OUTER(this); -if (typeof exports !== 'undefined') { exports.OUTER = OUTER; // This is probably unimportant. -} diff --git a/static/js/broadcast.js b/static/js/broadcast.js index f2aa048fbe0..b49b185a503 100644 --- a/static/js/broadcast.js +++ b/static/js/broadcast.js @@ -765,6 +765,4 @@ function loadBroadcastJS() receiveAuthorData(clientVars.historicalAuthorData); } -if (typeof exports !== 'undefined') { exports.loadBroadcastJS = loadBroadcastJS; -} diff --git a/static/js/broadcast_revisions.js b/static/js/broadcast_revisions.js index f60e58bb8d1..364ac3e8cc0 100644 --- a/static/js/broadcast_revisions.js +++ b/static/js/broadcast_revisions.js @@ -126,6 +126,4 @@ function loadBroadcastRevisionsJS() } } -if (typeof exports !== 'undefined') { exports.loadBroadcastRevisionsJS = loadBroadcastRevisionsJS; -} diff --git a/static/js/broadcast_slider.js b/static/js/broadcast_slider.js index 1d9f4928eb9..972190acbc1 100644 --- a/static/js/broadcast_slider.js +++ b/static/js/broadcast_slider.js @@ -497,6 +497,4 @@ function loadBroadcastSliderJS() }) } -if (typeof exports !== 'undefined') { exports.loadBroadcastSliderJS = loadBroadcastSliderJS; -} diff --git a/static/js/changesettracker.js b/static/js/changesettracker.js index db3ab94460f..7b0fb3e4602 100644 --- a/static/js/changesettracker.js +++ b/static/js/changesettracker.js @@ -210,6 +210,4 @@ function makeChangesetTracker(scheduler, apool, aceCallbacksProvider) } -if (typeof exports !== 'undefined') { exports.makeChangesetTracker = makeChangesetTracker; -} diff --git a/static/js/chat.js b/static/js/chat.js index b4d15f4e583..475d0193946 100644 --- a/static/js/chat.js +++ b/static/js/chat.js @@ -176,6 +176,4 @@ var chat = (function() return self; }()); -if (typeof exports !== 'undefined') { exports.chat = chat; -} diff --git a/static/js/collab_client.js b/static/js/collab_client.js index 1f4e21dc88b..b697d485324 100644 --- a/static/js/collab_client.js +++ b/static/js/collab_client.js @@ -725,7 +725,5 @@ function selectElementContents(elem) } } -if (typeof exports !== 'undefined') { exports.getCollabClient = getCollabClient; exports.selectElementContents = selectElementContents; -} diff --git a/static/js/colorutils.js b/static/js/colorutils.js index 1fc452b6a43..9bba39ad2a2 100644 --- a/static/js/colorutils.js +++ b/static/js/colorutils.js @@ -120,6 +120,4 @@ colorutils.blend = function(c1, c2, t) return [colorutils.scale(t, c1[0], c2[0]), colorutils.scale(t, c1[1], c2[1]), colorutils.scale(t, c1[2], c2[2])]; } -if (typeof exports !== 'undefined') { exports.colorutils = colorutils; -} diff --git a/static/js/contentcollector.js b/static/js/contentcollector.js index 5f78a3f249c..fd90a07be60 100644 --- a/static/js/contentcollector.js +++ b/static/js/contentcollector.js @@ -701,7 +701,5 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class return cc; } -if (typeof exports !== 'undefined') { exports.sanitizeUnicode = sanitizeUnicode; exports.makeContentCollector = makeContentCollector; -} diff --git a/static/js/cssmanager.js b/static/js/cssmanager.js index 1d45f302412..46075e57838 100644 --- a/static/js/cssmanager.js +++ b/static/js/cssmanager.js @@ -119,6 +119,4 @@ function makeCSSManager(emptyStylesheetTitle, top) }; } -if (typeof exports !== 'undefined') { exports.makeCSSManager = makeCSSManager; -} diff --git a/static/js/cssmanager_client.js b/static/js/cssmanager_client.js index 3db467e31a9..6d9d989e857 100644 --- a/static/js/cssmanager_client.js +++ b/static/js/cssmanager_client.js @@ -115,6 +115,4 @@ function makeCSSManager(emptyStylesheetTitle) }; } -if (typeof exports !== 'undefined') { exports.makeCSSManager = makeCSSManager; -} diff --git a/static/js/domline.js b/static/js/domline.js index 2d891392876..5de33c5aae6 100644 --- a/static/js/domline.js +++ b/static/js/domline.js @@ -319,6 +319,4 @@ domline.processSpaces = function(s, doesWrap) return parts.join(''); }; -if (typeof exports !== 'undefined') { exports.domline = domline; -} diff --git a/static/js/domline_client.js b/static/js/domline_client.js index 6a09a1723e1..b999e3589c2 100644 --- a/static/js/domline_client.js +++ b/static/js/domline_client.js @@ -318,6 +318,4 @@ domline.processSpaces = function(s, doesWrap) return parts.join(''); }; -if (typeof exports !== 'undefined') { exports.domline = domline; -} diff --git a/static/js/draggable.js b/static/js/draggable.js index 1d0ddb4c3f7..8d1975459fa 100644 --- a/static/js/draggable.js +++ b/static/js/draggable.js @@ -194,6 +194,4 @@ function makeResizableHPane(left, sep, right, minLeft, minRight, sepWidth, sepOf }); } -if (typeof exports !== 'undefined') { exports.makeDraggable = makeDraggable; -} diff --git a/static/js/easysync2.js b/static/js/easysync2.js index 81a416b2562..cef868a1d19 100644 --- a/static/js/easysync2.js +++ b/static/js/easysync2.js @@ -2509,7 +2509,5 @@ Changeset.followAttributes = function(att1, att2, pool) return buf.toString(); }; -if (typeof exports !== 'undefined') { exports.Changeset = Changeset; exports.AttribPool = AttribPool; -} diff --git a/static/js/easysync2_client.js b/static/js/easysync2_client.js index 5745110e63c..f4f3d08fbb9 100644 --- a/static/js/easysync2_client.js +++ b/static/js/easysync2_client.js @@ -2270,7 +2270,5 @@ Changeset.inverse = function(cs, lines, alines, pool) return Changeset.checkRep(builder.toString()); }; -if (typeof exports !== 'undefined') { exports.Changeset = Changeset; exports.AttribPool = AttribPool; -} diff --git a/static/js/linestylefilter.js b/static/js/linestylefilter.js index 9558ed71bd8..fa1b40dee61 100644 --- a/static/js/linestylefilter.js +++ b/static/js/linestylefilter.js @@ -362,6 +362,4 @@ linestylefilter.populateDomLine = function(textLine, aline, apool, domLineObj) func(text, ''); }; -if (typeof exports !== 'undefined') { exports.linestylefilter = linestylefilter; -} diff --git a/static/js/linestylefilter_client.js b/static/js/linestylefilter_client.js index 9b1cb83dcaa..7ff5bef4135 100644 --- a/static/js/linestylefilter_client.js +++ b/static/js/linestylefilter_client.js @@ -360,6 +360,4 @@ linestylefilter.populateDomLine = function(textLine, aline, apool, domLineObj) func(text, ''); }; -if (typeof exports !== 'undefined') { exports.linestylefilter = linestylefilter; -} diff --git a/static/js/pad2.js b/static/js/pad2.js index 5369d422a4e..65cd722184c 100644 --- a/static/js/pad2.js +++ b/static/js/pad2.js @@ -967,7 +967,6 @@ var alertBar = (function() return self; }()); -if (typeof exports !== 'undefined') { exports.settings = settings; exports.createCookie = createCookie; exports.readCookie = readCookie; @@ -978,4 +977,3 @@ exports.savePassword = savePassword; exports.handshake = handshake; exports.pad = pad; exports.alertBar = alertBar; -} diff --git a/static/js/pad_connectionstatus.js b/static/js/pad_connectionstatus.js index d3a7648cb29..1de024e8d30 100644 --- a/static/js/pad_connectionstatus.js +++ b/static/js/pad_connectionstatus.js @@ -88,6 +88,4 @@ var padconnectionstatus = (function() return self; }()); -if (typeof exports !== 'undefined') { exports.padconnectionstatus = padconnectionstatus; -} diff --git a/static/js/pad_cookie.js b/static/js/pad_cookie.js index 00dc28f39b3..24dc1e3fac6 100644 --- a/static/js/pad_cookie.js +++ b/static/js/pad_cookie.js @@ -130,6 +130,4 @@ var padcookie = (function() return self; }()); -if (typeof exports !== 'undefined') { exports.padcookie = padcookie; -} diff --git a/static/js/pad_docbar.js b/static/js/pad_docbar.js index 2bf1a1da07d..cf461c93dfa 100644 --- a/static/js/pad_docbar.js +++ b/static/js/pad_docbar.js @@ -463,6 +463,4 @@ var paddocbar = (function() return self; }()); -if (typeof exports !== 'undefined') { exports.paddocbar = paddocbar; -} diff --git a/static/js/pad_editbar.js b/static/js/pad_editbar.js index 77420894084..d542b05d79f 100644 --- a/static/js/pad_editbar.js +++ b/static/js/pad_editbar.js @@ -235,6 +235,4 @@ var padeditbar = (function() return self; }()); -if (typeof exports !== 'undefined') { exports.padeditbar = padeditbar; -} diff --git a/static/js/pad_editor.js b/static/js/pad_editor.js index 45a90f00695..bb775e957dd 100644 --- a/static/js/pad_editor.js +++ b/static/js/pad_editor.js @@ -159,6 +159,4 @@ var padeditor = (function() return self; }()); -if (typeof exports !== 'undefined') { exports.padeditor = padeditor; -} diff --git a/static/js/pad_impexp.js b/static/js/pad_impexp.js index 8f187a5cb57..aa99541eaf0 100644 --- a/static/js/pad_impexp.js +++ b/static/js/pad_impexp.js @@ -334,6 +334,4 @@ var padimpexp = (function() return self; }()); -if (typeof exports !== 'undefined') { exports.padimpexp = padimpexp; -} diff --git a/static/js/pad_modals.js b/static/js/pad_modals.js index 9d24c5f1a48..81ef0776bd2 100644 --- a/static/js/pad_modals.js +++ b/static/js/pad_modals.js @@ -371,6 +371,4 @@ var padmodals = (function() return self; }()); -if (typeof exports !== 'undefined') { exports.padmodals = padmodals; -} diff --git a/static/js/pad_savedrevs.js b/static/js/pad_savedrevs.js index 964c83386b0..bb52658b2cb 100644 --- a/static/js/pad_savedrevs.js +++ b/static/js/pad_savedrevs.js @@ -523,6 +523,4 @@ var padsavedrevs = (function() return self; }()); -if (typeof exports !== 'undefined') { exports.padsavedrevs = padsavedrevs; -} diff --git a/static/js/pad_userlist.js b/static/js/pad_userlist.js index b9d08932e51..e0a12f838d2 100644 --- a/static/js/pad_userlist.js +++ b/static/js/pad_userlist.js @@ -811,6 +811,4 @@ function showColorPicker() } } -if (typeof exports !== 'undefined') { exports.paduserlist = paduserlist; -} diff --git a/static/js/pad_utils.js b/static/js/pad_utils.js index 30ff308c01c..aa469d87b4d 100644 --- a/static/js/pad_utils.js +++ b/static/js/pad_utils.js @@ -489,6 +489,4 @@ window.onerror = function test (msg, url, linenumber) return false; }; -if (typeof exports !== 'undefined') { exports.padutils = padutils; -} diff --git a/static/js/plugins.js b/static/js/plugins.js index 2cf0e0e261e..ce3ec9bd738 100644 --- a/static/js/plugins.js +++ b/static/js/plugins.js @@ -32,6 +32,4 @@ plugins = { } }; -if (typeof exports !== 'undefined') { exports.plugins = plugins; -} diff --git a/static/js/skiplist.js b/static/js/skiplist.js index 995cd6bc75c..385f08f0d36 100644 --- a/static/js/skiplist.js +++ b/static/js/skiplist.js @@ -489,6 +489,4 @@ that is a string. return self; } -if (typeof exports !== 'undefined') { exports.newSkipList = newSkipList; -} diff --git a/static/js/undomodule.js b/static/js/undomodule.js index b515180d423..aff41a70cec 100644 --- a/static/js/undomodule.js +++ b/static/js/undomodule.js @@ -332,6 +332,4 @@ var undoModule = (function() }; // apool is filled in by caller })(); -if (typeof exports !== 'undefined') { exports.undoModule = undoModule; -} diff --git a/static/js/virtual_lines.js b/static/js/virtual_lines.js index 32fc588757d..2bcf5ed6312 100644 --- a/static/js/virtual_lines.js +++ b/static/js/virtual_lines.js @@ -385,6 +385,4 @@ function makeVirtualLineView(lineNode) } -if (typeof exports !== 'undefined') { exports.makeVirtualLineView = makeVirtualLineView; -}