~bcsaller/juju-gui/charmFind

« back to all changes in this revision

Viewing changes to lib/yui/build/dom-base/dom-base-debug.js

  • Committer: kapil.foss at gmail
  • Date: 2012-07-13 18:45:59 UTC
  • Revision ID: kapil.foss@gmail.com-20120713184559-2xl7be17egsrz0c9
reshape

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