|
1755 | 1755 | // Element#descendants (and therefore extend all nodes).
|
1756 | 1756 | function down_IE(element, expression, index) {
|
1757 | 1757 | element = $(element);
|
1758 |
| - if (arguments.length == 1) return element.firstDescendant(); |
1759 |
| - return Object.isNumber(expression) ? _descendants(element)[expression] : |
| 1758 | + if (arguments.length === 1) |
| 1759 | + return Element.firstDescendant(element); |
| 1760 | + |
| 1761 | + var node = Object.isNumber(expression) ? _descendants(element)[expression] : |
1760 | 1762 | Element.select(element, expression)[index || 0];
|
| 1763 | + return Element.extend(node); |
1761 | 1764 | }
|
1762 | 1765 |
|
1763 | 1766 | if (!Prototype.BrowserFeatures.ElementExtensions)
|
|
2115 | 2118 | * $('homo-erectus').descendantOf('homo-sapiens');
|
2116 | 2119 | * // -> false
|
2117 | 2120 | **/
|
2118 |
| - function descendantOf_DOM(element) { |
| 2121 | + function descendantOf_DOM(element, ancestor) { |
2119 | 2122 | element = $(element);
|
2120 | 2123 | while (element = element.parentNode)
|
2121 | 2124 | if (element === ancestor) return true;
|
|
2124 | 2127 |
|
2125 | 2128 | function descendantOf_contains(element, ancestor) {
|
2126 | 2129 | element = $(element), ancestor = $(ancestor);
|
| 2130 | + // Some nodes, like `document`, don't have the "contains" method. |
| 2131 | + if (!ancestor.contains) return descendantOf_DOM(element, ancestor); |
2127 | 2132 | return ancestor.contains(element) && ancestor !== element;
|
2128 | 2133 | }
|
2129 | 2134 |
|
|
2135 | 2140 | var descendantOf;
|
2136 | 2141 | if (DIV.compareDocumentPosition) {
|
2137 | 2142 | descendantOf = descendantOf_compareDocumentPosition;
|
2138 |
| - } else if (DIV.contains && typeof DIV.contains === 'function') { |
| 2143 | + } else if (DIV.contains) { |
2139 | 2144 | descendantOf = descendantOf_contains;
|
2140 | 2145 | } else {
|
2141 | 2146 | descendantOf = descendantOf_DOM;
|
|
2311 | 2316 | return element.getAttribute(attribute);
|
2312 | 2317 | }
|
2313 | 2318 |
|
| 2319 | + var PROBLEMATIC_ATTRIBUTE_READING = (function() { |
| 2320 | + DIV.setAttribute('onclick', Prototype.emptyFunction); |
| 2321 | + var value = DIV.getAttribute('onclick'); |
| 2322 | + var isFunction = (typeof value === 'function'); |
| 2323 | + DIV.removeAttribute('onclick'); |
| 2324 | + return isFunction; |
| 2325 | + })(); |
| 2326 | + |
| 2327 | + if (PROBLEMATIC_ATTRIBUTE_READING) { |
| 2328 | + readAttribute = readAttribute_IE; |
| 2329 | + } else if (Prototype.Browser.Opera) { |
| 2330 | + readAttribute = readAttribute_Opera; |
| 2331 | + } |
| 2332 | + |
2314 | 2333 |
|
2315 | 2334 | /**
|
2316 | 2335 | * Element.writeAttribute(@element, attribute[, value = true]) -> Element
|
|
2659 | 2678 |
|
2660 | 2679 | // STYLES
|
2661 | 2680 | function normalizeStyleName(style) {
|
2662 |
| - if (style === 'float') return 'cssFloat'; |
| 2681 | + if (style === 'float' || style === 'styleFloat') |
| 2682 | + return 'cssFloat'; |
2663 | 2683 | return style.camelize();
|
2664 | 2684 | }
|
2665 | 2685 |
|
2666 | 2686 | function normalizeStyleName_IE(style) {
|
2667 |
| - if (style === 'float') return 'styleFloat'; |
| 2687 | + if (style === 'float' || style === 'cssFloat') |
| 2688 | + return 'styleFloat'; |
2668 | 2689 | return style.camelize();
|
2669 | 2690 | }
|
2670 |
| - |
2671 | 2691 |
|
2672 | 2692 | /**
|
2673 | 2693 | * Element.setStyle(@element, styles) -> Element
|
|
2855 | 2875 | }
|
2856 | 2876 |
|
2857 | 2877 | function stripAlphaFromFilter_IE(filter) {
|
2858 |
| - return filter.replace(/alpha\([^\)]*\)/gi, ''); |
| 2878 | + return (filter || '').replace(/alpha\([^\)]*\)/gi, ''); |
2859 | 2879 | }
|
2860 | 2880 |
|
2861 | 2881 | function hasLayout_IE(element) {
|
|
2894 | 2914 | }
|
2895 | 2915 |
|
2896 | 2916 | function setOpacity_IE(element, value) {
|
2897 |
| - element = hasLayout($(element)); |
| 2917 | + element = hasLayout_IE($(element)); |
2898 | 2918 | var filter = Element.getStyle(element, 'filter'),
|
2899 |
| - style = element.style; |
| 2919 | + style = element.style; |
2900 | 2920 |
|
2901 | 2921 | if (value == 1 || value === '') {
|
2902 | 2922 | // Remove the `alpha` filter from IE's `filter` CSS property. If there
|
2903 | 2923 | // is anything left after removal, put it back where it was; otherwise
|
2904 | 2924 | // remove the property.
|
2905 | 2925 | filter = stripAlphaFromFilter_IE(filter);
|
2906 | 2926 | if (filter) style.filter = filter;
|
2907 |
| - else style.removeAttribute('filter'); |
| 2927 | + else style.removeAttribute('filter'); |
2908 | 2928 | return element;
|
2909 | 2929 | }
|
2910 | 2930 |
|
|
2928 | 2948 |
|
2929 | 2949 | function getOpacity_IE(element) {
|
2930 | 2950 | var filter = Element.getStyle(element, 'filter');
|
| 2951 | + if (filter.length === 0) return 1.0; |
2931 | 2952 | var match = (filter || '').match(/alpha\(opacity=(.*)\)/);
|
2932 | 2953 | if (match[1]) return parseFloat(match[1]) / 100;
|
2933 | 2954 | return 1.0;
|
|
2946 | 2967 | methods.setOpacity = setOpacity_IE;
|
2947 | 2968 | methods.getOpacity = getOpacity_IE;
|
2948 | 2969 | }
|
2949 |
| - |
2950 |
| - |
2951 | 2970 |
|
2952 | 2971 | // STORAGE
|
2953 | 2972 | var UID = 0;
|
2954 | 2973 |
|
2955 |
| - GLOBAL.Element.Storage = {}; |
| 2974 | + GLOBAL.Element.Storage = { UID: 0 }; |
2956 | 2975 |
|
2957 | 2976 | function getUniqueElementID(element) {
|
2958 | 2977 | if (element === window) return 0;
|
2959 | 2978 |
|
2960 | 2979 | // Need to use actual `typeof` operator to prevent errors in some
|
2961 | 2980 | // environments when accessing node expandos.
|
2962 | 2981 | if (typeof element._prototypeUID === 'undefined')
|
2963 |
| - element._prototypeUID = UID++; |
| 2982 | + element._prototypeUID = Element.Storage.UID++; |
2964 | 2983 | return element._prototypeUID;
|
2965 | 2984 | }
|
2966 | 2985 |
|
2967 | 2986 | // In Internet Explorer, DOM nodes have a `uniqueID` property. Saves us
|
2968 | 2987 | // from inventing our own.
|
2969 | 2988 | function getUniqueElementID_IE(element) {
|
2970 |
| - return element === window ? 0 : element.uniqueID; |
| 2989 | + if (element === window) return 0; |
| 2990 | + // The document object's `uniqueID` property changes each time you read it. |
| 2991 | + if (element == document) return 1; |
| 2992 | + return element.uniqueID; |
2971 | 2993 | }
|
2972 | 2994 |
|
2973 | 2995 | var HAS_UNIQUE_ID_PROPERTY = ('uniqueID' in DIV);
|
|
3139 | 3161 |
|
3140 | 3162 | return element;
|
3141 | 3163 | }
|
3142 |
| - |
3143 |
| - if (F.SpecificElementExtensions && HTMLOBJECTELEMENT_PROTOTYPE_BUGGY) |
3144 |
| - extend = extend_IE8; |
| 3164 | + |
| 3165 | + // If the browser lets us extend specific elements, we can replace `extend` |
| 3166 | + // with a thinner version (or, ideally, an empty version). |
| 3167 | + if (F.SpecificElementExtensions) { |
| 3168 | + extend = HTMLOBJECTELEMENT_PROTOTYPE_BUGGY ? extend_IE8 : Prototype.K; |
| 3169 | + } |
3145 | 3170 |
|
3146 | 3171 | function addMethodsToTagName(tagName, methods) {
|
3147 | 3172 | tagName = tagName.toUpperCase();
|
|
0 commit comments