react 0.8.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. package/README.md +0 -8
  2. package/addons.js +0 -3
  3. package/lib/AutoFocusMixin.js +32 -0
  4. package/lib/CSSCore.js +23 -22
  5. package/lib/CSSProperty.js +32 -1
  6. package/lib/CSSPropertyOperations.js +1 -1
  7. package/lib/ChangeEventPlugin.js +27 -5
  8. package/lib/ClientReactRootIndex.js +30 -0
  9. package/lib/CompositionEventPlugin.js +58 -10
  10. package/lib/DOMChildrenOperations.js +39 -3
  11. package/lib/DOMProperty.js +9 -5
  12. package/lib/DOMPropertyOperations.js +21 -8
  13. package/lib/Danger.js +9 -8
  14. package/lib/DefaultDOMPropertyConfig.js +23 -14
  15. package/lib/DefaultEventPluginOrder.js +1 -1
  16. package/lib/EnterLeaveEventPlugin.js +38 -5
  17. package/lib/EventConstants.js +4 -1
  18. package/lib/EventListener.js +42 -34
  19. package/lib/EventPluginHub.js +118 -13
  20. package/lib/EventPluginRegistry.js +62 -18
  21. package/lib/EventPluginUtils.js +33 -4
  22. package/lib/EventPropagators.js +7 -43
  23. package/lib/ExecutionEnvironment.js +4 -1
  24. package/lib/LinkedStateMixin.js +1 -1
  25. package/lib/LinkedValueUtils.js +160 -0
  26. package/lib/MobileSafariClickEventPlugin.js +1 -1
  27. package/lib/PooledClass.js +7 -1
  28. package/lib/React.js +30 -4
  29. package/lib/ReactBrowserComponentMixin.js +42 -0
  30. package/lib/ReactCSSTransitionGroup.js +65 -0
  31. package/lib/{ReactTransitionableChild.js → ReactCSSTransitionGroupChild.js} +22 -36
  32. package/lib/ReactChildren.js +4 -4
  33. package/lib/ReactComponent.js +163 -83
  34. package/lib/ReactComponentBrowserEnvironment.js +55 -71
  35. package/lib/ReactCompositeComponent.js +686 -119
  36. package/lib/ReactContext.js +67 -0
  37. package/lib/ReactCurrentOwner.js +1 -1
  38. package/lib/ReactDOM.js +19 -6
  39. package/lib/ReactDOMButton.js +6 -1
  40. package/lib/ReactDOMComponent.js +66 -24
  41. package/lib/ReactDOMForm.js +13 -3
  42. package/lib/ReactDOMIDOperations.js +106 -61
  43. package/lib/ReactDOMImg.js +61 -0
  44. package/lib/ReactDOMInput.js +28 -15
  45. package/lib/ReactDOMOption.js +13 -8
  46. package/lib/ReactDOMSelect.js +38 -18
  47. package/lib/ReactDOMSelection.js +1 -1
  48. package/lib/ReactDOMTextarea.js +19 -11
  49. package/lib/ReactDefaultBatchingStrategy.js +1 -1
  50. package/lib/ReactDefaultInjection.js +60 -26
  51. package/lib/ReactDefaultPerf.js +208 -371
  52. package/lib/ReactDefaultPerfAnalysis.js +199 -0
  53. package/lib/ReactErrorUtils.js +6 -15
  54. package/lib/ReactEventEmitter.js +144 -146
  55. package/lib/ReactEventEmitterMixin.js +1 -33
  56. package/lib/ReactEventTopLevelCallback.js +75 -15
  57. package/lib/ReactInjection.js +43 -0
  58. package/lib/ReactInputSelection.js +3 -2
  59. package/lib/ReactInstanceHandles.js +36 -20
  60. package/lib/ReactLink.js +2 -2
  61. package/lib/ReactMarkupChecksum.js +1 -1
  62. package/lib/ReactMount.js +136 -104
  63. package/lib/ReactMountReady.js +2 -2
  64. package/lib/ReactMultiChild.js +40 -49
  65. package/lib/ReactMultiChildUpdateTypes.js +3 -1
  66. package/lib/ReactOwner.js +17 -4
  67. package/lib/ReactPerf.js +6 -9
  68. package/lib/ReactPropTransferer.js +41 -22
  69. package/lib/ReactPropTypeLocationNames.js +31 -0
  70. package/lib/{ReactComponentEnvironment.js → ReactPropTypeLocations.js} +11 -6
  71. package/lib/ReactPropTypes.js +249 -48
  72. package/lib/ReactPutListenerQueue.js +61 -0
  73. package/lib/ReactReconcileTransaction.js +28 -7
  74. package/lib/ReactRootIndex.js +36 -0
  75. package/lib/ReactServerRendering.js +46 -19
  76. package/lib/ReactServerRenderingTransaction.js +116 -0
  77. package/lib/ReactStateSetters.js +1 -1
  78. package/lib/ReactTestUtils.js +394 -0
  79. package/lib/ReactTextComponent.js +33 -6
  80. package/lib/{ReactTransitionKeySet.js → ReactTransitionChildMapping.js} +43 -48
  81. package/lib/ReactTransitionEvents.js +1 -1
  82. package/lib/ReactTransitionGroup.js +133 -58
  83. package/lib/ReactUpdates.js +15 -12
  84. package/lib/ReactWithAddons.js +15 -3
  85. package/lib/SelectEventPlugin.js +23 -40
  86. package/lib/ServerReactRootIndex.js +36 -0
  87. package/lib/SimpleEventPlugin.js +55 -7
  88. package/lib/SyntheticClipboardEvent.js +8 -2
  89. package/lib/SyntheticCompositionEvent.js +1 -1
  90. package/lib/SyntheticDragEvent.js +44 -0
  91. package/lib/SyntheticEvent.js +3 -2
  92. package/lib/SyntheticFocusEvent.js +1 -1
  93. package/lib/SyntheticKeyboardEvent.js +5 -3
  94. package/lib/SyntheticMouseEvent.js +1 -1
  95. package/lib/SyntheticTouchEvent.js +1 -1
  96. package/lib/SyntheticUIEvent.js +1 -1
  97. package/lib/SyntheticWheelEvent.js +11 -8
  98. package/lib/Transaction.js +62 -37
  99. package/lib/ViewportMetrics.js +1 -1
  100. package/lib/accumulate.js +1 -1
  101. package/lib/adler32.js +1 -1
  102. package/lib/cloneWithProps.js +59 -0
  103. package/lib/containsNode.js +1 -1
  104. package/lib/copyProperties.js +1 -1
  105. package/lib/createArrayFrom.js +11 -14
  106. package/lib/createFullPageComponent.js +63 -0
  107. package/lib/createNodesFromMarkup.js +1 -1
  108. package/lib/createObjectFrom.js +1 -1
  109. package/lib/cx.js +3 -3
  110. package/lib/dangerousStyleValue.js +1 -1
  111. package/lib/emptyFunction.js +1 -1
  112. package/lib/emptyObject.js +27 -0
  113. package/lib/escapeTextForBrowser.js +1 -1
  114. package/lib/flattenChildren.js +6 -3
  115. package/lib/focusNode.js +33 -0
  116. package/lib/forEachAccumulated.js +1 -1
  117. package/lib/getActiveElement.js +5 -4
  118. package/lib/getEventKey.js +85 -0
  119. package/lib/getEventTarget.js +1 -1
  120. package/lib/getMarkupWrap.js +11 -1
  121. package/lib/getNodeForCharacterOffset.js +1 -1
  122. package/lib/getReactRootElementInContainer.js +1 -1
  123. package/lib/getTextContentAccessor.js +6 -4
  124. package/lib/getUnboundedScrollPosition.js +3 -3
  125. package/lib/hyphenate.js +1 -1
  126. package/lib/instantiateReactComponent.js +70 -0
  127. package/lib/invariant.js +20 -12
  128. package/lib/isEventSupported.js +8 -12
  129. package/lib/isNode.js +2 -2
  130. package/lib/isTextInputElement.js +1 -1
  131. package/lib/isTextNode.js +1 -1
  132. package/lib/joinClasses.js +1 -1
  133. package/lib/keyMirror.js +1 -1
  134. package/lib/keyOf.js +1 -1
  135. package/lib/memoizeStringOnly.js +1 -1
  136. package/lib/merge.js +1 -1
  137. package/lib/mergeHelpers.js +6 -7
  138. package/lib/mergeInto.js +1 -1
  139. package/lib/mixInto.js +1 -1
  140. package/lib/monitorCodeUse.js +37 -0
  141. package/lib/objMap.js +1 -1
  142. package/lib/objMapKeyVal.js +1 -1
  143. package/lib/onlyChild.js +43 -0
  144. package/lib/performanceNow.js +1 -1
  145. package/lib/shallowEqual.js +1 -1
  146. package/lib/shouldUpdateReactComponent.js +61 -0
  147. package/lib/toArray.js +75 -0
  148. package/lib/traverseAllChildren.js +72 -9
  149. package/lib/update.js +159 -0
  150. package/lib/warning.js +48 -0
  151. package/package.json +3 -3
  152. package/react.js +0 -3
  153. package/ReactJSErrors.js +0 -40
  154. package/lib/$.js +0 -46
  155. package/lib/CallbackRegistry.js +0 -91
  156. package/lib/LinkedValueMixin.js +0 -68
  157. package/lib/ex.js +0 -49
  158. package/lib/filterAttributes.js +0 -45
  159. package/lib/ge.js +0 -76
  160. package/lib/mutateHTMLNodeWithMarkup.js +0 -100
