📄 nodelist.js
字号:
if(!dojo._hasResource["dojo._base.NodeList"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.dojo._hasResource["dojo._base.NodeList"] = true;dojo.provide("dojo._base.NodeList");dojo.require("dojo._base.lang");dojo.require("dojo._base.array");(function(){ var d = dojo; var tnl = function(arr){ // decorate an array to make it look like a NodeList arr.constructor = dojo.NodeList; dojo._mixin(arr, dojo.NodeList.prototype); return arr; } var _mapIntoDojo = function(func, alwaysThis){ // returns a function which, when executed in the scope of its caller, // applies the passed arguments to a particular dojo.* function (named // in func) and aggregates the returns. if alwaysThis is true, it // always returns the scope object and not the collected returns from // the Dojo method return function(){ var _a = arguments; var aa = d._toArray(_a, 0, [null]); var s = this.map(function(i){ aa[0] = i; return d[func].apply(d, aa); }); return (alwaysThis || ( (_a.length > 1) || !d.isString(_a[0]) )) ? this : s; // String||dojo.NodeList } }; dojo.NodeList = function(){ // summary: // dojo.NodeList is as subclass of Array which adds syntactic // sugar for chaining, common iteration operations, animation, // and node manipulation. NodeLists are most often returned as // the result of dojo.query() calls. // example: // create a node list from a node // | new dojo.NodeList(dojo.byId("foo")); return tnl(Array.apply(null, arguments)); } dojo.NodeList._wrap = tnl; dojo.extend(dojo.NodeList, { // http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array#Methods // FIXME: handle return values for #3244 // http://trac.dojotoolkit.org/ticket/3244 // FIXME: // need to wrap or implement: // join (perhaps w/ innerHTML/outerHTML overload for toString() of items?) // reduce // reduceRight slice: function(/*===== begin, end =====*/){ // summary: // Returns a new NodeList, maintaining this one in place // description: // This method behaves exactly like the Array.slice method // with the caveat that it returns a dojo.NodeList and not a // raw Array. For more details, see: // http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:slice // begin: Integer // Can be a positive or negative integer, with positive // integers noting the offset to begin at, and negative // integers denoting an offset from the end (i.e., to the left // of the end) // end: Integer? // Optional parameter to describe what position relative to // the NodeList's zero index to end the slice at. Like begin, // can be positive or negative. var a = dojo._toArray(arguments); return tnl(a.slice.apply(this, a)); }, splice: function(/*===== index, howmany, item =====*/){ // summary: // Returns a new NodeList, manipulating this NodeList based on // the arguments passed, potentially splicing in new elements // at an offset, optionally deleting elements // description: // This method behaves exactly like the Array.splice method // with the caveat that it returns a dojo.NodeList and not a // raw Array. For more details, see: // <http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:splice> // index: Integer // begin can be a positive or negative integer, with positive // integers noting the offset to begin at, and negative // integers denoting an offset from the end (i.e., to the left // of the end) // howmany: Integer? // Optional parameter to describe what position relative to // the NodeList's zero index to end the slice at. Like begin, // can be positive or negative. // item: Object...? // Any number of optional parameters may be passed in to be // spliced into the NodeList // returns: // dojo.NodeList var a = dojo._toArray(arguments); return tnl(a.splice.apply(this, a)); }, concat: function(/*===== item =====*/){ // summary: // Returns a new NodeList comprised of items in this NodeList // as well as items passed in as parameters // description: // This method behaves exactly like the Array.concat method // with the caveat that it returns a dojo.NodeList and not a // raw Array. For more details, see: // <http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:concat> // item: Object...? // Any number of optional parameters may be passed in to be // spliced into the NodeList // returns: // dojo.NodeList var a = dojo._toArray(arguments, 0, [this]); return tnl(a.concat.apply([], a)); }, indexOf: function(/*Object*/ value, /*Integer?*/ fromIndex){ // summary: // see dojo.indexOf(). The primary difference is that the acted-on // array is implicitly this NodeList // value: // The value to search for. // fromIndex: // The loction to start searching from. Optional. Defaults to 0. // description: // For more details on the behavior of indexOf, see: // <http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:indexOf> // returns: // Positive Integer or 0 for a match, -1 of not found. return d.indexOf(this, value, fromIndex); // Integer }, lastIndexOf: function(/*===== value, fromIndex =====*/){ // summary: // see dojo.lastIndexOf(). The primary difference is that the // acted-on array is implicitly this NodeList // description: // For more details on the behavior of lastIndexOf, see: // <http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:lastIndexOf> // value: Object // The value to search for. // fromIndex: Integer? // The loction to start searching from. Optional. Defaults to 0. // returns: // Positive Integer or 0 for a match, -1 of not found. return d.lastIndexOf.apply(d, d._toArray(arguments, 0, [this])); // Integer }, every: function(/*Function*/callback, /*Object?*/thisObject){ // summary: // see `dojo.every()` and: // <http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:every> // Takes the same structure of arguments and returns as // dojo.every() with the caveat that the passed array is // implicitly this NodeList return d.every(this, callback, thisObject); // Boolean }, some: function(/*Function*/callback, /*Object?*/thisObject){ // summary: // see dojo.some() and: // http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:some // Takes the same structure of arguments and returns as // dojo.some() with the caveat that the passed array is // implicitly this NodeList return d.some(this, callback, thisObject); // Boolean }, map: function(/*Function*/ func, /*Function?*/ obj){ // summary: // see dojo.map(). The primary difference is that the acted-on // array is implicitly this NodeList and the return is a // dojo.NodeList (a subclass of Array) return d.map(this, func, obj, d.NodeList); // dojo.NodeList }, forEach: function(callback, thisObj){ // summary: // see dojo.forEach(). The primary difference is that the acted-on // array is implicitly this NodeList d.forEach(this, callback, thisObj); // non-standard return to allow easier chaining return this; // dojo.NodeList }, // custom methods coords: function(){ // summary: // Returns the box objects all elements in a node list as // an Array (*not* a NodeList) return d.map(this, d.coords); // Array }, /*===== attr: function(property, value){ // summary: // gets or sets the DOM attribute for every element in the // NodeList // property: String // the attribute to get/set // value: String? // optional. The value to set the property to // return: // if no value is passed, the result is an array of attribute values // If a value is passed, the return is this NodeList }, style: function(property, value){ // summary: // gets or sets the CSS property for every element in the NodeList // property: String // the CSS property to get/set, in JavaScript notation // ("lineHieght" instead of "line-height") // value: String? // optional. The value to set the property to // return: // if no value is passed, the result is an array of strings. // If a value is passed, the return is this NodeList }, addClass: function(className){ // summary: // adds the specified class to every node in the list // className: String // the CSS class to add // return: // dojo.NodeList, this list }, removeClass: function(className){ // summary: // removes the specified class from every node in the list // className: String // the CSS class to add // return: // dojo.NodeList, this list }, toggleClass: function(className, condition){ // summary: // Adds a class to node if not present, or removes if present. // Pass a boolean condition if you want to explicitly add or remove. // condition: Boolean? // If passed, true means to add the class, false means to remove. // className: String // the CSS class to add // return: dojo.NodeList // this list }, connect: function(methodName, objOrFunc, funcName){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -