From b977e1acd67eed53e32348841a5b7f72033c62ca Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Tue, 28 Feb 2012 20:08:24 -0800 Subject: [PATCH 1/3] Child frame uses parent's require. --- node/utils/Minify.js | 2 -- package.json | 2 +- static/js/ace.js | 18 +++--------------- 3 files changed, 4 insertions(+), 18 deletions(-) diff --git a/node/utils/Minify.js b/node/utils/Minify.js index a49195a7b..6cba62582 100644 --- a/node/utils/Minify.js +++ b/node/utils/Minify.js @@ -136,8 +136,6 @@ function getAceFile(callback) { if (!settings.minify) { founds = []; } - // Always include the require kernel. - founds.push('$$INCLUDE_JS("../static/js/require-kernel.js")'); data += ';\n'; data += 'Ace2Editor.EMBEDED = Ace2Editor.EMBEDED || {};\n'; diff --git a/package.json b/package.json index 01eb8e96a..4a8e06c9e 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "dependencies" : { "yajsml" : "1.1.2", "request" : "2.9.100", - "require-kernel" : "1.0.3", + "require-kernel" : "1.0.4", "socket.io" : "0.8.7", "ueberDB" : "0.1.7", "async" : "0.1.18", diff --git a/static/js/ace.js b/static/js/ace.js index 22d4eaa6e..f974744c2 100644 --- a/static/js/ace.js +++ b/static/js/ace.js @@ -154,16 +154,6 @@ function Ace2Editor() return {embeded: embededFiles, remote: remoteFiles}; } - function pushRequireScriptTo(buffer) { - var KERNEL_SOURCE = '../static/js/require-kernel.js'; - var KERNEL_BOOT = 'require.setRootURI("../minified/");\nrequire.setGlobalKeyPath("require");' - if (Ace2Editor.EMBEDED && Ace2Editor.EMBEDED[KERNEL_SOURCE]) { - buffer.push('\ '); pushScriptsTo(iframeHTML); From 5118dcc687057041e0ec1e788a7145df4023c20f Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Wed, 29 Feb 2012 13:09:47 -0800 Subject: [PATCH 2/3] Drop support for file inlining in Minify. --- node/utils/Minify.js | 88 +------------------------------------------- 1 file changed, 2 insertions(+), 86 deletions(-) diff --git a/node/utils/Minify.js b/node/utils/Minify.js index 6cba62582..5b9476726 100644 --- a/node/utils/Minify.js +++ b/node/utils/Minify.js @@ -126,52 +126,9 @@ exports.minify = function(req, res, next) }); } -// find all includes in ace.js and embed them. -function getAceFile(callback) { - fs.readFile(ROOT_DIR + 'js/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_]+\("[^"]*"\)/gi); - if (!settings.minify) { - founds = []; - } - - data += ';\n'; - data += 'Ace2Editor.EMBEDED = Ace2Editor.EMBEDED || {};\n'; - - // Request the contents of the included file on the server-side and write - // them into the file. - async.forEach(founds, function (item, callback) { - var filename = item.match(/"([^"]*)"/)[1]; - var request = require('request'); - - var baseURI = 'http://localhost:' + settings.port - - request(baseURI + path.normalize(path.join('/static/', filename)), function (error, response, body) { - if (!error && response.statusCode == 200) { - data += 'Ace2Editor.EMBEDED[' + JSON.stringify(filename) + '] = ' - + JSON.stringify(body || '') + ';\n'; - } else { - // Silence? - } - callback(); - }); - }, function(error) { - callback(error, data); - }); - }); -} - // Check for the existance of the file and get the last modification date. function statFile(filename, callback) { - if (filename == 'js/ace.js') { - // Sometimes static assets are inlined into this file, so we have to stat - // everything. - lastModifiedDateOfEverything(function (error, date) { - callback(error, date, !error); - }); - } else if (filename == 'js/require-kernel.js') { + if (filename == 'js/require-kernel.js') { callback(null, requireLastModified(), true); } else { fs.stat(ROOT_DIR + filename, function (error, stats) { @@ -198,45 +155,6 @@ function statFile(filename, callback) { }); } } -function lastModifiedDateOfEverything(callback) { - var folders2check = [ROOT_DIR + 'js/', ROOT_DIR + 'css/']; - var latestModification = 0; - //go trough this two folders - async.forEach(folders2check, function(path, callback) - { - //read the files in the folder - fs.readdir(path, function(err, files) - { - if(ERR(err, callback)) return; - - //we wanna check the directory itself for changes too - files.push("."); - - //go trough all files in this folder - async.forEach(files, function(filename, callback) - { - //get the stat data of this file - fs.stat(path + "/" + filename, function(err, stats) - { - if(ERR(err, callback)) return; - - //get the modification time - var modificationTime = stats.mtime.getTime(); - - //compare the modification time to the highest found - if(modificationTime > latestModification) - { - latestModification = modificationTime; - } - - callback(); - }); - }, callback); - }); - }, function () { - callback(null, latestModification); - }); -} // This should be provided by the module, but until then, just use startup // time. @@ -270,9 +188,7 @@ function getFileCompressed(filename, contentType, callback) { } function getFile(filename, callback) { - if (filename == 'js/ace.js') { - getAceFile(callback); - } else if (filename == 'js/require-kernel.js') { + if (filename == 'js/require-kernel.js') { callback(undefined, requireDefinition()); } else { fs.readFile(ROOT_DIR + filename, callback); From f3ba353d5877a54a4c4c4809238d8555f40da4c1 Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Wed, 29 Feb 2012 13:07:43 -0800 Subject: [PATCH 3/3] Don't inline styles or scripts in Ace. --- static/js/ace.js | 91 ++++++++---------------------------------------- 1 file changed, 15 insertions(+), 76 deletions(-) diff --git a/static/js/ace.js b/static/js/ace.js index f974744c2..4793feb73 100644 --- a/static/js/ace.js +++ b/static/js/ace.js @@ -133,62 +133,6 @@ function Ace2Editor() return info.ace_getUnhandledErrors(); }; - - - function sortFilesByEmbeded(files) { - var embededFiles = []; - var remoteFiles = []; - - if (Ace2Editor.EMBEDED) { - for (var i = 0, ii = files.length; i < ii; i++) { - var file = files[i]; - if (Object.prototype.hasOwnProperty.call(Ace2Editor.EMBEDED, file)) { - embededFiles.push(file); - } else { - remoteFiles.push(file); - } - } - } else { - remoteFiles = files; - } - - return {embeded: embededFiles, remote: remoteFiles}; - } - function pushScriptsTo(buffer) { - /* Folling is for packaging regular expression. */ - /* $$INCLUDE_JS("../minified/ace2_inner.js?callback=require.define"); */ - var ACE_SOURCE = '../minified/ace2_inner.js?callback=require.define'; - if (Ace2Editor.EMBEDED && Ace2Editor.EMBEDED[ACE_SOURCE]) { - buffer.push('\ +\n\ +\ '); - pushScriptsTo(iframeHTML); iframeHTML.push(''); iframeHTML.push(' '); @@ -264,12 +208,7 @@ function Ace2Editor() var outerHTML = [doctype, ''] - var includedCSS = []; - var $$INCLUDE_CSS = function(filename) {includedCSS.push(filename)}; - $$INCLUDE_CSS("../static/css/iframe_editor.css"); - $$INCLUDE_CSS("../static/css/pad.css"); - $$INCLUDE_CSS("../static/custom/pad.css"); - pushStyleTagsFor(outerHTML, includedCSS); + outerHTML.push(styleTags); // bizarrely, in FF2, a file with no "external" dependencies won't finish loading properly // (throbs busy while typing)