package/lib/$.js DELETED
@@ -1,46 +0,0 @@
1
- /**
2
- * Copyright 2013 Facebook, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- *
16
- * @providesModule $
17
- * @typechecks
18
- */
19
-
20
- var ge = require("./ge");
21
- var ex = require("./ex");
22
-
23
- /**
24
- * Find a node by ID.
25
- *
26
- * If your application code depends on the existence of the element, use $,
27
- * which will throw if the element doesn't exist.
28
- *
29
- * If you're not sure whether or not the element exists, use ge instead, and
30
- * manually check for the element's existence in your application code.
31
- *
32
- * @param {string|DOMDocument|DOMElement|DOMTextNode|Comment} id
33
- * @return {DOMDocument|DOMElement|DOMTextNode|Comment}
34
- */
35
- function $(id) {
36
- var element = ge(id);
37
- if (!element) {
38
- throw new Error(ex(
39
- 'Tried to get element with id of "%s" but it is not present on the page.',
40
- id
41
- ));
42
- }
43
- return element;
44
- }
45
-
46
- module.exports = $;
@@ -1,91 +0,0 @@
1
- /**
2
- * Copyright 2013 Facebook, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- *
16
- * @providesModule CallbackRegistry
17
- * @typechecks static-only
18
- */
19
-
20
- "use strict";
21
-
22
- var listenerBank = {};
23
-
24
- /**
25
- * Stores "listeners" by `registrationName`/`id`. There should be at most one
26
- * "listener" per `registrationName`/`id` in the `listenerBank`.
27
- *
28
- * Access listeners via `listenerBank[registrationName][id]`.
29
- *
30
- * @class CallbackRegistry
31
- * @internal
32
- */
33
- var CallbackRegistry = {
34
-
35
- /**
36
- * Stores `listener` at `listenerBank[registrationName][id]`. Is idempotent.
37
- *
38
- * @param {string} id ID of the DOM element.
39
- * @param {string} registrationName Name of listener (e.g. `onClick`).
40
- * @param {?function} listener The callback to store.
41
- */
42
- putListener: function(id, registrationName, listener) {
43
- var bankForRegistrationName =
44
- listenerBank[registrationName] || (listenerBank[registrationName] = {});
45
- bankForRegistrationName[id] = listener;
46
- },
47
-
48
- /**
49
- * @param {string} id ID of the DOM element.
50
- * @param {string} registrationName Name of listener (e.g. `onClick`).
51
- * @return {?function} The stored callback.
52
- */
53
- getListener: function(id, registrationName) {
54
- var bankForRegistrationName = listenerBank[registrationName];
55
- return bankForRegistrationName && bankForRegistrationName[id];
56
- },
57
-
58
- /**
59
- * Deletes a listener from the registration bank.
60
- *
61
- * @param {string} id ID of the DOM element.
62
- * @param {string} registrationName Name of listener (e.g. `onClick`).
63
- */
64
- deleteListener: function(id, registrationName) {
65
- var bankForRegistrationName = listenerBank[registrationName];
66
- if (bankForRegistrationName) {
67
- delete bankForRegistrationName[id];
68
- }
69
- },
70
-
71
- /**
72
- * Deletes all listeners for the DOM element with the supplied ID.
73
- *
74
- * @param {string} id ID of the DOM element.
75
- */
76
- deleteAllListeners: function(id) {
77
- for (var registrationName in listenerBank) {
78
- delete listenerBank[registrationName][id];
79
- }
80
- },
81
-
82
- /**
83
- * This is needed for tests only. Do not use!
84
- */
85
- __purge: function() {
86
- listenerBank = {};
87
- }
88
-
89
- };
90
-
91
- module.exports = CallbackRegistry;
@@ -1,68 +0,0 @@
1
- /**
2
- * Copyright 2013 Facebook, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- *
16
- * @providesModule LinkedValueMixin
17
- * @typechecks static-only
18
- */
19
-
20
- "use strict";
21
-
22
- var invariant = require("./invariant");
23
-
24
- /**
25
- * Provide a linked `value` attribute for controlled forms. You should not use
26
- * this outside of the ReactDOM controlled form components.
27
- */
28
- var LinkedValueMixin = {
29
- _assertLink: function() {
30
- ("production" !== process.env.NODE_ENV ? invariant(
31
- this.props.value == null && this.props.onChange == null,
32
- 'Cannot provide a valueLink and a value or onChange event. If you ' +
33
- 'want to use value or onChange, you probably don\'t want to use ' +
34
- 'valueLink'
35
- ) : invariant(this.props.value == null && this.props.onChange == null));
36
- },
37
-
38
- /**
39
- * @return {*} current value of the input either from value prop or link.
40
- */
41
- getValue: function() {
42
- if (this.props.valueLink) {
43
- this._assertLink();
44
- return this.props.valueLink.value;
45
- }
46
- return this.props.value;
47
- },
48
-
49
- /**
50
- * @return {function} change callback either from onChange prop or link.
51
- */
52
- getOnChange: function() {
53
- if (this.props.valueLink) {
54
- this._assertLink();
55
- return this._handleLinkedValueChange;
56
- }
57
- return this.props.onChange;
58
- },
59
-
60
- /**
61
- * @param {SyntheticEvent} e change event to handle
62
- */
63
- _handleLinkedValueChange: function(e) {
64
- this.props.valueLink.requestChange(e.target.value);
65
- }
66
- };
67
-
68
- module.exports = LinkedValueMixin;
package/lib/ex.js DELETED
@@ -1,49 +0,0 @@
1
- /**
2
- * Copyright 2013 Facebook, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- *
16
- * @providesModule ex
17
- * @typechecks
18
- * @nostacktrace
19
- */
20
-
21
- /**
22
- * This function transforms error message with arguments into plain text error
23
- * message, so that it can be passed to window.onerror without losing anything.
24
- * It can then be transformed back by `erx()` function.
25
- *
26
- * Usage:
27
- * throw new Error(ex('Error %s from %s', errorCode, userID));
28
- *
29
- * @param {string} errorMessage
30
- */
31
-
32
- var ex = function(errorMessage/*, arg1, arg2, ...*/) {
33
- var args = Array.prototype.slice.call(arguments).map(function(arg) {
34
- return String(arg);
35
- });
36
- var expectedLength = errorMessage.split('%s').length - 1;
37
-
38
- if (expectedLength !== args.length - 1) {
39
- // something wrong with the formatting string
40
- return ex('ex args number mismatch: %s', JSON.stringify(args));
41
- }
42
-
43
- return ex._prefix + JSON.stringify(args) + ex._suffix;
44
- };
45
-
46
- ex._prefix = '<![EX[';
47
- ex._suffix = ']]>';
48
-
49
- module.exports = ex;
@@ -1,45 +0,0 @@
1
- /**
2
- * Copyright 2013 Facebook, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- *
16
- * @providesModule filterAttributes
17
- * @typechecks static-only
18
- */
19
-
20
- /*jslint evil: true */
21
-
22
- 'use strict';
23
-
24
- /**
25
- * Like filter(), but for a DOM nodes attributes. Returns an array of
26
- * the filter DOMAttribute objects. Does some perf related this like
27
- * caching attributes.length.
28
- *
29
- * @param {DOMElement} node Node whose attributes you want to filter
30
- * @return {array} array of DOM attribute objects.
31
- */
32
- function filterAttributes(node, func, context) {
33
- var attributes = node.attributes;
34
- var numAttributes = attributes.length;
35
- var accumulator = [];
36
- for (var i = 0; i < numAttributes; i++) {
37
- var attr = attributes.item(i);
38
- if (func.call(context, attr)) {
39
- accumulator.push(attr);
40
- }
41
- }
42
- return accumulator;
43
- }
44
-
45
- module.exports = filterAttributes;
package/lib/ge.js DELETED
@@ -1,76 +0,0 @@
1
- /**
2
- * Copyright 2013 Facebook, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- *
16
- * @providesModule ge
17
- */
18
-
19
- /**
20
- * Find a node by ID. Optionally search a sub-tree outside of the document
21
- *
22
- * Use ge if you're not sure whether or not the element exists. You can test
23
- * for existence yourself in your application code.
24
- *
25
- * If your application code depends on the existence of the element, use $
26
- * instead, which will throw in DEV if the element doesn't exist.
27
- */
28
- function ge(arg, root, tag) {
29
- return typeof arg != 'string' ? arg :
30
- !root ? document.getElementById(arg) :
31
- _geFromSubtree(arg, root, tag);
32
- }
33
-
34
- function _geFromSubtree(id, root, tag) {
35
- var elem, children, ii;
36
-
37
- if (_getNodeID(root) == id) {
38
- return root;
39
- } else if (root.getElementsByTagName) {
40
- // All Elements implement this, which does an iterative DFS, which is
41
- // faster than recursion and doesn't run into stack depth issues.
42
- children = root.getElementsByTagName(tag || '*');
43
- for (ii = 0; ii < children.length; ii++) {
44
- if (_getNodeID(children[ii]) == id) {
45
- return children[ii];
46
- }
47
- }
48
- } else {
49
- // DocumentFragment does not implement getElementsByTagName, so
50
- // recurse over its children. Its children must be Elements, so
51
- // each child will use the getElementsByTagName case instead.
52
- children = root.childNodes;
53
- for (ii = 0; ii < children.length; ii++) {
54
- elem = _geFromSubtree(id, children[ii]);
55
- if (elem) {
56
- return elem;
57
- }
58
- }
59
- }
60
-
61
- return null;
62
- }
63
-
64
- /**
65
- * Return the ID value for a given node. This allows us to avoid issues
66
- * with forms that contain inputs with name="id".
67
- *
68
- * @return string (null if attribute not set)
69
- */
70
- function _getNodeID(node) {
71
- // #document and #document-fragment do not have getAttributeNode.
72
- var id = node.getAttributeNode && node.getAttributeNode('id');
73
- return id ? id.value : null;
74
- }
75
-
76
- module.exports = ge;
@@ -1,100 +0,0 @@
1
- /**
2
- * Copyright 2013 Facebook, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- *
16
- * @providesModule mutateHTMLNodeWithMarkup
17
- * @typechecks static-only
18
- */
19
-
20
- /*jslint evil: true */
21
-
22
- 'use strict';
23
-
24
- var createNodesFromMarkup = require("./createNodesFromMarkup");
25
- var filterAttributes = require("./filterAttributes");
26
- var invariant = require("./invariant");
27
-
28
- /**
29
- * You can't set the innerHTML of a document. Unless you have
30
- * this function.
31
- *
32
- * @param {DOMElement} node with tagName == 'html'
33
- * @param {string} markup markup string including <html>.
34
- */
35
- function mutateHTMLNodeWithMarkup(node, markup) {
36
- ("production" !== process.env.NODE_ENV ? invariant(
37
- node.tagName.toLowerCase() === 'html',
38
- 'mutateHTMLNodeWithMarkup(): node must have tagName of "html", got %s',
39
- node.tagName
40
- ) : invariant(node.tagName.toLowerCase() === 'html'));
41
-
42
- markup = markup.trim();
43
- ("production" !== process.env.NODE_ENV ? invariant(
44
- markup.toLowerCase().indexOf('<html') === 0,
45
- 'mutateHTMLNodeWithMarkup(): markup must start with <html'
46
- ) : invariant(markup.toLowerCase().indexOf('<html') === 0));
47
-
48
- // First let's extract the various pieces of markup.
49
- var htmlOpenTagEnd = markup.indexOf('>') + 1;
50
- var htmlCloseTagStart = markup.lastIndexOf('<');
51
- var htmlOpenTag = markup.substring(0, htmlOpenTagEnd);
52
- var innerHTML = markup.substring(htmlOpenTagEnd, htmlCloseTagStart);
53
-
54
- // Now for the fun stuff. Pass through both sets of attributes and
55
- // bring them up-to-date. We get the new set by creating a markup
56
- // fragment.
57
- var shouldExtractAttributes = htmlOpenTag.indexOf(' ') > -1;
58
- var attributeHolder = null;
59
-
60
- if (shouldExtractAttributes) {
61
- // We extract the attributes by creating a <span> and evaluating
62
- // the node.
63
- attributeHolder = createNodesFromMarkup(
64
- htmlOpenTag.replace('html ', 'span ') + '</span>'
65
- )[0];
66
-
67
- // Add all attributes present in attributeHolder
68
- var attributesToSet = filterAttributes(
69
- attributeHolder,
70
- function(attr) {
71
- return node.getAttributeNS(attr.namespaceURI, attr.name) !== attr.value;
72
- }
73
- );
74
- attributesToSet.forEach(function(attr) {
75
- node.setAttributeNS(attr.namespaceURI, attr.name, attr.value);
76
- });
77
- }
78
-
79
- // Remove all attributes not present in attributeHolder
80
- var attributesToRemove = filterAttributes(
81
- node,
82
- function(attr) {
83
- // Remove all attributes if attributeHolder is null or if it does not have
84
- // the desired attribute.
85
- return !(
86
- attributeHolder &&
87
- attributeHolder.hasAttributeNS(attr.namespaceURI, attr.name)
88
- );
89
- }
90
- );
91
- attributesToRemove.forEach(function(attr) {
92
- node.removeAttributeNS(attr.namespaceURI, attr.name);
93
- });
94
-
95
- // Finally, set the inner HTML. No tricks needed. Do this last to
96
- // minimize likelihood of triggering reflows.
97
- node.innerHTML = innerHTML;
98
- }
99
-
100
- module.exports = mutateHTMLNodeWithMarkup;