109
103
element.textContent = content;
111
105
} : function(element, content) {
106
if ('innerText' in element) {
113
107
element.innerText = content;
108
} else if ('nodeValue' in element) {
109
element.nodeValue = content;
118
* Finds the previous sibling of the element.
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.
128
previous: function(element, fn, all) {
129
return Y.DOM.elementByAxis(element, PREVIOUS_SIBLING, fn, all);
133
* Finds the next sibling of the element.
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.
143
next: function(element, fn, all) {
144
return Y.DOM.elementByAxis(element, NEXT_SIBLING, fn, all);
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.
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.
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);
367
else { Y.log('bad input to setAttribute', 'warn', 'dom'); }
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.
373
378
getAttribute: function(el, attr, ieAttr) {
374
379
ieAttr = (ieAttr !== undefined) ? ieAttr : 2;
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);
380
385
if (ret === null) {
381
386
ret = ''; // per DOM spec
389
else { Y.log('bad input to getAttribute', 'warn', 'dom'); }
387
393
isWindow: function(obj) {
388
return obj.alert && obj.document;
394
return !!(obj && obj.alert && obj.document);
603
617
* @return {Object} The window for the given element or the default window.
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;
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;
627
args = Array.prototype.slice.call(arguments, 2),
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;
623
return ret.length ? ret : nodes;
628
_IESimpleCreate: function(html, doc) {
629
doc = doc || Y.config.doc;
630
return doc.createElement(html);
633
while ((node = nodes[i++])) {
634
result = result = fn.call(Y_DOM, node, arg1, arg2, arg3, etc);
635
if (typeof result !== 'undefined') {
642
return (typeof ret !== 'undefined') ? ret : nodes;
645
wrap: function(node, html) {
646
var parent = Y.DOM.create(html),
647
nodes = parent.getElementsByTagName('*');
650
parent = nodes[nodes.length - 1];
653
if (node.parentNode) {
654
node.parentNode.replaceChild(parent, node);
656
parent.appendChild(node);
659
unwrap: function(node) {
660
var parent = node.parentNode,
661
lastChild = parent.lastChild,
662
node = parent.firstChild,
667
grandparent = parent.parentNode;
669
while (node !== lastChild) {
670
next = node.nextSibling;
671
grandparent.insertBefore(node, parent);
674
grandparent.replaceChild(lastChild, parent);
676
parent.removeChild(node);
681
generateID: function(el) {
695
addFeature('innerhtml', 'table', {
697
var node = Y.config.doc.createElement('table');
699
node.innerHTML = '<tbody></tbody>';
703
return (node.firstChild && node.firstChild.nodeName === 'TBODY');
707
addFeature('innerhtml-div', 'tr', {
709
return createFromDIV('<tr></tr>', 'tr');
713
addFeature('innerhtml-div', 'script', {
715
return createFromDIV('<script></script>', 'script');
719
addFeature('value-set', 'select', {
721
var node = Y.config.doc.createElement('select');
722
node.innerHTML = '<option>1</option><option>2</option>';
724
return (node.value && node.value === '2');
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/,
640
733
TABLE_OPEN = '<table>',
641
734
TABLE_CLOSE = '</table>';
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];
651
if (frag.children.length > 1 && tb && !re_tbody.test(html)) {
652
tb[PARENT_NODE].removeChild(tb); // strip extraneous tbody
657
script: function(html, doc) {
658
var frag = doc.createElement('div');
660
frag.innerHTML = '-' + html;
661
frag.removeChild(frag[FIRST_CHILD]);
667
Y.mix(Y.DOM.VALUE_GETTERS, {
668
button: function(node) {
669
return (node.attributes && node.attributes.value) ? node.attributes.value.value : '';
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;
678
attr = node[OWNER_DOCUMENT].createAttribute('value');
679
node.setAttributeNode(attr);
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);
696
Y.DOM.creators.style = Y.DOM.creators.script;
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];
743
if (frag.children.length > 1 && tb && !re_tbody.test(html)) {
744
tb[PARENT_NODE].removeChild(tb); // strip extraneous tbody
750
if (!testFeature('innerhtml-div', 'script')) {
751
creators.script = function(html, doc) {
752
var frag = doc.createElement('div');
754
frag.innerHTML = '-' + html;
755
frag.removeChild(frag[FIRST_CHILD]);
759
Y_DOM.creators.link = Y_DOM.creators.style = Y_DOM.creators.script;
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');
776
Y.mix(Y_DOM.VALUE_GETTERS, {
777
button: function(node) {
778
return (node.attributes && node.attributes.value) ? node.attributes.value.value : '';
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;
787
attr = node[OWNER_DOCUMENT].createAttribute('value');
788
node.setAttributeNode(attr);
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);