mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Summary: This makes a few changes to React Core, most notably `ReactEventEmitter` and `ReactEventTopLevelCallback`. - Changed `ReactEventEmitter` to use `EventListener` (instead of `NormalizedEventListener`). - Deleted `NormalizedEventListener` (which was previously broken). - Created `getEventTarget` which is used to get a normalized `target` from a native event. - Changed `ReactEventTopLevelCallback` to use `getEventTarget`. - Renamed `abstractEventType` to `reactEventType` in `AbstractEvent`. - Reanmed `abstractTargetID` to `reactTargetID` in `AbstractEvent`. - Removed `originatingTopLevelEventType` from `AbstractEvent` (unused and violates encapsulation). - Removed `nativeEvent.target === window` check when refreshing authoritative scroll values (unnecessary). This actually fixes React because `NormalizedEventListener` does not currently do what it promises to do (which is normalizing `target` on the native event). The `target` event is read-only on native events. This also revises documentation and adds `@typechecks` to a few modules. NOTE: Most importantly, this sets the stage for replacing `AbstractEvent` with `ReactEvent` and subclasses, piecemeal.
40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
/**
|
|
* Copyright 2013 Facebook, Inc.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*
|
|
* @providesModule getDOMNodeID
|
|
* @typechecks
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
/**
|
|
* Accessing "id" or calling getAttribute('id') on a form element can return its
|
|
* control whose name or ID is "id". However, not all DOM nodes support
|
|
* `getAttributeNode` (document - which is not a form) so that is checked first.
|
|
*
|
|
* @param {DOMElement|DOMWindow|DOMDocument} domNode DOM node.
|
|
* @returns {string} ID of the supplied `domNode`.
|
|
*/
|
|
function getDOMNodeID(domNode) {
|
|
if (domNode.getAttributeNode) {
|
|
var attributeNode = domNode.getAttributeNode('id');
|
|
return attributeNode && attributeNode.value || '';
|
|
} else {
|
|
return domNode.id || '';
|
|
}
|
|
}
|
|
|
|
module.exports = getDOMNodeID;
|