Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed iframe div #1179

Merged
merged 1 commit into from
Aug 22, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 29 additions & 23 deletions src/js/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
// Helpers for event handling

attachDOMEvent: function (targets, event, listener, useCapture) {
targets = MediumEditor.util.isElement(targets) || [window, document].indexOf(targets) > -1 ? [targets] : targets;
var win = this.base.options.contentWindow,
doc = this.base.options.ownerDocument;

targets = MediumEditor.util.isElement(targets) || [win, doc].indexOf(targets) > -1 ? [targets] : targets;

Array.prototype.forEach.call(targets, function (target) {
target.addEventListener(event, listener, useCapture);
Expand All @@ -45,8 +48,11 @@
},

detachDOMEvent: function (targets, event, listener, useCapture) {
var index, e;
targets = MediumEditor.util.isElement(targets) || [window, document].indexOf(targets) > -1 ? [targets] : targets;
var index, e,
win = this.base.options.contentWindow,
doc = this.base.options.ownerDocument;

targets = MediumEditor.util.isElement(targets) || [win, doc].indexOf(targets) > -1 ? [targets] : targets;

Array.prototype.forEach.call(targets, function (target) {
index = this.indexOfListener(target, event, listener, useCapture);
Expand Down Expand Up @@ -214,23 +220,23 @@

// Helper method to call all listeners to execCommand
var callListeners = function (args, result) {
if (doc.execCommand.listeners) {
doc.execCommand.listeners.forEach(function (listener) {
listener({
command: args[0],
value: args[2],
args: args,
result: result
});
if (doc.execCommand.listeners) {
doc.execCommand.listeners.forEach(function (listener) {
listener({
command: args[0],
value: args[2],
args: args,
result: result
});
}
},
});
}
},

// Create a wrapper method for execCommand which will:
// 1) Call document.execCommand with the correct arguments
// 2) Loop through any listeners and notify them that execCommand was called
// passing extra info on the call
// 3) Return the result
// Create a wrapper method for execCommand which will:
// 1) Call document.execCommand with the correct arguments
// 2) Loop through any listeners and notify them that execCommand was called
// passing extra info on the call
// 3) Return the result
wrapper = function () {
var result = doc.execCommand.orig.apply(this, arguments);

Expand Down Expand Up @@ -405,10 +411,10 @@
// For clicks, we need to know if the mousedown that caused the click happened inside the existing focused element
// or one of the extension elements. If so, we don't want to focus another element
if (hadFocus &&
eventObj.type === 'click' &&
this.lastMousedownTarget &&
(MediumEditor.util.isDescendant(hadFocus, this.lastMousedownTarget, true) ||
isElementDescendantOfExtension(this.base.extensions, this.lastMousedownTarget))) {
eventObj.type === 'click' &&
this.lastMousedownTarget &&
(MediumEditor.util.isDescendant(hadFocus, this.lastMousedownTarget, true) ||
isElementDescendantOfExtension(this.base.extensions, this.lastMousedownTarget))) {
toFocus = hadFocus;
}

Expand All @@ -426,7 +432,7 @@

// Check if the target is external (not part of the editor, toolbar, or any other extension)
var externalEvent = !MediumEditor.util.isDescendant(hadFocus, target, true) &&
!isElementDescendantOfExtension(this.base.extensions, target);
!isElementDescendantOfExtension(this.base.extensions, target);

if (toFocus !== hadFocus) {
// If element has focus, and focus is going outside of editor
Expand Down