incubator-xap-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mtu...@apache.org
Subject svn commit: r469194 - in /incubator/xap/trunk/src/xap: data/controller/Iterator.js xml/dom/XapElement.js
Date Mon, 30 Oct 2006 16:57:02 GMT
Author: mturyn
Date: Mon Oct 30 08:57:02 2006
New Revision: 469194

URL: http://svn.apache.org/viewvc?view=rev&rev=469194
Log:
Gave XapElement an insertChildAt() method so that Iterator could use it---handles odd cases.

Modified:
    incubator/xap/trunk/src/xap/data/controller/Iterator.js
    incubator/xap/trunk/src/xap/xml/dom/XapElement.js

Modified: incubator/xap/trunk/src/xap/data/controller/Iterator.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/data/controller/Iterator.js?view=diff&rev=469194&r1=469193&r2=469194
==============================================================================
--- incubator/xap/trunk/src/xap/data/controller/Iterator.js (original)
+++ incubator/xap/trunk/src/xap/data/controller/Iterator.js Mon Oct 30 08:57:02 2006
@@ -414,8 +414,7 @@
                                 location = new xap.data.controller.ElementLocation(childClone);
                                 this._iteratedLocations.addElement(location);
                             }
-//                          this._parentElement.insertChildAt(insertIndex, childClone);
-							this._parentElement.appendChild(childClone) ;
+							this._parentElement.insertChildAt(insertIndex, childClone);
                         } else {
                             if (child instanceof String) {
                                 this._parentElement.insertChildAt(insertIndex, child);

Modified: incubator/xap/trunk/src/xap/xml/dom/XapElement.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/xml/dom/XapElement.js?view=diff&rev=469194&r1=469193&r2=469194
==============================================================================
--- incubator/xap/trunk/src/xap/xml/dom/XapElement.js (original)
+++ incubator/xap/trunk/src/xap/xml/dom/XapElement.js Mon Oct 30 08:57:02 2006
@@ -287,6 +287,37 @@
 	return this._insertBefore( child );  
 }
 
+/**
+ * Inserts the new child newNode at the given index.
+ * @param {google.XNode} newChild The new child to insert.
+ * @param {int} index The index at which to insert the new child
+ */
+xap.xml.dom.XapElement.prototype.insertChildAt = function(index, newChild) {
+	var nChildren = this.childNodes.length ;
+	if(index > nChildren){
+		var event = new xap.xml.dom.events.StructureChangeEvent(this, newChild, index);
+		throw new xap.xml.dom.events.ChangeRejectedException( 
+				xap.xml.dom.events.ChangeRejectedException.REJECTED_WITH_REASON_MSGID,
+		      	["Attempted to insert at invalid index: "+index+"; last child is at nChildren"],

+		      	null, 
+		      	event 
+		      													);	
+	}
+	// reduce to known cases:
+	var result = null ;
+	if( index == nChildren){
+		// At the end:
+		result = this.appendChild(newChild) ;
+	} else {
+		// This is a bit backwards, but at this
+		// point I'd rather not (e.g.) just copy
+		// most of the code from _insertBefore
+		result = this.insertBefore( newChild, this.childNodes[index] );
+	}
+	return result ;
+}
+
+
 
 /**
  * Removes the given child from this element.



Mime
View raw message