~bjornt/lazr-js/prefetch-yui-3.5

« back to all changes in this revision

Viewing changes to src-js/lazrjs/yui/dom/dom-debug.js

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-01-14 23:32:29 UTC
  • mfrom: (197.1.7 yui-3.3.0)
  • Revision ID: launchpad@pqm.canonical.com-20110114233229-r6i4cazdiiw18o7p
Upgrade to YUI 3.3.0 [r=mars]

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3
3
Code licensed under the BSD License:
4
4
http://developer.yahoo.com/yui/license.html
5
 
version: 3.2.0
6
 
build: 2676
 
5
version: 3.3.0
 
6
build: 3167
7
7
*/
8
8
YUI.add('dom-base', function(Y) {
9
9
 
36
36
    CONTAINS = 'contains',
37
37
    COMPARE_DOCUMENT_POSITION = 'compareDocumentPosition',
38
38
    EMPTY_STRING = '',
 
39
    EMPTY_ARRAY = [],
39
40
 
40
41
    documentElement = Y.config.doc.documentElement,
41
42
 
42
 
    re_tag = /<([a-z]+)/i;
43
 
 
44
 
Y.DOM = {
 
43
    re_tag = /<([a-z]+)/i,
 
44
 
 
45
    createFromDIV = function(html, tag) {
 
46
        var div = Y.config.doc.createElement('div'),
 
47
            ret = true;
 
48
 
 
49
        div.innerHTML = html;
 
50
        if (!div.firstChild || div.firstChild.tagName !== tag.toUpperCase()) {
 
51
            ret = false;
 
52
        }
 
53
 
 
54
        return ret;
 
55
    },
 
56
 
 
57
    addFeature = Y.Features.add,
 
58
    testFeature = Y.Features.test,
 
59
    
 
60
Y_DOM = {
45
61
    /**
46
62
     * Returns the HTMLElement with the given ID (Wrapper for document.getElementById).
47
63
     * @method byId         
51
67
     */
52
68
    byId: function(id, doc) {
53
69
        // handle dupe IDs and IE name collision
54
 
        return Y.DOM.allById(id, doc)[0] || null;
55
 
    },
56
 
 
57
 
    // @deprecated
58
 
    children: function(node, tag) {
59
 
        var ret = [];
60
 
        if (node) {
61
 
            tag = tag || '*';
62
 
            ret = Y.Selector.query('> ' + tag, node); 
63
 
        }
64
 
        return ret;
65
 
    },
66
 
 
67
 
    // @deprecated
68
 
    firstByTag: function(tag, root) {
69
 
        var ret;
70
 
        root = root || Y.config.doc;
71
 
 
72
 
        if (tag && root.getElementsByTagName) {
73
 
            ret = root.getElementsByTagName(tag)[0];
74
 
        }
75
 
 
76
 
        return ret || null;
 
70
        return Y_DOM.allById(id, doc)[0] || null;
77
71
    },
78
72
 
79
73
    /**
92
86
        } : function(element) {
93
87
            var ret = '';
94
88
            if (element) {
95
 
                ret = element.innerText;
 
89
                ret = element.innerText || element.nodeValue; // might be a textNode
96
90
            }
97
91
            return ret || '';
98
92
        },
109
103
                element.textContent = content;
110
104
            }
111
105
        } : function(element, content) {
112
 
            if (element) {
 
106
            if ('innerText' in element) {
113
107
                element.innerText = content;
 
108
            } else if ('nodeValue' in element) {
 
109
                element.nodeValue = content;
114
110
            }
 
111
 
115
112
        },
116
113
 
117
114
    /*
118
 
     * Finds the previous sibling of the element.
119
 
     * @method previous
120
 
     * @deprecated Use elementByAxis
121
 
     * @param {HTMLElement} element The html element.
122
 
     * @param {Function} fn optional An optional boolean test to apply.
123
 
     * The optional function is passed the current DOM node being tested as its only argument.
124
 
     * If no function is given, the first sibling is returned.
125
 
     * @param {Boolean} all optional Whether all node types should be scanned, or just element nodes.
126
 
     * @return {HTMLElement | null} The matching DOM node or null if none found. 
127
 
     */
128
 
    previous: function(element, fn, all) {
129
 
        return Y.DOM.elementByAxis(element, PREVIOUS_SIBLING, fn, all);
130
 
    },
131
 
 
132
 
    /*
133
 
     * Finds the next sibling of the element.
134
 
     * @method next
135
 
     * @deprecated Use elementByAxis
136
 
     * @param {HTMLElement} element The html element.
137
 
     * @param {Function} fn optional An optional boolean test to apply.
138
 
     * The optional function is passed the current DOM node being tested as its only argument.
139
 
     * If no function is given, the first sibling is returned.
140
 
     * @param {Boolean} all optional Whether all node types should be scanned, or just element nodes.
141
 
     * @return {HTMLElement | null} The matching DOM node or null if none found. 
142
 
     */
143
 
    next: function(element, fn, all) {
144
 
        return Y.DOM.elementByAxis(element, NEXT_SIBLING, fn, all);
145
 
    },
146
 
 
147
 
    /*
148
115
     * Finds the ancestor of the element.
149
116
     * @method ancestor
150
 
     * @deprecated Use elementByAxis
151
117
     * @param {HTMLElement} element The html element.
152
118
     * @param {Function} fn optional An optional boolean test to apply.
153
119
     * The optional function is passed the current DOM node being tested as its only argument.
161
127
            ret = (!fn || fn(element)) ? element : null;
162
128
 
163
129
        }
164
 
        return ret || Y.DOM.elementByAxis(element, PARENT_NODE, fn, null);
 
130
        return ret || Y_DOM.elementByAxis(element, PARENT_NODE, fn, null);
 
131
    },
 
132
 
 
133
    /*
 
134
     * Finds the ancestors of the element.
 
135
     * @method ancestors
 
136
     * @param {HTMLElement} element The html element.
 
137
     * @param {Function} fn optional An optional boolean test to apply.
 
138
     * The optional function is passed the current DOM node being tested as its only argument.
 
139
     * If no function is given, all ancestors are returned.
 
140
     * @param {Boolean} testSelf optional Whether or not to include the element in the scan 
 
141
     * @return {Array} An array containing all matching DOM nodes.
 
142
     */
 
143
    ancestors: function(element, fn, testSelf) {
 
144
        var ancestor = Y_DOM.ancestor.apply(Y_DOM, arguments),
 
145
            ret = (ancestor) ? [ancestor] : [];
 
146
 
 
147
        while ((ancestor = Y_DOM.ancestor(ancestor, fn))) {
 
148
            if (ancestor) {
 
149
                ret.unshift(ancestor);
 
150
            }
 
151
        }
 
152
 
 
153
        return ret;
165
154
    },
166
155
 
167
156
    /**
200
189
            if (Y.UA.opera || needle[NODE_TYPE] === 1) { // IE & SAF contains fail if needle not an ELEMENT_NODE
201
190
                ret = element[CONTAINS](needle);
202
191
            } else {
203
 
                ret = Y.DOM._bruteContains(element, needle); 
 
192
                ret = Y_DOM._bruteContains(element, needle); 
204
193
            }
205
194
        } else if (element[COMPARE_DOCUMENT_POSITION]) { // gecko
206
195
            if (element === needle || !!(element[COMPARE_DOCUMENT_POSITION](needle) & 16)) { 
231
220
            if (rootNode && rootNode.contains && element.tagName) {
232
221
                ret = rootNode.contains(element);
233
222
            } else {
234
 
                ret = Y.DOM.contains(rootNode, element);
 
223
                ret = Y_DOM.contains(rootNode, element);
235
224
            }
236
225
        }
237
226
 
250
239
            ret = root.querySelectorAll('[id="' + id + '"]');
251
240
        } else if (root.all) {
252
241
            nodes = root.all(id);
253
 
            if (nodes && nodes.nodeType) { // root.all may return one or many
254
 
                nodes = [nodes];
255
 
            }
256
 
 
257
 
            if (nodes && nodes.length) {
258
 
                for (i = 0; node = nodes[i++];) { // check for a match
259
 
                    if (node.attributes && node.attributes.id
260
 
                            && node.attributes.id.value === id) { // avoid false positive for node.name & form.id
261
 
                        ret.push(node);
 
242
 
 
243
            if (nodes) {
 
244
                // root.all may return HTMLElement or HTMLCollection.
 
245
                // some elements are also HTMLCollection (FORM, SELECT).
 
246
                if (nodes.nodeName) {
 
247
                    if (nodes.id === id) { // avoid false positive on name
 
248
                        ret.push(nodes);
 
249
                        nodes = EMPTY_ARRAY; // done, no need to filter
 
250
                    } else { //  prep for filtering
 
251
                        nodes = [nodes];
 
252
                    }
 
253
                }
 
254
 
 
255
                if (nodes.length) {
 
256
                    // filter out matches on node.name
 
257
                    // and element.id as reference to element with id === 'id'
 
258
                    for (i = 0; node = nodes[i++];) {
 
259
                        if (node.id === id  || 
 
260
                                (node.attributes && node.attributes.id &&
 
261
                                node.attributes.id.value === id)) { 
 
262
                            ret.push(node);
 
263
                        }
262
264
                    }
263
265
                }
264
266
            }
265
267
        } else {
266
 
            ret = [Y.DOM._getDoc(root).getElementById(id)];
 
268
            ret = [Y_DOM._getDoc(root).getElementById(id)];
267
269
        }
268
270
    
269
271
        return ret;
286
288
 
287
289
        doc = doc || Y.config.doc;
288
290
        var m = re_tag.exec(html),
289
 
            create = Y.DOM._create,
290
 
            custom = Y.DOM.creators,
 
291
            create = Y_DOM._create,
 
292
            custom = Y_DOM.creators,
291
293
            ret = null,
 
294
            creator,
292
295
            tag, nodes;
293
296
 
294
297
        if (html != undefined) { // not undefined or null
295
 
            if (m && custom[m[1]]) {
296
 
                if (typeof custom[m[1]] === 'function') {
297
 
                    create = custom[m[1]];
 
298
            if (m && m[1]) {
 
299
                creator = custom[m[1].toLowerCase()];
 
300
                if (typeof creator === 'function') {
 
301
                    create = creator; 
298
302
                } else {
299
 
                    tag = custom[m[1]];
 
303
                    tag = creator;
300
304
                }
301
305
            }
302
306
 
309
313
                    ret = nodes[0].nextSibling;
310
314
                } else {
311
315
                    nodes[0].parentNode.removeChild(nodes[0]); 
312
 
                     ret = Y.DOM._nl2frag(nodes, doc);
 
316
                     ret = Y_DOM._nl2frag(nodes, doc);
313
317
                }
314
318
            } else { // return multiple nodes as a fragment
315
 
                 ret = Y.DOM._nl2frag(nodes, doc);
 
319
                 ret = Y_DOM._nl2frag(nodes, doc);
316
320
            }
317
321
        }
318
322
 
351
355
    /**
352
356
     * Provides a normalized attribute interface. 
353
357
     * @method setAttibute
354
 
     * @param {String | HTMLElement} el The target element for the attribute.
 
358
     * @param {HTMLElement} el The target element for the attribute.
355
359
     * @param {String} attr The attribute to set.
356
360
     * @param {String} val The value of the attribute.
357
361
     */
358
362
    setAttribute: function(el, attr, val, ieAttr) {
359
 
        if (el && el.setAttribute) {
360
 
            attr = Y.DOM.CUSTOM_ATTRIBUTES[attr] || attr;
 
363
        if (el && attr && el.setAttribute) {
 
364
            attr = Y_DOM.CUSTOM_ATTRIBUTES[attr] || attr;
361
365
            el.setAttribute(attr, val, ieAttr);
362
366
        }
 
367
        else { Y.log('bad input to setAttribute', 'warn', 'dom'); }
363
368
    },
364
369
 
365
370
 
366
371
    /**
367
372
     * Provides a normalized attribute interface. 
368
373
     * @method getAttibute
369
 
     * @param {String | HTMLElement} el The target element for the attribute.
 
374
     * @param {HTMLElement} el The target element for the attribute.
370
375
     * @param {String} attr The attribute to get.
371
376
     * @return {String} The current value of the attribute. 
372
377
     */
373
378
    getAttribute: function(el, attr, ieAttr) {
374
379
        ieAttr = (ieAttr !== undefined) ? ieAttr : 2;
375
380
        var ret = '';
376
 
        if (el && el.getAttribute) {
377
 
            attr = Y.DOM.CUSTOM_ATTRIBUTES[attr] || attr;
 
381
        if (el && attr && el.getAttribute) {
 
382
            attr = Y_DOM.CUSTOM_ATTRIBUTES[attr] || attr;
378
383
            ret = el.getAttribute(attr, ieAttr);
379
384
 
380
385
            if (ret === null) {
381
386
                ret = ''; // per DOM spec
382
387
            }
383
388
        }
 
389
        else { Y.log('bad input to getAttribute', 'warn', 'dom'); }
384
390
        return ret;
385
391
    },
386
392
 
387
393
    isWindow: function(obj) {
388
 
        return obj.alert && obj.document;
 
394
        return !!(obj && obj.alert && obj.document);
389
395
    },
390
396
 
391
397
    _fragClones: {},
393
399
    _create: function(html, doc, tag) {
394
400
        tag = tag || 'div';
395
401
 
396
 
        var frag = Y.DOM._fragClones[tag];
 
402
        var frag = Y_DOM._fragClones[tag];
397
403
        if (frag) {
398
404
            frag = frag.cloneNode(false);
399
405
        } else {
400
 
            frag = Y.DOM._fragClones[tag] = doc.createElement(tag);
 
406
            frag = Y_DOM._fragClones[tag] = doc.createElement(tag);
401
407
        }
402
408
        frag.innerHTML = html;
403
409
        return frag;
413
419
     * Inserts content in a node at the given location 
414
420
     * @method addHTML
415
421
     * @param {HTMLElement} node The node to insert into
416
 
     * @param {String | HTMLElement} content The content to be inserted 
417
 
     * @param {String | HTMLElement} where Where to insert the content
 
422
     * @param {HTMLElement | Array | HTMLCollection} content The content to be inserted 
 
423
     * @param {HTMLElement} where Where to insert the content
418
424
     * If no "where" is given, content is appended to the node
419
425
     * Possible values for "where"
420
426
     * <dl>
432
438
     */
433
439
    addHTML: function(node, content, where) {
434
440
        var nodeParent = node.parentNode,
 
441
            i = 0,
 
442
            item,
 
443
            ret = content,
435
444
            newNode;
436
445
            
437
 
        if (content !== undefined && content !== null) {
438
 
            if (content.nodeType) { // domNode
 
446
 
 
447
        if (content != undefined) { // not null or undefined (maybe 0)
 
448
            if (content.nodeType) { // DOM node, just add it
439
449
                newNode = content;
440
 
            } else { // create from string and cache
441
 
                newNode = Y.DOM.create(content);
 
450
            } else if (typeof content == 'string' || typeof content == 'number') {
 
451
                ret = newNode = Y_DOM.create(content);
 
452
            } else if (content[0] && content[0].nodeType) { // array or collection 
 
453
                newNode = Y.config.doc.createDocumentFragment();
 
454
                while ((item = content[i++])) {
 
455
                    newNode.appendChild(item); // append to fragment for insertion
 
456
                }
442
457
            }
443
458
        }
444
459
 
445
460
        if (where) {
446
461
            if (where.nodeType) { // insert regardless of relationship to node
447
 
                // TODO: check if node.contains(where)?
448
462
                where.parentNode.insertBefore(newNode, where);
449
463
            } else {
450
464
                switch (where) {
470
484
                        node.appendChild(newNode);
471
485
                }
472
486
            }
473
 
        } else {
 
487
        } else if (newNode) {
474
488
            node.appendChild(newNode);
475
489
        }
476
490
 
477
 
        return newNode;
 
491
        return ret;
478
492
    },
479
493
 
480
494
    VALUE_SETTERS: {},
486
500
            getter;
487
501
 
488
502
        if (node && node[TAG_NAME]) {
489
 
            getter = Y.DOM.VALUE_GETTERS[node[TAG_NAME].toLowerCase()];
 
503
            getter = Y_DOM.VALUE_GETTERS[node[TAG_NAME].toLowerCase()];
490
504
 
491
505
            if (getter) {
492
506
                ret = getter(node);
508
522
        var setter;
509
523
 
510
524
        if (node && node[TAG_NAME]) {
511
 
            setter = Y.DOM.VALUE_SETTERS[node[TAG_NAME].toLowerCase()];
 
525
            setter = Y_DOM.VALUE_SETTERS[node[TAG_NAME].toLowerCase()];
512
526
 
513
527
            if (setter) {
514
528
                setter(node, val);
568
582
     */
569
583
    _getRegExp: function(str, flags) {
570
584
        flags = flags || '';
571
 
        Y.DOM._regexCache = Y.DOM._regexCache || {};
572
 
        if (!Y.DOM._regexCache[str + flags]) {
573
 
            Y.DOM._regexCache[str + flags] = new RegExp(str, flags);
 
585
        Y_DOM._regexCache = Y_DOM._regexCache || {};
 
586
        if (!Y_DOM._regexCache[str + flags]) {
 
587
            Y_DOM._regexCache[str + flags] = new RegExp(str, flags);
574
588
        }
575
 
        return Y.DOM._regexCache[str + flags];
 
589
        return Y_DOM._regexCache[str + flags];
576
590
    },
577
591
 
578
592
// TODO: make getDoc/Win true privates?
603
617
     * @return {Object} The window for the given element or the default window. 
604
618
     */
605
619
    _getWin: function(element) {
606
 
        var doc = Y.DOM._getDoc(element);
 
620
        var doc = Y_DOM._getDoc(element);
607
621
        return doc[DEFAULT_VIEW] || doc[PARENT_WINDOW] || Y.config.win;
608
622
    },
609
623
 
610
624
    _batch: function(nodes, fn, arg1, arg2, arg3, etc) {
611
 
        fn = (typeof name === 'string') ? Y.DOM[fn] : fn;
 
625
        fn = (typeof fn === 'string') ? Y_DOM[fn] : fn;
612
626
        var result,
613
 
            ret = [];
 
627
            args = Array.prototype.slice.call(arguments, 2),
 
628
            i = 0,
 
629
            node,
 
630
            ret;
614
631
 
615
632
        if (fn && nodes) {
616
 
            Y.each(nodes, function(node) {
617
 
                if ((result = fn.call(Y.DOM, node, arg1, arg2, arg3, etc)) !== undefined) {
618
 
                    ret[ret.length] = result;
619
 
                }
620
 
            });
621
 
        }
622
 
 
623
 
        return ret.length ? ret : nodes;
624
 
    },
625
 
 
626
 
    creators: {},
627
 
 
628
 
    _IESimpleCreate: function(html, doc) {
629
 
        doc = doc || Y.config.doc;
630
 
        return doc.createElement(html);
631
 
    }
 
633
            while ((node = nodes[i++])) {
 
634
                result = result = fn.call(Y_DOM, node, arg1, arg2, arg3, etc);
 
635
                if (typeof result !== 'undefined') {
 
636
                    (ret) || (ret = []);
 
637
                    ret.push(result);
 
638
                }
 
639
            }
 
640
        }
 
641
 
 
642
        return (typeof ret !== 'undefined') ? ret : nodes;
 
643
    },
 
644
 
 
645
    wrap: function(node, html) {
 
646
        var parent = Y.DOM.create(html),
 
647
            nodes = parent.getElementsByTagName('*');
 
648
 
 
649
        if (nodes.length) {
 
650
            parent = nodes[nodes.length - 1];
 
651
        }
 
652
 
 
653
        if (node.parentNode) { 
 
654
            node.parentNode.replaceChild(parent, node);
 
655
        }
 
656
        parent.appendChild(node);
 
657
    },
 
658
 
 
659
    unwrap: function(node) {
 
660
        var parent = node.parentNode,
 
661
            lastChild = parent.lastChild,
 
662
            node = parent.firstChild,
 
663
            next = node,
 
664
            grandparent;
 
665
 
 
666
        if (parent) {
 
667
            grandparent = parent.parentNode;
 
668
            if (grandparent) {
 
669
                while (node !== lastChild) {
 
670
                    next = node.nextSibling;
 
671
                    grandparent.insertBefore(node, parent);
 
672
                    node = next;
 
673
                }
 
674
                grandparent.replaceChild(lastChild, parent);
 
675
            } else {
 
676
                parent.removeChild(node);
 
677
            }
 
678
        }
 
679
    },
 
680
 
 
681
    generateID: function(el) {
 
682
        var id = el.id;
 
683
 
 
684
        if (!id) {
 
685
            id = Y.stamp(el);
 
686
            el.id = id; 
 
687
        }   
 
688
 
 
689
        return id; 
 
690
    },
 
691
 
 
692
    creators: {}
632
693
};
633
694
 
 
695
addFeature('innerhtml', 'table', {
 
696
    test: function() {
 
697
        var node = Y.config.doc.createElement('table');
 
698
        try {
 
699
            node.innerHTML = '<tbody></tbody>';
 
700
        } catch(e) {
 
701
            return false;
 
702
        }
 
703
        return (node.firstChild && node.firstChild.nodeName === 'TBODY');
 
704
    }
 
705
});
 
706
 
 
707
addFeature('innerhtml-div', 'tr', {
 
708
    test: function() {
 
709
        return createFromDIV('<tr></tr>', 'tr');
 
710
    }
 
711
});
 
712
 
 
713
addFeature('innerhtml-div', 'script', {
 
714
    test: function() {
 
715
        return createFromDIV('<script></script>', 'script');
 
716
    }
 
717
});
 
718
 
 
719
addFeature('value-set', 'select', {
 
720
    test: function() {
 
721
        var node = Y.config.doc.createElement('select');
 
722
        node.innerHTML = '<option>1</option><option>2</option>';
 
723
        node.value = '2';
 
724
        return (node.value && node.value === '2');
 
725
    }
 
726
});
634
727
 
635
728
(function(Y) {
636
 
    var creators = Y.DOM.creators,
637
 
        create = Y.DOM.create,
 
729
    var creators = Y_DOM.creators,
 
730
        create = Y_DOM.create,
638
731
        re_tbody = /(?:\/(?:thead|tfoot|tbody|caption|col|colgroup)>)+\s*<tbody/,
639
732
 
640
733
        TABLE_OPEN = '<table>',
641
734
        TABLE_CLOSE = '</table>';
642
735
 
643
 
    if (Y.UA.ie) {
644
 
        Y.mix(creators, {
 
736
    if (!testFeature('innerhtml', 'table')) {
645
737
        // TODO: thead/tfoot with nested tbody
646
738
            // IE adds TBODY when creating TABLE elements (which may share this impl)
647
 
            tbody: function(html, doc) {
648
 
                var frag = create(TABLE_OPEN + html + TABLE_CLOSE, doc),
649
 
                    tb = frag.children.tags('tbody')[0];
650
 
 
651
 
                if (frag.children.length > 1 && tb && !re_tbody.test(html)) {
652
 
                    tb[PARENT_NODE].removeChild(tb); // strip extraneous tbody
653
 
                }
654
 
                return frag;
655
 
            },
656
 
 
657
 
            script: function(html, doc) {
658
 
                var frag = doc.createElement('div');
659
 
 
660
 
                frag.innerHTML = '-' + html;
661
 
                frag.removeChild(frag[FIRST_CHILD]);
662
 
                return frag;
663
 
            }
664
 
 
665
 
        }, true);
666
 
 
667
 
        Y.mix(Y.DOM.VALUE_GETTERS, {
668
 
            button: function(node) {
669
 
                return (node.attributes && node.attributes.value) ? node.attributes.value.value : '';
670
 
            }
671
 
        });
672
 
 
673
 
        Y.mix(Y.DOM.VALUE_SETTERS, {
674
 
            // IE: node.value changes the button text, which should be handled via innerHTML
675
 
            button: function(node, val) {
676
 
                var attr = node.attributes.value;
677
 
                if (!attr) {
678
 
                    attr = node[OWNER_DOCUMENT].createAttribute('value');
679
 
                    node.setAttributeNode(attr);
680
 
                }
681
 
 
682
 
                attr.value = val;
683
 
            },
684
 
 
685
 
            select: function(node, val) {
686
 
                for (var i = 0, options = node.getElementsByTagName('option'), option;
687
 
                        option = options[i++];) {
688
 
                    if (Y.DOM.getValue(option) === val) {
689
 
                        Y.DOM.setAttribute(option, 'selected', true);
690
 
                        break;
691
 
                    }
692
 
                }
693
 
            }
694
 
        });
695
 
 
696
 
        Y.DOM.creators.style = Y.DOM.creators.script;
697
 
    }
698
 
 
699
 
    if (Y.UA.gecko || Y.UA.ie) {
 
739
        creators.tbody = function(html, doc) {
 
740
            var frag = create(TABLE_OPEN + html + TABLE_CLOSE, doc),
 
741
                tb = frag.children.tags('tbody')[0];
 
742
 
 
743
            if (frag.children.length > 1 && tb && !re_tbody.test(html)) {
 
744
                tb[PARENT_NODE].removeChild(tb); // strip extraneous tbody
 
745
            }
 
746
            return frag;
 
747
        };
 
748
    }
 
749
 
 
750
    if (!testFeature('innerhtml-div', 'script')) {
 
751
        creators.script = function(html, doc) {
 
752
            var frag = doc.createElement('div');
 
753
 
 
754
            frag.innerHTML = '-' + html;
 
755
            frag.removeChild(frag[FIRST_CHILD]);
 
756
            return frag;
 
757
        }
 
758
 
 
759
        Y_DOM.creators.link = Y_DOM.creators.style = Y_DOM.creators.script;
 
760
    }
 
761
 
 
762
    
 
763
    if (!testFeature('value-set', 'select')) {
 
764
        Y_DOM.VALUE_SETTERS.select = function(node, val) {
 
765
            for (var i = 0, options = node.getElementsByTagName('option'), option;
 
766
                    option = options[i++];) {
 
767
                if (Y_DOM.getValue(option) === val) {
 
768
                    option.selected = true;
 
769
                    //Y_DOM.setAttribute(option, 'selected', 'selected');
 
770
                    break;
 
771
                }
 
772
            }
 
773
        }
 
774
    }
 
775
 
 
776
    Y.mix(Y_DOM.VALUE_GETTERS, {
 
777
        button: function(node) {
 
778
            return (node.attributes && node.attributes.value) ? node.attributes.value.value : '';
 
779
        }
 
780
    });
 
781
 
 
782
    Y.mix(Y_DOM.VALUE_SETTERS, {
 
783
        // IE: node.value changes the button text, which should be handled via innerHTML
 
784
        button: function(node, val) {
 
785
            var attr = node.attributes.value;
 
786
            if (!attr) {
 
787
                attr = node[OWNER_DOCUMENT].createAttribute('value');
 
788
                node.setAttributeNode(attr);
 
789
            }
 
790
 
 
791
            attr.value = val;
 
792
        }
 
793
    });
 
794
 
 
795
 
 
796
    if (!testFeature('innerhtml-div', 'tr')) {
700
797
        Y.mix(creators, {
701
798
            option: function(html, doc) {
702
799
                return create('<select><option class="yui3-big-dummy" selected></option>' + html + '</select>', doc);
710
807
                return create('<tr>' + html + '</tr>', doc);
711
808
            }, 
712
809
 
713
 
            tbody: function(html, doc) {
714
 
                return create(TABLE_OPEN + html + TABLE_CLOSE, doc);
715
 
            }
 
810
            col: function(html, doc) {
 
811
                return create('<colgroup>' + html + '</colgroup>', doc);
 
812
            }, 
 
813
 
 
814
            tbody: 'table'
716
815
        });
717
816
 
718
817
        Y.mix(creators, {
722
821
            tfoot: creators.tbody,
723
822
            caption: creators.tbody,
724
823
            colgroup: creators.tbody,
725
 
            col: creators.tbody,
726
824
            optgroup: creators.option
727
825
        });
728
826
    }
729
827
 
730
 
    Y.mix(Y.DOM.VALUE_GETTERS, {
 
828
    Y.mix(Y_DOM.VALUE_GETTERS, {
731
829
        option: function(node) {
732
830
            var attrs = node.attributes;
733
831
            return (attrs.value && attrs.value.specified) ? node.value : node.text;
737
835
            var val = node.value,
738
836
                options = node.options;
739
837
 
740
 
            if (options && options.length && val === '') {
 
838
            if (options && options.length) {
741
839
                // TODO: implement multipe select
742
840
                if (node.multiple) {
743
841
                    Y.log('multiple select normalization not implemented', 'warn', 'DOM');
744
842
                } else {
745
 
                    val = Y.DOM.getValue(options[node.selectedIndex]);
 
843
                    val = Y_DOM.getValue(options[node.selectedIndex]);
746
844
                }
747
845
            }
748
846
 
751
849
    });
752
850
})(Y);
753
851
 
 
852
Y.DOM = Y_DOM;
754
853
})(Y);
755
854
var addClass, hasClass, removeClass;
756
855
 
884
983
});
885
984
 
886
985
 
887
 
}, '3.2.0' ,{requires:['oop']});
 
986
}, '3.3.0' ,{requires:['oop']});
888
987
YUI.add('dom-style', function(Y) {
889
988
 
890
989
(function(Y) {
906
1005
    GET_COMPUTED_STYLE = 'getComputedStyle',
907
1006
    GET_BOUNDING_CLIENT_RECT = 'getBoundingClientRect',
908
1007
 
 
1008
    WINDOW = Y.config.win,
909
1009
    DOCUMENT = Y.config.doc,
910
1010
    UNDEFINED = undefined,
911
1011
 
921
1021
    re_color = /color$/i,
922
1022
    re_unit = /width|height|top|left|right|bottom|margin|padding/i;
923
1023
 
924
 
 
925
1024
Y.Array.each(VENDOR_TRANSFORM, function(val) {
926
1025
    if (val in DOCUMENT[DOCUMENT_ELEMENT].style) {
927
1026
        TRANSFORM = val;
944
1043
     */
945
1044
    setStyle: function(node, att, val, style) {
946
1045
        style = style || node.style;
947
 
        var CUSTOM_STYLES = Y_DOM.CUSTOM_STYLES,
948
 
            current;
 
1046
        var CUSTOM_STYLES = Y_DOM.CUSTOM_STYLES;
949
1047
 
950
1048
        if (style) {
951
1049
            if (val === null || val === '') { // normalize unsetting
961
1059
                } else if (typeof CUSTOM_STYLES[att] === 'string') {
962
1060
                    att = CUSTOM_STYLES[att];
963
1061
                }
 
1062
            } else if (att === '') { // unset inline styles
 
1063
                att = 'cssText';
 
1064
                val = '';
964
1065
            }
965
1066
            style[att] = val; 
966
1067
        }
1018
1119
        var val = '',
1019
1120
            doc = node[OWNER_DOCUMENT];
1020
1121
 
1021
 
        if (node[STYLE]) {
 
1122
        if (node[STYLE] && doc[DEFAULT_VIEW] && doc[DEFAULT_VIEW][GET_COMPUTED_STYLE]) {
1022
1123
            val = doc[DEFAULT_VIEW][GET_COMPUTED_STYLE](node, null)[att];
1023
1124
        }
1024
1125
        return val;
1126
1227
        return Y_DOM[GET_COMPUTED_STYLE](node, TRANSFORM);
1127
1228
    }
1128
1229
};
 
1230
 
 
1231
 
1129
1232
})(Y);
1130
1233
(function(Y) {
1131
1234
var PARSE_INT = parseInt,
1203
1306
 
1204
1307
 
1205
1308
 
1206
 
}, '3.2.0' ,{requires:['dom-base']});
 
1309
}, '3.3.0' ,{requires:['dom-base']});
1207
1310
YUI.add('dom-screen', function(Y) {
1208
1311
 
1209
1312
(function(Y) {
1335
1438
                    bLeft, bTop,
1336
1439
                    mode,
1337
1440
                    doc,
 
1441
                    inDoc,
1338
1442
                    rootNode;
1339
1443
 
1340
1444
                if (node && node.tagName) {
1383
1487
                            }
1384
1488
 
1385
1489
                        if ((scrollTop || scrollLeft)) {
1386
 
                            if (!Y.UA.ios) {
 
1490
                            if (!Y.UA.ios || (Y.UA.ios >= 4.2)) {
1387
1491
                                xy[0] += scrollLeft;
1388
1492
                                xy[1] += scrollTop;
1389
1493
                            }
1639
1743
     * @for DOM
1640
1744
     * @method region
1641
1745
     * @param {HTMLElement} element The DOM element. 
1642
 
     @return {Object} Object literal containing the following about this element: (top, right, bottom, left)
 
1746
     * @return {Object} Object literal containing the following about this element: (top, right, bottom, left)
1643
1747
     */
1644
1748
    region: function(node) {
1645
1749
        var xy = DOM.getXY(node),
1664
1768
     * @param {HTMLElement} element The first element 
1665
1769
     * @param {HTMLElement | Object} element2 The element or region to check the interect with
1666
1770
     * @param {Object} altRegion An object literal containing the region for the first element if we already have the data (for performance i.e. DragDrop)
1667
 
     @return {Object} Object literal containing the following intersection data: (top, right, bottom, left, area, yoff, xoff, inRegion)
 
1771
     * @return {Object} Object literal containing the following intersection data: (top, right, bottom, left, area, yoff, xoff, inRegion)
1668
1772
     */
1669
1773
    intersect: function(node, node2, altRegion) {
1670
1774
        var r = altRegion || DOM.region(node), region = {},
1787
1891
})(Y);
1788
1892
 
1789
1893
 
1790
 
}, '3.2.0' ,{requires:['dom-base', 'dom-style', 'event-base']});
 
1894
}, '3.3.0' ,{requires:['dom-base', 'dom-style', 'event-base']});
1791
1895
YUI.add('selector-native', function(Y) {
1792
1896
 
1793
1897
(function(Y) {
2056
2160
})(Y);
2057
2161
 
2058
2162
 
2059
 
}, '3.2.0' ,{requires:['dom-base']});
 
2163
}, '3.3.0' ,{requires:['dom-base']});
2060
2164
YUI.add('selector-css2', function(Y) {
2061
2165
 
2062
2166
/**
2506
2610
 
2507
2611
 
2508
2612
 
2509
 
}, '3.2.0' ,{requires:['selector-native']});
2510
 
 
2511
 
 
2512
 
YUI.add('selector', function(Y){}, '3.2.0' ,{use:['selector-native', 'selector-css2']});
2513
 
 
2514
 
 
2515
 
 
2516
 
YUI.add('dom', function(Y){}, '3.2.0' ,{use:['dom-base', 'dom-style', 'dom-screen', 'selector']});
 
2613
}, '3.3.0' ,{requires:['selector-native']});
 
2614
 
 
2615
 
 
2616
YUI.add('selector', function(Y){}, '3.3.0' ,{use:['selector-native', 'selector-css2']});
 
2617
 
 
2618
 
 
2619
 
 
2620
YUI.add('dom', function(Y){}, '3.3.0' ,{use:['dom-base', 'dom-style', 'dom-screen', 'selector']});
2517
2621