Never add style attributes to existing elements
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Fri, 22 Jul 2011 11:46:30 -0600
changeset 445 773713229861
parent 444 de9cb2028556
child 446 2e6ffc2bd1bb
Never add style attributes to existing elements

There's no point in doing so in just one special case. It's confusing.
Better to be consistent.
editcommands.html
implementation.js
source.html
--- a/editcommands.html	Fri Jul 22 11:43:07 2011 -0600
+++ b/editcommands.html	Fri Jul 22 11:46:30 2011 -0600
@@ -2261,39 +2261,14 @@
 
     <li>Remove <var title="">new parent</var> from its <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-parent title=concept-tree-parent>parent</a>.
 
-    <li>If <var title="">new parent</var> is a <code class=external data-anolis-spec=html title="the span element"><a href=http://www.whatwg.org/html/#the-span-element>span</a></code>, and either a)
-    <var title="">command</var> is "underline" or "strikethrough", or b)
-    <var title="">command</var> is "fontSize" and <var title="">new value</var> is not
-    "xxx-large", or c) <var title="">command</var> is not "fontSize" and the
-    <a href=#relevant-css-property>relevant CSS property</a> for <var title="">command</var> is not null:
-
-    <ol>
-      <li>If the <a href=#relevant-css-property>relevant CSS property</a> for <var title="">command</var> is
-      not null, set that CSS property of <var title="">node</var> to <var title="">new
-      value</var>.
-
-      <li>If <var title="">command</var> is "strikethrough" and <var title="">new value</var> is
-      "line-through", alter the "text-decoration" property of <var title="">node</var>
-      to include "line-through" (preserving "overline" or "underline" if
-      present).
-
-      <li>If <var title="">command</var> is "underline" and <var title="">new value</var> is
-      "underline", alter the "text-decoration" property of <var title="">node</var> to
-      include "underline" (preserving "overline" or "line-through" if present).
-    </ol>
-
-    <li>Otherwise:
-
-    <ol>
-      <li>Let <var title="">children</var> be all <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-child title=concept-tree-child>children</a> of <var title="">node</var>,
-      omitting any that are <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#element>Element</a></code>s whose <a href=#specified-command-value>specified command
-      value</a> for <var title="">command</var> is neither null nor equal to <var title="">new
-      value</var>.
-
-      <li><a href=#force-the-value>Force the value</a> of each <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-node title=concept-node>node</a> in <var title="">children</var>,
-      with <var title="">command</var> and <var title="">new value</var> as in this invocation
-      of the algorithm.
-    </ol>
+    <li>Let <var title="">children</var> be all <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-tree-child title=concept-tree-child>children</a> of <var title="">node</var>,
+    omitting any that are <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#element>Element</a></code>s whose <a href=#specified-command-value>specified command
+    value</a> for <var title="">command</var> is neither null nor equal to <var title="">new
+    value</var>.
+
+    <li><a href=#force-the-value>Force the value</a> of each <a class=external data-anolis-spec=domcore href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-node title=concept-node>node</a> in <var title="">children</var>,
+    with <var title="">command</var> and <var title="">new value</var> as in this invocation of
+    the algorithm.
   </ol>
 </ol>
 
--- a/implementation.js	Fri Jul 22 11:43:07 2011 -0600
+++ b/implementation.js	Fri Jul 22 11:46:30 2011 -0600
@@ -2848,70 +2848,26 @@
 		// "Remove new parent from its parent."
 		newParent.parentNode.removeChild(newParent);
 
