89
* The name of the component
94
* The name of the component
93
98
Y_Node.NAME = 'node';
96
* The pattern used to identify ARIA attributes
101
* The pattern used to identify ARIA attributes
98
103
Y_Node.re_aria = /^(?:role$|aria-)/;
105
Y_Node.SHOW_TRANSITION = 'fadeIn';
106
Y_Node.HIDE_TRANSITION = 'fadeOut';
101
* List of events that route to DOM events
109
* List of events that route to DOM events
103
111
* @property DOM_EVENTS
106
114
Y_Node.DOM_EVENTS = {
190
199
* @return {Y.Node | Y.NodeList | any} Depends on what is returned from the DOM node.
192
201
Y_Node.scrubVal = function(val, node) {
193
if (node && val) { // only truthy values are risky
194
if (typeof val === 'object' || typeof val === 'function') { // safari nodeList === function
202
if (val) { // only truthy values are risky
203
if (typeof val == 'object' || typeof val == 'function') { // safari nodeList === function
195
204
if (NODE_TYPE in val || Y_DOM.isWindow(val)) {// node || window
196
205
val = Y.one(val);
197
206
} else if ((val.item && !val._nodes) || // dom collection or Node instance
213
222
* @method addMethod
216
* @param {String} name The name of the method to add
217
* @param {Function} fn The function that becomes the method
225
* @param {String} name The name of the method to add
226
* @param {Function} fn The function that becomes the method
218
227
* @param {Object} context An optional context to call the method with
219
228
* (defaults to the Node instance)
220
229
* @return {any} Depends on what is returned from the DOM node.
222
231
Y_Node.addMethod = function(name, fn, context) {
223
if (name && fn && typeof fn === 'function') {
232
if (name && fn && typeof fn == 'function') {
224
233
Y_Node.prototype[name] = function() {
225
context = context || this;
226
var args = Y.Array(arguments, 0, true),
234
var args = _slice.call(arguments),
229
if (args[0] && args[0] instanceof Y_Node) {
238
if (args[0] && Y.instanceOf(args[0], Y_Node)) {
230
239
args[0] = args[0]._node;
233
if (args[1] && args[1] instanceof Y_Node) {
242
if (args[1] && Y.instanceOf(args[1], Y_Node)) {
234
243
args[1] = args[1]._node;
236
args.unshift(this._node);
237
ret = Y_Node.scrubVal(fn.apply(context, args), this);
245
args.unshift(node._node);
247
ret = fn.apply(node, args);
249
if (ret) { // scrub truthy
250
ret = Y_Node.scrubVal(ret, node);
253
(typeof ret != 'undefined') || (ret = node);
246
262
* @method importMethod
249
* @param {Object} host The object that contains the method to import.
265
* @param {Object} host The object that contains the method to import.
250
266
* @param {String} name The name of the method to import
251
* @param {String} altName An optional name to use in place of the host name
267
* @param {String} altName An optional name to use in place of the host name
252
268
* @param {Object} context An optional context to call the method with
254
270
Y_Node.importMethod = function(host, name, altName) {
255
if (typeof name === 'string') {
271
if (typeof name == 'string') {
256
272
altName = altName || name;
257
273
Y_Node.addMethod(altName, host[name], host);
309
* Returns a single Node instance bound to the node or the
310
* first element matching the given selector.
312
* @deprecated Use Y.one
314
* @param {String | HTMLElement} node a node or Selector
315
* @param {Y.Node || HTMLElement} doc an optional document to scan. Defaults to Y.config.doc.
317
Y_Node.get = function() {
318
return Y_Node.one.apply(Y_Node, arguments);
322
* Creates a new dom node using the provided markup string.
325
* Returns a new dom node using the provided markup string.
325
328
* @param {String} html The markup used to create the element
326
* @param {HTMLDocument} doc An optional document context
327
* @return {Node} A Node instance bound to a DOM node or fragment
329
* @param {HTMLDocument} doc An optional document context
330
* @return {Node} A Node instance bound to a DOM node or fragment
329
Y_Node.create = function() {
330
return Y.one(Y_DOM.create.apply(Y_DOM, arguments));
332
Y_Node.create = function(html, doc) {
333
if (doc && doc._node) {
336
return Y.one(Y_DOM.create(html, doc));
395
401
Y_DOM.setValue(this._node, val);
402
* Flat data store for off-DOM usage
405
* @deprecated Use getData/setData
409
return this._dataVal;
411
setter: function(val) {
420
* The default setter for DOM properties
408
* The default setter for DOM properties
421
409
* Called with instance context (this === the Node instance)
422
410
* @method DEFAULT_SETTER
424
* @param {String} name The attribute/property being set
425
* @param {any} val The value to be set
412
* @param {String} name The attribute/property being set
413
* @param {any} val The value to be set
426
414
* @return {any} The value
428
416
Y_Node.DEFAULT_SETTER = function(name, val) {
548
536
* Sets an attribute on the Node instance.
549
* Unless pre-configured (via Node.ATTRS), set hands
537
* Unless pre-configured (via Node.ATTRS), set hands
550
538
* off to the underlying DOM node. Only valid
551
539
* attributes/properties for the node will be set.
552
540
* To set custom attributes use setAttribute.
554
* @param {String} attr The attribute to be set.
555
* @param {any} val The value to set the attribute to.
542
* @param {String} attr The attribute to be set.
543
* @param {any} val The value to set the attribute to.
558
546
set: function(attr, val) {
562
550
this._setAttr.apply(this, arguments);
563
551
} else { // use setters inline
564
552
if (attrConfig && attrConfig.setter) {
565
attrConfig.setter.call(this, val);
553
attrConfig.setter.call(this, val, attr);
566
554
} else if (Y_Node.re_aria.test(attr)) { // special case Aria
567
555
this._node.setAttribute(attr, val);
624
612
* Node instances can be compared to each other and/or HTMLElements.
625
613
* @method compareTo
626
614
* @param {HTMLElement | Node} refNode The reference node to compare to the node.
627
* @return {Boolean} True if the nodes match, false if they do not.
615
* @return {Boolean} True if the nodes match, false if they do not.
629
617
compareTo: function(refNode) {
630
618
var node = this._node;
632
if (refNode instanceof Y_Node) {
620
if (Y.instanceOf(refNode, Y_Node)) {
633
621
refNode = refNode._node;
635
623
return node === refNode;
673
661
return Y.one(Y_DOM.ancestor(this._node, _wrapFn(fn), testSelf));
665
* Returns the ancestors that pass the test applied by supplied boolean method.
667
* @param {String | Function} fn A selector string or boolean method for testing elements.
668
* @param {Boolean} testSelf optional Whether or not to include the element in the scan
669
* If a function is used, it receives the current node being tested as the only argument.
670
* @return {NodeList} A NodeList instance containing the matching elements
672
ancestors: function(fn, testSelf) {
673
return Y.all(Y_DOM.ancestors(this._node, _wrapFn(fn), testSelf));
677
* Returns the previous matching sibling.
677
* Returns the previous matching sibling.
678
678
* Returns the nearest element node sibling if no method provided.
679
679
* @method previous
680
680
* @param {String | Function} fn A selector or boolean method for testing elements.
684
684
previous: function(fn, all) {
685
685
return Y.one(Y_DOM.elementByAxis(this._node, 'previousSibling', _wrapFn(fn), all));
689
* Returns the next matching sibling.
689
* Returns the next matching sibling.
690
690
* Returns the nearest element node sibling if no method provided.
692
692
* @param {String | Function} fn A selector or boolean method for testing elements.
724
* Retrieves a Node instance of nodes based on the given CSS selector.
726
* @deprecated Use one()
727
* @param {string} selector The CSS selector to test against.
728
* @return {Node} A Node instance for the matching HTMLElement.
730
query: function(selector) {
731
return this.one(selector);
735
* Retrieves a nodeList based on the given CSS selector.
724
* Retrieves a nodeList based on the given CSS selector.
738
727
* @param {string} selector The CSS selector to test against.
802
782
replace: function(newNode) {
803
783
var node = this._node;
784
if (typeof newNode == 'string') {
785
newNode = Y_Node.create(newNode);
804
787
node.parentNode.replaceChild(Y_Node.getDOMNode(newNode), node);
792
* @method replaceChild
794
* @param {String | HTMLElement | Node} node Node to be inserted
795
* @param {HTMLElement | Node} refNode Node to be replaced
796
* @return {Node} The replaced node
798
replaceChild: function(node, refNode) {
799
if (typeof node == 'string') {
800
node = Y_DOM.create(node);
803
return Y.one(this._node.replaceChild(Y_Node.getDOMNode(node), Y_Node.getDOMNode(refNode)));
807
* @method appendChild
808
* @param {String | HTMLElement | Node} node Node to be appended
809
* @return {Node} The appended node
811
appendChild: function(node) {
812
return Y_Node.scrubVal(this._insert(node));
816
* @method insertBefore
817
* @param {String | HTMLElement | Node} newNode Node to be appended
818
* @param {HTMLElement | Node} refNode Node to be inserted before
819
* @return {Node} The inserted node
821
insertBefore: function(newNode, refNode) {
822
return Y.Node.scrubVal(this._insert(newNode, refNode));
809
826
* Removes event listeners from the node and (optionally) its subtree
811
828
* @param {Boolean} recurse (optional) Whether or not to remove listeners from the
826
843
* node's subtree (default is false)
829
destroy: function(recursivePurge) {
830
delete Y_Node._instances[this[UID]];
831
this.purge(recursivePurge);
846
destroy: function(recursive) {
847
this.purge(); // TODO: only remove events add via this Node
833
849
if (this.unplug) { // may not be a PluginHost
837
this._node._yuid = null;
856
this.all('*').destroy();
838
859
this._node = null;
839
860
this._stateProxy = null;
862
delete Y_Node._instances[this[UID]];
843
* Invokes a method on the Node instance
866
* Invokes a method on the Node instance
845
868
* @param {String} method The name of the method to invoke
846
* @param {Any} a, b, c, etc. Arguments to invoke the method with.
847
* @return Whatever the underly method returns.
869
* @param {Any} a, b, c, etc. Arguments to invoke the method with.
870
* @return Whatever the underly method returns.
848
871
* DOM Nodes and Collections return values
849
872
* are converted to Node/NodeList instances.
853
876
var node = this._node,
856
if (a && a instanceof Y_Node) {
879
if (a && Y.instanceOf(a, Y_Node)) {
860
if (b && b instanceof Y_Node) {
883
if (b && Y.instanceOf(b, Y_Node)) {
864
ret = node[method](a, b, c, d, e);
887
ret = node[method](a, b, c, d, e);
865
888
return Y_Node.scrubVal(ret, this);
869
* Applies the given function to each Node in the NodeList.
871
* @deprecated Use NodeList
872
* @param {Function} fn The function to apply
873
* @param {Object} context optional An optional context to apply the function with
874
* Default context is the NodeList instance
877
each: function(fn, context) {
878
context = context || this;
879
return fn.call(context, this);
883
* Retrieves the Node instance at the given index.
885
* @deprecated Use NodeList
887
* @param {Number} index The index of the target Node.
888
* @return {Node} The Node instance at the given index.
890
item: function(index) {
895
* Returns the current number of items in the Node.
897
* @deprecated Use NodeList
898
* @return {Int} The number of items in the Node.
901
return this._node ? 1 : 0;
905
* Inserts the content before the reference node.
892
* Inserts the content before the reference node.
907
* @param {String | Y.Node | HTMLElement} content The content to insert
894
* @param {String | Y.Node | HTMLElement | Y.NodeList | HTMLCollection} content The content to insert
908
895
* @param {Int | Y.Node | HTMLElement | String} where The position to insert at.
909
896
* Possible "where" arguments
928
915
insert: function(content, where) {
929
var node = this._node;
932
if (typeof where === 'number') { // allow index
933
where = this._node.childNodes[where];
934
} else if (where && where._node) { // Node
938
if (typeof content !== 'string') { // allow Node or NodeList/Array instances
939
if (content._node) { // Node
940
content = content._node;
941
} else if (content._nodes || (!content.nodeType && content.length)) { // NodeList or Array
942
content = Y.all(content);
943
Y.each(content._nodes, function(n) {
944
Y_DOM.addHTML(node, n, where);
947
return this; // NOTE: early return
950
Y_DOM.addHTML(node, content, where);
916
this._insert(content, where);
920
_insert: function(content, where) {
921
var node = this._node,
924
if (typeof where == 'number') { // allow index
925
where = this._node.childNodes[where];
926
} else if (where && where._node) { // Node
930
if (content && typeof content != 'string') { // allow Node or NodeList/Array instances
931
content = content._node || content._nodes || content;
933
ret = Y_DOM.addHTML(node, content, where);
957
* Inserts the content as the firstChild of the node.
939
* Inserts the content as the firstChild of the node.
958
940
* @method prepend
959
* @param {String | Y.Node | HTMLElement} content The content to insert
941
* @param {String | Y.Node | HTMLElement} content The content to insert
962
944
prepend: function(content) {
959
* Appends the node to the given node.
961
* @param {Y.Node | HTMLElement} node The node to append to
964
appendTo: function(node) {
965
Y.one(node).append(this);
977
970
* Replaces the node's current content with the content.
978
971
* @method setContent
979
* @param {String | Y.Node | HTMLElement} content The content to insert
972
* @param {String | Y.Node | HTMLElement | Y.NodeList | HTMLCollection} content The content to insert
982
975
setContent: function(content) {
984
if (content._node) { // map to DOMNode
985
content = content._node;
986
} else if (content._nodes) { // convert DOMNodeList to documentFragment
987
content = Y_DOM._nl2frag(content._nodes);
992
Y_DOM.addHTML(this._node, content, 'replace');
976
this._insert(content, 'replace');
981
* Returns the node's current content (e.g. innerHTML)
983
* @return {String} The current content
985
getContent: function(content) {
986
return this.get('innerHTML');
998
991
* @description Swap DOM locations with the given node.
999
992
* This does not change which DOM node each Node instance refers to.
1000
993
* @param {Node} otherNode The node to swap with
1003
swap: Y.config.doc.documentElement.swapNode ?
996
swap: Y.config.doc.documentElement.swapNode ?
1004
997
function(otherNode) {
1005
998
this._node.swapNode(Y_Node.getDOMNode(otherNode));
1061
1054
this._data = name;
1068
1061
* @method clearData
1069
* @description Clears stored data.
1062
* @description Clears stored data.
1070
1063
* @param {string} name The name of the field to clear. If no name
1071
* is given, all data is cleared..
1064
* is given, all data is cleared.
1074
1067
clearData: function(name) {
1075
if (this._data && arguments.length) {
1076
delete this._data[name];
1068
if ('_data' in this) {
1070
delete this._data[name];
1084
1079
hasMethod: function(method) {
1085
1080
var node = this._node;
1086
1081
return !!(node && method in node &&
1087
typeof node[method] !== 'unknown' &&
1088
(typeof node[method] === 'function' ||
1082
typeof node[method] != 'unknown' &&
1083
(typeof node[method] == 'function' ||
1089
1084
String(node[method]).indexOf('function') === 1)); // IE reports as object, prepends space
1087
SHOW_TRANSITION: null,
1088
HIDE_TRANSITION: null,
1091
* Makes the node visible.
1092
* If the "transition" module is loaded, show optionally
1093
* animates the showing of the node using either the default
1094
* transition effect ('fadeIn'), or the given named effect.
1096
* @param {String} name A named Transition effect to use as the show effect.
1097
* @param {Object} config Options to use with the transition.
1098
* @param {Function} callback An optional function to run after the transition completes.
1101
show: function(callback) {
1102
callback = arguments[arguments.length - 1];
1103
this.toggleView(true, callback);
1108
* The implementation for showing nodes.
1109
* Default is to toggle the style.display property.
1114
this.setStyle('display', '');
1118
_isHidden: function() {
1119
return Y.DOM.getStyle(this._node, 'display') === 'none';
1122
toggleView: function(on, callback) {
1123
this._toggleView.apply(this, arguments);
1126
_toggleView: function(on, callback) {
1127
callback = arguments[arguments.length - 1];
1129
// base on current state if not forcing
1130
if (typeof on != 'boolean') {
1131
on = (this._isHidden()) ? 1 : 0;
1140
if (typeof callback == 'function') {
1141
callback.call(this);
1149
* If the "transition" module is loaded, hide optionally
1150
* animates the hiding of the node using either the default
1151
* transition effect ('fadeOut'), or the given named effect.
1153
* @param {String} name A named Transition effect to use as the show effect.
1154
* @param {Object} config Options to use with the transition.
1155
* @param {Function} callback An optional function to run after the transition completes.
1158
hide: function(callback) {
1159
callback = arguments[arguments.length - 1];
1160
this.toggleView(false, callback);
1165
* The implementation for hiding nodes.
1166
* Default is to toggle the style.display property.
1171
this.setStyle('display', 'none');
1174
isFragment: function() {
1175
return (this.get('nodeType') === 11);
1179
* Removes all of the child nodes from the node.
1180
* @param {Boolean} destroy Whether the nodes should also be destroyed.
1183
empty: function(destroy) {
1184
this.get('childNodes').remove(destroy);
1093
1190
Y.Node = Y_Node;
1095
1191
Y.one = Y.Node.one;
1097
1193
* The NodeList module provides support for managing collections of Nodes.
1099
1195
* @submodule nodelist
1103
1199
* The NodeList class provides a wrapper for manipulating DOM NodeLists.
1115
1211
nodes = Y.Selector.query(nodes);
1116
1212
} else if (nodes.nodeType || Y_DOM.isWindow(nodes)) { // domNode || window
1117
1213
nodes = [nodes];
1118
} else if (nodes instanceof Y.Node) {
1214
} else if (Y.instanceOf(nodes, Y.Node)) {
1119
1215
nodes = [nodes._node];
1120
} else if (nodes[0] instanceof Y.Node) { // allow array of Y.Nodes
1216
} else if (Y.instanceOf(nodes[0], Y.Node)) { // allow array of Y.Nodes
1121
1217
Y.Array.each(nodes, function(node) {
1122
1218
if (node._node) {
1123
1219
tmp.push(node._node);
1143
1239
* @method NodeList.getDOMNodes
1146
* @param {Y.NodeList} node The NodeList instance
1242
* @param {Y.NodeList} nodelist The NodeList instance
1147
1243
* @return {Array} The array of DOM nodes bound to the NodeList
1149
NodeList.getDOMNodes = function(nodeList) {
1150
return nodeList._nodes;
1245
NodeList.getDOMNodes = function(nodelist) {
1246
return (nodelist && nodelist._nodes) ? nodelist._nodes : nodelist;
1153
1249
NodeList.each = function(instance, fn, context) {
1308
* Creates a new NodeList containing all nodes at every n indices, where
1404
* Creates a new NodeList containing all nodes at every n indices, where
1309
1405
* remainder n % index equals r.
1310
1406
* (zero-based index).
1311
1407
* @method modulus
1312
1408
* @param {Int} n The offset to use (return every nth node)
1313
* @param {Int} r An optional remainder to use with the modulus operation (defaults to zero)
1314
* @return {NodeList} NodeList containing the updated collection
1409
* @param {Int} r An optional remainder to use with the modulus operation (defaults to zero)
1410
* @return {NodeList} NodeList containing the updated collection
1316
1412
modulus: function(n, r) {
1391
* Applies an event listener to each Node bound to the NodeList.
1487
* Applies an event listener to each Node bound to the NodeList.
1393
1489
* @param {String} type The event being listened for
1394
1490
* @param {Function} fn The handler to call when the event fires
1395
1491
* @param {Object} context The context to call the handler with.
1396
* Default is the NodeList instance.
1397
* @return {Object} Returns an event handle that can later be use to detach().
1492
* Default is the NodeList instance.
1493
* @param {Object} context The context to call the handler with.
1494
* param {mixed} arg* 0..n additional arguments to supply to the subscriber
1495
* when the event fires.
1496
* @return {Object} Returns an event handle that can later be use to detach().
1398
1497
* @see Event.on
1400
1499
on: function(type, fn, context) {
1405
* Applies an event listener to each Node bound to the NodeList.
1504
* Applies an one-time event listener to each Node bound to the NodeList.
1506
* @param {String} type The event being listened for
1507
* @param {Function} fn The handler to call when the event fires
1508
* @param {Object} context The context to call the handler with.
1509
* Default is the NodeList instance.
1510
* @return {Object} Returns an event handle that can later be use to detach().
1513
once: function(type, fn, context) {
1514
return Y.once.apply(Y, this._prepEvtArgs.apply(this, arguments));
1518
* Applies an event listener to each Node bound to the NodeList.
1406
1519
* The handler is called only after all on() handlers are called
1407
1520
* and the event is not prevented.
1408
1521
* @method after
1409
1522
* @param {String} type The event being listened for
1410
1523
* @param {Function} fn The handler to call when the event fires
1411
1524
* @param {Object} context The context to call the handler with.
1412
* Default is the NodeList instance.
1413
* @return {Object} Returns an event handle that can later be use to detach().
1525
* Default is the NodeList instance.
1526
* @return {Object} Returns an event handle that can later be use to detach().
1414
1527
* @see Event.on
1416
1529
after: function(type, fn, context) {
1511
1636
* @method setContent
1512
1637
* @see Node.setContent
1642
* Makes each node visible.
1643
* If the "transition" module is loaded, show optionally
1644
* animates the showing of the node using either the default
1645
* transition effect ('fadeIn'), or the given named effect.
1647
* @param {String} name A named Transition effect to use as the show effect.
1648
* @param {Object} config Options to use with the transition.
1649
* @param {Function} callback An optional function to run after the transition completes.
1656
* If the "transition" module is loaded, hide optionally
1657
* animates the hiding of the node using either the default
1658
* transition effect ('fadeOut'), or the given named effect.
1660
* @param {String} name A named Transition effect to use as the show effect.
1661
* @param {Object} config Options to use with the transition.
1662
* @param {Function} callback An optional function to run after the transition completes.
1517
1670
// one-off implementation to convert array of Nodes to NodeList
1567
1720
* Passes through to DOM method.
1568
* @method replaceChild
1570
* @param {HTMLElement | Node} node Node to be inserted
1571
* @param {HTMLElement | Node} refNode Node to be replaced
1572
* @return {Node} The replaced node
1577
* Passes through to DOM method.
1578
* @method appendChild
1579
* @param {HTMLElement | Node} node Node to be appended
1580
* @return {Node} The appended node
1585
* Passes through to DOM method.
1586
* @method insertBefore
1587
* @param {HTMLElement | Node} newNode Node to be appended
1588
* @param {HTMLElement | Node} refNode Node to be inserted before
1589
* @return {Node} The inserted node
1594
* Passes through to DOM method.
1595
1722
* @method removeChild
1596
1723
* @param {HTMLElement | Node} node Node to be removed
1597
1724
* @return {Node} The removed node
1716
1852
* @param {string} name The attribute name
1717
1853
* @return {string} The attribute value
1858
* Wraps the given HTML around the node.
1860
* @param {String} html The markup to wrap around the node.
1866
* Removes the node's parent node.
1873
* Applies a unique ID to the node if none exists
1874
* @method generateID
1875
* @return {String} The existing or generated ID
1880
Y.NodeList.importMethod(Y.Node.prototype, [
1882
* Allows getting attributes on DOM nodes, normalizing in some cases.
1883
* This passes through to the DOM node, allowing for custom attributes.
1884
* @method getAttribute
1887
* @param {string} name The attribute name
1888
* @return {string} The attribute value
1723
1893
* Allows setting attributes on DOM nodes, normalizing in some cases.
1724
1894
* This passes through to the DOM node, allowing for custom attributes.
1729
1899
* @param {string} name The attribute name
1730
1900
* @param {string} value The value to set
1734
* Allows getting attributes on DOM nodes, normalizing in some cases.
1735
* This passes through to the DOM node, allowing for custom attributes.
1736
* @method getAttribute
1739
* @param {string} name The attribute name
1740
* @return {string} The attribute value
1744
1905
* Allows for removing attributes on DOM nodes.
1745
1906
* This passes through to the DOM node, allowing for custom attributes.
1748
1909
* @for NodeList
1749
1910
* @param {string} name The attribute to remove
1751
Y.NodeList.importMethod(Y.Node.prototype, ['getAttribute', 'setAttribute', 'removeAttribute']);
1914
* Removes the parent node from node in the list.
1920
* Wraps the given HTML around each node.
1922
* @param {String} html The markup to wrap around the node.
1928
* Applies a unique ID to each node if none exists
1929
* @method generateID
1930
* @return {String} The existing or generated ID
1753
1935
var methods = [
1933
}, '3.2.0' ,{requires:['dom-base', 'selector-css2', 'event-base']});
2123
var Y_NodeList = Y.NodeList,
2124
ArrayProto = Array.prototype,
2126
/** Returns a new NodeList combining the given NodeList(s)
2129
* @param {NodeList | Array} valueN Arrays/NodeLists and/or values to
2130
* concatenate to the resulting NodeList
2131
* @return {NodeList} A new NodeList comprised of this NodeList joined with the input.
2134
/** Removes the first last from the NodeList and returns it.
2137
* @return {Node} The last item in the NodeList.
2140
/** Adds the given Node(s) to the end of the NodeList.
2143
* @param {Node | DOMNode} nodeN One or more nodes to add to the end of the NodeList.
2146
/** Removes the first item from the NodeList and returns it.
2149
* @return {Node} The first item in the NodeList.
2152
/** Returns a new NodeList comprising the Nodes in the given range.
2155
* @param {Number} begin Zero-based index at which to begin extraction.
2156
As a negative index, start indicates an offset from the end of the sequence. slice(-2) extracts the second-to-last element and the last element in the sequence.
2157
* @param {Number} end Zero-based index at which to end extraction. slice extracts up to but not including end.
2158
slice(1,4) extracts the second element through the fourth element (elements indexed 1, 2, and 3).
2159
As a negative index, end indicates an offset from the end of the sequence. slice(2,-1) extracts the third element through the second-to-last element in the sequence.
2160
If end is omitted, slice extracts to the end of the sequence.
2161
* @return {NodeList} A new NodeList comprised of this NodeList joined with the input.
2164
/** Changes the content of the NodeList, adding new elements while removing old elements.
2167
* @param {Number} index Index at which to start changing the array. If negative, will begin that many elements from the end.
2168
* @param {Number} howMany An integer indicating the number of old array elements to remove. If howMany is 0, no elements are removed. In this case, you should specify at least one new element. If no howMany parameter is specified (second syntax above, which is a SpiderMonkey extension), all elements after index are removed.
2169
* {Node | DOMNode| element1, ..., elementN
2170
The elements to add to the array. If you don't specify any elements, splice simply removes elements from the array.
2171
* @return {NodeList} The element(s) removed.
2174
/** Adds the given Node(s) to the beginning of the NodeList.
2177
* @param {Node | DOMNode} nodeN One or more nodes to add to the NodeList.
2183
Y.Array.each(ArrayMethods, function(name) {
2184
Y_NodeList.prototype[name] = function() {
2189
while ((arg = arguments[i++])) { // use DOM nodes/nodeLists
2190
args.push(arg._node || arg._nodes || arg);
2192
return Y.Node.scrubVal(ArrayProto[name].apply(this._nodes, args));
2197
}, '3.3.0' ,{requires:['dom-base', 'selector-css2', 'event-base']});
1934
2198
YUI.add('node-style', function(Y) {
2215
2479
// these need special treatment to extract 2nd node arg
2217
* Compares the intersection of the node with another node or region
2481
* Compares the intersection of the node with another node or region
2220
2484
* @param {Node|Object} node2 The node or region to compare with.
2221
* @param {Object} altRegion An alternate region to use (rather than this node's).
2222
* @return {Object} An object representing the intersection of the regions.
2485
* @param {Object} altRegion An alternate region to use (rather than this node's).
2486
* @return {Object} An object representing the intersection of the regions.
2224
2488
Y.Node.prototype.intersect = function(node2, altRegion) {
2225
2489
var node1 = Y.Node.getDOMNode(this);
2226
if (node2 instanceof Y.Node) { // might be a region object
2490
if (Y.instanceOf(node2, Y.Node)) { // might be a region object
2227
2491
node2 = Y.Node.getDOMNode(node2);
2229
return Y.DOM.intersect(node1, node2, altRegion);
2493
return Y.DOM.intersect(node1, node2, altRegion);
2233
2497
* Determines whether or not the node is within the giving region.
2235
2499
* @param {Node|Object} node2 The node or region to compare with.
2236
* @param {Boolean} all Whether or not all of the node must be in the region.
2237
* @param {Object} altRegion An alternate region to use (rather than this node's).
2238
* @return {Object} An object representing the intersection of the regions.
2500
* @param {Boolean} all Whether or not all of the node must be in the region.
2501
* @param {Object} altRegion An alternate region to use (rather than this node's).
2502
* @return {Object} An object representing the intersection of the regions.
2240
2504
Y.Node.prototype.inRegion = function(node2, all, altRegion) {
2241
2505
var node1 = Y.Node.getDOMNode(this);
2242
if (node2 instanceof Y.Node) { // might be a region object
2506
if (Y.instanceOf(node2, Y.Node)) { // might be a region object
2243
2507
node2 = Y.Node.getDOMNode(node2);
2245
return Y.DOM.inRegion(node1, node2, all, altRegion);
2509
return Y.DOM.inRegion(node1, node2, all, altRegion);
2249
}, '3.2.0' ,{requires:['dom-screen']});
2513
}, '3.3.0' ,{requires:['dom-screen']});
2250
2514
YUI.add('node-pluginhost', function(Y) {
2343
2607
* @return {EventHandle} the detach handle
2346
Y.Node.prototype.delegate = function(type, fn, selector) {
2348
var args = Y.Array(arguments, 0, true);
2350
args.splice(2, 0, this._node);
2610
Y.Node.prototype.delegate = function(type) {
2612
var args = Y.Array(arguments, 0, true),
2613
index = (Y.Lang.isObject(type) && !Y.Lang.isArray(type)) ? 1 : 2;
2615
args.splice(index, 0, this._node);
2352
2617
return Y.delegate.apply(Y, args);
2356
}, '3.2.0' ,{requires:['node-base', 'event-delegate']});
2359
YUI.add('node', function(Y){}, '3.2.0' ,{requires:['dom', 'event-base', 'event-delegate', 'pluginhost'], use:['node-base', 'node-style', 'node-screen', 'node-pluginhost', 'node-event-delegate'], skinnable:false});
2621
}, '3.3.0' ,{requires:['node-base', 'event-delegate']});
2624
YUI.add('node', function(Y){}, '3.3.0' ,{requires:['dom', 'event-base', 'event-delegate', 'pluginhost'], use:['node-base', 'node-style', 'node-screen', 'node-pluginhost', 'node-event-delegate'], skinnable:false});