mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-21 07:56:16 -04:00
commit
7f6a81b0ed
2 changed files with 108 additions and 83 deletions
|
@ -24,6 +24,8 @@
|
||||||
// requires: plugins
|
// requires: plugins
|
||||||
// requires: undefined
|
// requires: undefined
|
||||||
|
|
||||||
|
var KERNEL_SOURCE = '../static/js/require-kernel.js';
|
||||||
|
|
||||||
Ace2Editor.registry = {
|
Ace2Editor.registry = {
|
||||||
nextId: 1
|
nextId: 1
|
||||||
};
|
};
|
||||||
|
@ -31,6 +33,14 @@ Ace2Editor.registry = {
|
||||||
var hooks = require('./pluginfw/hooks');
|
var hooks = require('./pluginfw/hooks');
|
||||||
var _ = require('./underscore');
|
var _ = require('./underscore');
|
||||||
|
|
||||||
|
function scriptTag(source) {
|
||||||
|
return (
|
||||||
|
'<script type="text/javascript">\n'
|
||||||
|
+ source.replace(/<\//g, '<\\/') +
|
||||||
|
'</script>'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
function Ace2Editor()
|
function Ace2Editor()
|
||||||
{
|
{
|
||||||
var ace2 = Ace2Editor;
|
var ace2 = Ace2Editor;
|
||||||
|
@ -155,24 +165,6 @@ function Ace2Editor()
|
||||||
|
|
||||||
return {embeded: embededFiles, remote: remoteFiles};
|
return {embeded: embededFiles, remote: remoteFiles};
|
||||||
}
|
}
|
||||||
function pushRequireScriptTo(buffer) {
|
|
||||||
var KERNEL_SOURCE = '../static/js/require-kernel.js';
|
|
||||||
var KERNEL_BOOT = '\
|
|
||||||
require.setRootURI("../javascripts/src");\n\
|
|
||||||
require.setLibraryURI("../javascripts/lib");\n\
|
|
||||||
require.setGlobalKeyPath("require");\n\
|
|
||||||
';
|
|
||||||
if (Ace2Editor.EMBEDED && Ace2Editor.EMBEDED[KERNEL_SOURCE]) {
|
|
||||||
buffer.push('<script type="text/javascript">');
|
|
||||||
buffer.push(Ace2Editor.EMBEDED[KERNEL_SOURCE]);
|
|
||||||
buffer.push(KERNEL_BOOT);
|
|
||||||
buffer.push('<\/script>');
|
|
||||||
} else {
|
|
||||||
// Remotely src'd script tag will not work in IE; it must be embedded, so
|
|
||||||
// throw an error if it is not.
|
|
||||||
throw new Error("Require script could not be embedded.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function pushStyleTagsFor(buffer, files) {
|
function pushStyleTagsFor(buffer, files) {
|
||||||
var sorted = sortFilesByEmbeded(files);
|
var sorted = sortFilesByEmbeded(files);
|
||||||
var embededFiles = sorted.embeded;
|
var embededFiles = sorted.embeded;
|
||||||
|
@ -236,23 +228,30 @@ require.setGlobalKeyPath("require");\n\
|
||||||
|
|
||||||
pushStyleTagsFor(iframeHTML, includedCSS);
|
pushStyleTagsFor(iframeHTML, includedCSS);
|
||||||
|
|
||||||
var includedJS = [];
|
if (!Ace2Editor.EMBEDED && Ace2Editor.EMBEDED[KERNEL_SOURCE]) {
|
||||||
pushRequireScriptTo(iframeHTML);
|
// Remotely src'd script tag will not work in IE; it must be embedded, so
|
||||||
|
// throw an error if it is not.
|
||||||
|
throw new Error("Require kernel could not be found.");
|
||||||
|
}
|
||||||
|
|
||||||
// Inject my plugins into my child.
|
iframeHTML.push(scriptTag(
|
||||||
iframeHTML.push('\
|
Ace2Editor.EMBEDED[KERNEL_SOURCE] + '\n\
|
||||||
<script type="text/javascript">\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 hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks");\n\
|
||||||
var plugins = require("ep_etherpad-lite/static/js/pluginfw/client_plugins");\n\
|
var plugins = require("ep_etherpad-lite/static/js/pluginfw/client_plugins");\n\
|
||||||
hooks.plugins = plugins;\n\
|
hooks.plugins = plugins;\n\
|
||||||
plugins.adoptPluginsFromAncestorsOf(window);\n\
|
plugins.adoptPluginsFromAncestorsOf(window);\n\
|
||||||
</script>\
|
\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\
|
||||||
iframeHTML.push('<script type="text/javascript">');
|
\n\
|
||||||
iframeHTML.push('$ = jQuery = require("ep_etherpad-lite/static/js/rjquery").jQuery; // Expose jQuery #HACK');
|
plugins.ensure(function () {\n\
|
||||||
iframeHTML.push('require("ep_etherpad-lite/static/js/ace2_inner");');
|
Ace2Inner.init();\n\
|
||||||
iframeHTML.push('<\/script>');
|
});\n\
|
||||||
|
'));
|
||||||
|
|
||||||
iframeHTML.push('<style type="text/css" title="dynamicsyntax"></style>');
|
iframeHTML.push('<style type="text/css" title="dynamicsyntax"></style>');
|
||||||
|
|
||||||
|
@ -266,8 +265,32 @@ require.setGlobalKeyPath("require");\n\
|
||||||
var thisFunctionsName = "ChildAccessibleAce2Editor";
|
var thisFunctionsName = "ChildAccessibleAce2Editor";
|
||||||
(function () {return this}())[thisFunctionsName] = Ace2Editor;
|
(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.name = "ace_inner";' + 'iframe.scrolling = "no"; var outerdocbody = document.getElementById("outerdocbody"); ' + 'iframe.frameBorder = 0; iframe.allowTransparency = true; ' + // for IE
|
var outerScript = '\
|
||||||
'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); }';
|
editorId = ' + JSON.stringify(info.id) + ';\n\
|
||||||
|
editorInfo = parent[' + JSON.stringify(thisFunctionsName) + '].registry[editorId];\n\
|
||||||
|
window.onload = function () {\n\
|
||||||
|
window.onload = null;\n\
|
||||||
|
setTimeout(function () {\n\
|
||||||
|
var iframe = document.createElement("IFRAME");\n\
|
||||||
|
iframe.name = "ace_inner";\n\
|
||||||
|
iframe.scrolling = "no";\n\
|
||||||
|
var outerdocbody = document.getElementById("outerdocbody");\n\
|
||||||
|
iframe.frameBorder = 0;\n\
|
||||||
|
iframe.allowTransparency = true; // for IE\n\
|
||||||
|
outerdocbody.insertBefore(iframe, outerdocbody.firstChild);\n\
|
||||||
|
iframe.ace_outerWin = window;\n\
|
||||||
|
readyFunc = function () {\n\
|
||||||
|
editorInfo.onEditorReady();\n\
|
||||||
|
readyFunc = null;\n\
|
||||||
|
editorInfo = null;\n\
|
||||||
|
};\n\
|
||||||
|
var doc = iframe.contentWindow.document;\n\
|
||||||
|
doc.open();\n\
|
||||||
|
var text = (' + JSON.stringify(iframeHTML.join('\n')) + ');\n\
|
||||||
|
doc.write(text);\n\
|
||||||
|
doc.close();\n\
|
||||||
|
}, 0);\n\
|
||||||
|
}';
|
||||||
|
|
||||||
var outerHTML = [doctype, '<html><head>']
|
var outerHTML = [doctype, '<html><head>']
|
||||||
|
|
||||||
|
@ -285,7 +308,7 @@ require.setGlobalKeyPath("require");\n\
|
||||||
|
|
||||||
// bizarrely, in FF2, a file with no "external" dependencies won't finish loading properly
|
// bizarrely, in FF2, a file with no "external" dependencies won't finish loading properly
|
||||||
// (throbs busy while typing)
|
// (throbs busy while typing)
|
||||||
outerHTML.push('<link rel="stylesheet" type="text/css" href="data:text/css,"/>', '\x3cscript>\n', outerScript.replace(/<\//g, '<\\/'), '\n\x3c/script>', '</head><body id="outerdocbody"><div id="sidediv"><!-- --></div><div id="linemetricsdiv">x</div><div id="overlaysdiv"><!-- --></div></body></html>');
|
outerHTML.push('<link rel="stylesheet" type="text/css" href="data:text/css,"/>', scriptTag(outerScript), '</head><body id="outerdocbody"><div id="sidediv"><!-- --></div><div id="linemetricsdiv">x</div><div id="overlaysdiv"><!-- --></div></body></html>');
|
||||||
|
|
||||||
var outerFrame = document.createElement("IFRAME");
|
var outerFrame = document.createElement("IFRAME");
|
||||||
outerFrame.name = "ace_outer";
|
outerFrame.name = "ace_outer";
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
var editor, _, $, jQuery, plugins, Ace2Common;
|
var _, $, jQuery, plugins, Ace2Common;
|
||||||
|
|
||||||
Ace2Common = require('./ace2_common');
|
Ace2Common = require('./ace2_common');
|
||||||
|
|
||||||
|
@ -5430,6 +5430,7 @@ function Ace2Inner(){
|
||||||
return documentAttributeManager.setAttributesOnRange.apply(documentAttributeManager, arguments);
|
return documentAttributeManager.setAttributesOnRange.apply(documentAttributeManager, arguments);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.init = function () {
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
doc = document; // defined as a var in scope outside
|
doc = document; // defined as a var in scope outside
|
||||||
inCallStack("setup", function()
|
inCallStack("setup", function()
|
||||||
|
@ -5482,10 +5483,11 @@ function Ace2Inner(){
|
||||||
|
|
||||||
isSetUp = true;
|
isSetUp = true;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure that plugins are loaded before initializing the editor
|
exports.init = function () {
|
||||||
plugins.ensure(function () {
|
var editor = new Ace2Inner()
|
||||||
var editor = new Ace2Inner();
|
editor.init();
|
||||||
});
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue