Simplify a bit
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Sun, 22 May 2011 15:08:59 -0600
changeset 161 b5e34f38f6ec
parent 160 a048a4793c97
child 162 14e80c71bb73
Simplify a bit
editcommands.html
implementation.js
source.html
--- a/editcommands.html	Sun May 22 15:04:17 2011 -0600
+++ b/editcommands.html	Sun May 22 15:08:59 2011 -0600
@@ -273,7 +273,8 @@
 
 <p>An <dfn id=editing-host>editing host</dfn> is a <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> that is either an <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#element>Element</a></code> with
 a <code class=external data-anolis-spec=html title=attr-contenteditable><a href=http://www.whatwg.org/html/#attr-contenteditable>contenteditable</a></code>
-attribute set to the true state, or a <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#document>Document</a></code> whose <code class=external data-anolis-spec=html><a href=http://www.whatwg.org/html/#designmode>designMode</a></code> is enabled.
+attribute set to the true state, or the <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#element>Element</a></code> child of a <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#document>Document</a></code>
+whose <code class=external data-anolis-spec=html><a href=http://www.whatwg.org/html/#designmode>designMode</a></code> is enabled.
 
 <p>Something is <dfn id=editable>editable</dfn> if it is a <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> which is not an
 <a href=#editing-host>editing host</a>, does not have a <code class=external data-anolis-spec=html title=attr-contenteditable><a href=http://www.whatwg.org/html/#attr-contenteditable>contenteditable</a></code> attribute set to the false
@@ -1582,13 +1583,6 @@
 <ol>
   <li>Let <var title="">command</var> be the current <a href=#command>command</a>.
 
-  <li>If <var title="">node</var> is a <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#document>Document</a></code>, <a href=#set-the-value>set the value</a> of its
-  <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#element>Element</a></code> <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>child</a> (if it has one) and abort this algorithm.
-
-  <li>If <var title="">node</var> is a <code class=external data-anolis-spec=domcore><a href=http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#documentfragment>DocumentFragment</a></code>, let <var title="">children</var> be
-  a list of its <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>.  <a href=#set-the-value>Set the value</a> of each member of
-  <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>, then abort this algorithm.
-
   <li>If <var title="">node</var> is not <a href=#editable>editable</a>:
   <!--
   IE9: Allows everything to be modified by execCommand(), regardless of whether
--- a/implementation.js	Sun May 22 15:04:17 2011 -0600
+++ b/implementation.js	Sun May 22 15:08:59 2011 -0600
@@ -630,11 +630,15 @@
 }
 
 // "An editing host is a node that is either an Element with a contenteditable
-// attribute set to the true state, or a Document whose designMode is enabled."
+// attribute set to the true state, or the Element child of a Document whose
+// designMode is enabled."
 function isEditingHost(node) {
 	return node
-		&& ((node.nodeType == Node.ELEMENT_NODE && node.contentEditable == "true")
-		|| (node.nodeType == Node.DOCUMENT_NODE && node.designMode == "on"));
+		&& node.nodeType == Node.ELEMENT_NODE
+		&& (node.contentEditable == "true"
+		|| (node.parentNode
+		&& node.parentNode.nodeType == Node.DOCUMENT_NODE
+		&& node.parentNodedesignMode == "on"));
 }
 
 // "Something is editable if it is a node which is not an editing host, does
@@ -2157,37 +2161,6 @@
 }
 
 function setNodeValue(node, command, newValue) {
-	// "If node is a Document, set the value of its Element child (if it has
-	// one) and abort this algorithm."
-	if (node.nodeType == Node.DOCUMENT_NODE) {
-		for (var i = 0; i < node.childNodes.length; i++) {
-			if (node.childNodes[i].nodeType == Node.ELEMENT_NODE) {
-				setNodeValue(node.childNodes[i], command, newValue);
-				break;
-			}
-		}
-		return;
-	}
-
-	// "If node is a DocumentFragment, let children be a list of its children.
-	// Set the value of each member of children, then abort this algorithm."
-	if (node.nodeType == Node.DOCUMENT_FRAGMENT_NODE) {
-		var children = [];
-		for (var i = 0; i < node.childNodes.length; i++) {
-			children.push(node.childNodes[i]);
-		}
-		for (var i = 0; i < children.length; i++) {
-			setNodeValue(children[i], command, newValue);
-		}
-		return;
-	}
-
-	// "If node's parent is null, or if node is a DocumentType, abort this
-	// algorithm."
-	if (!node.parentNode || node.nodeType == Node.DOCUMENT_TYPE_NODE) {
-		return;
-	}
-
 	// "If node is not editable:"
 	if (!isEditable(node)) {
 		// "Let children be the children of node."
--- a/source.html	Sun May 22 15:04:17 2011 -0600
+++ b/source.html	Sun May 22 15:08:59 2011 -0600
@@ -229,8 +229,8 @@
 
 <p>An <dfn>editing host</dfn> is a [[node]] that is either an [[element]] with
 a <code data-anolis-spec=html title=attr-contenteditable>contenteditable</code>
-attribute set to the true state, or a [[document]] whose <code
-data-anolis-spec=html>designMode</code> is enabled.
+attribute set to the true state, or the [[element]] child of a [[document]]
+whose <code data-anolis-spec=html>designMode</code> is enabled.
 
 <p>Something is <dfn>editable</dfn> if it is a [[node]] which is not an
 <span>editing host</span>, does not have a <code data-anolis-spec=html
@@ -1573,13 +1573,6 @@
 <ol>
   <li>Let <var>command</var> be the current <span>command</span>.
 
-  <li>If <var>node</var> is a [[document]], <span>set the value</span> of its
-  [[element]] [[child]] (if it has one) and abort this algorithm.
-
-  <li>If <var>node</var> is a [[documentfragment]], let <var>children</var> be
-  a list of its [[children]].  <span>Set the value</span> of each member of
-  [[children]], then abort this algorithm.
-
   <li>If <var>node</var> is not <span>editable</span>:
   <!--
   IE9: Allows everything to be modified by execCommand(), regardless of whether