-
Notifications
You must be signed in to change notification settings - Fork 250
feat: PREVENT_DEFAULT command #187
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
Merged
michaelobriena
merged 1 commit into
Famous:develop
from
alexanderGugel:preventDefault-optional
Jun 11, 2015
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -104,16 +104,80 @@ function DOMRenderer (element, selector, compositor) { | |
| * | ||
| * @return {undefined} undefined | ||
| */ | ||
| DOMRenderer.prototype.subscribe = function subscribe(type, preventDefault) { | ||
| // TODO preventDefault should be a separate command | ||
| DOMRenderer.prototype.subscribe = function subscribe(type) { | ||
| this._assertTargetLoaded(); | ||
|
|
||
| this._target.preventDefault[type] = preventDefault; | ||
| this._listen(type); | ||
| this._target.subscribe[type] = true; | ||
| }; | ||
|
|
||
| /** | ||
| * Unsubscribes from all events that are of the specified type. | ||
| * | ||
| * @method | ||
| * | ||
| * @param {String} type Event type to unsubscribe from. | ||
| * @return {undefined} undefined | ||
| */ | ||
| DOMRenderer.prototype.unsubscribe = function unsubscribe(type) { | ||
| this._assertTargetLoaded(); | ||
| this._listen(type); | ||
| this._target.subscribe[type] = false; | ||
| }; | ||
|
|
||
| /** | ||
| * Used to preventDefault if an event of the specified type is being emitted on | ||
| * the currently loaded target. | ||
| * | ||
| * @method | ||
| * | ||
| * @param {String} type The type of events that should be prevented. | ||
| * @return {undefined} undefined | ||
| */ | ||
| DOMRenderer.prototype.preventDefault = function preventDefault(type) { | ||
|
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. Needs docs |
||
| this._assertTargetLoaded(); | ||
| this._listen(type); | ||
| this._target.preventDefault[type] = true; | ||
| }; | ||
|
|
||
| /** | ||
| * Used to undo a previous call to preventDefault. No longer `preventDefault` | ||
| * for this event on the loaded target. | ||
| * | ||
| * @method | ||
| * @private | ||
| * | ||
| * @param {String} type The event type that should no longer be affected by | ||
| * `preventDefault`. | ||
| * @return {undefined} undefined | ||
| */ | ||
| DOMRenderer.prototype.allowDefault = function allowDefault(type) { | ||
| this._assertTargetLoaded(); | ||
| this._listen(type); | ||
| this._target.preventDefault[type] = false; | ||
| }; | ||
|
|
||
| /** | ||
| * Internal helper function used for adding an event listener for the the | ||
| * currently loaded ElementCache. | ||
| * | ||
| * If the event can be delegated as specified in the {@link EventMap}, the | ||
| * bound {@link _triggerEvent} function will be added as a listener on the | ||
| * root element. Otherwise, the listener will be added directly to the target | ||
| * element. | ||
| * | ||
| * @private | ||
| * @method | ||
| * | ||
| * @param {String} type The event type to listen to (e.g. click). | ||
| * @return {undefined} undefined | ||
| */ | ||
| DOMRenderer.prototype._listen = function _listen(type) { | ||
|
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. Needs docs |
||
| this._assertTargetLoaded(); | ||
|
|
||
| if ( | ||
| !this._target.listeners[type] && !this._root.listeners[type] | ||
| ) { | ||
| // FIXME Add to content DIV if available | ||
| var target = eventMap[type][1] ? this._root : this._target; | ||
| target.listeners[type] = this._boundTriggerEvent; | ||
| target.element.addEventListener(type, this._boundTriggerEvent); | ||
|
|
@@ -143,18 +207,18 @@ DOMRenderer.prototype._triggerEvent = function _triggerEvent(ev) { | |
| var path = evPath[i].dataset.faPath; | ||
| if (!path) continue; | ||
|
|
||
| // Optionally preventDefault. This needs forther consideration and | ||
| // should be optional. Eventually this should be a separate command/ | ||
| // method. | ||
| if (this._elements[path].preventDefault[ev.type]) { | ||
| ev.preventDefault(); | ||
| } | ||
|
|
||
| // Stop further event propogation and path traversal as soon as the | ||
| // first ElementCache subscribing for the emitted event has been found. | ||
| if (this._elements[path] && this._elements[path].subscribe[ev.type]) { | ||
| ev.stopPropagation(); | ||
|
|
||
| // Optionally preventDefault. This needs forther consideration and | ||
| // should be optional. Eventually this should be a separate command/ | ||
| // method. | ||
| if (this._elements[path].preventDefault[ev.type]) { | ||
| ev.preventDefault(); | ||
| } | ||
|
|
||
| var NormalizedEventConstructor = eventMap[ev.type][0]; | ||
|
|
||
| // Finally send the event to the Worker Thread through the | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Needs docs