diff --git a/sandbox/_frame.html b/sandbox/_frame.html new file mode 100644 index 0000000000..75916d700f --- /dev/null +++ b/sandbox/_frame.html @@ -0,0 +1,94 @@ + + + + + + + +
+

Aloha Editor

+

+ + Lorem ipsum  dolor sit amet, consectetur adipiscin + elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecen + congue ligula ac quam viverra nec consectetur ante hendrerit +

+
Aloha Block
+

+ Donec et mollis dolor. Praesent et diam eget libero egesta + mattis sit amet vitae augue. Nam tincidunt congue enim, u + porta lorem lacinia consectetur. Donec ut libero sed arc + vehicula ultricies a non tortor* +

+ +

+ Donec et mollis dolor. Praesent et diam eget libero egesta + mattis sit amet vitae augue. + Nam tincidunt congue enim, u porta lorem lacinia consectetur. + Donec ut libero sed arc vehicula ultricies a non tortor +

+
+ + diff --git a/sandbox/frame.html b/sandbox/frame.html new file mode 100644 index 0000000000..e1ce3bc7ce --- /dev/null +++ b/sandbox/frame.html @@ -0,0 +1,42 @@ + + + + Aloha Editor + + + + + + + + + + + diff --git a/src/aloha.js b/src/aloha.js index b414488086..709a9a59ba 100644 --- a/src/aloha.js +++ b/src/aloha.js @@ -57,7 +57,8 @@ define([ alohaEvent.editor = editor; Fn.comp( setSelection, - //Selections.handle, + Selections.handle, + Keys.handle, Typing.handle, Blocks.handle, DragDrop.handle, @@ -66,17 +67,14 @@ define([ alohaEvent.editable = alohaEvent.editor.editables[1]; return alohaEvent; }, - Mouse.handle, - Keys.handle + Mouse.handle )(alohaEvent); } editor.editables = {}; editor.BLOCK_CLASS = 'aloha-block'; editor.CARET_CLASS = 'aloha-caret'; - editor.selectionContext = Selections.Context(); - Events.setup(editor, document); /* SelectionChange.addHandler(document, SelectionChange.handler( @@ -94,6 +92,8 @@ define([ * Also serves as short aloha.aloha. */ function aloha(elem) { + editor.selectionContext = Selections.Context(elem.ownerDocument); + Events.setup(editor, elem.ownerDocument); var editable = Editables.Editable(elem); editable.overrides = []; editable.settings = { diff --git a/src/keys.js b/src/keys.js index 2b9bcbfed3..32f9c8f0d6 100644 --- a/src/keys.js +++ b/src/keys.js @@ -104,7 +104,8 @@ define([ if (!event) { return alohaEvent; } - var range = (event instanceof KeyboardEvent) ? Ranges.get() : null; + var doc = alohaEvent.editor.selectionContext.caret.ownerDocument; + var range = (event instanceof KeyboardEvent) ? Ranges.get(doc) : null; if (range) { alohaEvent.range = range; var editable = Editables.fromBoundary( diff --git a/src/selections.js b/src/selections.js index 6fb8ce5283..7750266efa 100644 --- a/src/selections.js +++ b/src/selections.js @@ -560,11 +560,11 @@ define([ * * Will create a DOM element at the end of the document body to be used to * represent the caret position. - * + * @param {Document} doc * @return {Object} */ - function Context() { - var caret = document.createElement('div'); + function Context(doc) { + var caret = doc.createElement('div'); caret.style.display = 'none'; Dom.addClass(caret, 'aloha-caret'); Dom.insert(caret, caret.ownerDocument.body, true); @@ -622,7 +622,7 @@ define([ alohaEvent.range.commonAncestorContainer.ownerDocument ); } - return Ranges.get(); + return Ranges.get(alohaEvent.editor.selectionContext.caret.ownerDocument); } /** diff --git a/src/undo.js b/src/undo.js index 497b4d198a..902216aad5 100644 --- a/src/undo.js +++ b/src/undo.js @@ -798,7 +798,7 @@ define([ lastInsertNode = null; var node = record.node; var path = containerPath.concat(pathBeforeNode(container, node)); - changes.push(makeDeleteChange(path, [document.createTextNode(record.oldValue)])); + changes.push(makeDeleteChange(path, [node.ownerDocument.createTextNode(record.oldValue)])); changes.push(makeInsertChange(path, [Dom.clone(node)])); } else { // NB: only COMPOUND_DELETEs should occur in a recordTree,