Explorar el Código

added Node.nodes()

Nicolas Cannasse hace 19 años
padre
commit
8b7eac468c
Se han modificado 3 ficheros con 44 adiciones y 1 borrados
  1. 3 0
      std/Node.hx
  2. 20 1
      std/flash/Boot.hx
  3. 21 0
      std/neko/NekoNode__.hx

+ 3 - 0
std/Node.hx

@@ -58,4 +58,7 @@ extern class Node {
 	/* added in Flash */
 	function replaceChild( newChild : Node, oldChild : Node ) : Void;
 
+
+	/* added for haXe */
+	function nodes() : Iterator<Node>;
 }

+ 20 - 1
std/flash/Boot.hx

@@ -165,7 +165,26 @@ class Boot {
 				this.insertBefore(cnew,cold);
 				this.removeChild(cold);
 			};
-
+			Node.prototype.nodes = function() {
+				return untyped {
+					p : 0,
+					a : childNodes,
+					next : function() {
+						return this.a[this.p++];
+					},
+					hasNext : function() {
+						while true {
+							var x = this.a[this.p];
+							if( x == null )
+								return false;
+							if( x.nodeType == 1 )
+								return true;
+							this.p++;
+						}
+						return null;
+					}
+				};
+			};
 			Array.prototype.copy = Array.prototype.slice;
 			Array.prototype.insert = function(i,x) {
 				this.splice(i,0,x);

+ 21 - 0
std/neko/NekoNode__.hx

@@ -100,4 +100,25 @@ class NekoNode__ implements Node {
 		throw "not implemented";
 	}
 
+	public function nodes() {
+		return untyped {
+			p : 0,
+			a : childNodes,
+			next : function() {
+				return this.a[this.p++];
+			},
+			hasNext : function() {
+				while true {
+					var x = this.a[this.p];
+					if( x == null )
+						return false;
+					if( x.nodeType == element_node )
+						return true;
+					this.p++;
+				}
+				return null;
+			}
+		};
+	}
+
 }