More AMDificatioN

i18n
Egil Moeller 2015-04-11 23:08:09 +02:00
parent 4234681efd
commit 7a1f065702
18 changed files with 233 additions and 290 deletions

View File

@ -1,79 +1,2 @@
{
"pad.js": [
"pad.js"
, "pad_utils.js"
, "browser.js"
, "pad_cookie.js"
, "pad_editor.js"
, "pad_editbar.js"
, "pad_docbar.js"
, "pad_modals.js"
, "ace.js"
, "collab_client.js"
, "pad_userlist.js"
, "pad_impexp.js"
, "pad_savedrevs.js"
, "pad_connectionstatus.js"
, "chat.js"
, "gritter.js"
, "$tinycon/tinycon.js"
, "excanvas.js"
, "farbtastic.js"
]
, "timeslider.js": [
"timeslider.js"
, "colorutils.js"
, "draggable.js"
, "pad_utils.js"
, "browser.js"
, "pad_cookie.js"
, "pad_editor.js"
, "pad_editbar.js"
, "pad_docbar.js"
, "pad_modals.js"
, "pad_savedrevs.js"
, "pad_impexp.js"
, "AttributePool.js"
, "Changeset.js"
, "domline.js"
, "linestylefilter.js"
, "cssmanager.js"
, "broadcast.js"
, "broadcast_slider.js"
, "broadcast_revisions.js"
]
, "ace2_inner.js": [
"ace2_inner.js"
, "browser.js"
, "AttributePool.js"
, "Changeset.js"
, "ChangesetUtils.js"
, "skiplist.js"
, "cssmanager.js"
, "colorutils.js"
, "undomodule.js"
, "$unorm.js"
, "contentcollector.js"
, "changesettracker.js"
, "linestylefilter.js"
, "domline.js"
, "AttributeManager.js"
]
, "ace2_common.js": [
"ace2_common.js"
, "browser.js"
, "jquery.js"
, "rjquery.js"
, "$async.js"
, "$async/lib/async.js"
, "underscore.js"
, "$underscore.js"
, "$underscore/underscore.js"
, "security.js"
, "$security.js"
, "json2.js"
, "pluginfw/client_plugins.js"
, "pluginfw/shared.js"
, "pluginfw/hooks.js"
]
}

View File

@ -30,7 +30,7 @@ Ace2Editor.registry = {
nextId: 1
};
var hooks = require('./pluginfw/hooks');
var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
var _ = require('./underscore');
function scriptTag(source) {
@ -241,23 +241,35 @@ function Ace2Editor()
}
iframeHTML.push(scriptTag(
Ace2Editor.EMBEDED[KERNEL_SOURCE] + '\n\
require.setRootURI("../javascripts/src");\n\
require.setLibraryURI("../javascripts/lib");\n\
require.setGlobalKeyPath("require");\n\
\n\
var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks");\n\
var plugins = require("ep_etherpad-lite/static/js/pluginfw/client_plugins");\n\
hooks.plugins = plugins;\n\
plugins.adoptPluginsFromAncestorsOf(window);\n\
\n\
$ = jQuery = require("ep_etherpad-lite/static/js/rjquery").jQuery; // Expose jQuery #HACK\n\
var Ace2Inner = require("ep_etherpad-lite/static/js/ace2_inner");\n\
\n\
plugins.ensure(function () {\n\
Ace2Inner.init();\n\
});\n\
'));
Ace2Editor.EMBEDED[KERNEL_SOURCE] + '\n\
require.setRootURI("../javascripts/src");\n\
require.setLibraryURI("../javascripts/lib");\n\
require.setGlobalKeyPath("require");\n\
'));
iframeHTML.push('<script type="text/javascript" src="../static/plugins/requirejs/require.js"></script>');
iframeHTML.push(scriptTag('\n\
var pathComponents = parent.parent.location.pathname.split("/");\n\
var baseURL = pathComponents.slice(0,pathComponents.length-2).join("/") + "/";\n\
requirejs.config({\n\
baseUrl: baseURL + "static/plugins",\n\
paths: {underscore: baseURL + "static/plugins/underscore/underscore"}\n\
});\n\
\n\
requirejs(["ep_etherpad-lite/static/js/rjquery", "ep_etherpad-lite/static/js/pluginfw/client_plugins", "ep_etherpad-lite/static/js/ace2_inner"], function (j, plugins, Ace2Inner) {\n\
jQuery = $ = window.jQuery = window.$ = j; // Expose jQuery #HACK\n\
\n\
plugins.adoptPluginsFromAncestorsOf(window, function () {\n\
var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks");\n\
hooks.plugins = plugins;\n\
\n\
plugins.ensure(function () {\n\
Ace2Inner.init();\n\
});\n\
});\n\
});\n\
'));
iframeHTML.push('<style type="text/css" title="dynamicsyntax"></style>');

