Lines Matching defs:Element
412 var div = new Element('div');
1513 function $(element) {
1519 if (Object.isString(element))
1520 element = document.getElementById(element);
1521 return Element.extend(element);
1530 results.push(Element.extend(query.snapshotItem(i)));
1558 var element = this.Element;
1559 this.Element = function(tagName, attributes) {
1562 var cache = Element.cache;
1566 return Element.writeAttribute(document.createElement(tagName), attributes);
1568 if (!cache[tagName]) cache[tagName] = Element.extend(document.createElement(tagName));
1569 return Element.writeAttribute(cache[tagName].cloneNode(false), attributes);
1571 Object.extend(this.Element, element || { });
1572 if (element) this.Element.prototype = element.prototype;
1575 Element.cache = { };
1577 Element.Methods = {
1578 visible: function(element) {
1579 return $(element).style.display != 'none';
1582 toggle: function(element) {
1583 element = $(element);
1584 Element[Element.visible(element) ? 'hide' : 'show'](element);
1585 return element;
1588 hide: function(element) {
1589 element = $(element);
1590 element.style.display = 'none';
1591 return element;
1594 show: function(element) {
1595 element = $(element);
1596 element.style.display = '';
1597 return element;
1600 remove: function(element) {
1601 element = $(element);
1602 element.parentNode.removeChild(element);
1603 return element;
1606 update: function(element, content) {
1607 element = $(element);
1609 if (Object.isElement(content)) return element.update().insert(content);
1611 element.innerHTML = content.stripScripts();
1613 return element;
1616 replace: function(element, content) {
1617 element = $(element);
1621 var range = element.ownerDocument.createRange();
1622 range.selectNode(element);
1626 element.parentNode.replaceChild(content, element);
1627 return element;
1630 insert: function(element, insertions) {
1631 element = $(element);
1642 insert = Element._insertionTranslations[position];
1646 insert(element, content);
1653 ? element.parentNode : element).tagName.toUpperCase();
1655 childNodes = Element._getContentFromAnonymousElement(tagName, content.stripScripts());
1658 childNodes.each(insert.curry(element));
1663 return element;
1666 wrap: function(element, wrapper, attributes) {
1667 element = $(element);
1670 else if (Object.isString(wrapper)) wrapper = new Element(wrapper, attributes);
1671 else wrapper = new Element('div', wrapper);
1672 if (element.parentNode)
1673 element.parentNode.replaceChild(wrapper, element);
1674 wrapper.appendChild(element);
1678 inspect: function(element) {
1679 element = $(element);
1680 var result = '<' + element.tagName.toLowerCase();
1683 var value = (element[property] || '').toString();
1689 recursivelyCollect: function(element, property) {
1690 element = $(element);
1692 while (element = element[property])
1693 if (element.nodeType == 1)
1694 elements.push(Element.extend(element));
1698 ancestors: function(element) {
1699 return $(element).recursivelyCollect('parentNode');
1702 descendants: function(element) {
1703 return $(element).select("*");
1706 firstDescendant: function(element) {
1707 element = $(element).firstChild;
1708 while (element && element.nodeType != 1) element = element.nextSibling;
1709 return $(element);
1712 immediateDescendants: function(element) {
1713 if (!(element = $(element).firstChild)) return [];
1714 while (element && element.nodeType != 1) element = element.nextSibling;
1715 if (element) return [element].concat($(element).nextSiblings());
1719 previousSiblings: function(element) {
1720 return $(element).recursivelyCollect('previousSibling');
1723 nextSiblings: function(element) {
1724 return $(element).recursivelyCollect('nextSibling');
1727 siblings: function(element) {
1728 element = $(element);
1729 return element.previousSiblings().reverse().concat(element.nextSiblings());
1732 match: function(element, selector) {
1735 return selector.match($(element));
1738 up: function(element, expression, index) {
1739 element = $(element);
1740 if (arguments.length == 1) return $(element.parentNode);
1741 var ancestors = element.ancestors();
1746 down: function(element, expression, index) {
1747 element = $(element);
1748 if (arguments.length == 1) return element.firstDescendant();
1749 return Object.isNumber(expression) ? element.descendants()[expression] :
1750 Element.select(element, expression)[index || 0];
1753 previous: function(element, expression, index) {
1754 element = $(element);
1755 if (arguments.length == 1) return $(Selector.handlers.previousElementSibling(element));
1756 var previousSiblings = element.previousSiblings();
1761 next: function(element, expression, index) {
1762 element = $(element);
1763 if (arguments.length == 1) return $(Selector.handlers.nextElementSibling(element));
1764 var nextSiblings = element.nextSiblings();
1770 var args = $A(arguments), element = $(args.shift());
1771 return Selector.findChildElements(element, args);
1775 var args = $A(arguments), element = $(args.shift());
1776 return Selector.findChildElements(elementelement);
1779 identify: function(element) {
1780 element = $(element);
1781 var id = element.readAttribute('id'), self = arguments.callee;
1784 element.writeAttribute('id', id);
1788 readAttribute: function(element, name) {
1789 element = $(element);
1791 var t = Element._attributeTranslations.read;
1792 if (t.values[name]) return t.values[name](element, name);
1795 return (!element.attributes || !element.attributes[name]) ? null :
1796 element.attributes[name].value;
1799 return element.getAttribute(name);
1802 writeAttribute: function(element, name, value) {
1803 element = $(element);
1804 var attributes = { }, t = Element._attributeTranslations.write;
1812 if (t.values[attr]) name = t.values[attr](element, value);
1814 element.removeAttribute(name);
1816 element.setAttribute(name, name);
1817 else element.setAttribute(name, value);
1819 return element;
1822 getHeight: function(element) {
1823 return $(element).getDimensions().height;
1826 getWidth: function(element) {
1827 return $(element).getDimensions().width;
1830 classNames: function(element) {
1831 return new Element.ClassNames(element);
1834 hasClassName: function(element, className) {
1835 if (!(element = $(element))) return;
1836 var elementClassName = element.className;
1841 addClassName: function(element, className) {
1842 if (!(element = $(element))) return;
1843 if (!element.hasClassName(className))
1844 element.className += (element.className ? ' ' : '') + className;
1845 return element;
1848 removeClassName: function(element, className) {
1849 if (!(element = $(element))) return;
1850 element.className = element.className.replace(
1852 return element;
1855 toggleClassName: function(element, className) {
1856 if (!(element = $(element))) return;
1857 return element[element.hasClassName(className) ?
1862 cleanWhitespace: function(element) {
1863 element = $(element);
1864 var node = element.firstChild;
1868 element.removeChild(node);
1871 return element;
1874 empty: function(element) {
1875 return $(element).innerHTML.blank();
1878 descendantOf: function(element, ancestor) {
1879 element = $(element), ancestor = $(ancestor);
1881 if (element.compareDocumentPosition)
1882 return (element.compareDocumentPosition(ancestor) & 8) === 8;
1885 return ancestor.contains(element) && ancestor !== element;
1887 while (element = element.parentNode)
1888 if (element == ancestor) return true;
1893 scrollTo: function(element) {
1894 element = $(element);
1895 var pos = element.cumulativeOffset();
1897 return element;
1900 getStyle: function(element, style) {
1901 element = $(element);
1903 var value = element.style[style];
1905 var css = document.defaultView.getComputedStyle(element, null);
1912 getOpacity: function(element) {
1913 return $(element).getStyle('opacity');
1916 setStyle: function(element, styles) {
1917 element = $(element);
1918 var elementStyle = element.style, match;
1920 element.style.cssText += ';' + styles;
1922 element.setOpacity(styles.match(/opacity:\s*(\d?\.?\d*)/)[1]) : element;
1925 if (property == 'opacity') element.setOpacity(styles[property]);
1931 return element;
1934 setOpacity: function(element, value) {
1935 element = $(element);
1936 element.style.opacity = (value == 1 || value === '') ? '' :
1938 return element;
1941 getDimensions: function(element) {
1942 element = $(element);
1943 var display = element.getStyle('display');
1945 return {width: element.offsetWidth, height: element.offsetHeight};
1948 // so enable the element temporarily
1949 var els = element.style;
1956 var originalWidth = element.clientWidth;
1957 var originalHeight = element.clientHeight;
1964 makePositioned: function(element) {
1965 element = $(element);
1966 var pos = Element.getStyle(element, 'position');
1968 element._madePositioned = true;
1969 element.style.position = 'relative';
1971 // element is position relative but top and left have not been defined
1973 element.style.top = 0;
1974 element.style.left = 0;
1977 return element;
1980 undoPositioned: function(element) {
1981 element = $(element);
1982 if (element._madePositioned) {
1983 element._madePositioned = undefined;
1984 element.style.position =
1985 element.style.top =
1986 element.style.left =
1987 element.style.bottom =
1988 element.style.right = '';
1990 return element;
1993 makeClipping: function(element) {
1994 element = $(element);
1995 if (element._overflow) return element;
1996 element._overflow = Element.getStyle(element, 'overflow') || 'auto';
1997 if (element._overflow !== 'hidden')
1998 element.style.overflow = 'hidden';
1999 return element;
2002 undoClipping: function(element) {
2003 element = $(element);
2004 if (!element._overflow) return element;
2005 element.style.overflow = element._overflow == 'auto' ? '' : element._overflow;
2006 element._overflow = null;
2007 return element;
2010 cumulativeOffset: function(element) {
2013 valueT += element.offsetTop || 0;
2014 valueL += element.offsetLeft || 0;
2015 element = element.offsetParent;
2016 } while (element);
2017 return Element._returnOffset(valueL, valueT);
2020 positionedOffset: function(element) {
2023 valueT += element.offsetTop || 0;
2024 valueL += element.offsetLeft || 0;
2025 element = element.offsetParent;
2026 if (element) {
2027 if (element.tagName.toUpperCase() == 'BODY') break;
2028 var p = Element.getStyle(element, 'position');
2031 } while (element);
2032 return Element._returnOffset(valueL, valueT);
2035 absolutize: function(element) {
2036 element = $(element);
2037 if (element.getStyle('position') == 'absolute') return element;
2040 var offsets = element.positionedOffset();
2043 var width = element.clientWidth;
2044 var height = element.clientHeight;
2046 element._originalLeft = left - parseFloat(element.style.left || 0);
2047 element._originalTop = top - parseFloat(element.style.top || 0);
2048 element._originalWidth = element.style.width;
2049 element._originalHeight = element.style.height;
2051 element.style.position = 'absolute';
2052 element.style.top = top + 'px';
2053 element.style.left = left + 'px';
2054 element.style.width = width + 'px';
2055 element.style.height = height + 'px';
2056 return element;
2059 relativize: function(element) {
2060 element = $(element);
2061 if (element.getStyle('position') == 'relative') return element;
2064 element.style.position = 'relative';
2065 var top = parseFloat(element.style.top || 0) - (element._originalTop || 0);
2066 var left = parseFloat(element.style.left || 0) - (element._originalLeft || 0);
2068 element.style.top = top + 'px';
2069 element.style.left = left + 'px';
2070 element.style.height = element._originalHeight;
2071 element.style.width = element._originalWidth;
2072 return element;
2075 cumulativeScrollOffset: function(element) {
2078 valueT += element.scrollTop || 0;
2079 valueL += element.scrollLeft || 0;
2080 element = element.parentNode;
2081 } while (element);
2082 return Element._returnOffset(valueL, valueT);
2085 getOffsetParent: function(element) {
2086 if (element.offsetParent) return $(element.offsetParent);
2087 if (element == document.body) return $(element);
2089 while ((element = element.parentNode) && element != document.body)
2090 if (Element.getStyle(element, 'position') != 'static')
2091 return $(element);
2099 var element = forElement;
2101 valueT += element.offsetTop || 0;
2102 valueL += element.offsetLeft || 0;
2105 if (element.offsetParent == document.body &&
2106 Element.getStyle(element, 'position') == 'absolute') break;
2108 } while (element = element.offsetParent);
2110 element = forElement;
2112 if (!Prototype.Browser.Opera || (element.tagName && (element.tagName.toUpperCase() == 'BODY'))) {
2113 valueT -= element.scrollTop || 0;
2114 valueL -= element.scrollLeft || 0;
2116 } while (element = element.parentNode);
2118 return Element._returnOffset(valueL, valueT);
2121 clonePosition: function(element, source) {
2136 element = $(element);
2141 if (Element.getStyle(element, 'position') == 'absolute') {
2142 parent = element.getOffsetParent();
2153 if (options.setLeft) element.style.left = (p[0] - delta[0] + options.offsetLeft) + 'px';
2154 if (options.setTop) element.style.top = (p[1] - delta[1] + options.offsetTop) + 'px';
2155 if (options.setWidth) element.style.width = source.offsetWidth + 'px';
2156 if (options.setHeight) element.style.height = source.offsetHeight + 'px';
2157 return element;
2161 Element.Methods.identify.counter = 1;
2163 Object.extend(Element.Methods, {
2164 getElementsBySelector: Element.Methods.select,
2165 childElements: Element.Methods.immediateDescendants
2168 Element._attributeTranslations = {
2179 Element.Methods.getStyle = Element.Methods.getStyle.wrap(
2180 function(proceed, element, style) {
2183 if (proceed(element, 'position') === 'static') return null;
2186 if (!Element.visible(element)) return null;
2190 var dim = parseInt(proceed(element, style), 10);
2192 if (dim !== element['offset' + style.capitalize()])
2205 var val = proceed(element, property);
2208 default: return proceed(element, style);
2213 Element.Methods.readAttribute = Element.Methods.readAttribute.wrap(
2214 function(proceed, element, attribute) {
2215 if (attribute === 'title') return element.title;
2216 return proceed(element, attribute);
2224 Element.Methods.getOffsetParent = Element.Methods.getOffsetParent.wrap(
2225 function(proceed, element) {
2226 element = $(element);
2227 // IE throws an error if element is not in document
2228 try { element.offsetParent }
2230 var position = element.getStyle('position');
2231 if (position !== 'static') return proceed(element);
2232 element.setStyle({ position: 'relative' });
2233 var value = proceed(element);
2234 element.setStyle({ position: position });
2240 Element.Methods[method] = Element.Methods[method].wrap(
2241 function(proceed, element) {
2242 element = $(element);
2243 try { element.offsetParent }
2244 catch(e) { return Element._returnOffset(0,0) }
2245 var position = element.getStyle('position');
2246 if (position !== 'static') return proceed(element);
2249 var offsetParent = element.getOffsetParent();
2252 element.setStyle({ position: 'relative' });
2253 var value = proceed(element);
2254 element.setStyle({ position: position });
2260 Element.Methods.cumulativeOffset = Element.Methods.cumulativeOffset.wrap(
2261 function(proceed, element) {
2262 try { element.offsetParent }
2263 catch(e) { return Element._returnOffset(0,0) }
2264 return proceed(element);
2268 Element.Methods.getStyle = function(element, style) {
2269 element = $(element);
2271 var value = element.style[style];
2272 if (!value && element.currentStyle) value = element.currentStyle[style];
2275 if (value = (element.getStyle('filter') || '').match(/alpha\(opacity=(.*)\)/))
2281 if ((style == 'width' || style == 'height') && (element.getStyle('display') != 'none'))
2282 return element['offset' + style.capitalize()] + 'px';
2288 Element.Methods.setOpacity = function(element, value) {
2292 element = $(element);
2293 var currentStyle = element.currentStyle;
2295 (!currentStyle && element.style.zoom == 'normal'))
2296 element.style.zoom = 1;
2298 var filter = element.getStyle('filter'), style = element.style;
2302 return element;
2306 return element;
2309 Element._attributeTranslations = {
2316 _getAttr: function(element, attribute) {
2317 return element.getAttribute(attribute, 2);
2319 _getAttrNode: function(element, attribute) {
2320 var node = element.getAttributeNode(attribute);
2323 _getEv: function(element, attribute) {
2324 attribute = element.getAttribute(attribute);
2327 _flag: function(element, attribute) {
2328 return $(element).hasAttribute(attribute) ? attribute : null;
2330 style: function(element) {
2331 return element.style.cssText.toLowerCase();
2333 title: function(element) {
2334 return element.title;
2340 Element._attributeTranslations.write = {
2344 }, Element._attributeTranslations.read.names),
2346 checked: function(element, value) {
2347 element.checked = !!value;
2350 style: function(element, value) {
2351 element.style.cssText = value ? value : '';
2356 Element._attributeTranslations.has = {};
2360 Element._attributeTranslations.write.names[attr.toLowerCase()] = attr;
2361 Element._attributeTranslations.has[attr.toLowerCase()] = attr;
2393 })(Element._attributeTranslations.read.values);
2397 Element.Methods.setOpacity = function(element, value) {
2398 element = $(element);
2399 element.style.opacity = (value == 1) ? 0.999999 :
2401 return element;
2406 Element.Methods.setOpacity = function(element, value) {
2407 element = $(element);
2408 element.style.opacity = (value == 1 || value === '') ? '' :
2412 if(element.tagName.toUpperCase() == 'IMG' && element.width) {
2413 element.width++; element.width--;
2416 element.appendChild(n);
2417 element.removeChild(n);
2420 return element;
2424 // positioned. For performance reasons, redefine Element#cumulativeOffset for
2426 Element.Methods.cumulativeOffset = function(element) {
2429 valueT += element.offsetTop || 0;
2430 valueL += element.offsetLeft || 0;
2431 if (element.offsetParent == document.body)
2432 if (Element.getStyle(element, 'position') == 'absolute') break;
2434 element = element.offsetParent;
2435 } while (element);
2437 return Element._returnOffset(valueL, valueT);
2443 Element.Methods.update = function(element, content) {
2444 element = $(element);
2447 if (Object.isElement(content)) return element.update().insert(content);
2450 var tagName = element.tagName.toUpperCase();
2452 if (tagName in Element._insertionTranslations.tags) {
2453 $A(element.childNodes).each(function(node) { element.removeChild(node) });
2454 Element._getContentFromAnonymousElement(tagName, content.stripScripts())
2455 .each(function(node) { element.appendChild(node) });
2457 else element.innerHTML = content.stripScripts();
2460 return element;
2465 Element.Methods.replace = function(element, content) {
2466 element = $(element);
2470 element.parentNode.replaceChild(content, element);
2471 return element;
2475 var parent = element.parentNode, tagName = parent.tagName.toUpperCase();
2477 if (Element._insertionTranslations.tags[tagName]) {
2478 var nextSibling = element.next();
2479 var fragments = Element._getContentFromAnonymousElement(tagName, content.stripScripts());
2480 parent.removeChild(element);
2486 else element.outerHTML = content.stripScripts();
2489 return element;
2493 Element._returnOffset = function(l, t) {
2500 Element._getContentFromAnonymousElement = function(tagName, html) {
2501 var div = new Element('div'), t = Element._insertionTranslations.tags[tagName];
2509 Element._insertionTranslations = {
2510 before: function(element, node) {
2511 element.parentNode.insertBefore(node, element);
2513 top: function(element, node) {
2514 element.insertBefore(node, element.firstChild);
2516 bottom: function(element, node) {
2517 element.appendChild(node);
2519 after: function(element, node) {
2520 element.parentNode.insertBefore(node, element.nextSibling);
2537 }).call(Element._insertionTranslations);
2539 Element.Methods.Simulated = {
2540 hasAttribute: function(element, attribute) {
2541 attribute = Element._attributeTranslations.has[attribute] || attribute;
2542 var node = $(element).getAttributeNode(attribute);
2547 Element.Methods.ByTag = { };
2549 Object.extend(Element, Element.Methods);
2558 Element.extend = (function() {
2562 var Methods = { }, ByTag = Element.Methods.ByTag;
2564 var extend = Object.extend(function(element) {
2565 if (!element || element._extendedByPrototype ||
2566 element.nodeType != 1 || element == window) return element;
2569 tagName = element.tagName.toUpperCase(), property, value;
2576 if (Object.isFunction(value) && !(property in element))
2577 element[property] = value.methodize();
2580 element._extendedByPrototype = Prototype.emptyFunction;
2581 return element;
2587 Object.extend(Methods, Element.Methods);
2588 Object.extend(Methods, Element.Methods.Simulated);
2597 Element.hasAttribute = function(element, attribute) {
2598 if (element.hasAttribute) return element.hasAttribute(attribute);
2599 return Element.Methods.Simulated.hasAttribute(element, attribute);
2602 Element.addMethods = function(methods) {
2603 var F = Prototype.BrowserFeatures, T = Element.Methods.ByTag;
2607 Object.extend(Form.Element, Form.Element.Methods);
2608 Object.extend(Element.Methods.ByTag, {
2610 "INPUT": Object.clone(Form.Element.Methods),
2611 "SELECT": Object.clone(Form.Element.Methods),
2612 "TEXTAREA": Object.clone(Form.Element.Methods)
2621 if (!tagName) Object.extend(Element.Methods, methods || { });
2629 if (!Element.Methods.ByTag[tagName])
2630 Element.Methods.ByTag[tagName] = { };
2631 Object.extend(Element.Methods.ByTag[tagName], methods);
2657 if (trans[tagName]) klass = 'HTML' + trans[tagName] + 'Element';
2659 klass = 'HTML' + tagName + 'Element';
2661 klass = 'HTML' + tagName.capitalize() + 'Element';
2670 copy(Element.Methods, HTMLElement.prototype);
2671 copy(Element.Methods.Simulated, HTMLElement.prototype, true);
2675 for (var tag in Element.Methods.ByTag) {
2682 Object.extend(Element, Element.Methods);
2683 delete Element.ByTag;
2685 if (Element.extend.refresh) Element.extend.refresh();
2686 Element.cache = { };
2716 return Element._returnOffset(
2762 if (!Selector._div) Selector._div = new Element('div');
2765 // isolated element to minimize cost of this check.
2837 // of the context element. That's not what we want.
2844 results = $A(root.querySelectorAll(e)).map(Element.extend);
2855 match: function(element) {
2874 return this.findElements(document).include(element);
2883 if (!Selector.assertions[name](element, matches)) {
3042 // for Selector.match and Element#match
3044 tagName: function(element, matches) {
3045 return matches[1].toUpperCase() == element.tagName.toUpperCase();
3048 className: function(element, matches) {
3049 return Element.hasClassName(element, matches[1]);
3052 id: function(element, matches) {
3053 return element.id === matches[1];
3056 attrPresence: function(element, matches) {
3057 return Element.hasAttribute(element, matches[1]);
3060 attr: function(element, matches) {
3061 var nodeValue = Element.readAttribute(element, matches[1]);
3112 results.push(Element.extend(n));
3145 h.concat(results, Element.nextSiblings(node));
3192 if (Element.descendantOf(targetNode, node)) return [targetNode];
3203 return (targetNode && Element.descendantOf(targetNode, root)) ? [targetNode] : [];
3228 if (Element.hasAttribute(node, attr)) results.push(node);
3237 var nodeValue = Element.readAttribute(node, attr);
3339 // IE treats comments as element nodes
3400 for (var i = 0, results = [], element; element = elements[i]; i++)
3401 if (element._countedByPrototype) results.push(element);
3413 findChildElements: function(element, expressions) {
3418 h.concat(results, selector.findElements(element));
3457 var data = elements.inject({ }, function(result, element) {
3458 if (!element.disabled && element.name) {
3459 key = element.name; value = $(element).getValue();
3460 if (value != null && element.type != 'file' && (element.type != 'submit' || (!submitted &&
3485 if (Form.Element.Serializers[child.tagName.toLowerCase()])
3486 elements.push(Element.extend(child));
3496 if (!typeName && !name) return $A(inputs).map(Element.extend);
3502 matchingInputs.push(Element.extend(input));
3521 var elements = $(form).getElements().findAll(function(element) {
3522 return 'hidden' != element.type && !element.disabled;
3524 var firstByIndex = elements.findAll(function(element) {
3525 return element.hasAttribute('tabIndex') && element.tabIndex >= 0;
3526 }).sortBy(function(element) { return element.tabIndex }).first();
3528 return firstByIndex ? firstByIndex : elements.find(function(element) {
3529 return ['input', 'select', 'textarea'].include(element.tagName.toLowerCase());
3560 Form.Element = {
3561 focus: function(element) {
3562 $(element).focus();
3563 return element;
3566 select: function(element) {
3567 $(element).select();
3568 return element;
3572 Form.Element.Methods = {
3573 serialize: function(element) {
3574 element = $(element);
3575 if (!element.disabled && element.name) {
3576 var value = element.getValue();
3579 pair[element.name] = value;
3586 getValue: function(element) {
3587 element = $(element);
3588 var method = element.tagName.toLowerCase();
3589 return Form.Element.Serializers[method](element);
3592 setValue: function(element, value) {
3593 element = $(element);
3594 var method = element.tagName.toLowerCase();
3595 Form.Element.Serializers[method](element, value);
3596 return element;
3599 clear: function(element) {
3600 $(element).value = '';
3601 return element;
3604 present: function(element) {
3605 return $(element).value != '';
3608 activate: function(element) {
3609 element = $(element);
3611 element.focus();
3612 if (element.select && (element.tagName.toLowerCase() != 'input' ||
3613 !['button', 'reset', 'submit'].include(element.type)))
3614 element.select();
3616 return element;
3619 disable: function(element) {
3620 element = $(element);
3621 element.disabled = true;
3622 return element;
3625 enable: function(element) {
3626 element = $(element);
3627 element.disabled = false;
3628 return element;
3634 var Field = Form.Element;
3635 var $F = Form.Element.Methods.getValue;
3639 Form.Element.Serializers = {
3640 input: function(element, value) {
3641 switch (element.type.toLowerCase()) {
3644 return Form.Element.Serializers.inputSelector(element, value);
3646 return Form.Element.Serializers.textarea(element, value);
3650 inputSelector: function(element, value) {
3651 if (Object.isUndefined(value)) return element.checked ? element.value : null;
3652 else element.checked = !!value;
3655 textarea: function(element, value) {
3656 if (Object.isUndefined(value)) return element.value;
3657 else element.value = value;
3660 select: function(element, value) {
3662 return this[element.type == 'select-one' ?
3663 'selectOne' : 'selectMany'](element);
3666 for (var i = 0, length = element.length; i < length; i++) {
3667 opt = element.options[i];
3680 selectOne: function(element) {
3681 var index = element.selectedIndex;
3682 return index >= 0 ? this.optionValue(element.options[index]) : null;
3685 selectMany: function(element) {
3686 var values, length = element.length;
3690 var opt = element.options[i];
3697 // extend element because hasAttribute may not be native
3698 return Element.extend(opt).hasAttribute('value') ? opt.value : opt.text;
3705 initialize: function($super, element, frequency, callback) {
3707 this.element = $(element);
3715 this.callback(this.element, value);
3721 Form.Element.Observer = Class.create(Abstract.TimedObserver, {
3723 return Form.Element.getValue(this.element);
3729 return Form.serialize(this.element);
3736 initialize: function(element, callback) {
3737 this.element = $(element);
3741 if (this.element.tagName.toLowerCase() == 'form')
3744 this.registerCallback(this.element);
3750 this.callback(this.element, value);
3756 Form.getElements(this.element).each(this.registerCallback, this);
3759 registerCallback: function(element) {
3760 if (element.type) {
3761 switch (element.type.toLowerCase()) {
3764 Event.observe(element, 'click', this.onElementEvent.bind(this));
3767 Event.observe(element, 'change', this.onElementEvent.bind(this));
3774 Form.Element.EventObserver = Class.create(Abstract.EventObserver, {
3776 return Form.Element.getValue(this.element);
3782 return Form.serialize(this.element);
3806 var element;
3808 case 'mouseover': element = event.fromElement; break;
3809 case 'mouseout': element = event.toElement; break;
3812 return Element.extend(element);
3845 element: function(event) {
3862 return Element.extend(node);
3866 var element = Event.element(event);
3867 if (!expression) return element;
3868 var elements = [element].concat(element.ancestors());
3935 function getEventID(element) {
3936 if (element._prototypeEventID) return element._prototypeEventID[0];
3938 return element._prototypeEventID = [++arguments.callee.id];
3955 function createWrapper(element, eventName, handler) {
3956 var id = getEventID(element);
3966 handler.call(element, event);
4006 observe: function(element, eventName, handler) {
4007 element = $(element);
4010 var wrapper = createWrapper(element, eventName, handler);
4011 if (!wrapper) return element;
4013 if (element.addEventListener) {
4014 element.addEventListener(name, wrapper, false);
4016 element.attachEvent("on" + name, wrapper);
4019 return element;
4022 stopObserving: function(element, eventName, handler) {
4023 element = $(element);
4024 var id = getEventID(element), name = getDOMEventName(eventName);
4028 element.stopObserving(eventName, wrapper.handler);
4030 return element;
4034 element.stopObserving(eventName);
4036 return element;
4040 if (!wrapper) return element;
4042 if (element.removeEventListener) {
4043 element.removeEventListener(name, wrapper, false);
4045 element.detachEvent("on" + name, wrapper);
4050 return element;
4053 fire: function(element, eventName, memo) {
4054 element = $(element);
4055 if (element == document && document.createEvent && !element.dispatchEvent)
4056 element = document.documentElement;
4071 element.dispatchEvent(event);
4073 element.fireEvent(event.eventType, event);
4083 Element.addMethods({
4090 fire: Element.Methods.fire.methodize(),
4091 observe: Element.Methods.observe.methodize(),
4092 stopObserving: Element.Methods.stopObserving.methodize(),
4137 var Toggle = { display: Element.toggle };
4139 Element.Methods.childOf = Element.Methods.descendantOf;
4142 Before: function(element, content) {
4143 return Element.insert(element, {before:content});
4146 Top: function(element, content) {
4147 return Element.insert(element, {top:content});
4150 Bottom: function(element, content) {
4151 return Element.insert(element, {bottom:content});
4154 After: function(element, content) {
4155 return Element.insert(element, {after:content});
4162 // further below, that map to the newer Element methods.
4183 within: function(element, x, y) {
4185 return this.withinIncludingScrolloffsets(element, x, y);
4188 this.offset = Element.cumulativeOffset(element);
4191 y < this.offset[1] + element.offsetHeight &&
4193 x < this.offset[0] + element.offsetWidth);
4196 withinIncludingScrolloffsets: function(element, x, y) {
4197 var offsetcache = Element.cumulativeScrollOffset(element);
4201 this.offset = Element.cumulativeOffset(element);
4204 this.ycomp < this.offset[1] + element.offsetHeight &&
4206 this.xcomp < this.offset[0] + element.offsetWidth);
4210 overlap: function(mode, element) {
4213 return ((this.offset[1] + element.offsetHeight) - this.ycomp) /
4214 element.offsetHeight;
4216 return ((this.offset[0] + element.offsetWidth) - this.xcomp) /
4217 element.offsetWidth;
4220 // Deprecation layer -- use newer Element methods now (1.5.2).
4222 cumulativeOffset: Element.Methods.cumulativeOffset,
4224 positionedOffset: Element.Methods.positionedOffset,
4226 absolutize: function(element) {
4228 return Element.absolutize(element);
4231 relativize: function(element) {
4233 return Element.relativize(element);
4236 realOffset: Element.Methods.cumulativeScrollOffset,
4238 offsetParent: Element.Methods.getOffsetParent,
4240 page: Element.Methods.viewportOffset,
4244 return Element.clonePosition(target, source, options);
4256 function(element, className) {
4259 return cond ? document._getElementsByXPath('.//*' + cond, element) : [];
4260 } : function(element, className) {
4265 var nodes = $(element).getElementsByTagName('*');
4273 elements.push(Element.extend(child));
4281 }(Element.Methods);
4285 Element.ClassNames = Class.create();
4286 Element.ClassNames.prototype = {
4287 initialize: function(element) {
4288 this.element = $(element);
4292 this.element.className.split(/\s+/).select(function(name) {
4298 this.element.className = className;
4316 Object.extend(Element.ClassNames.prototype, Enumerable);
4320 Element.addMethods();