2007-01-18 22:24:27 +00:00
|
|
|
function $(element) {
|
|
|
|
if (arguments.length > 1) {
|
|
|
|
for (var i = 0, elements = [], length = arguments.length; i < length; i++)
|
|
|
|
elements.push($(arguments[i]));
|
|
|
|
return elements;
|
|
|
|
}
|
|
|
|
if (typeof element == 'string')
|
|
|
|
element = document.getElementById(element);
|
|
|
|
return Element.extend(element);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Prototype.BrowserFeatures.XPath) {
|
|
|
|
document._getElementsByXPath = function(expression, parentElement) {
|
|
|
|
var results = [];
|
|
|
|
var query = document.evaluate(expression, $(parentElement) || document,
|
|
|
|
null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
|
|
|
|
for (var i = 0, length = query.snapshotLength; i < length; i++)
|
|
|
|
results.push(query.snapshotItem(i));
|
|
|
|
return results;
|
|
|
|
};
|
2007-06-17 22:26:46 +00:00
|
|
|
}
|
2007-01-18 22:24:27 +00:00
|
|
|
|
|
|
|
/*--------------------------------------------------------------------------*/
|
|
|
|
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
(function() {
|
|
|
|
var element = this.Element;
|
|
|
|
this.Element = function(tagName, attributes) {
|
|
|
|
attributes = attributes || {};
|
|
|
|
tagName = tagName.toLowerCase();
|
|
|
|
var cache = Element.cache;
|
|
|
|
if (Prototype.Browser.IE && attributes.name) {
|
|
|
|
tagName = '<' + tagName + ' name="' + attributes.name + '">';
|
|
|
|
delete attributes.name;
|
|
|
|
return Element.writeAttribute(document.createElement(tagName), attributes);
|
|
|
|
}
|
|
|
|
if (!cache[tagName]) cache[tagName] = Element.extend(document.createElement(tagName));
|
|
|
|
return Element.writeAttribute(cache[tagName].cloneNode(false), attributes);
|
|
|
|
};
|
|
|
|
Object.extend(this.Element, element || {});
|
|
|
|
}).call(window);
|
|
|
|
|
|
|
|
Element.cache = {};
|
2007-01-27 19:45:34 +00:00
|
|
|
|
2007-01-18 22:24:27 +00:00
|
|
|
Element.Methods = {
|
|
|
|
visible: function(element) {
|
|
|
|
return $(element).style.display != 'none';
|
|
|
|
},
|
|
|
|
|
|
|
|
toggle: function(element) {
|
|
|
|
element = $(element);
|
|
|
|
Element[Element.visible(element) ? 'hide' : 'show'](element);
|
|
|
|
return element;
|
|
|
|
},
|
|
|
|
|
|
|
|
hide: function(element) {
|
|
|
|
$(element).style.display = 'none';
|
|
|
|
return element;
|
|
|
|
},
|
|
|
|
|
|
|
|
show: function(element) {
|
|
|
|
$(element).style.display = '';
|
|
|
|
return element;
|
|
|
|
},
|
|
|
|
|
|
|
|
remove: function(element) {
|
|
|
|
element = $(element);
|
|
|
|
element.parentNode.removeChild(element);
|
|
|
|
return element;
|
|
|
|
},
|
|
|
|
|
|
|
|
update: function(element, html) {
|
|
|
|
html = typeof html == 'undefined' ? '' : html.toString();
|
|
|
|
$(element).innerHTML = html.stripScripts();
|
2007-04-29 05:37:07 +00:00
|
|
|
html.evalScripts.bind(html).defer();
|
2007-01-18 22:24:27 +00:00
|
|
|
return element;
|
|
|
|
},
|
|
|
|
|
|
|
|
replace: function(element, html) {
|
|
|
|
element = $(element);
|
|
|
|
html = typeof html == 'undefined' ? '' : html.toString();
|
|
|
|
if (element.outerHTML) {
|
|
|
|
element.outerHTML = html.stripScripts();
|
|
|
|
} else {
|
|
|
|
var range = element.ownerDocument.createRange();
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
range.selectNode(element);
|
2007-01-18 22:24:27 +00:00
|
|
|
element.parentNode.replaceChild(
|
|
|
|
range.createContextualFragment(html.stripScripts()), element);
|
|
|
|
}
|
2007-04-29 05:37:07 +00:00
|
|
|
html.evalScripts.bind(html).defer();
|
2007-01-18 22:24:27 +00:00
|
|
|
return element;
|
|
|
|
},
|
|
|
|
|
2007-06-02 15:08:50 +00:00
|
|
|
insert: function(element, insertions) {
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
element = $(element);
|
2007-06-02 15:08:50 +00:00
|
|
|
|
2007-06-02 16:00:47 +00:00
|
|
|
if (typeof insertions == 'string' || typeof insertions == 'number' ||
|
|
|
|
(insertions && insertions.ownerDocument === document))
|
|
|
|
insertions = {bottom:insertions};
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
|
2007-06-02 15:08:50 +00:00
|
|
|
var content, t, range;
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
|
2007-06-02 15:08:50 +00:00
|
|
|
for (position in insertions) {
|
|
|
|
content = insertions[position];
|
|
|
|
position = position.toLowerCase();
|
|
|
|
t = Element._insertionTranslations[position];
|
|
|
|
|
|
|
|
if (content && content.ownerDocument === document) {
|
|
|
|
t.insert(element, content);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-06-02 16:00:47 +00:00
|
|
|
content = String.interpret(content);
|
2007-06-02 15:08:50 +00:00
|
|
|
|
|
|
|
range = element.ownerDocument.createRange();
|
|
|
|
t.initializeRange(element, range);
|
|
|
|
t.insert(element, range.createContextualFragment(content.stripScripts()));
|
|
|
|
|
|
|
|
content.evalScripts.bind(content).defer();
|
|
|
|
}
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
|
|
|
|
return element;
|
|
|
|
},
|
|
|
|
|
|
|
|
wrap: function(element, wrapper) {
|
|
|
|
element = $(element);
|
|
|
|
wrapper = wrapper || 'div';
|
|
|
|
if (typeof wrapper == 'string') wrapper = new Element(wrapper);
|
|
|
|
else Element.extend(wrapper);
|
|
|
|
element.parentNode.replaceChild(wrapper, element);
|
|
|
|
wrapper.appendChild(element);
|
|
|
|
return element;
|
|
|
|
},
|
|
|
|
|
2007-01-18 22:24:27 +00:00
|
|
|
inspect: function(element) {
|
|
|
|
element = $(element);
|
|
|
|
var result = '<' + element.tagName.toLowerCase();
|
|
|
|
$H({'id': 'id', 'className': 'class'}).each(function(pair) {
|
|
|
|
var property = pair.first(), attribute = pair.last();
|
|
|
|
var value = (element[property] || '').toString();
|
|
|
|
if (value) result += ' ' + attribute + '=' + value.inspect(true);
|
|
|
|
});
|
|
|
|
return result + '>';
|
|
|
|
},
|
|
|
|
|
|
|
|
recursivelyCollect: function(element, property) {
|
|
|
|
element = $(element);
|
|
|
|
var elements = [];
|
|
|
|
while (element = element[property])
|
|
|
|
if (element.nodeType == 1)
|
|
|
|
elements.push(Element.extend(element));
|
|
|
|
return elements;
|
|
|
|
},
|
|
|
|
|
|
|
|
ancestors: function(element) {
|
|
|
|
return $(element).recursivelyCollect('parentNode');
|
|
|
|
},
|
|
|
|
|
|
|
|
descendants: function(element) {
|
2007-03-11 10:59:06 +00:00
|
|
|
return $A($(element).getElementsByTagName('*')).each(Element.extend);
|
2007-01-18 22:24:27 +00:00
|
|
|
},
|
|
|
|
|
2007-04-24 06:06:44 +00:00
|
|
|
firstDescendant: function(element) {
|
|
|
|
element = $(element).firstChild;
|
|
|
|
while (element && element.nodeType != 1) element = element.nextSibling;
|
|
|
|
return $(element);
|
|
|
|
},
|
|
|
|
|
2007-01-18 22:24:27 +00:00
|
|
|
immediateDescendants: function(element) {
|
|
|
|
if (!(element = $(element).firstChild)) return [];
|
|
|
|
while (element && element.nodeType != 1) element = element.nextSibling;
|
|
|
|
if (element) return [element].concat($(element).nextSiblings());
|
|
|
|
return [];
|
|
|
|
},
|
|
|
|
|
|
|
|
previousSiblings: function(element) {
|
|
|
|
return $(element).recursivelyCollect('previousSibling');
|
|
|
|
},
|
|
|
|
|
|
|
|
nextSiblings: function(element) {
|
|
|
|
return $(element).recursivelyCollect('nextSibling');
|
|
|
|
},
|
|
|
|
|
|
|
|
siblings: function(element) {
|
|
|
|
element = $(element);
|
|
|
|
return element.previousSiblings().reverse().concat(element.nextSiblings());
|
|
|
|
},
|
|
|
|
|
|
|
|
match: function(element, selector) {
|
|
|
|
if (typeof selector == 'string')
|
|
|
|
selector = new Selector(selector);
|
|
|
|
return selector.match($(element));
|
|
|
|
},
|
|
|
|
|
|
|
|
up: function(element, expression, index) {
|
2007-04-24 06:06:44 +00:00
|
|
|
element = $(element);
|
|
|
|
if (arguments.length == 1) return $(element.parentNode);
|
|
|
|
var ancestors = element.ancestors();
|
2007-03-09 04:12:13 +00:00
|
|
|
return expression ? Selector.findElement(ancestors, expression, index) :
|
|
|
|
ancestors[index || 0];
|
2007-01-18 22:24:27 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
down: function(element, expression, index) {
|
2007-04-24 06:06:44 +00:00
|
|
|
element = $(element);
|
|
|
|
if (arguments.length == 1) return element.firstDescendant();
|
|
|
|
var descendants = element.descendants();
|
2007-03-09 04:12:13 +00:00
|
|
|
return expression ? Selector.findElement(descendants, expression, index) :
|
|
|
|
descendants[index || 0];
|
2007-01-18 22:24:27 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
previous: function(element, expression, index) {
|
2007-04-24 06:06:44 +00:00
|
|
|
element = $(element);
|
|
|
|
if (arguments.length == 1) return $(Selector.handlers.previousElementSibling(element));
|
|
|
|
var previousSiblings = element.previousSiblings();
|
2007-03-09 04:12:13 +00:00
|
|
|
return expression ? Selector.findElement(previousSiblings, expression, index) :
|
|
|
|
previousSiblings[index || 0];
|
2007-01-18 22:24:27 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
next: function(element, expression, index) {
|
2007-04-24 06:06:44 +00:00
|
|
|
element = $(element);
|
|
|
|
if (arguments.length == 1) return $(Selector.handlers.nextElementSibling(element));
|
|
|
|
var nextSiblings = element.nextSiblings();
|
2007-03-09 04:12:13 +00:00
|
|
|
return expression ? Selector.findElement(nextSiblings, expression, index) :
|
|
|
|
nextSiblings[index || 0];
|
2007-01-18 22:24:27 +00:00
|
|
|
},
|
|
|
|
|
2007-07-13 08:36:14 +00:00
|
|
|
select: function() {
|
2007-01-18 22:24:27 +00:00
|
|
|
var args = $A(arguments), element = $(args.shift());
|
|
|
|
return Selector.findChildElements(element, args);
|
|
|
|
},
|
|
|
|
|
2007-07-13 08:36:14 +00:00
|
|
|
adjacent: function() {
|
|
|
|
var args = $A(arguments), element = $(args.shift());
|
|
|
|
return Selector.findChildElements(element.parentNode, args).without(element);
|
|
|
|
},
|
|
|
|
|
2007-07-24 17:41:27 +00:00
|
|
|
identify: function(element) {
|
|
|
|
element = $(element);
|
|
|
|
var id = element.readAttribute('id'), self = arguments.callee;
|
|
|
|
if (id) return id;
|
|
|
|
do { id = 'anonymous_element_' + self.counter++ } while ($(id));
|
|
|
|
element.writeAttribute('id', id);
|
|
|
|
return id;
|
|
|
|
},
|
|
|
|
|
2007-01-18 22:24:27 +00:00
|
|
|
readAttribute: function(element, name) {
|
|
|
|
element = $(element);
|
2007-03-09 04:12:13 +00:00
|
|
|
if (Prototype.Browser.IE) {
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
var t = Element._attributeTranslations.read;
|
2007-01-18 22:24:27 +00:00
|
|
|
if (t.values[name]) return t.values[name](element, name);
|
2007-07-24 17:31:23 +00:00
|
|
|
if (t.names[name]) name = t.names[name];
|
2007-01-18 22:24:27 +00:00
|
|
|
}
|
|
|
|
return element.getAttribute(name);
|
|
|
|
},
|
|
|
|
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
writeAttribute: function(element, name, value) {
|
|
|
|
element = $(element);
|
|
|
|
var attributes = {}, t = Element._attributeTranslations.write;
|
|
|
|
|
|
|
|
if (typeof name == 'object') attributes = name;
|
|
|
|
else attributes[name] = value === undefined ? true : value;
|
|
|
|
|
|
|
|
for (var attr in attributes) {
|
|
|
|
var name = t.names[attr] || attr, value = attributes[attr];
|
|
|
|
if (t.values[attr]) name = t.values[attr](element, value);
|
|
|
|
if (value === false || value === null)
|
|
|
|
element.removeAttribute(name);
|
|
|
|
else if (value === true)
|
|
|
|
element.setAttribute(name, name);
|
|
|
|
else element.setAttribute(name, value);
|
|
|
|
}
|
|
|
|
return element;
|
|
|
|
},
|
|
|
|
|
2007-01-18 22:24:27 +00:00
|
|
|
getHeight: function(element) {
|
|
|
|
return $(element).getDimensions().height;
|
|
|
|
},
|
|
|
|
|
|
|
|
getWidth: function(element) {
|
|
|
|
return $(element).getDimensions().width;
|
|
|
|
},
|
|
|
|
|
|
|
|
classNames: function(element) {
|
|
|
|
return new Element.ClassNames(element);
|
|
|
|
},
|
|
|
|
|
|
|
|
hasClassName: function(element, className) {
|
|
|
|
if (!(element = $(element))) return;
|
|
|
|
var elementClassName = element.className;
|
2007-06-17 22:14:07 +00:00
|
|
|
return (elementClassName.length > 0 && (elementClassName == className ||
|
|
|
|
elementClassName.match(new RegExp("(^|\\s)" + className + "(\\s|$)"))));
|
2007-01-18 22:24:27 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
addClassName: function(element, className) {
|
|
|
|
if (!(element = $(element))) return;
|
|
|
|
Element.classNames(element).add(className);
|
|
|
|
return element;
|
|
|
|
},
|
|
|
|
|
|
|
|
removeClassName: function(element, className) {
|
|
|
|
if (!(element = $(element))) return;
|
|
|
|
Element.classNames(element).remove(className);
|
|
|
|
return element;
|
|
|
|
},
|
|
|
|
|
|
|
|
toggleClassName: function(element, className) {
|
|
|
|
if (!(element = $(element))) return;
|
|
|
|
Element.classNames(element)[element.hasClassName(className) ? 'remove' : 'add'](className);
|
|
|
|
return element;
|
|
|
|
},
|
|
|
|
|
|
|
|
observe: function() {
|
|
|
|
Event.observe.apply(Event, arguments);
|
|
|
|
return $A(arguments).first();
|
|
|
|
},
|
|
|
|
|
|
|
|
stopObserving: function() {
|
|
|
|
Event.stopObserving.apply(Event, arguments);
|
|
|
|
return $A(arguments).first();
|
|
|
|
},
|
|
|
|
|
|
|
|
// removes whitespace-only text node children
|
|
|
|
cleanWhitespace: function(element) {
|
|
|
|
element = $(element);
|
|
|
|
var node = element.firstChild;
|
|
|
|
while (node) {
|
|
|
|
var nextNode = node.nextSibling;
|
|
|
|
if (node.nodeType == 3 && !/\S/.test(node.nodeValue))
|
|
|
|
element.removeChild(node);
|
|
|
|
node = nextNode;
|
|
|
|
}
|
|
|
|
return element;
|
|
|
|
},
|
|
|
|
|
|
|
|
empty: function(element) {
|
2007-02-19 21:32:37 +00:00
|
|
|
return $(element).innerHTML.blank();
|
2007-01-18 22:24:27 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
descendantOf: function(element, ancestor) {
|
|
|
|
element = $(element), ancestor = $(ancestor);
|
|
|
|
while (element = element.parentNode)
|
|
|
|
if (element == ancestor) return true;
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
scrollTo: function(element) {
|
|
|
|
element = $(element);
|
2007-06-06 14:30:01 +00:00
|
|
|
var pos = element.cumulativeOffset();
|
2007-01-18 22:24:27 +00:00
|
|
|
window.scrollTo(pos[0], pos[1]);
|
|
|
|
return element;
|
|
|
|
},
|
|
|
|
|
|
|
|
getStyle: function(element, style) {
|
|
|
|
element = $(element);
|
2007-02-27 11:35:21 +00:00
|
|
|
style = style == 'float' ? 'cssFloat' : style.camelize();
|
2007-01-18 22:24:27 +00:00
|
|
|
var value = element.style[style];
|
|
|
|
if (!value) {
|
2007-02-27 11:35:21 +00:00
|
|
|
var css = document.defaultView.getComputedStyle(element, null);
|
|
|
|
value = css ? css[style] : null;
|
2007-01-18 22:24:27 +00:00
|
|
|
}
|
2007-02-27 11:35:21 +00:00
|
|
|
if (style == 'opacity') return value ? parseFloat(value) : 1.0;
|
2007-01-18 22:24:27 +00:00
|
|
|
return value == 'auto' ? null : value;
|
|
|
|
},
|
|
|
|
|
2007-02-27 11:35:21 +00:00
|
|
|
getOpacity: function(element) {
|
|
|
|
return $(element).getStyle('opacity');
|
|
|
|
},
|
|
|
|
|
2007-03-02 12:36:09 +00:00
|
|
|
setStyle: function(element, styles, camelized) {
|
2007-01-18 22:24:27 +00:00
|
|
|
element = $(element);
|
2007-02-23 01:19:18 +00:00
|
|
|
var elementStyle = element.style;
|
2007-03-02 12:16:42 +00:00
|
|
|
|
|
|
|
for (var property in styles)
|
|
|
|
if (property == 'opacity') element.setOpacity(styles[property])
|
|
|
|
else
|
|
|
|
elementStyle[(property == 'float' || property == 'cssFloat') ?
|
2007-03-02 12:36:09 +00:00
|
|
|
(elementStyle.styleFloat === undefined ? 'cssFloat' : 'styleFloat') :
|
|
|
|
(camelized ? property : property.camelize())] = styles[property];
|
2007-03-02 12:16:42 +00:00
|
|
|
|
2007-01-18 22:24:27 +00:00
|
|
|
return element;
|
|
|
|
},
|
|
|
|
|
2007-02-23 01:19:18 +00:00
|
|
|
setOpacity: function(element, value) {
|
|
|
|
element = $(element);
|
2007-02-27 11:35:21 +00:00
|
|
|
element.style.opacity = (value == 1 || value === '') ? '' :
|
|
|
|
(value < 0.00001) ? 0 : value;
|
2007-02-23 01:19:18 +00:00
|
|
|
return element;
|
|
|
|
},
|
|
|
|
|
2007-01-18 22:24:27 +00:00
|
|
|
getDimensions: function(element) {
|
|
|
|
element = $(element);
|
|
|
|
var display = $(element).getStyle('display');
|
|
|
|
if (display != 'none' && display != null) // Safari bug
|
2007-04-05 12:50:59 +00:00
|
|
|
return {width: element.offsetWidth, height: element.offsetHeight};
|
|
|
|
|
2007-01-18 22:24:27 +00:00
|
|
|
// All *Width and *Height properties give 0 on elements with display none,
|
|
|
|
// so enable the element temporarily
|
2007-04-05 12:50:59 +00:00
|
|
|
var els = element.style;
|
|
|
|
var originalVisibility = els.visibility;
|
|
|
|
var originalPosition = els.position;
|
|
|
|
var originalDisplay = els.display;
|
|
|
|
els.visibility = 'hidden';
|
|
|
|
els.position = 'absolute';
|
|
|
|
els.display = 'block';
|
|
|
|
var originalWidth = element.clientWidth;
|
2007-01-18 22:24:27 +00:00
|
|
|
var originalHeight = element.clientHeight;
|
2007-04-05 12:50:59 +00:00
|
|
|
els.display = originalDisplay;
|
|
|
|
els.position = originalPosition;
|
|
|
|
els.visibility = originalVisibility;
|
|
|
|
return {width: originalWidth, height: originalHeight};
|
2007-01-18 22:24:27 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
makePositioned: function(element) {
|
|
|
|
element = $(element);
|
|
|
|
var pos = Element.getStyle(element, 'position');
|
|
|
|
if (pos == 'static' || !pos) {
|
|
|
|
element._madePositioned = true;
|
|
|
|
element.style.position = 'relative';
|
|
|
|
// Opera returns the offset relative to the positioning context, when an
|
|
|
|
// element is position relative but top and left have not been defined
|
|
|
|
if (window.opera) {
|
|
|
|
element.style.top = 0;
|
|
|
|
element.style.left = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return element;
|
|
|
|
},
|
|
|
|
|
|
|
|
undoPositioned: function(element) {
|
|
|
|
element = $(element);
|
|
|
|
if (element._madePositioned) {
|
|
|
|
element._madePositioned = undefined;
|
|
|
|
element.style.position =
|
|
|
|
element.style.top =
|
|
|
|
element.style.left =
|
|
|
|
element.style.bottom =
|
|
|
|
element.style.right = '';
|
|
|
|
}
|
|
|
|
return element;
|
|
|
|
},
|
|
|
|
|
|
|
|
makeClipping: function(element) {
|
|
|
|
element = $(element);
|
|
|
|
if (element._overflow) return element;
|
|
|
|
element._overflow = element.style.overflow || 'auto';
|
|
|
|
if ((Element.getStyle(element, 'overflow') || 'visible') != 'hidden')
|
|
|
|
element.style.overflow = 'hidden';
|
|
|
|
return element;
|
|
|
|
},
|
|
|
|
|
|
|
|
undoClipping: function(element) {
|
|
|
|
element = $(element);
|
|
|
|
if (!element._overflow) return element;
|
|
|
|
element.style.overflow = element._overflow == 'auto' ? '' : element._overflow;
|
|
|
|
element._overflow = null;
|
|
|
|
return element;
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
cumulativeOffset: function(element) {
|
|
|
|
var valueT = 0, valueL = 0;
|
|
|
|
do {
|
|
|
|
valueT += element.offsetTop || 0;
|
|
|
|
valueL += element.offsetLeft || 0;
|
|
|
|
element = element.offsetParent;
|
|
|
|
} while (element);
|
|
|
|
return Element._returnOffset(valueL, valueT);
|
|
|
|
},
|
|
|
|
|
|
|
|
positionedOffset: function(element) {
|
|
|
|
var valueT = 0, valueL = 0;
|
|
|
|
do {
|
|
|
|
valueT += element.offsetTop || 0;
|
|
|
|
valueL += element.offsetLeft || 0;
|
|
|
|
element = element.offsetParent;
|
|
|
|
if (element) {
|
|
|
|
if (element.tagName == 'BODY') break;
|
|
|
|
var p = Element.getStyle(element, 'position');
|
|
|
|
if (p == 'relative' || p == 'absolute') break;
|
|
|
|
}
|
|
|
|
} while (element);
|
|
|
|
return Element._returnOffset(valueL, valueT);
|
|
|
|
},
|
|
|
|
|
|
|
|
absolutize: function(element) {
|
|
|
|
element = $(element);
|
2007-06-06 14:30:01 +00:00
|
|
|
if (element.getStyle('position') == 'absolute') return;
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
// Position.prepare(); // To be done manually by Scripty when it needs it.
|
|
|
|
|
|
|
|
var offsets = element.positionedOffset();
|
|
|
|
var top = offsets[1];
|
|
|
|
var left = offsets[0];
|
|
|
|
var width = element.clientWidth;
|
|
|
|
var height = element.clientHeight;
|
|
|
|
|
|
|
|
element._originalLeft = left - parseFloat(element.style.left || 0);
|
|
|
|
element._originalTop = top - parseFloat(element.style.top || 0);
|
|
|
|
element._originalWidth = element.style.width;
|
|
|
|
element._originalHeight = element.style.height;
|
|
|
|
|
|
|
|
element.style.position = 'absolute';
|
|
|
|
element.style.top = top + 'px';
|
|
|
|
element.style.left = left + 'px';
|
|
|
|
element.style.width = width + 'px';
|
|
|
|
element.style.height = height + 'px';
|
|
|
|
return element;
|
|
|
|
},
|
|
|
|
|
|
|
|
relativize: function(element) {
|
|
|
|
element = $(element);
|
2007-06-06 14:30:01 +00:00
|
|
|
if (element.getStyle('position') == 'relative') return;
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
// Position.prepare(); // To be done manually by Scripty when it needs it.
|
|
|
|
|
|
|
|
element.style.position = 'relative';
|
|
|
|
var top = parseFloat(element.style.top || 0) - (element._originalTop || 0);
|
|
|
|
var left = parseFloat(element.style.left || 0) - (element._originalLeft || 0);
|
|
|
|
|
|
|
|
element.style.top = top + 'px';
|
|
|
|
element.style.left = left + 'px';
|
|
|
|
element.style.height = element._originalHeight;
|
|
|
|
element.style.width = element._originalWidth;
|
|
|
|
return element;
|
|
|
|
},
|
|
|
|
|
|
|
|
cumulativeScrollOffset: function(element) {
|
|
|
|
var valueT = 0, valueL = 0;
|
|
|
|
do {
|
|
|
|
valueT += element.scrollTop || 0;
|
|
|
|
valueL += element.scrollLeft || 0;
|
|
|
|
element = element.parentNode;
|
|
|
|
} while (element);
|
|
|
|
return Element._returnOffset(valueL, valueT);
|
|
|
|
},
|
|
|
|
|
|
|
|
getOffsetParent: function(element) {
|
|
|
|
if (element.offsetParent) return $(element.offsetParent);
|
|
|
|
if (element == document.body) return $(element);
|
|
|
|
|
|
|
|
while ((element = element.parentNode) && element != document.body)
|
|
|
|
if (Element.getStyle(element, 'position') != 'static')
|
|
|
|
return $(element);
|
|
|
|
|
|
|
|
return $(document.body);
|
|
|
|
},
|
|
|
|
|
|
|
|
viewportOffset: function(forElement) {
|
|
|
|
var valueT = 0, valueL = 0;
|
|
|
|
|
|
|
|
var element = forElement;
|
|
|
|
do {
|
|
|
|
valueT += element.offsetTop || 0;
|
|
|
|
valueL += element.offsetLeft || 0;
|
|
|
|
|
|
|
|
// Safari fix
|
2007-05-18 01:21:41 +00:00
|
|
|
if (element.offsetParent == document.body &&
|
|
|
|
Element.getStyle(element, 'position') == 'absolute') break;
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
|
|
|
|
} while (element = element.offsetParent);
|
|
|
|
|
|
|
|
element = forElement;
|
|
|
|
do {
|
2007-05-18 01:21:41 +00:00
|
|
|
if (!Prototype.Browser.Opera || element.tagName == 'BODY') {
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
valueT -= element.scrollTop || 0;
|
|
|
|
valueL -= element.scrollLeft || 0;
|
|
|
|
}
|
|
|
|
} while (element = element.parentNode);
|
|
|
|
|
|
|
|
return Element._returnOffset(valueL, valueT);
|
|
|
|
},
|
|
|
|
|
|
|
|
clonePosition: function(element, source) {
|
|
|
|
var options = Object.extend({
|
|
|
|
setLeft: true,
|
|
|
|
setTop: true,
|
|
|
|
setWidth: true,
|
|
|
|
setHeight: true,
|
|
|
|
offsetTop: 0,
|
|
|
|
offsetLeft: 0
|
2007-05-18 01:21:41 +00:00
|
|
|
}, arguments[2] || {});
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
|
|
|
|
// find page position of source
|
|
|
|
source = $(source);
|
|
|
|
var p = source.viewportOffset();
|
|
|
|
|
|
|
|
// find coordinate system to use
|
|
|
|
element = $(element);
|
|
|
|
var delta = [0, 0];
|
|
|
|
var parent = null;
|
|
|
|
// delta [0,0] will do fine with position: fixed elements,
|
|
|
|
// position:absolute needs offsetParent deltas
|
2007-05-18 01:21:41 +00:00
|
|
|
if (Element.getStyle(element, 'position') == 'absolute') {
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
parent = element.getOffsetParent();
|
2007-05-18 01:12:35 +00:00
|
|
|
delta = parent.viewportOffset();
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// correct by body offsets (fixes Safari)
|
|
|
|
if (parent == document.body) {
|
|
|
|
delta[0] -= document.body.offsetLeft;
|
|
|
|
delta[1] -= document.body.offsetTop;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set position
|
2007-05-18 01:21:41 +00:00
|
|
|
if (options.setLeft) element.style.left = (p[0] - delta[0] + options.offsetLeft) + 'px';
|
|
|
|
if (options.setTop) element.style.top = (p[1] - delta[1] + options.offsetTop) + 'px';
|
|
|
|
if (options.setWidth) element.style.width = source.offsetWidth + 'px';
|
|
|
|
if (options.setHeight) element.style.height = source.offsetHeight + 'px';
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
return element;
|
|
|
|
}
|
2007-01-18 22:24:27 +00:00
|
|
|
};
|
|
|
|
|
2007-07-24 17:41:27 +00:00
|
|
|
Element.Methods.identify.counter = 1;
|
2007-07-13 08:36:14 +00:00
|
|
|
|
2007-06-17 22:26:46 +00:00
|
|
|
if (!document.getElementsByClassName) document.getElementsByClassName = function(instanceMethods){
|
|
|
|
function isArray(className) {
|
2007-06-19 20:59:14 +00:00
|
|
|
return ;
|
2007-06-17 22:26:46 +00:00
|
|
|
}
|
|
|
|
function iter(name) {
|
2007-06-19 20:59:14 +00:00
|
|
|
return name.blank() ? null : "[contains(concat(' ', @class, ' '), ' " + name + " ')]";
|
2007-06-17 22:26:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
instanceMethods.getElementsByClassName = Prototype.BrowserFeatures.XPath ?
|
|
|
|
function(element, className) {
|
2007-06-19 20:59:14 +00:00
|
|
|
className = className.toString().strip();
|
|
|
|
var cond = /\s/.test(className) ? $w(className).map(iter).join('') : iter(className);
|
2007-06-17 22:26:46 +00:00
|
|
|
return cond ? document._getElementsByXPath('.//*' + cond, element) : [];
|
|
|
|
} : function(element, className) {
|
2007-06-19 20:59:14 +00:00
|
|
|
className = className.toString().strip();
|
|
|
|
var elements = [], classNames = (/\s/.test(className) ? $w(className) : null);
|
|
|
|
if (!classNames && !className) return elements;
|
|
|
|
|
2007-06-17 22:26:46 +00:00
|
|
|
var nodes = $(element).getElementsByTagName('*');
|
2007-06-19 20:59:14 +00:00
|
|
|
className = ' ' + className + ' ';
|
2007-06-17 22:26:46 +00:00
|
|
|
|
|
|
|
for (var i = 0, child, cn; child = nodes[i]; i++) {
|
|
|
|
if (child.className && (cn = ' ' + child.className + ' ') && (cn.include(className) ||
|
|
|
|
(classNames && classNames.all(function(name) {
|
|
|
|
return !name.toString().blank() && cn.include(' ' + name + ' ');
|
|
|
|
}))))
|
|
|
|
elements.push(Element.extend(child));
|
|
|
|
}
|
|
|
|
return elements;
|
|
|
|
};
|
|
|
|
|
|
|
|
return function(className, parentElement) {
|
|
|
|
return $(parentElement || document.body).getElementsByClassName(className);
|
|
|
|
};
|
|
|
|
}(Element.Methods);
|
|
|
|
|
2007-04-24 06:17:59 +00:00
|
|
|
Object.extend(Element.Methods, {
|
2007-07-24 17:41:27 +00:00
|
|
|
getElementsBySelector: Element.Methods.select,
|
2007-04-24 06:17:59 +00:00
|
|
|
childElements: Element.Methods.immediateDescendants
|
|
|
|
});
|
2007-01-18 22:24:27 +00:00
|
|
|
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
Element._attributeTranslations = {
|
|
|
|
write: {
|
|
|
|
names: {
|
|
|
|
className: 'class',
|
|
|
|
htmlFor: 'for'
|
|
|
|
},
|
|
|
|
values: {}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if (!document.createRange || Prototype.Browser.Opera) {
|
2007-06-02 15:08:50 +00:00
|
|
|
Element.Methods.insert = function(element, insertions) {
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
element = $(element);
|
|
|
|
|
2007-06-02 16:00:47 +00:00
|
|
|
if (typeof insertions == 'string' || typeof insertions == 'number' ||
|
|
|
|
(insertions && insertions.ownerDocument === document))
|
|
|
|
insertions = {bottom:insertions};
|
2007-06-02 15:08:50 +00:00
|
|
|
|
|
|
|
var t = Element._insertionTranslations, content, position, pos, tagName;
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
|
2007-06-02 15:08:50 +00:00
|
|
|
for (position in insertions) {
|
|
|
|
content = insertions[position];
|
|
|
|
position = position.toLowerCase();
|
|
|
|
pos = t[position];
|
|
|
|
|
|
|
|
if (content && content.ownerDocument === document) {
|
|
|
|
pos.insert(element, content);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-06-02 16:00:47 +00:00
|
|
|
content = String.interpret(content);
|
2007-06-02 15:08:50 +00:00
|
|
|
tagName = ((position == 'before' || position == 'after')
|
|
|
|
? element.parentNode : element).tagName.toUpperCase();
|
|
|
|
|
|
|
|
if (t.tags[tagName]) {
|
|
|
|
var fragments = Element._getContentFromAnonymousElement(tagName, content.stripScripts());
|
|
|
|
if (position == 'top' || position == 'after') fragments.reverse();
|
|
|
|
fragments.each(pos.insert.curry(element));
|
|
|
|
}
|
|
|
|
else element.insertAdjacentHTML(pos.adjacency, content.stripScripts());
|
|
|
|
|
|
|
|
content.evalScripts.bind(content).defer();
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-27 11:35:21 +00:00
|
|
|
if (Prototype.Browser.Opera) {
|
|
|
|
Element.Methods._getStyle = Element.Methods.getStyle;
|
|
|
|
Element.Methods.getStyle = function(element, style) {
|
|
|
|
switch(style) {
|
|
|
|
case 'left':
|
|
|
|
case 'top':
|
|
|
|
case 'right':
|
|
|
|
case 'bottom':
|
2007-03-09 04:23:28 +00:00
|
|
|
if (Element._getStyle(element, 'position') == 'static') return null;
|
2007-02-27 11:35:21 +00:00
|
|
|
default: return Element._getStyle(element, style);
|
2007-03-09 04:23:28 +00:00
|
|
|
}
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
};
|
|
|
|
Element.Methods._readAttribute = Element.Methods.readAttribute;
|
|
|
|
Element.Methods.readAttribute = function(element, attribute) {
|
|
|
|
if (attribute == 'title') return element.title;
|
|
|
|
return Element._readAttribute(element, attribute);
|
|
|
|
};
|
2007-02-27 11:35:21 +00:00
|
|
|
}
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
|
2007-03-04 22:55:08 +00:00
|
|
|
else if (Prototype.Browser.IE) {
|
2007-02-27 11:35:21 +00:00
|
|
|
Element.Methods.getStyle = function(element, style) {
|
|
|
|
element = $(element);
|
|
|
|
style = (style == 'float' || style == 'cssFloat') ? 'styleFloat' : style.camelize();
|
|
|
|
var value = element.style[style];
|
|
|
|
if (!value && element.currentStyle) value = element.currentStyle[style];
|
|
|
|
|
|
|
|
if (style == 'opacity') {
|
|
|
|
if (value = (element.getStyle('filter') || '').match(/alpha\(opacity=(.*)\)/))
|
|
|
|
if (value[1]) return parseFloat(value[1]) / 100;
|
|
|
|
return 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value == 'auto') {
|
|
|
|
if ((style == 'width' || style == 'height') && (element.getStyle('display') != 'none'))
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
return element['offset' + style.capitalize()] + 'px';
|
2007-02-27 11:35:21 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
};
|
|
|
|
|
2007-02-23 01:19:18 +00:00
|
|
|
Element.Methods.setOpacity = function(element, value) {
|
2007-05-19 00:11:46 +00:00
|
|
|
function stripAlpha(filter){
|
|
|
|
return filter.replace(/alpha\([^\)]*\)/gi,'');
|
|
|
|
}
|
2007-02-23 01:19:18 +00:00
|
|
|
element = $(element);
|
|
|
|
var filter = element.getStyle('filter'), style = element.style;
|
|
|
|
if (value == 1 || value === '') {
|
2007-05-19 00:11:46 +00:00
|
|
|
(filter = stripAlpha(filter)) ?
|
|
|
|
style.filter = filter : style.removeAttribute('filter');
|
2007-02-23 01:19:18 +00:00
|
|
|
return element;
|
|
|
|
} else if (value < 0.00001) value = 0;
|
2007-05-19 00:11:46 +00:00
|
|
|
style.filter = stripAlpha(filter) +
|
2007-02-23 01:19:18 +00:00
|
|
|
'alpha(opacity=' + (value * 100) + ')';
|
|
|
|
return element;
|
|
|
|
};
|
2007-01-27 19:45:34 +00:00
|
|
|
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
Element._attributeTranslations = {
|
|
|
|
read: {
|
|
|
|
names: {
|
2007-07-24 17:31:23 +00:00
|
|
|
'class': 'className',
|
|
|
|
'for': 'htmlFor'
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
},
|
|
|
|
values: {
|
|
|
|
_getAttr: function(element, attribute) {
|
|
|
|
return element.getAttribute(attribute, 2);
|
|
|
|
},
|
2007-07-24 17:31:23 +00:00
|
|
|
_getEv: function(element, attribute) {
|
|
|
|
var attribute = element.getAttribute(attribute);
|
|
|
|
return attribute ? attribute.toString().slice(23, -2) : null;
|
|
|
|
},
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
_flag: function(element, attribute) {
|
|
|
|
return $(element).hasAttribute(attribute) ? attribute : null;
|
|
|
|
},
|
|
|
|
style: function(element) {
|
|
|
|
return element.style.cssText.toLowerCase();
|
|
|
|
},
|
|
|
|
title: function(element) {
|
2007-07-24 17:31:23 +00:00
|
|
|
return element.title;
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
}
|
2007-01-18 22:24:27 +00:00
|
|
|
}
|
|
|
|
}
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Element._attributeTranslations.write = {
|
|
|
|
names: Object.extend({
|
2007-07-24 17:31:23 +00:00
|
|
|
colspan: 'colSpan',
|
|
|
|
rowspan: 'rowSpan',
|
|
|
|
valign: 'vAlign',
|
|
|
|
datetime: 'dateTime',
|
|
|
|
accesskey: 'accessKey',
|
|
|
|
tabindex: 'tabIndex',
|
|
|
|
enctype: 'encType',
|
|
|
|
maxlength: 'maxLength',
|
|
|
|
readonly: 'readOnly',
|
|
|
|
longdesc: 'longDesc'
|
|
|
|
}, Element._attributeTranslations.read.names),
|
|
|
|
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
values: {
|
|
|
|
checked: function(element, value) {
|
|
|
|
element.checked = !!value;
|
|
|
|
},
|
|
|
|
|
|
|
|
style: function(element, value) {
|
|
|
|
element.style.cssText = value ? value : '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-07-24 17:31:23 +00:00
|
|
|
(function(v) {
|
|
|
|
Object.extend(v, {
|
|
|
|
href: v._getAttr,
|
|
|
|
src: v._getAttr,
|
|
|
|
type: v._getAttr,
|
|
|
|
disabled: v._flag,
|
|
|
|
checked: v._flag,
|
|
|
|
readonly: v._flag,
|
|
|
|
multiple: v._flag,
|
|
|
|
onload: v._getEv,
|
|
|
|
onunload: v._getEv,
|
|
|
|
onclick: v._getEv,
|
|
|
|
ondblclick: v._getEv,
|
|
|
|
onmousedown: v._getEv,
|
|
|
|
onmouseup: v._getEv,
|
|
|
|
onmouseover: v._getEv,
|
|
|
|
onmousemove: v._getEv,
|
|
|
|
onmouseout: v._getEv,
|
|
|
|
onfocus: v._getEv,
|
|
|
|
onblur: v._getEv,
|
|
|
|
onkeypress: v._getEv,
|
|
|
|
onkeydown: v._getEv,
|
|
|
|
onkeyup: v._getEv,
|
|
|
|
onsubmit: v._getEv,
|
|
|
|
onreset: v._getEv,
|
|
|
|
onselect: v._getEv,
|
|
|
|
onchange: v._getEv
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
});
|
2007-07-24 17:31:23 +00:00
|
|
|
})(Element._attributeTranslations.read.values);
|
2007-03-04 22:55:08 +00:00
|
|
|
}
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
|
2007-03-04 22:55:08 +00:00
|
|
|
else if (Prototype.Browser.Gecko) {
|
|
|
|
Element.Methods.setOpacity = function(element, value) {
|
|
|
|
element = $(element);
|
|
|
|
element.style.opacity = (value == 1) ? 0.999999 :
|
|
|
|
(value === '') ? '' : (value < 0.00001) ? 0 : value;
|
|
|
|
return element;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
else if (Prototype.Browser.WebKit) {
|
2007-06-17 18:13:37 +00:00
|
|
|
Element.Methods.setOpacity = function(element, value) {
|
|
|
|
element = $(element);
|
|
|
|
element.style.opacity = (value == 1 || value === '') ? '' :
|
|
|
|
(value < 0.00001) ? 0 : value;
|
|
|
|
|
|
|
|
if (value == 1)
|
|
|
|
if(element.tagName == 'IMG' && element.width) {
|
|
|
|
element.width++; element.width--;
|
|
|
|
} else try {
|
|
|
|
var n = document.createTextNode(' ');
|
|
|
|
element.appendChild(n);
|
|
|
|
element.removeChild(n);
|
|
|
|
} catch (e) {}
|
|
|
|
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
// Safari returns margins on body which is incorrect if the child is absolutely
|
|
|
|
// positioned. For performance reasons, redefine Position.cumulativeOffset for
|
|
|
|
// KHTML/WebKit only.
|
|
|
|
Element.Methods.cumulativeOffset = function(element) {
|
|
|
|
var valueT = 0, valueL = 0;
|
|
|
|
do {
|
|
|
|
valueT += element.offsetTop || 0;
|
|
|
|
valueL += element.offsetLeft || 0;
|
|
|
|
if (element.offsetParent == document.body)
|
|
|
|
if (Element.getStyle(element, 'position') == 'absolute') break;
|
|
|
|
|
|
|
|
element = element.offsetParent;
|
|
|
|
} while (element);
|
|
|
|
|
|
|
|
return [valueL, valueT];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Prototype.Browser.IE || Prototype.Browser.Opera) {
|
|
|
|
// IE and Opera are missing .innerHTML support for TABLE-related and SELECT elements
|
|
|
|
Element.Methods.update = function(element, html) {
|
|
|
|
element = $(element);
|
|
|
|
html = typeof html == 'undefined' ? '' : html.toString();
|
|
|
|
var tagName = element.tagName.toUpperCase();
|
|
|
|
|
|
|
|
if (Element._insertionTranslations.tags[tagName]) {
|
|
|
|
$A(element.childNodes).each(function(node) { element.removeChild(node) });
|
|
|
|
Element._getContentFromAnonymousElement(tagName, html.stripScripts())
|
|
|
|
.each(function(node) { element.appendChild(node) });
|
|
|
|
}
|
|
|
|
else element.innerHTML = html.stripScripts();
|
|
|
|
|
|
|
|
html.evalScripts.bind(html).defer();
|
|
|
|
return element;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
Element._returnOffset = function(l, t) {
|
|
|
|
var result = [l, t];
|
|
|
|
result.left = l;
|
|
|
|
result.top = t;
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
|
|
|
Element._getContentFromAnonymousElement = function(tagName, html) {
|
|
|
|
var div = new Element('div'); t = Element._insertionTranslations.tags[tagName]
|
|
|
|
div.innerHTML = t[0] + html + t[1];
|
|
|
|
t[2].times(function() { div = div.firstChild });
|
|
|
|
return $A(div.childNodes);
|
|
|
|
};
|
|
|
|
|
|
|
|
Element._insertionTranslations = {
|
|
|
|
before: {
|
|
|
|
adjacency: 'beforeBegin',
|
|
|
|
insert: function(element, node) {
|
|
|
|
element.parentNode.insertBefore(node, element);
|
2007-03-04 22:55:08 +00:00
|
|
|
},
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
initializeRange: function(element, range) {
|
|
|
|
range.setStartBefore(element);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
top: {
|
|
|
|
adjacency: 'afterBegin',
|
|
|
|
insert: function(element, node) {
|
|
|
|
element.insertBefore(node, element.firstChild);
|
2007-03-04 22:55:08 +00:00
|
|
|
},
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
initializeRange: function(element, range) {
|
|
|
|
range.selectNodeContents(element);
|
|
|
|
range.collapse(true);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
bottom: {
|
|
|
|
adjacency: 'beforeEnd',
|
|
|
|
insert: function(element, node) {
|
|
|
|
element.appendChild(node);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
after: {
|
|
|
|
adjacency: 'afterEnd',
|
|
|
|
insert: function(element, node) {
|
|
|
|
element.parentNode.insertBefore(node, element.nextSibling);
|
2007-03-04 22:55:08 +00:00
|
|
|
},
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
initializeRange: function(element, range) {
|
|
|
|
range.setStartAfter(element);
|
2007-03-04 22:55:08 +00:00
|
|
|
}
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
},
|
|
|
|
tags: {
|
|
|
|
TABLE: ['<table>', '</table>', 1],
|
|
|
|
TBODY: ['<table><tbody>', '</tbody></table>', 2],
|
|
|
|
TR: ['<table><tbody><tr>', '</tr></tbody></table>', 3],
|
|
|
|
TD: ['<table><tbody><tr><td>', '</td></tr></tbody></table>', 4],
|
|
|
|
SELECT: ['<select>', '</select>', 1]
|
2007-03-04 22:55:08 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-03-08 22:43:18 +00:00
|
|
|
(function() {
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
this.bottom.initializeRange = this.top.initializeRange;
|
|
|
|
Object.extend(this.tags, {
|
|
|
|
THEAD: this.tags.TBODY,
|
|
|
|
TFOOT: this.tags.TBODY,
|
|
|
|
TH: this.tags.TD
|
2007-03-08 22:45:07 +00:00
|
|
|
});
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
}).call(Element._insertionTranslations);
|
2007-03-04 22:55:08 +00:00
|
|
|
|
|
|
|
Element.Methods.Simulated = {
|
|
|
|
hasAttribute: function(element, attribute) {
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
var t = Element._attributeTranslations.read, node;
|
2007-03-04 22:55:08 +00:00
|
|
|
attribute = t.names[attribute] || attribute;
|
|
|
|
node = $(element).getAttributeNode(attribute);
|
|
|
|
return node && node.specified;
|
|
|
|
}
|
2007-01-18 22:24:27 +00:00
|
|
|
};
|
|
|
|
|
2007-03-04 22:55:08 +00:00
|
|
|
Element.Methods.ByTag = {};
|
|
|
|
|
2007-01-18 22:24:27 +00:00
|
|
|
Object.extend(Element, Element.Methods);
|
|
|
|
|
2007-06-09 01:51:26 +00:00
|
|
|
if (!Prototype.BrowserFeatures.ElementExtensions &&
|
|
|
|
document.createElement('div').__proto__) {
|
|
|
|
window.HTMLElement = {};
|
|
|
|
window.HTMLElement.prototype = document.createElement('div').__proto__;
|
|
|
|
Prototype.BrowserFeatures.ElementExtensions = true;
|
|
|
|
}
|
|
|
|
|
2007-05-12 04:32:30 +00:00
|
|
|
Element.extend = (function() {
|
|
|
|
if (Prototype.BrowserFeatures.SpecificElementExtensions)
|
|
|
|
return Prototype.K;
|
|
|
|
|
|
|
|
var Methods = {}, ByTag = Element.Methods.ByTag;
|
|
|
|
|
|
|
|
var extend = Object.extend(function(element) {
|
|
|
|
if (!element || element._extendedByPrototype ||
|
|
|
|
element.nodeType != 1 || element == window) return element;
|
|
|
|
|
|
|
|
var methods = Object.clone(Methods),
|
|
|
|
tagName = element.tagName, property, value;
|
|
|
|
|
|
|
|
// extend methods for specific tags
|
|
|
|
if (ByTag[tagName]) Object.extend(methods, ByTag[tagName]);
|
|
|
|
|
|
|
|
for (property in methods) {
|
|
|
|
value = methods[property];
|
|
|
|
if (typeof value == 'function' && !(property in element))
|
|
|
|
element[property] = value.methodize();
|
|
|
|
}
|
|
|
|
|
|
|
|
element._extendedByPrototype = Prototype.emptyFunction;
|
|
|
|
return element;
|
|
|
|
|
|
|
|
}, {
|
|
|
|
refresh: function() {
|
|
|
|
// extend methods for all tags (Safari doesn't need this)
|
|
|
|
if (!Prototype.BrowserFeatures.ElementExtensions) {
|
|
|
|
Object.extend(Methods, Element.Methods);
|
|
|
|
Object.extend(Methods, Element.Methods.Simulated);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
extend.refresh();
|
|
|
|
return extend;
|
|
|
|
})();
|
|
|
|
|
2007-03-09 04:12:13 +00:00
|
|
|
Element.hasAttribute = function(element, attribute) {
|
|
|
|
if (element.hasAttribute) return element.hasAttribute(attribute);
|
|
|
|
return Element.Methods.Simulated.hasAttribute(element, attribute);
|
|
|
|
};
|
|
|
|
|
2007-01-18 22:24:27 +00:00
|
|
|
Element.addMethods = function(methods) {
|
2007-01-27 19:45:34 +00:00
|
|
|
var F = Prototype.BrowserFeatures, T = Element.Methods.ByTag;
|
2007-04-28 02:32:21 +00:00
|
|
|
|
|
|
|
if (!methods) {
|
|
|
|
Object.extend(Form, Form.Methods);
|
|
|
|
Object.extend(Form.Element, Form.Element.Methods);
|
|
|
|
Object.extend(Element.Methods.ByTag, {
|
|
|
|
"FORM": Object.clone(Form.Methods),
|
|
|
|
"INPUT": Object.clone(Form.Element.Methods),
|
|
|
|
"SELECT": Object.clone(Form.Element.Methods),
|
|
|
|
"TEXTAREA": Object.clone(Form.Element.Methods)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2007-01-27 19:45:34 +00:00
|
|
|
if (arguments.length == 2) {
|
|
|
|
var tagName = methods;
|
|
|
|
methods = arguments[1];
|
|
|
|
}
|
|
|
|
|
2007-03-04 22:55:08 +00:00
|
|
|
if (!tagName) Object.extend(Element.Methods, methods || {});
|
2007-01-27 19:45:34 +00:00
|
|
|
else {
|
2007-03-04 22:55:08 +00:00
|
|
|
if (tagName.constructor == Array) tagName.each(extend);
|
2007-01-27 19:45:34 +00:00
|
|
|
else extend(tagName);
|
|
|
|
}
|
2007-01-18 22:24:27 +00:00
|
|
|
|
2007-01-27 19:45:34 +00:00
|
|
|
function extend(tagName) {
|
|
|
|
tagName = tagName.toUpperCase();
|
|
|
|
if (!Element.Methods.ByTag[tagName])
|
|
|
|
Element.Methods.ByTag[tagName] = {};
|
|
|
|
Object.extend(Element.Methods.ByTag[tagName], methods);
|
|
|
|
}
|
|
|
|
|
2007-01-18 22:24:27 +00:00
|
|
|
function copy(methods, destination, onlyIfAbsent) {
|
|
|
|
onlyIfAbsent = onlyIfAbsent || false;
|
|
|
|
for (var property in methods) {
|
|
|
|
var value = methods[property];
|
2007-05-12 04:32:30 +00:00
|
|
|
if (typeof value != 'function') continue;
|
2007-01-18 22:24:27 +00:00
|
|
|
if (!onlyIfAbsent || !(property in destination))
|
2007-05-12 04:32:30 +00:00
|
|
|
destination[property] = value.methodize();
|
2007-01-18 22:24:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-27 19:45:34 +00:00
|
|
|
function findDOMClass(tagName) {
|
|
|
|
var klass;
|
|
|
|
var trans = {
|
|
|
|
"OPTGROUP": "OptGroup", "TEXTAREA": "TextArea", "P": "Paragraph",
|
|
|
|
"FIELDSET": "FieldSet", "UL": "UList", "OL": "OList", "DL": "DList",
|
|
|
|
"DIR": "Directory", "H1": "Heading", "H2": "Heading", "H3": "Heading",
|
|
|
|
"H4": "Heading", "H5": "Heading", "H6": "Heading", "Q": "Quote",
|
|
|
|
"INS": "Mod", "DEL": "Mod", "A": "Anchor", "IMG": "Image", "CAPTION":
|
|
|
|
"TableCaption", "COL": "TableCol", "COLGROUP": "TableCol", "THEAD":
|
|
|
|
"TableSection", "TFOOT": "TableSection", "TBODY": "TableSection", "TR":
|
|
|
|
"TableRow", "TH": "TableCell", "TD": "TableCell", "FRAMESET":
|
|
|
|
"FrameSet", "IFRAME": "IFrame"
|
|
|
|
};
|
|
|
|
if (trans[tagName]) klass = 'HTML' + trans[tagName] + 'Element';
|
|
|
|
if (window[klass]) return window[klass];
|
|
|
|
klass = 'HTML' + tagName + 'Element';
|
|
|
|
if (window[klass]) return window[klass];
|
|
|
|
klass = 'HTML' + tagName.capitalize() + 'Element';
|
|
|
|
if (window[klass]) return window[klass];
|
|
|
|
|
|
|
|
window[klass] = {};
|
|
|
|
window[klass].prototype = document.createElement(tagName).__proto__;
|
|
|
|
return window[klass];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (F.ElementExtensions) {
|
2007-01-18 22:24:27 +00:00
|
|
|
copy(Element.Methods, HTMLElement.prototype);
|
|
|
|
copy(Element.Methods.Simulated, HTMLElement.prototype, true);
|
|
|
|
}
|
2007-01-27 19:45:34 +00:00
|
|
|
|
|
|
|
if (F.SpecificElementExtensions) {
|
|
|
|
for (var tag in Element.Methods.ByTag) {
|
|
|
|
var klass = findDOMClass(tag);
|
|
|
|
if (typeof klass == "undefined") continue;
|
|
|
|
copy(T[tag], klass.prototype);
|
|
|
|
}
|
|
|
|
}
|
2007-04-24 05:23:41 +00:00
|
|
|
|
|
|
|
Object.extend(Element, Element.Methods);
|
|
|
|
delete Element.ByTag;
|
2007-05-12 04:32:30 +00:00
|
|
|
|
|
|
|
if (Element.extend.refresh) Element.extend.refresh();
|
Merge -r6634:HEAD from ../branches/dom.
* Make Element#update and Element#insert work for SELECT tags in IE and Opera. [Tobie Langel]
* Make Element#insert and Element#update better handle TABLE related elements in IE and Opera. Closes #7776, #8040, #7550, #7776, #7938. [Tobie Langel]
* Make Element#readAttribute('title') work in Opera. [Tobie Langel]
* Make Element#replace work with form elements in Firefox and Safari. Closes #8010, #7989. [dsl239, Tobie Langel]
* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel]
* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel]
* Insertion overhaul: Add Element.insert(content[, position = 'Bottom']). Deprecate Insertion (kept for backwards compatibility). Make Ajax.Updater option.insertion accept both Insertion.Top or the now preferred 'Top'. Closes #7907. [Tobie Langel]
2007-05-12 05:01:56 +00:00
|
|
|
Element.cache = {};
|
2007-01-27 19:45:34 +00:00
|
|
|
};
|
2007-01-18 22:24:27 +00:00
|
|
|
|
|
|
|
/*--------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
Element.ClassNames = Class.create();
|
|
|
|
Element.ClassNames.prototype = {
|
|
|
|
initialize: function(element) {
|
|
|
|
this.element = $(element);
|
|
|
|
},
|
|
|
|
|
|
|
|
_each: function(iterator) {
|
|
|
|
this.element.className.split(/\s+/).select(function(name) {
|
|
|
|
return name.length > 0;
|
|
|
|
})._each(iterator);
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function(className) {
|
|
|
|
this.element.className = className;
|
|
|
|
},
|
|
|
|
|
|
|
|
add: function(classNameToAdd) {
|
|
|
|
if (this.include(classNameToAdd)) return;
|
|
|
|
this.set($A(this).concat(classNameToAdd).join(' '));
|
|
|
|
},
|
|
|
|
|
|
|
|
remove: function(classNameToRemove) {
|
|
|
|
if (!this.include(classNameToRemove)) return;
|
|
|
|
this.set($A(this).without(classNameToRemove).join(' '));
|
|
|
|
},
|
|
|
|
|
|
|
|
toString: function() {
|
|
|
|
return $A(this).join(' ');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Object.extend(Element.ClassNames.prototype, Enumerable);
|