~ubuntu-branches/ubuntu/utopic/moodle/utopic

« back to all changes in this revision

Viewing changes to lib/yuilib/3.9.1/build/dom-base/dom-base.js

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2014-05-12 16:10:38 UTC
  • mfrom: (36.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20140512161038-puyqf65k4e0s8ytz
Tags: 2.6.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

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