~andreserl/maas/packaging_precise_rebase

« back to all changes in this revision

Viewing changes to debian/extras/jslibs/yui/dom-base/dom-base.js

  • Committer: Andres Rodriguez
  • Date: 2013-03-20 18:12:30 UTC
  • mfrom: (145.2.22 precise.sru)
  • Revision ID: andreserl@ubuntu.com-20130320181230-6l5guc0nhlv2z4p7
Re-base againts latest quantal released branch towards SRU

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
YUI 3.5.1 (build 22)
 
3
Copyright 2012 Yahoo! Inc. All rights reserved.
 
4
Licensed under the BSD License.
 
5
http://yuilibrary.com/license/
 
6
*/
 
7
YUI.add('dom-base', function(Y) {
 
8
 
 
9
/**
 
10
* @for DOM
 
11
* @module dom
 
12
*/
 
13
var documentElement = Y.config.doc.documentElement,
 
14
    Y_DOM = Y.DOM,
 
15
    TAG_NAME = 'tagName',
 
16
    OWNER_DOCUMENT = 'ownerDocument',
 
17
    EMPTY_STRING = '',
 
18
    addFeature = Y.Features.add,
 
19
    testFeature = Y.Features.test;
 
20
 
 
21
Y.mix(Y_DOM, {
 
22
    /**
 
23
     * Returns the text content of the HTMLElement. 
 
24
     * @method getText         
 
25
     * @param {HTMLElement} element The html element. 
 
26
     * @return {String} The text content of the element (includes text of any descending elements).
 
27
     */
 
28
    getText: (documentElement.textContent !== undefined) ?
 
29
        function(element) {
 
30
            var ret = '';
 
31
            if (element) {
 
32
                ret = element.textContent;
 
33
            }
 
34
            return ret || '';
 
35
        } : function(element) {
 
36
            var ret = '';
 
37
            if (element) {
 
38
                ret = element.innerText || element.nodeValue; // might be a textNode
 
39
            }
 
40
            return ret || '';
 
41
        },
 
42
 
 
43
    /**
 
44
     * Sets the text content of the HTMLElement. 
 
45
     * @method setText         
 
46
     * @param {HTMLElement} element The html element. 
 
47
     * @param {String} content The content to add. 
 
48
     */
 
49
    setText: (documentElement.textContent !== undefined) ?
 
50
        function(element, content) {
 
51
            if (element) {
 
52
                element.textContent = content;
 
53
            }
 
54
        } : function(element, content) {
 
55
            if ('innerText' in element) {
 
56
                element.innerText = content;
 
57
            } else if ('nodeValue' in element) {
 
58
                element.nodeValue = content;
 
59
            }
 
60
    },
 
61
 
 
62
    CUSTOM_ATTRIBUTES: (!documentElement.hasAttribute) ? { // IE < 8
 
63
        'for': 'htmlFor',
 
64
        'class': 'className'
 
65
    } : { // w3c
 
66
        'htmlFor': 'for',
 
67
        'className': 'class'
 
68
    },
 
69
 
 
70
    /**
 
71
     * Provides a normalized attribute interface. 
 
72
     * @method setAttribute
 
73
     * @param {HTMLElement} el The target element for the attribute.
 
74
     * @param {String} attr The attribute to set.
 
75
     * @param {String} val The value of the attribute.
 
76
     */
 
77
    setAttribute: function(el, attr, val, ieAttr) {
 
78
        if (el && attr && el.setAttribute) {
 
79
            attr = Y_DOM.CUSTOM_ATTRIBUTES[attr] || attr;
 
80
            el.setAttribute(attr, val, ieAttr);
 
81
        }
 
82
    },
 
83
 
 
84
 
 
85
    /**
 
86
     * Provides a normalized attribute interface. 
 
87
     * @method getAttribute
 
88
     * @param {HTMLElement} el The target element for the attribute.
 
89
     * @param {String} attr The attribute to get.
 
90
     * @return {String} The current value of the attribute. 
 
91
     */
 
92
    getAttribute: function(el, attr, ieAttr) {
 
93
        ieAttr = (ieAttr !== undefined) ? ieAttr : 2;
 
94
        var ret = '';
 
95
        if (el && attr && el.getAttribute) {
 
96
            attr = Y_DOM.CUSTOM_ATTRIBUTES[attr] || attr;
 
97
            ret = el.getAttribute(attr, ieAttr);
 
98
 
 
99
            if (ret === null) {
 
100
                ret = ''; // per DOM spec
 
101
            }
 
102
        }
 
103
        return ret;
 
104
    },
 
105
 
 
106
    VALUE_SETTERS: {},
 
107
 
 
108
    VALUE_GETTERS: {},
 
109
 
 
110
    getValue: function(node) {
 
111
        var ret = '', // TODO: return null?
 
112
            getter;
 
113
 
 
114
        if (node && node[TAG_NAME]) {
 
115
            getter = Y_DOM.VALUE_GETTERS[node[TAG_NAME].toLowerCase()];
 
116
 
 
117
            if (getter) {
 
118
                ret = getter(node);
 
119
            } else {
 
120
                ret = node.value;
 
121
            }
 
122
        }
 
123
 
 
124
        // workaround for IE8 JSON stringify bug
 
125
        // which converts empty string values to null
 
126
        if (ret === EMPTY_STRING) {
 
127
            ret = EMPTY_STRING; // for real
 
128
        }
 
129
 
 
130
        return (typeof ret === 'string') ? ret : '';
 
131
    },
 
132
 
 
133
    setValue: function(node, val) {
 
134
        var setter;
 
135
 
 
136
        if (node && node[TAG_NAME]) {
 
137
            setter = Y_DOM.VALUE_SETTERS[node[TAG_NAME].toLowerCase()];
 
138
 
 
139
            if (setter) {
 
140
                setter(node, val);
 
141
            } else {
 
142
                node.value = val;
 
143
            }
 
144
        }
 
145
    },
 
146
 
 
147
    creators: {}
 
148
});
 
149
 
 
150
addFeature('value-set', 'select', {
 
151
    test: function() {
 
152
        var node = Y.config.doc.createElement('select');
 
153
        node.innerHTML = '<option>1</option><option>2</option>';
 
154
        node.value = '2';
 
155
        return (node.value && node.value === '2');
 
156
    }
 
157
});
 
158
 
 
159
if (!testFeature('value-set', 'select')) {
 
160
    Y_DOM.VALUE_SETTERS.select = function(node, val) {
 
161
        for (var i = 0, options = node.getElementsByTagName('option'), option;
 
162
                option = options[i++];) {
 
163
            if (Y_DOM.getValue(option) === val) {
 
164
                option.selected = true;
 
165
                //Y_DOM.setAttribute(option, 'selected', 'selected');
 
166
                break;
 
167
            }
 
168
        }
 
169
    }
 
170
}
 
171
 
 
172
Y.mix(Y_DOM.VALUE_GETTERS, {
 
173
    button: function(node) {
 
174
        return (node.attributes && node.attributes.value) ? node.attributes.value.value : '';
 
175
    }
 
176
});
 
177
 
 
178
Y.mix(Y_DOM.VALUE_SETTERS, {
 
179
    // IE: node.value changes the button text, which should be handled via innerHTML
 
180
    button: function(node, val) {
 
181
        var attr = node.attributes.value;
 
182
        if (!attr) {
 
183
            attr = node[OWNER_DOCUMENT].createAttribute('value');
 
184
            node.setAttributeNode(attr);
 
185
        }
 
186
 
 
187
        attr.value = val;
 
188
    }
 
189
});
 
190
 
 
191
 
 
192
Y.mix(Y_DOM.VALUE_GETTERS, {
 
193
    option: function(node) {
 
194
        var attrs = node.attributes;
 
195
        return (attrs.value && attrs.value.specified) ? node.value : node.text;
 
196
    },
 
197
 
 
198
    select: function(node) {
 
199
        var val = node.value,
 
200
            options = node.options;
 
201
 
 
202
        if (options && options.length) {
 
203
            // TODO: implement multipe select
 
204
            if (node.multiple) {
 
205
            } else if (node.selectedIndex > -1) {
 
206
                val = Y_DOM.getValue(options[node.selectedIndex]);
 
207
            }
 
208
        }
 
209
 
 
210
        return val;
 
211
    }
 
212
});
 
213
var addClass, hasClass, removeClass;
 
214
 
 
215
Y.mix(Y.DOM, {
 
216
    /**
 
217
     * Determines whether a DOM element has the given className.
 
218
     * @method hasClass
 
219
     * @for DOM
 
220
     * @param {HTMLElement} element The DOM element. 
 
221
     * @param {String} className the class name to search for
 
222
     * @return {Boolean} Whether or not the element has the given class. 
 
223
     */
 
224
    hasClass: function(node, className) {
 
225
        var re = Y.DOM._getRegExp('(?:^|\\s+)' + className + '(?:\\s+|$)');
 
226
        return re.test(node.className);
 
227
    },
 
228
 
 
229
    /**
 
230
     * Adds a class name to a given DOM element.
 
231
     * @method addClass         
 
232
     * @for DOM
 
233
     * @param {HTMLElement} element The DOM element. 
 
234
     * @param {String} className the class name to add to the class attribute
 
235
     */
 
236
    addClass: function(node, className) {
 
237
        if (!Y.DOM.hasClass(node, className)) { // skip if already present 
 
238
            node.className = Y.Lang.trim([node.className, className].join(' '));
 
239
        }
 
240
    },
 
241
 
 
242
    /**
 
243
     * Removes a class name from a given element.
 
244
     * @method removeClass         
 
245
     * @for DOM
 
246
     * @param {HTMLElement} element The DOM element. 
 
247
     * @param {String} className the class name to remove from the class attribute
 
248
     */
 
249
    removeClass: function(node, className) {
 
250
        if (className && hasClass(node, className)) {
 
251
            node.className = Y.Lang.trim(node.className.replace(Y.DOM._getRegExp('(?:^|\\s+)' +
 
252
                            className + '(?:\\s+|$)'), ' '));
 
253
 
 
254
            if ( hasClass(node, className) ) { // in case of multiple adjacent
 
255
                removeClass(node, className);
 
256
            }
 
257
        }                 
 
258
    },
 
259
 
 
260
    /**
 
261
     * Replace a class with another class for a given element.
 
262
     * If no oldClassName is present, the newClassName is simply added.
 
263
     * @method replaceClass  
 
264
     * @for DOM
 
265
     * @param {HTMLElement} element The DOM element 
 
266
     * @param {String} oldClassName the class name to be replaced
 
267
     * @param {String} newClassName the class name that will be replacing the old class name
 
268
     */
 
269
    replaceClass: function(node, oldC, newC) {
 
270
        removeClass(node, oldC); // remove first in case oldC === newC
 
271
        addClass(node, newC);
 
272
    },
 
273
 
 
274
    /**
 
275
     * If the className exists on the node it is removed, if it doesn't exist it is added.
 
276
     * @method toggleClass  
 
277
     * @for DOM
 
278
     * @param {HTMLElement} element The DOM element
 
279
     * @param {String} className the class name to be toggled
 
280
     * @param {Boolean} addClass optional boolean to indicate whether class
 
281
     * should be added or removed regardless of current state
 
282
     */
 
283
    toggleClass: function(node, className, force) {
 
284
        var add = (force !== undefined) ? force :
 
285
                !(hasClass(node, className));
 
286
 
 
287
        if (add) {
 
288
            addClass(node, className);
 
289
        } else {
 
290
            removeClass(node, className);
 
291
        }
 
292
    }
 
293
});
 
294
 
 
295
hasClass = Y.DOM.hasClass;
 
296
removeClass = Y.DOM.removeClass;
 
297
addClass = Y.DOM.addClass;
 
298
 
 
299
var re_tag = /<([a-z]+)/i,
 
300
 
 
301
    Y_DOM = Y.DOM,
 
302
 
 
303
    addFeature = Y.Features.add,
 
304
    testFeature = Y.Features.test,
 
305
 
 
306
    creators = {},
 
307
 
 
308
    createFromDIV = function(html, tag) {
 
309
        var div = Y.config.doc.createElement('div'),
 
310
            ret = true;
 
311
 
 
312
        div.innerHTML = html;
 
313
        if (!div.firstChild || div.firstChild.tagName !== tag.toUpperCase()) {
 
314
            ret = false;
 
315
        }
 
316
 
 
317
        return ret;
 
318
    },
 
319
 
 
320
    re_tbody = /(?:\/(?:thead|tfoot|tbody|caption|col|colgroup)>)+\s*<tbody/,
 
321
 
 
322
    TABLE_OPEN = '<table>',
 
323
    TABLE_CLOSE = '</table>';
 
324
 
 
325
Y.mix(Y.DOM, {
 
326
    _fragClones: {},
 
327
 
 
328
    _create: function(html, doc, tag) {
 
329
        tag = tag || 'div';
 
330
 
 
331
        var frag = Y_DOM._fragClones[tag];
 
332
        if (frag) {
 
333
            frag = frag.cloneNode(false);
 
334
        } else {
 
335
            frag = Y_DOM._fragClones[tag] = doc.createElement(tag);
 
336
        }
 
337
        frag.innerHTML = html;
 
338
        return frag;
 
339
    },
 
340
 
 
341
    _children: function(node, tag) {
 
342
            var i = 0,
 
343
            children = node.children,
 
344
            childNodes,
 
345
            hasComments,
 
346
            child;
 
347
 
 
348
        if (children && children.tags) { // use tags filter when possible
 
349
            if (tag) {
 
350
                children = node.children.tags(tag);
 
351
            } else { // IE leaks comments into children
 
352
                hasComments = children.tags('!').length;
 
353
            }
 
354
        }
 
355
        
 
356
        if (!children || (!children.tags && tag) || hasComments) {
 
357
            childNodes = children || node.childNodes;
 
358
            children = [];
 
359
            while ((child = childNodes[i++])) {
 
360
                if (child.nodeType === 1) {
 
361
                    if (!tag || tag === child.tagName) {
 
362
                        children.push(child);
 
363
                    }
 
364
                }
 
365
            }
 
366
        }
 
367
 
 
368
        return children || [];
 
369
    },
 
370
 
 
371
    /**
 
372
     * Creates a new dom node using the provided markup string. 
 
373
     * @method create
 
374
     * @param {String} html The markup used to create the element
 
375
     * @param {HTMLDocument} doc An optional document context 
 
376
     * @return {HTMLElement|DocumentFragment} returns a single HTMLElement 
 
377
     * when creating one node, and a documentFragment when creating
 
378
     * multiple nodes.
 
379
     */
 
380
    create: function(html, doc) {
 
381
        if (typeof html === 'string') {
 
382
            html = Y.Lang.trim(html); // match IE which trims whitespace from innerHTML
 
383
 
 
384
        }
 
385
 
 
386
        doc = doc || Y.config.doc;
 
387
        var m = re_tag.exec(html),
 
388
            create = Y_DOM._create,
 
389
            custom = creators,
 
390
            ret = null,
 
391
            creator,
 
392
            tag, nodes;
 
393
 
 
394
        if (html != undefined) { // not undefined or null
 
395
            if (m && m[1]) {
 
396
                creator = custom[m[1].toLowerCase()];
 
397
                if (typeof creator === 'function') {
 
398
                    create = creator; 
 
399
                } else {
 
400
                    tag = creator;
 
401
                }
 
402
            }
 
403
 
 
404
            nodes = create(html, doc, tag).childNodes;
 
405
 
 
406
            if (nodes.length === 1) { // return single node, breaking parentNode ref from "fragment"
 
407
                ret = nodes[0].parentNode.removeChild(nodes[0]);
 
408
            } else if (nodes[0] && nodes[0].className === 'yui3-big-dummy') { // using dummy node to preserve some attributes (e.g. OPTION not selected)
 
409
                if (nodes.length === 2) {
 
410
                    ret = nodes[0].nextSibling;
 
411
                } else {
 
412
                    nodes[0].parentNode.removeChild(nodes[0]); 
 
413
                    ret = Y_DOM._nl2frag(nodes, doc);
 
414
                }
 
415
            } else { // return multiple nodes as a fragment
 
416
                 ret = Y_DOM._nl2frag(nodes, doc);
 
417
            }
 
418
 
 
419
        }
 
420
 
 
421
        return ret;
 
422
    },
 
423
 
 
424
    _nl2frag: function(nodes, doc) {
 
425
        var ret = null,
 
426
            i, len;
 
427
 
 
428
        if (nodes && (nodes.push || nodes.item) && nodes[0]) {
 
429
            doc = doc || nodes[0].ownerDocument; 
 
430
            ret = doc.createDocumentFragment();
 
431
 
 
432
            if (nodes.item) { // convert live list to static array
 
433
                nodes = Y.Array(nodes, 0, true);
 
434
            }
 
435
 
 
436
            for (i = 0, len = nodes.length; i < len; i++) {
 
437
                ret.appendChild(nodes[i]); 
 
438
            }
 
439
        } // else inline with log for minification
 
440
        return ret;
 
441
    },
 
442
 
 
443
    /**
 
444
     * Inserts content in a node at the given location 
 
445
     * @method addHTML
 
446
     * @param {HTMLElement} node The node to insert into
 
447
     * @param {HTMLElement | Array | HTMLCollection} content The content to be inserted 
 
448
     * @param {HTMLElement} where Where to insert the content
 
449
     * If no "where" is given, content is appended to the node
 
450
     * Possible values for "where"
 
451
     * <dl>
 
452
     * <dt>HTMLElement</dt>
 
453
     * <dd>The element to insert before</dd>
 
454
     * <dt>"replace"</dt>
 
455
     * <dd>Replaces the existing HTML</dd>
 
456
     * <dt>"before"</dt>
 
457
     * <dd>Inserts before the existing HTML</dd>
 
458
     * <dt>"before"</dt>
 
459
     * <dd>Inserts content before the node</dd>
 
460
     * <dt>"after"</dt>
 
461
     * <dd>Inserts content after the node</dd>
 
462
     * </dl>
 
463
     */
 
464
    addHTML: function(node, content, where) {
 
465
        var nodeParent = node.parentNode,
 
466
            i = 0,
 
467
            item,
 
468
            ret = content,
 
469
            newNode;
 
470
            
 
471
 
 
472
        if (content != undefined) { // not null or undefined (maybe 0)
 
473
            if (content.nodeType) { // DOM node, just add it
 
474
                newNode = content;
 
475
            } else if (typeof content == 'string' || typeof content == 'number') {
 
476
                ret = newNode = Y_DOM.create(content);
 
477
            } else if (content[0] && content[0].nodeType) { // array or collection 
 
478
                newNode = Y.config.doc.createDocumentFragment();
 
479
                while ((item = content[i++])) {
 
480
                    newNode.appendChild(item); // append to fragment for insertion
 
481
                }
 
482
            }
 
483
        }
 
484
 
 
485
        if (where) {
 
486
            if (newNode && where.parentNode) { // insert regardless of relationship to node
 
487
                where.parentNode.insertBefore(newNode, where);
 
488
            } else {
 
489
                switch (where) {
 
490
                    case 'replace':
 
491
                        while (node.firstChild) {
 
492
                            node.removeChild(node.firstChild);
 
493
                        }
 
494
                        if (newNode) { // allow empty content to clear node
 
495
                            node.appendChild(newNode);
 
496
                        }
 
497
                        break;
 
498
                    case 'before':
 
499
                        if (newNode) {
 
500
                            nodeParent.insertBefore(newNode, node);
 
501
                        }
 
502
                        break;
 
503
                    case 'after':
 
504
                        if (newNode) {
 
505
                            if (node.nextSibling) { // IE errors if refNode is null
 
506
                                nodeParent.insertBefore(newNode, node.nextSibling);
 
507
                            } else {
 
508
                                nodeParent.appendChild(newNode);
 
509
                            }
 
510
                        }
 
511
                        break;
 
512
                    default:
 
513
                        if (newNode) {
 
514
                            node.appendChild(newNode);
 
515
                        }
 
516
                }
 
517
            }
 
518
        } else if (newNode) {
 
519
            node.appendChild(newNode);
 
520
        }
 
521
 
 
522
        return ret;
 
523
    },
 
524
 
 
525
    wrap: function(node, html) {
 
526
        var parent = (html && html.nodeType) ? html : Y.DOM.create(html),
 
527
            nodes = parent.getElementsByTagName('*');
 
528
 
 
529
        if (nodes.length) {
 
530
            parent = nodes[nodes.length - 1];
 
531
        }
 
532
 
 
533
        if (node.parentNode) { 
 
534
            node.parentNode.replaceChild(parent, node);
 
535
        }
 
536
        parent.appendChild(node);
 
537
    },
 
538
 
 
539
    unwrap: function(node) {
 
540
        var parent = node.parentNode,
 
541
            lastChild = parent.lastChild,
 
542
            next = node,
 
543
            grandparent;
 
544
 
 
545
        if (parent) {
 
546
            grandparent = parent.parentNode;
 
547
            if (grandparent) {
 
548
                node = parent.firstChild;
 
549
                while (node !== lastChild) {
 
550
                    next = node.nextSibling;
 
551
                    grandparent.insertBefore(node, parent);
 
552
                    node = next;
 
553
                }
 
554
                grandparent.replaceChild(lastChild, parent);
 
555
            } else {
 
556
                parent.removeChild(node);
 
557
            }
 
558
        }
 
559
    }
 
560
});
 
561
 
 
562
addFeature('innerhtml', 'table', {
 
563
    test: function() {
 
564
        var node = Y.config.doc.createElement('table');
 
565
        try {
 
566
            node.innerHTML = '<tbody></tbody>';
 
567
        } catch(e) {
 
568
            return false;
 
569
        }
 
570
        return (node.firstChild && node.firstChild.nodeName === 'TBODY');
 
571
    }
 
572
});
 
573
 
 
574
addFeature('innerhtml-div', 'tr', {
 
575
    test: function() {
 
576
        return createFromDIV('<tr></tr>', 'tr');
 
577
    }
 
578
});
 
579
 
 
580
addFeature('innerhtml-div', 'script', {
 
581
    test: function() {
 
582
        return createFromDIV('<script></script>', 'script');
 
583
    }
 
584
});
 
585
 
 
586
if (!testFeature('innerhtml', 'table')) {
 
587
    // TODO: thead/tfoot with nested tbody
 
588
        // IE adds TBODY when creating TABLE elements (which may share this impl)
 
589
    creators.tbody = function(html, doc) {
 
590
        var frag = Y_DOM.create(TABLE_OPEN + html + TABLE_CLOSE, doc),
 
591
            tb = Y.DOM._children(frag, 'tbody')[0];
 
592
 
 
593
        if (frag.children.length > 1 && tb && !re_tbody.test(html)) {
 
594
            tb.parentNode.removeChild(tb); // strip extraneous tbody
 
595
        }
 
596
        return frag;
 
597
    };
 
598
}
 
599
 
 
600
if (!testFeature('innerhtml-div', 'script')) {
 
601
    creators.script = function(html, doc) {
 
602
        var frag = doc.createElement('div');
 
603
 
 
604
        frag.innerHTML = '-' + html;
 
605
        frag.removeChild(frag.firstChild);
 
606
        return frag;
 
607
    }
 
608
 
 
609
    creators.link = creators.style = creators.script;
 
610
}
 
611
 
 
612
if (!testFeature('innerhtml-div', 'tr')) {
 
613
    Y.mix(creators, {
 
614
        option: function(html, doc) {
 
615
            return Y_DOM.create('<select><option class="yui3-big-dummy" selected></option>' + html + '</select>', doc);
 
616
        },
 
617
 
 
618
        tr: function(html, doc) {
 
619
            return Y_DOM.create('<tbody>' + html + '</tbody>', doc);
 
620
        },
 
621
 
 
622
        td: function(html, doc) {
 
623
            return Y_DOM.create('<tr>' + html + '</tr>', doc);
 
624
        }, 
 
625
 
 
626
        col: function(html, doc) {
 
627
            return Y_DOM.create('<colgroup>' + html + '</colgroup>', doc);
 
628
        }, 
 
629
 
 
630
        tbody: 'table'
 
631
    });
 
632
 
 
633
    Y.mix(creators, {
 
634
        legend: 'fieldset',
 
635
        th: creators.td,
 
636
        thead: creators.tbody,
 
637
        tfoot: creators.tbody,
 
638
        caption: creators.tbody,
 
639
        colgroup: creators.tbody,
 
640
        optgroup: creators.option
 
641
    });
 
642
}
 
643
 
 
644
Y_DOM.creators = creators;
 
645
Y.mix(Y.DOM, {
 
646
    /**
 
647
     * Sets the width of the element to the given size, regardless
 
648
     * of box model, border, padding, etc.
 
649
     * @method setWidth
 
650
     * @param {HTMLElement} element The DOM element. 
 
651
     * @param {String|Number} size The pixel height to size to
 
652
     */
 
653
 
 
654
    setWidth: function(node, size) {
 
655
        Y.DOM._setSize(node, 'width', size);
 
656
    },
 
657
 
 
658
    /**
 
659
     * Sets the height of the element to the given size, regardless
 
660
     * of box model, border, padding, etc.
 
661
     * @method setHeight
 
662
     * @param {HTMLElement} element The DOM element. 
 
663
     * @param {String|Number} size The pixel height to size to
 
664
     */
 
665
 
 
666
    setHeight: function(node, size) {
 
667
        Y.DOM._setSize(node, 'height', size);
 
668
    },
 
669
 
 
670
    _setSize: function(node, prop, val) {
 
671
        val = (val > 0) ? val : 0;
 
672
        var size = 0;
 
673
 
 
674
        node.style[prop] = val + 'px';
 
675
        size = (prop === 'height') ? node.offsetHeight : node.offsetWidth;
 
676
 
 
677
        if (size > val) {
 
678
            val = val - (size - val);
 
679
 
 
680
            if (val < 0) {
 
681
                val = 0;
 
682
            }
 
683
 
 
684
            node.style[prop] = val + 'px';
 
685
        }
 
686
    }
 
687
});
 
688
 
 
689
 
 
690
}, '3.5.1' ,{requires:['dom-core']});