added jQuery to ace2_inner, make it embeddable, ace hooks work now propertly in ace2_inner

This commit is contained in:
Matthias Bartelmeß 2012-03-14 01:41:05 +01:00
parent 70940521f2
commit 1cf3ffef4a
4 changed files with 102 additions and 154 deletions

View File

@ -51,6 +51,7 @@
]
, "ace2_inner.js": [
"ace2_common.js"
, "rjquery.js"
, "AttributePoolFactory.js"
, "Changeset.js"
, "security.js"

View File

@ -19,38 +19,39 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var editor, $, jQuery, plugins, Ace2Common;
var Ace2Common = require('./ace2_common');
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 binarySearchInfinite = Ace2Common.binarySearchInfinite;
var htmlPrettyEscape = Ace2Common.htmlPrettyEscape;
var map = Ace2Common.map;
var noop = Ace2Common.noop;
plugins = require('ep_etherpad-lite/static/js/pluginfw/plugins');
$ = jQuery = require('./rjquery').$;
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('./AttributePoolFactory').createAttributePool;
var Changeset = require('./Changeset');
var linestylefilter = require('./linestylefilter').linestylefilter;
var newSkipList = require('./skiplist').newSkipList;
var undoModule = require('./undomodule').undoModule;
var makeVirtualLineView = require('./virtual_lines').makeVirtualLineView;
var isNodeText = Ace2Common.isNodeText,
object = Ace2Common.object,
extend = Ace2Common.extend,
browser = Ace2Common.browser,
getAssoc = Ace2Common.getAssoc,
setAssoc = Ace2Common.setAssoc,
isTextNode = Ace2Common.isTextNode,
binarySearchInfinite = Ace2Common.binarySearchInfinite,
htmlPrettyEscape = Ace2Common.htmlPrettyEscape,
noop = Ace2Common.noop;
function Ace2Inner(){
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('./AttributePoolFactory').createAttributePool;
var Changeset = require('./Changeset');
var linestylefilter = require('./linestylefilter').linestylefilter;
var newSkipList = require('./skiplist').newSkipList;
var undoModule = require('./undomodule').undoModule;
var makeVirtualLineView = require('./virtual_lines').makeVirtualLineView;
var DEBUG = false; //$$ build script replaces the string "var DEBUG=true;//$$" with "var DEBUG=false;"
// changed to false
var isSetUp = false;
@ -69,7 +70,6 @@ function Ace2Inner(){
var thisAuthor = '';
var disposed = false;
var editorInfo = parent.editorInfo;
var iframe = window.frameElement;
@ -883,9 +883,7 @@ function Ace2Inner(){
{
return fn(editorInfo);
};
if (normalize !== undefined)
{
var wrapper1 = wrapper;
@ -4532,7 +4530,7 @@ function Ace2Inner(){
enforceEditability();
addClass(sideDiv, 'sidedivdelayed');
$(sideDiv).addClass('sidedivdelayed');
}
function getScrollXY()
@ -4591,8 +4589,6 @@ function Ace2Inner(){
});
}
bindEventHandler(window, "load", setup);
function setDesignMode(newVal)
{
try
@ -4669,20 +4665,20 @@ function Ace2Inner(){
function bindTheEventHandlers()
{
bindEventHandler(document, "keydown", handleKeyEvent);
bindEventHandler(document, "keypress", handleKeyEvent);
bindEventHandler(document, "keyup", handleKeyEvent);
bindEventHandler(document, "click", handleClick);
bindEventHandler(root, "blur", handleBlur);
$(document).on("keydown", handleKeyEvent);
$(document).on("keypress", handleKeyEvent);
$(document).on("keyup", handleKeyEvent);
$(document).on("click", handleClick);
$(root).on("blur", handleBlur);
if (browser.msie)
{
bindEventHandler(document, "click", handleIEOuterClick);
$(document).on("click", handleIEOuterClick);
}
if (browser.msie) bindEventHandler(root, "paste", handleIEPaste);
if (browser.msie) $(root).on("paste", handleIEPaste);
if ((!browser.msie) && document.documentElement)
{
bindEventHandler(document.documentElement, "compositionstart", handleCompositionEvent);
bindEventHandler(document.documentElement, "compositionend", handleCompositionEvent);
$(document.documentElement).on("compositionstart", handleCompositionEvent);
$(document.documentElement).on("compositionend", handleCompositionEvent);
}
}
@ -4729,91 +4725,10 @@ function Ace2Inner(){
elem.className = array.join(' ');
}
function addClass(elem, className)
{
var seen = false;
var cc = getClassArray(elem, function(c)
{
if (c == className) seen = true;
return true;
});
if (!seen)
{
cc.push(className);
setClassArray(elem, cc);
}
}
function removeClass(elem, className)
{
var seen = false;
var cc = getClassArray(elem, function(c)
{
if (c == className)
{
seen = true;
return false;
}
return true;
});
if (seen)
{
setClassArray(elem, cc);
}
}
function setClassPresence(elem, className, present)
{
if (present) addClass(elem, className);
else removeClass(elem, className);
}
function setup()
{
doc = document; // defined as a var in scope outside
inCallStack("setup", function()
{
var body = doc.getElementById("innerdocbody");
root = body; // defined as a var in scope outside
if (browser.mozilla) addClass(root, "mozilla");
if (browser.safari) addClass(root, "safari");
if (browser.msie) addClass(root, "msie");
if (browser.msie)
{
// cache CSS background images
try
{
doc.execCommand("BackgroundImageCache", false, true);
}
catch (e)
{ /* throws an error in some IE 6 but not others! */
}
}
setClassPresence(root, "authorColors", true);
setClassPresence(root, "doesWrap", doesWrap);
initDynamicCSS();
enforceEditability();
// set up dom and rep
while (root.firstChild) root.removeChild(root.firstChild);
var oneEntry = createDomLineEntry("");
doRepLineSplice(0, rep.lines.length(), [oneEntry]);
insertDomLines(null, [oneEntry.domInfo], null);
rep.alines = Changeset.splitAttributionLines(
Changeset.makeAttribution("\n"), "\n");
bindTheEventHandlers();
});
scheduler.setTimeout(function()
{
parent.readyFunc(); // defined in code that sets up the inner iframe
}, 0);
isSetUp = true;
if (present) $(elem).addClass(className);
else $(elem).removeClass(elem, className);
}
function focus()
@ -4832,32 +4747,6 @@ function Ace2Inner(){
}
}
function bindEventHandler(target, type, func)
{
var handler;
if ((typeof func._wrapper) != "function")
{
func._wrapper = function(event)
{
func(fixEvent(event || window.event || {}));
}
}
var handler = func._wrapper;
if (target.addEventListener) target.addEventListener(type, handler, false);
else target.attachEvent("on" + type, handler);
_teardownActions.push(function()
{
unbindEventHandler(target, type, func);
});
}
function unbindEventHandler(target, type, func)
{
var handler = func._wrapper;
if (target.removeEventListener) target.removeEventListener(type, handler, false);
else target.detachEvent("on" + type, handler);
}
function getSelectionPointX(point)
{
// doesn't work in wrap-mode
@ -5553,7 +5442,7 @@ function Ace2Inner(){
if (!event.target && event.srcElement) event.target = event.srcElement;
// check if target is a textnode (safari)
if (browser.safari && event.target.nodeType == 3) event.target = originalEvent.target.parentNode;
if (browser.safari && isTextNode(event.target)) event.target = originalEvent.target.parentNode;
// Add relatedTarget, if necessary
if (!event.relatedTarget && event.fromElement) event.relatedTarget = event.fromElement == event.target ? event.toElement : event.fromElement;
@ -5664,6 +5553,56 @@ function Ace2Inner(){
}
}
$(document).ready(function(){
doc = document; // defined as a var in scope outside
inCallStack("setup", function()
{
var body = doc.getElementById("innerdocbody");
root = body; // defined as a var in scope outside
if (browser.mozilla) $(root).addClass("mozilla");
if (browser.safari) $(root).addClass("safari");
if (browser.msie) $(root).addClass("msie");
if (browser.msie)
{
// cache CSS background images
try
{
doc.execCommand("BackgroundImageCache", false, true);
}
catch (e)
{ /* throws an error in some IE 6 but not others! */
}
}
setClassPresence(root, "authorColors", true);
setClassPresence(root, "doesWrap", doesWrap);
initDynamicCSS();
enforceEditability();
// set up dom and rep
while (root.firstChild) root.removeChild(root.firstChild);
var oneEntry = createDomLineEntry("");
doRepLineSplice(0, rep.lines.length(), [oneEntry]);
insertDomLines(null, [oneEntry.domInfo], null);
rep.alines = Changeset.splitAttributionLines(
Changeset.makeAttribution("\n"), "\n");
bindTheEventHandlers();
});
scheduler.setTimeout(function()
{
parent.readyFunc(); // defined in code that sets up the inner iframe
}, 0);
isSetUp = true;
});
}
exports.editor = new Ace2Inner();
// Ensure that plugins are loaded before initializing the editor
plugins.ensure(function () {
var editor = new Ace2Inner();
});

View File

@ -10,6 +10,9 @@ if (!exports.isClient) {
var fs = require("fs");
var tsort = require("./tsort");
var util = require("util");
}else{
var $, jQuery;
$ = jQuery = require("ep_etherpad-lite/static/js/rjquery").$;
}
exports.prefix = 'ep_';

5
src/static/js/rjquery.js Normal file
View File

@ -0,0 +1,5 @@
// Proviedes a require'able version of jQuery without leaking $ and jQuery;
require('./jquery');
exports.jQuery = exports.$ = $.noConflict(true);