// If we are presented with the following defintion for a NodeList:
// | var l = new dojo.NodeList(dojo.byId("foo"), dojo.byId("bar"));
// it's possible to find all span elements under paragraphs
// contained by these elements with this sub-query:
// | var spans = l.query("p span");
// FIXME: probably slow
if(!queryStr){ return this; }
var ret = this.map(function(node){
// FIXME: why would we ever get undefined here?
return d.query(queryStr, node).filter(function(subNode){ return subNode !== undefined; });
});
return this._wrap(apc.apply([], ret), this); // dojo.NodeList
},
filter: function(/*String|Function*/ simpleFilter){
// summary:
// "masks" the built-in javascript filter() method (supported
// in Dojo via `dojo.filter`) to support passing a simple
// string filter in addition to supporting filtering function
// objects.
// simpleFilter:
// If a string, a single-expression CSS rule. For example,
// ".thinger" or "#someId[attrName='value']" but not "div >
// span". In short, anything which does not invoke a descent
// to evaluate but can instead be used to test a single node
// is acceptable.
// example:
// "regular" JS filter syntax as exposed in dojo.filter:
// | dojo.query("*").filter(function(item){
// | // highlight every paragraph
// | return (item.nodeName == "p");
// | }).style("backgroundColor", "yellow");
// example:
// the same filtering using a CSS selector
// | dojo.query("*").filter("p").styles("backgroundColor", "yellow");
var a = arguments, items = this, start = 0;
if(typeof simpleFilter == "string"){ // inline'd type check
items = d._filterQueryResult(this, a[0]);
if(a.length == 1){
// if we only got a string query, pass back the filtered results
return items._stash(this); // dojo.NodeList
}
// if we got a callback, run it over the filtered items
start = 1;
}
return this._wrap(d.filter(items, a[start], a[start + 1]), this); // dojo.NodeList
},
/*
// FIXME: should this be "copyTo" and include parenting info?
clone: function(){
// summary:
// creates node clones of each element of this list
// and returns a new list containing the clones
},
*/
addContent: function(/*String||DomNode||Object||dojo.NodeList*/ content, /*String||Integer?*/ position){
// summary:
// add a node, NodeList or some HTML as a string to every item in the
// list. Returns the original list.
// description:
// a copy of the HTML content is added to each item in the
// list, with an optional position argument. If no position
// argument is provided, the content is appended to the end of
// each item.
// content:
// DOM node, HTML in string format, a NodeList or an Object. If a DOM node or
// NodeList, the content will be cloned if the current NodeList has more than one
// element. Only the DOM nodes are cloned, no event handlers. If it is an Object,
// it should be an object with at "template" String property that has the HTML string
// to insert. If dojo.string has already been dojo.required, then dojo.string.substitute
// will be used on the "template" to generate the final HTML string. Other allowed
// properties on the object are: "parse" if the HTML
// string should be parsed for widgets (dojo.require("dojo.parser") to get that
// option to work), and "templateFunc" if a template function besides dojo.string.substitute
// should be used to transform the "template".
// position:
// can be one of:
// | "last"||"end" (default)
// | "first||"start"
// | "before"
// | "after"
// | "replace" (replaces nodes in this NodeList with new content)
// | "only" (removes other children of the nodes so new content is hte only child)
// or an offset in the childNodes property
// example:
// appends content to the end if the position is ommitted
// | dojo.query("h3 > p").addContent("hey there!");
// example:
// add something to the front of each element that has a
// "thinger" property:
// | dojo.query("[thinger]").addContent("...", "first");
// example:
// adds a header before each element of the list
// | dojo.query(".note").addContent("