query.js
3.02 KB
//>>built
define("./_base/kernel ./has ./dom ./on ./_base/array ./_base/lang ./selector/_loader ./selector/_loader!default".split(" "),function(f,z,v,w,h,l,x,u){function r(a,b){var c=function(c,d){if("string"==typeof d&&(d=v.byId(d),!d))return new b([]);c="string"==typeof c?a(c,d):c?c.end&&c.on?c:[c]:[];return c.end&&c.on?c:new b(c)};c.matches=a.match||function(a,b,d){return 0<c.filter([a],b,d).length};c.filter=a.filter||function(a,b,d){return c(b,d).filter(function(b){return-1<h.indexOf(a,b)})};if("function"!=
typeof a){var d=a.search;a=function(a,b){return d(b||document,a)}}return c}var t=Array.prototype,m=t.slice,y=t.concat,n=h.forEach,p=function(a,b,c){b=[0].concat(m.call(b,0));c=c||f.global;return function(d){b[0]=d;return a.apply(c,b)}},g=function(a){var b=this instanceof e&&1;"number"==typeof a&&(a=Array(a));var c=a&&"length"in a?a:arguments;if(b||!c.sort){for(var d=b?this:[],g=d.length=c.length,f=0;f<g;f++)d[f]=c[f];if(b)return d;c=d}l._mixin(c,q);c._NodeListCtor=function(a){return e(a)};return c},
e=g,q=e.prototype=[];e._wrap=q._wrap=function(a,b,c){a=new (c||this._NodeListCtor||e)(a);return b?a._stash(b):a};e._adaptAsMap=function(a,b){return function(){return this.map(p(a,arguments,b))}};e._adaptAsForEach=function(a,b){return function(){this.forEach(p(a,arguments,b));return this}};e._adaptAsFilter=function(a,b){return function(){return this.filter(p(a,arguments,b))}};e._adaptWithCondition=function(a,b,c){return function(){var d=arguments,e=p(a,d,c);if(b.call(c||f.global,d))return this.map(e);
this.forEach(e);return this}};n(["slice","splice"],function(a){var b=t[a];q[a]=function(){return this._wrap(b.apply(this,arguments),"slice"==a?this:null)}});n(["indexOf","lastIndexOf","every","some"],function(a){var b=h[a];q[a]=function(){return b.apply(f,[this].concat(m.call(arguments,0)))}});l.extend(g,{constructor:e,_NodeListCtor:e,toString:function(){return this.join(",")},_stash:function(a){this._parent=a;return this},on:function(a,b){var c=this.map(function(c){return w(c,a,b)});c.remove=function(){for(var a=
0;a<c.length;a++)c[a].remove()};return c},end:function(){return this._parent?this._parent:new this._NodeListCtor(0)},concat:function(a){var b=m.call(this,0),c=h.map(arguments,function(a){return m.call(a,0)});return this._wrap(y.apply(b,c),this)},map:function(a,b){return this._wrap(h.map(this,a,b),this)},forEach:function(a,b){n(this,a,b);return this},filter:function(a){var b=arguments,c=this,d=0;if("string"==typeof a){c=k._filterResult(this,b[0]);if(1==b.length)return c._stash(this);d=1}return this._wrap(h.filter(c,
b[d],b[d+1]),this)},instantiate:function(a,b){var c=l.isFunction(a)?a:l.getObject(a);b=b||{};return this.forEach(function(a){new c(b,a)})},at:function(){var a=new this._NodeListCtor(0);n(arguments,function(b){0>b&&(b=this.length+b);this[b]&&a.push(this[b])},this);return a._stash(this)}});var k=r(u,g);f.query=r(u,function(a){return g(a)});k.load=function(a,b,c){x.load(a,b,function(a){c(r(a,g))})};f._filterQueryResult=k._filterResult=function(a,b,c){return new g(k.filter(a,b,c))};f.NodeList=k.NodeList=
g;return k});