2 Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
3 Available via Academic Free License >= 2.1 OR the modified BSD license.
4 see: http://dojotoolkit.org/license for details
8 if(!dojo._hasResource["dojo._base.NodeList"]){
9 dojo._hasResource["dojo._base.NodeList"]=true;
10 dojo.provide("dojo._base.NodeList");
11 dojo.require("dojo._base.lang");
12 dojo.require("dojo._base.array");
15 var ap=Array.prototype,_1=ap.slice,_2=ap.concat;
16 var _3=function(a,_4,_5){
20 var _6=_5||this._NodeListCtor||d._NodeListCtor;
22 dojo._mixin(a,_6.prototype);
24 return _4?a._stash(_4):a;
26 var _7=function(f,a,o){
27 a=[0].concat(_1.call(a,0));
36 this.forEach(_7(f,arguments,o));
42 return this.map(_7(f,arguments,o));
47 return this.filter(_7(f,arguments,o));
50 var _c=function(f,g,o){
52 var a=arguments,_d=_7(f,a,o);
53 if(g.call(o||d.global,a)){
61 return a.length==1&&(typeof a[0]=="string");
69 dojo.NodeList=function(){
70 return _3(Array.apply(null,arguments));
72 d._NodeListCtor=d.NodeList;
73 var nl=d.NodeList,nlp=nl.prototype;
74 nl._wrap=nlp._wrap=_3;
76 nl._adaptAsForEach=_9;
78 nl._adaptWithCondition=_c;
79 d.forEach(["slice","splice"],function(_11){
82 return this._wrap(f.apply(this,arguments),_11=="slice"?this:null);
85 d.forEach(["indexOf","lastIndexOf","every","some"],function(_12){
88 return f.apply(d,[this].concat(_1.call(arguments,0)));
91 d.forEach(["attr","style"],function(_13){
92 nlp[_13]=_c(d[_13],_e);
94 d.forEach(["connect","addClass","removeClass","toggleClass","empty","removeAttr"],function(_14){
97 dojo.extend(dojo.NodeList,{_normalize:function(_15,_16){
98 var _17=_15.parse===true?true:false;
99 if(typeof _15.template=="string"){
100 var _18=_15.templateFunc||(dojo.string&&dojo.string.substitute);
101 _15=_18?_18(_15.template,_15):_15;
103 var _19=(typeof _15);
104 if(_19=="string"||_19=="number"){
105 _15=dojo._toDom(_15,(_16&&_16.ownerDocument));
106 if(_15.nodeType==11){
107 _15=dojo._toArray(_15.childNodes);
112 if(!dojo.isArrayLike(_15)){
115 if(!dojo.isArray(_15)){
116 _15=dojo._toArray(_15);
124 },_cloneNode:function(_1a){
125 return _1a.cloneNode(true);
126 },_place:function(ary,_1b,_1c,_1d){
127 if(_1b.nodeType!=1&&_1c=="only"){
132 for(var i=_20-1;i>=0;i--){
133 var _21=(_1d?this._cloneNode(ary[i]):ary[i]);
134 if(ary._runParse&&dojo.parser&&dojo.parser.parse){
136 _1f=_1e.ownerDocument.createElement("div");
138 _1f.appendChild(_21);
139 dojo.parser.parse(_1f);
141 while(_1f.firstChild){
142 _1f.removeChild(_1f.firstChild);
146 dojo.place(_21,_1e,_1c);
148 _1e.parentNode.insertBefore(_21,_1e);
152 },_stash:function(_22){
159 return new this._NodeListCtor();
161 },concat:function(_23){
162 var t=d.isArray(this)?this:_1.call(this,0),m=d.map(arguments,function(a){
163 return a&&!d.isArray(a)&&(typeof NodeList!="undefined"&&a.constructor===NodeList||a.constructor===this._NodeListCtor)?_1.call(a,0):a;
165 return this._wrap(_2.apply(t,m),this);
166 },map:function(_24,obj){
167 return this._wrap(d.map(this,_24,obj),this);
168 },forEach:function(_25,_26){
169 d.forEach(this,_25,_26);
171 },coords:_a(d.coords),position:_a(d.position),place:function(_27,_28){
172 var _29=d.query(_27)[0];
173 return this.forEach(function(_2a){
174 d.place(_2a,_29,_28);
176 },orphan:function(_2b){
177 return (_2b?d._filterQueryResult(this,_2b):this).forEach(_f);
178 },adopt:function(_2c,_2d){
179 return d.query(_2c).place(this[0],_2d)._stash(this);
180 },query:function(_2e){
184 var ret=this.map(function(_2f){
185 return d.query(_2e,_2f).filter(function(_30){
186 return _30!==undefined;
189 return this._wrap(_2.apply([],ret),this);
190 },filter:function(_31){
191 var a=arguments,_32=this,_33=0;
192 if(typeof _31=="string"){
193 _32=d._filterQueryResult(this,a[0]);
195 return _32._stash(this);
199 return this._wrap(d.filter(_32,a[_33],a[_33+1]),this);
200 },addContent:function(_34,_35){
201 _34=this._normalize(_34,this[0]);
202 for(var i=0,_36;_36=this[i];i++){
203 this._place(_34,_36,_35,i>0);
206 },instantiate:function(_37,_38){
207 var c=d.isFunction(_37)?_37:d.getObject(_37);
209 return this.forEach(function(_39){
213 var t=new this._NodeListCtor();
214 d.forEach(arguments,function(i){
222 return t._stash(this);
224 nl.events=["blur","focus","change","click","error","keydown","keypress","keyup","load","mousedown","mouseenter","mouseleave","mousemove","mouseout","mouseover","mouseup","submit"];
225 d.forEach(nl.events,function(evt){
227 nlp[_3a]=function(a,b){
228 return this.connect(_3a,a,b);