-		// "If new parent is a span, and either a) command is "underline" or
-		// "strikethrough", or b) command is "fontSize" and new value is not
-		// "xxx-large", or c) command is not "fontSize" and the relevant CSS
-		// property for command is not null:"
-		if (newParent.tagName == "SPAN"
-		&& (
-			(command == "underline" || command == "strikethrough")
-			|| (command == "fontsize" && newValue != "xxx-large")
-			|| (command != "fontsize" && property !== null)
-		)) {
-			// "If the relevant CSS property for command is not null, set that
-			// CSS property of node to new value."
-			if (property !== null) {
-				node.style[property] = newValue;
-			}
-
-			// "If command is "strikethrough" and new value is "line-through",
-			// alter the "text-decoration" property of node to include
-			// "line-through" (preserving "overline" or "underline" if
-			// present)."
-			if (command == "strikethrough" && newValue == "line-through") {
-				if (node.style.textDecoration == ""
-				|| node.style.textDecoration == "none") {
-					node.style.textDecoration = "line-through";
-				} else {
-					node.style.textDecoration += " line-through";
+		// "Let children be all children of node, omitting any that are
+		// Elements whose specified command value for command is neither null
+		// nor equal to new value."
+		var children = [];
+		for (var i = 0; i < node.childNodes.length; i++) {
+			if (node.childNodes[i].nodeType == Node.ELEMENT_NODE) {
+				var specifiedValue = getSpecifiedCommandValue(node.childNodes[i], command);
+
+				if (specifiedValue !== null
+				&& !valuesEqual(command, newValue, specifiedValue)) {
+					continue;
 				}
 			}
-
-			// "If command is "underline" and new value is "underline", alter
-			// the "text-decoration" property of node to include "underline"
-			// (preserving "overline" or "line-through" if present)."
-			if (command == "underline" && newValue == "underline") {
-				if (node.style.textDecoration == ""
-				|| node.style.textDecoration == "none") {
-					node.style.textDecoration = "underline";
-				} else {
-					node.style.textDecoration += " underline";
-				}
-			}
-
-		// "Otherwise:"
-		} else {
-			// "Let children be all children of node, omitting any that are
-			// Elements whose specified command value for command is neither
-			// null nor equal to new value."
-			var children = [];
-			for (var i = 0; i < node.childNodes.length; i++) {
-				if (node.childNodes[i].nodeType == Node.ELEMENT_NODE) {
-					var specifiedValue = getSpecifiedCommandValue(node.childNodes[i], command);
-
-					if (specifiedValue !== null
-					&& !valuesEqual(command, newValue, specifiedValue)) {
-						continue;
-					}
-				}
-				children.push(node.childNodes[i]);
-			}
-
-			// "Force the value of each Node in children, with command and new
-			// value as in this invocation of the algorithm."
-			for (var i = 0; i < children.length; i++) {
-				forceValue(children[i], command, newValue);
-			}
+			children.push(node.childNodes[i]);
+		}
+
+		// "Force the value of each Node in children, with command and new
+		// value as in this invocation of the algorithm."
+		for (var i = 0; i < children.length; i++) {
+			forceValue(children[i], command, newValue);
 		}
 	}
 }
--- a/source.html	Fri Jul 22 11:43:07 2011 -0600
+++ b/source.html	Fri Jul 22 11:46:30 2011 -0600
@@ -2246,39 +2246,14 @@
 
     <li>Remove <var>new parent</var> from its [[parent]].
 
-    <li>If <var>new parent</var> is a [[span]], and either a)
-    <var>command</var> is "underline" or "strikethrough", or b)
-    <var>command</var> is "fontSize" and <var>new value</var> is not
-    "xxx-large", or c) <var>command</var> is not "fontSize" and the
-    <span>relevant CSS property</span> for <var>command</var> is not null:
-
-    <ol>
-      <li>If the <span>relevant CSS property</span> for <var>command</var> is
-      not null, set that CSS property of <var>node</var> to <var>new
-      value</var>.
-
-      <li>If <var>command</var> is "strikethrough" and <var>new value</var> is
-      "line-through", alter the "text-decoration" property of <var>node</var>
-      to include "line-through" (preserving "overline" or "underline" if
-      present).
-
-      <li>If <var>command</var> is "underline" and <var>new value</var> is
-      "underline", alter the "text-decoration" property of <var>node</var> to
-      include "underline" (preserving "overline" or "line-through" if present).
-    </ol>
-
-    <li>Otherwise:
-
-    <ol>
-      <li>Let <var>children</var> be all [[children]] of <var>node</var>,
-      omitting any that are [[element]]s whose <span>specified command
-      value</span> for <var>command</var> is neither null nor equal to <var>new
-      value</var>.
-
-      <li><span>Force the value</span> of each [[node]] in <var>children</var>,
-      with <var>command</var> and <var>new value</var> as in this invocation
-      of the algorithm.
-    </ol>
+    <li>Let <var>children</var> be all [[children]] of <var>node</var>,
+    omitting any that are [[element]]s whose <span>specified command
+    value</span> for <var>command</var> is neither null nor equal to <var>new
+    value</var>.
+
+    <li><span>Force the value</span> of each [[node]] in <var>children</var>,
+    with <var>command</var> and <var>new value</var> as in this invocation of
+    the algorithm.
   </ol>
 </ol>