294
293
return node; // NOTE: return
298
instance = Y_Node._instances[uid]; // reuse exising instances
299
cachedNode = instance ? instance._node : null;
300
if (!instance || (cachedNode && node !== cachedNode)) { // new Node when nodes don't match
301
instance = new Y_Node(node);
296
if (node.nodeType || Y.DOM.isWindow(node)) { // avoid bad input (numbers, boolean, etc)
297
uid = (node.uniqueID && node.nodeType !== 9) ? node.uniqueID : node._yuid;
298
instance = Y_Node._instances[uid]; // reuse exising instances
299
cachedNode = instance ? instance._node : null;
300
if (!instance || (cachedNode && node !== cachedNode)) { // new Node when nodes don't match
301
instance = new Y_Node(node);
479
472
* @return {String} A string representation of the Node instance
481
474
toString: function() {
483
errorMsg = this[UID] + ': not bound to a node',
475
var str = this[UID] + ': not bound to a node',
484
476
node = this._node,
485
id = node.getAttribute('id'); // form.id may be a field name
477
attrs, id, className;
488
str += node[NODE_NAME];
480
attrs = node.attributes;
481
id = (attrs && attrs.id) ? node.getAttribute('id') : null;
482
className = (attrs && attrs.className) ? node.getAttribute('className') : null;
483
str = node[NODE_NAME];
493
if (node.className) {
494
str += '.' + node.className.replace(' ', '.');
490
str += '.' + className.replace(' ', '.');
497
493
// TODO: add yuid?
498
494
str += ' ' + this[UID];
500
return str || errorMsg;
908
907
* @param {String | Y.Node | HTMLElement} content The content to insert
909
908
* @param {Int | Y.Node | HTMLElement | String} where The position to insert at.
909
* Possible "where" arguments
912
* <dd>The Node to insert before</dd>
913
* <dt>HTMLElement</dt>
914
* <dd>The element to insert before</dd>
916
* <dd>The index of the child element to insert before</dd>
918
* <dd>Replaces the existing HTML</dd>
920
* <dd>Inserts before the existing HTML</dd>
922
* <dd>Inserts content before the node</dd>
924
* <dd>Inserts content after the node</dd>
912
928
insert: function(content, where) {
1375
_prepEvtArgs: function(type, fn, context) {
1376
// map to Y.on/after signature (type, fn, nodes, context, arg1, arg2, etc)
1377
var args = Y.Array(arguments, 0, true);
1379
if (args.length < 2) { // type only (event hash) just add nodes
1380
args[2] = this._nodes;
1382
args.splice(2, 0, this._nodes);
1385
args[3] = context || this; // default to NodeList instance as context
1361
1391
* Applies an event listener to each Node bound to the NodeList.
1848
1880
_bypassProxy: true // don't update DOM when using with Attribute
1852
}, '3.1.2' ,{requires:['dom-base', 'selector-css2', 'event-base']});
1883
if (Y.config.doc.createElement('form').elements.nodeType) {
1884
// IE: elements collection is also FORM node which trips up scrubVal.
1885
Y.Node.ATTRS.elements = {
1886
getter: function() {
1887
return this.all('input, textarea, button, select');
1892
Y.mix(Y.Node.ATTRS, {
1894
setter: function(h) {
1895
Y.DOM.setHeight(this._node, h);
1899
getter: function() {
1900
return this._node.offsetHeight;
1905
setter: function(w) {
1906
Y.DOM.setWidth(this._node, w);
1910
getter: function() {
1911
return this._node.offsetWidth;
1916
Y.mix(Y.Node.prototype, {
1917
sizeTo: function(w, h) {
1919
if (arguments.length < 2) {
1921
w = node.get('offsetWidth');
1922
h = node.get('offsetHeight');
1933
}, '3.2.0' ,{requires:['dom-base', 'selector-css2', 'event-base']});
1853
1934
YUI.add('node-style', function(Y) {
1931
2012
Y.NodeList.importMethod(Y.Node.prototype, methods);
1933
Y.mix(Y.Node.ATTRS, {
1935
setter: function(h) {
1936
Y.DOM.setHeight(this._node, h);
1940
getter: function() {
1941
return this._node.offsetHeight;
1946
setter: function(w) {
1947
Y.DOM.setWidth(this._node, w);
1951
getter: function() {
1952
return this._node.offsetWidth;
1957
Y.mix(Y.Node.prototype, {
1958
sizeTo: function(w, h) {
1960
if (arguments.length < 2) {
1962
w = node.get('offsetWidth');
1963
h = node.get('offsetHeight');
1974
}, '3.1.2' ,{requires:['dom-style', 'node-base']});
2016
}, '3.2.0' ,{requires:['dom-style', 'node-base']});
1975
2017
YUI.add('node-screen', function(Y) {
2271
* Functionality to make the node a delegated event container
2313
* <p>Sets up a delegation listener for an event occurring inside the Node.
2314
* The delegated event will be verified against a supplied selector or
2315
* filtering function to test if the event references at least one node that
2316
* should trigger the subscription callback.</p>
2318
* <p>Selector string filters will trigger the callback if the event originated
2319
* from a node that matches it or is contained in a node that matches it.
2320
* Function filters are called for each Node up the parent axis to the
2321
* subscribing container node, and receive at each level the Node and the event
2322
* object. The function should return true (or a truthy value) if that Node
2323
* should trigger the subscription callback. Note, it is possible for filters
2324
* to match multiple Nodes for a single event. In this case, the delegate
2325
* callback will be executed for each matching Node.</p>
2327
* <p>For each matching Node, the callback will be executed with its 'this'
2328
* object set to the Node matched by the filter (unless a specific context was
2329
* provided during subscription), and the provided event's
2330
* <code>currentTarget</code> will also be set to the matching Node. The
2331
* containing Node from which the subscription was originally made can be
2332
* referenced as <code>e.container</code>.
2272
2334
* @method delegate
2273
2335
* @param type {String} the event type to delegate
2274
* @param fn {Function} the function to execute
2275
* @param selector {String} a selector that must match the target of the event.
2276
* @return {Event.Handle} the detach handle
2336
* @param fn {Function} the callback function to execute. This function
2337
* will be provided the event object for the delegated event.
2338
* @param spec {String|Function} a selector that must match the target of the
2339
* event or a function to test target and its parents for a match
2340
* @param context {Object} optional argument that specifies what 'this' refers to.
2341
* @param args* {any} 0..n additional arguments to pass on to the callback function.
2342
* These arguments will be added after the event object.
2343
* @return {EventHandle} the detach handle
2279
2346
Y.Node.prototype.delegate = function(type, fn, selector) {
2281
var args = Array.prototype.slice.call(arguments, 3),
2282
a = [type, fn, Y.Node.getDOMNode(this), selector];
2285
return Y.delegate.apply(Y, a);
2348
var args = Y.Array(arguments, 0, true);
2350
args.splice(2, 0, this._node);
2352
return Y.delegate.apply(Y, args);
2289
}, '3.1.2' ,{requires:['node-base', 'event-delegate', 'pluginhost']});
2292
YUI.add('node', function(Y){}, '3.1.2' ,{requires:['dom', 'event-base', 'event-delegate', 'pluginhost'], skinnable:false, use:['node-base', 'node-style', 'node-screen', 'node-pluginhost', 'node-event-delegate']});
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});