View File

@ -19,7 +19,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var _, $, jQuery, plugins, Ace2Common;
define(["ep_etherpad-lite/static/js/rjquery", "underscore"], function ($, _) {
var exports = {};
var browser = require('./browser').browser;
if(browser.msie){
@ -32,11 +34,7 @@ if(browser.msie){
}
}
Ace2Common = require('./ace2_common');
plugins = require('ep_etherpad-lite/static/js/pluginfw/client_plugins');
$ = jQuery = require('./rjquery').$;
_ = require("./underscore");
var Ace2Common = require('./ace2_common');
var isNodeText = Ace2Common.isNodeText,
getAssoc = Ace2Common.getAssoc,
@ -45,7 +43,7 @@ var isNodeText = Ace2Common.isNodeText,
binarySearchInfinite = Ace2Common.binarySearchInfinite,
htmlPrettyEscape = Ace2Common.htmlPrettyEscape,
noop = Ace2Common.noop;
var hooks = require('./pluginfw/hooks');
var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
function Ace2Inner(){
@ -5470,3 +5468,6 @@ exports.init = function () {
var editor = new Ace2Inner()
editor.init();
};
return exports;
});

View File

@ -27,7 +27,7 @@ var Changeset = require('./Changeset');
var linestylefilter = require('./linestylefilter').linestylefilter;
var colorutils = require('./colorutils').colorutils;
var _ = require('./underscore');
var hooks = require('./pluginfw/hooks');
var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
// These parameters were global, now they are injected. A reference to the
// Timeslider controller would probably be more appropriate.

View File

@ -17,7 +17,7 @@
var padutils = require('./pad_utils').padutils;
var padcookie = require('./pad_cookie').padcookie;
var Tinycon = require('tinycon/tinycon');
var hooks = require('./pluginfw/hooks');
var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
var padeditor = require('./pad_editor').padeditor;
var chat = (function()

View File

@ -21,7 +21,7 @@
*/
var chat = require('./chat').chat;
var hooks = require('./pluginfw/hooks');
var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
// Dependency fill on init. This exists for `pad.socket` only.
// TODO: bind directly to the socket.

View File

@ -27,7 +27,7 @@ var _MAX_LIST_LEVEL = 16;
var UNorm = require('unorm');
var Changeset = require('./Changeset');
var hooks = require('./pluginfw/hooks');
var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
var _ = require('./underscore');
function sanitizeUnicode(s)

View File

@ -27,7 +27,7 @@
// requires: undefined
var Security = require('./security');
var hooks = require('./pluginfw/hooks');
var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
var _ = require('./underscore');
var lineAttributeMarker = require('./linestylefilter').lineAttributeMarker;
var noop = function(){};

View File

@ -29,7 +29,7 @@
// requires: undefined
var Changeset = require('./Changeset');
var hooks = require('./pluginfw/hooks');
var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
var linestylefilter = {};
var _ = require('./underscore');
var AttributeManager = require('./AttributeManager');

View File

@ -48,7 +48,7 @@ var readCookie = require('./pad_utils').readCookie;
var randomString = require('./pad_utils').randomString;
var gritter = require('./gritter').gritter;
var hooks = require('./pluginfw/hooks');
var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
var receivedClientVars = false;

View File

@ -20,7 +20,7 @@
* limitations under the License.
*/
var hooks = require('./pluginfw/hooks');
var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
var padutils = require('./pad_utils').padutils;
var padeditor = require('./pad_editor').padeditor;
var padsavedrevs = require('./pad_savedrevs');

View File

@ -21,7 +21,7 @@
*/
var padutils = require('./pad_utils').padutils;
var hooks = require('./pluginfw/hooks');
var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
var myUserInfo = {};

View File

@ -1,72 +1,83 @@
var $, jQuery;
$ = jQuery = require("ep_etherpad-lite/static/js/rjquery").$;
var _ = require("underscore");
define(["ep_etherpad-lite/static/js/rjquery", "underscore", './shared'], function ($, _, pluginUtils) {
var exports = {};
var pluginUtils = require('./shared');
exports.loaded = false;
exports.plugins = {};
exports.parts = [];
exports.hooks = {};
exports.baseURL = '';
exports.loaded = false;
exports.plugins = {};
exports.parts = [];
exports.hooks = {};
exports.baseURL = '';
exports.ensure = function (cb) {
if (!exports.loaded)
exports.update(cb);
else
cb();
};
exports.update = function (cb) {
// It appears that this response (see #620) may interrupt the current thread
// of execution on Firefox. This schedules the response in the run-loop,
// which appears to fix the issue.
var callback = function () {setTimeout(cb, 0);};
jQuery.getJSON(exports.baseURL + 'pluginfw/plugin-definitions.json', function(data) {
exports.plugins = data.plugins;
exports.parts = data.parts;
pluginUtils.extractHooks(exports.parts, "client_hooks", undefined, function (err, hooks) {
exports.hooks = hooks;
exports.loaded = true;
callback();
});
}).error(function(xhr, s, err){
console.error("Failed to load plugin-definitions: " + err);
callback();
});
};
function adoptPlugins(plugins) {
var keys = [
'loaded', 'plugins', 'parts', 'hooks', 'baseURL', 'ensure', 'update'];
for (var i = 0, ii = keys.length; i < ii; i++) {
var key = keys[i];
exports[key] = plugins[key];
exports.loadModule = function(path, cb) {
requirejs([path], cb);
}
}
function adoptPluginsFromAncestorsOf(frame) {
// Bind plugins with parent;
var parentRequire = null;
try {
while (frame = frame.parent) {
if (typeof (frame.require) !== "undefined") {
parentRequire = frame.require;
break;
}
exports.ensure = function (cb) {
if (!exports.loaded)
exports.update(cb);
else
cb();
};
exports.update = function (cb) {
// It appears that this response (see #620) may interrupt the current thread
// of execution on Firefox. This schedules the response in the run-loop,
// which appears to fix the issue.
var callback = function () {setTimeout(cb, 0);};
$.getJSON(exports.baseURL + 'pluginfw/plugin-definitions.json', function(data) {
exports.plugins = data.plugins;
exports.parts = data.parts;
pluginUtils.extractHooks(exports.parts, "client_hooks", exports.loadModule, function (err, hooks) {
exports.hooks = hooks;
exports.loaded = true;
callback();
});
}).error(function(xhr, s, err){
console.error("Failed to load plugin-definitions: " + err);
callback();
});
};
function adoptPlugins(plugins) {
var keys = [
'loaded', 'plugins', 'parts', 'hooks', 'baseURL', 'ensure', 'update'];
for (var i = 0, ii = keys.length; i < ii; i++) {
var key = keys[i];
exports[key] = plugins[key];
}
} catch (error) {
// Silence (this can only be a XDomain issue).
}
if (parentRequire) {
var ancestorPlugins = parentRequire("ep_etherpad-lite/static/js/pluginfw/client_plugins");
exports.adoptPlugins(ancestorPlugins);
} else {
throw new Error("Parent plugins could not be found.")
}
}
exports.adoptPlugins = adoptPlugins;
exports.adoptPluginsFromAncestorsOf = adoptPluginsFromAncestorsOf;
function adoptPluginsFromAncestorsOf(frame, cb) {
// Bind plugins with parent;
var parentRequire = null;
try {
while (frame = frame.parent) {
if (typeof (frame.require) !== "undefined") {
parentRequire = frame.requirejs;
break;
}
}
} catch (error) {
// Silence (this can only be a XDomain issue).
}
if (parentRequire) {
parentRequire(["ep_etherpad-lite/static/js/pluginfw/client_plugins"], function (ancestorPlugins) {
exports.adoptPlugins(ancestorPlugins);
cb();
});
} else {
throw new Error("Parent plugins could not be found.")
}
}
exports.adoptPlugins = adoptPlugins;
exports.adoptPluginsFromAncestorsOf = adoptPluginsFromAncestorsOf;
out = {};
Object.keys(exports).map(function(key) {
out[key] = typeof(exports[key]);
});
return exports;
});

View File

@ -8,8 +8,6 @@ var util = require("util");
var _ = require("underscore");
var requirejs = require('requirejs');
var pluginUtils = require('./shared');
exports.prefix = 'ep_';
exports.loaded = false;
exports.plugins = {};
@ -76,8 +74,13 @@ exports.callInit = function (cb) {
);
}
exports.pathNormalization = function (part, hook_fn_name) {
return path.normalize(path.join(path.dirname(exports.plugins[part.plugin].package.path), hook_fn_name));
exports.loadModule = function(path, cb) {
try {
cb(require(path));
console.warn("Module uses old CommonJS format: " + path);
} catch (e) {
requirejs([path], cb);
}
}
exports.update = function (cb) {
@ -94,13 +97,16 @@ exports.update = function (cb) {
if (err) cb(err);
exports.plugins = plugins;
exports.parts = sortParts(parts);
pluginUtils.extractHooks(exports.parts, "hooks", exports.pathNormalization, function (err, hooks) {
exports.hooks = hooks;
// Load client side hooks here too, so we don't have to call it from formatHooks (which is synchronous)
pluginUtils.extractHooks(exports.parts, "client_hooks", exports.pathNormalization, function (err, hooks) {
exports.client_hooks = hooks;
exports.loaded = true;
exports.callInit(cb);
requirejs(["ep_etherpad-lite/static/js/pluginfw/shared"], function (pluginUtils) {
pluginUtils.extractHooks(exports.parts, "hooks", exports.loadModule, function (err, hooks) {
exports.hooks = hooks;
// Load client side hooks here too, so we don't have to call it from formatHooks (which is synchronous)
pluginUtils.extractHooks(exports.parts, "client_hooks", exports.loadModule, function (err, hooks) {
exports.client_hooks = hooks;
exports.loaded = true;
exports.callInit(cb);
});
});
});
}

View File

@ -1,85 +1,67 @@
var _ = require("underscore");
var async = require("async/lib/async");
if (typeof(requirejs) == "undefined") {
if (typeof(window) != "undefined") {
var requirejs = window.requirejs;
} else {
var requirejs = require('requirejs');
}
}
define(["underscore", "async/lib/async"], function (_, async) {
var exports = {};
function loadFn(path, hookName, cb) {
var functionName
, parts = path.split(":");
// on windows: C:\foo\bar:xyz
if (parts[0].length == 1) {
if (parts.length == 3) {
functionName = parts.pop();
if (typeof(requirejs) == "undefined") {
if (typeof(window) != "undefined") {
var requirejs = window.requirejs;
} else {
var requirejs = require('requirejs');
}
path = parts.join(":");
} else {
path = parts[0];
functionName = parts[1];
}
var handleFunction = function (fn) {
functionName = functionName ? functionName : hookName;
function loadFn(path, hookName, loadModule, cb) {
var functionName
, parts = path.split(":");
_.each(functionName.split("."), function (name) {
fn = fn[name];
// on windows: C:\foo\bar:xyz
if (parts[0].length == 1) {
if (parts.length == 3) {
functionName = parts.pop();
}
path = parts.join(":");
} else {
path = parts[0];
functionName = parts[1];
}
loadModule(path, function (fn) {
functionName = functionName ? functionName : hookName;
_.each(functionName.split("."), function (name) {
fn = fn[name];
});
cb(null, fn);
});
cb(null, fn);
};
if (require.resolve != undefined) {
/* We're apparently in NodeJS, so try to load using the built-in require first */
try {
handleFunction(require(path));
console.warn("Module uses old CommonJS format: " + path);
} catch (e) {
requirejs([path], handleFunction);
}
} else {
requirejs([path], handleFunction);
}
};
function extractHooks(parts, hook_set_name, loadModule, cb) {
var hooks = {};
function extractHooks(parts, hook_set_name, normalizer, cb) {
var hooks = {};
async.each(parts, function (part, cb) {
if (part[hook_set_name] == undefined) {
cb(null);
} else {
async.each(Object.keys(part[hook_set_name]), function (hook_name, cb) {
if (hooks[hook_name] === undefined) hooks[hook_name] = [];
async.each(parts, function (part, cb) {
if (part[hook_set_name] == undefined) {
cb(null);
} else {
async.each(Object.keys(part[hook_set_name]), function (hook_name, cb) {
if (hooks[hook_name] === undefined) hooks[hook_name] = [];
var hook_fn_name = part[hook_set_name][hook_name];
var hook_fn_name = part[hook_set_name][hook_name];
loadFn(hook_fn_name, hook_name, loadModule, function (err, hook_fn) {
if (hook_fn) {
hooks[hook_name].push({"hook_name": hook_name, "hook_fn": hook_fn, "hook_fn_name": hook_fn_name, "part": part});
} else {
console.error("Failed to load '" + hook_fn_name + "' for '" + part.full_name + "/" + hook_set_name + "/" + hook_name + ":" + err.toString());
}
cb(err);
});
}, cb);
}
}, function (err) {
cb(err, hooks);
});
};
/* On the server side, you can't just
* require("pluginname/whatever") if the plugin is installed as
* a dependency of another plugin! Bah, pesky little details of
* npm... */
/*
if (normalizer) {
hook_fn_name = normalizer(part, hook_fn_name);
}
*/
exports.extractHooks = extractHooks;
loadFn(hook_fn_name, hook_name, function (err, hook_fn) {
if (hook_fn) {
hooks[hook_name].push({"hook_name": hook_name, "hook_fn": hook_fn, "hook_fn_name": hook_fn_name, "part": part});
} else {
console.error("Failed to load '" + hook_fn_name + "' for '" + part.full_name + "/" + hook_set_name + "/" + hook_name + ":" + err.toString());
}
cb(err);
});
}, cb);
}
}, function (err) {
cb(err, hooks);
});
};
exports.extractHooks = extractHooks;
return exports;
});

View File

@ -1,5 +1,7 @@
// Proviedes a require'able version of jQuery without leaking $ and jQuery;
require('./jquery');
var jq = window.$.noConflict(true);
exports.jQuery = exports.$ = jq;
/* Proviedes a require'able version of jQuery without leaking $ and jQuery;
* works around wierdnesses in jquerys own packaging that makes dummy be undefined in the call below
*/
define.amd.jQuery = true;
define(["ep_etherpad-lite/static/js/jquery"], function (dummy) {
return window.$.noConflict(true);
});

View File

@ -28,7 +28,7 @@ JSON = require('./json2');
var createCookie = require('./pad_utils').createCookie;
var readCookie = require('./pad_utils').readCookie;
var randomString = require('./pad_utils').randomString;
var hooks = require('./pluginfw/hooks');
var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
var token, padId, export_links;

View File

@ -371,8 +371,8 @@
<script type="text/javascript" src="../static/plugins/requirejs/require.js"></script>
<!-- Include base packages manually (this help with debugging) -->
<script type="text/javascript" src="../javascripts/lib/ep_etherpad-lite/static/js/pad.js?callback=require.define"></script>
<script type="text/javascript" src="../javascripts/lib/ep_etherpad-lite/static/js/ace2_common.js?callback=require.define"></script>
<!-- script type="text/javascript" src="../javascripts/lib/ep_etherpad-lite/static/js/pad.js?callback=require.define"></script>
<script type="text/javascript" src="../javascripts/lib/ep_etherpad-lite/static/js/ace2_common.js?callback=require.define"></script -->
<% e.begin_block("customScripts"); %>
<script type="text/javascript" src="../static/custom/pad.js"></script>
@ -391,38 +391,44 @@
require.setLibraryURI(baseURL + "javascripts/lib");
require.setGlobalKeyPath("require");
window.requireKernel = require;
requirejs.config({
baseUrl: baseURL + "static/plugins"
baseUrl: baseURL + "static/plugins",
paths: {'underscore': baseURL + "static/plugins/underscore/underscore"}
});
$ = jQuery = require('ep_etherpad-lite/static/js/rjquery').jQuery; // Expose jQuery #HACK
browser = require('ep_etherpad-lite/static/js/browser').browser;
if ((!browser.msie) && (!(browser.mozilla && browser.version.indexOf("1.8.") == 0))) {
document.domain = document.domain; // for comet
}
requirejs(["ep_etherpad-lite/static/js/rjquery", 'ep_etherpad-lite/static/js/pluginfw/client_plugins'], function ($, plugins) {
window.$ = $; // Expose jQuery #HACK
window.jQuery = $;
var plugins = require('ep_etherpad-lite/static/js/pluginfw/client_plugins');
var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
browser = require('ep_etherpad-lite/static/js/browser').browser;
if ((!browser.msie) && (!(browser.mozilla && browser.version.indexOf("1.8.") == 0))) {
document.domain = document.domain; // for comet
}
plugins.baseURL = baseURL;
plugins.update(function () {
hooks.plugins = plugins;
var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
// Call documentReady hook
$(function() {
hooks.aCallAll('documentReady');
plugins.baseURL = baseURL;
plugins.update(function () {
hooks.plugins = plugins;
// Call documentReady hook
$(function() {
hooks.aCallAll('documentReady');
});
var pad = require('ep_etherpad-lite/static/js/pad');
pad.baseURL = baseURL;
pad.init();
});
var pad = require('ep_etherpad-lite/static/js/pad');
pad.baseURL = baseURL;
pad.init();
/* TODO: These globals shouldn't exist. */
pad = require('ep_etherpad-lite/static/js/pad').pad;
chat = require('ep_etherpad-lite/static/js/chat').chat;
padeditbar = require('ep_etherpad-lite/static/js/pad_editbar').padeditbar;
padimpexp = require('ep_etherpad-lite/static/js/pad_impexp').padimpexp;
});
/* TODO: These globals shouldn't exist. */
pad = require('ep_etherpad-lite/static/js/pad').pad;
chat = require('ep_etherpad-lite/static/js/chat').chat;
padeditbar = require('ep_etherpad-lite/static/js/pad_editbar').padeditbar;
padimpexp = require('ep_etherpad-lite/static/js/pad_impexp').padimpexp;
}());
</script>
<% e.end_block(); %>