-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Enable / disable editors individually #1073
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
base: master
Are you sure you want to change the base?
Changes from all commits
9820e1e
622ce69
7ceb6fd
b2e19b3
e8a2830
14ae206
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,11 +16,27 @@ | |
| // Helpers for event handling | ||
|
|
||
| attachDOMEvent: function (targets, event, listener, useCapture) { | ||
| var selectiveListener = function (event) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was the goal of this feature to not emit any DOM events on 'disabled' elements, or to just prevent any medium-editor behavior on 'disabled' elements? |
||
| var i, disabled, target; | ||
| disabled = this.options.disable; | ||
| target = event.target; | ||
|
|
||
| if (disabled) { | ||
| disabled = Array.isArray(disabled) ? disabled : [disabled]; | ||
| for (i in disabled) { | ||
| if (target.matches && target.matches(disabled[i])) { | ||
| return; | ||
| } | ||
| } | ||
| } | ||
| listener.apply(this, arguments); | ||
| }.bind(this); | ||
|
|
||
| targets = MediumEditor.util.isElement(targets) || [window, document].indexOf(targets) > -1 ? [targets] : targets; | ||
|
|
||
| Array.prototype.forEach.call(targets, function (target) { | ||
| target.addEventListener(event, listener, useCapture); | ||
| this.events.push([target, event, listener, useCapture]); | ||
| target.addEventListener(event, selectiveListener, useCapture); | ||
| this.events.push([target, event, listener, useCapture, selectiveListener]); | ||
| }.bind(this)); | ||
| }, | ||
|
|
||
|
|
@@ -32,7 +48,7 @@ | |
| index = this.indexOfListener(target, event, listener, useCapture); | ||
| if (index !== -1) { | ||
| e = this.events.splice(index, 1)[0]; | ||
| e[0].removeEventListener(e[1], e[2], e[3]); | ||
| e[0].removeEventListener(e[1], e[4], e[3]); | ||
| } | ||
| }.bind(this)); | ||
| }, | ||
|
|
@@ -51,7 +67,7 @@ | |
| detachAllDOMEvents: function () { | ||
| var e = this.events.pop(); | ||
| while (e) { | ||
| e[0].removeEventListener(e[1], e[2], e[3]); | ||
| e[0].removeEventListener(e[1], e[4], e[3]); | ||
| e = this.events.pop(); | ||
| } | ||
| }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1052,6 +1052,10 @@ | |
| } else { | ||
| el.parentNode.removeChild(el); | ||
| } | ||
| }, | ||
|
|
||
| toArr: function (arraylike) { | ||
| return [].slice.call(arraylike); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a benefit to calling
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for megaslow response. Yes: it's just a bit smaller :)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But now I'm not sure that is's not slower. Gonna test it. |
||
| } | ||
| }; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once you merge the latest master into your branch, you'll likely want to move this logic into
initElement. It's a function that will be called for every editor element during initialization and when elements are added dynamically.