Skip to content

Commit e5c8fce

Browse files
Various fixes.
1 parent 5cd09c7 commit e5c8fce

File tree

1 file changed

+44
-19
lines changed

1 file changed

+44
-19
lines changed

src/dom/dom.js

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,9 +1755,12 @@
17551755
// Element#descendants (and therefore extend all nodes).
17561756
function down_IE(element, expression, index) {
17571757
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] :
17601762
Element.select(element, expression)[index || 0];
1763+
return Element.extend(node);
17611764
}
17621765

17631766
if (!Prototype.BrowserFeatures.ElementExtensions)
@@ -2115,7 +2118,7 @@
21152118
* $('homo-erectus').descendantOf('homo-sapiens');
21162119
* // -> false
21172120
**/
2118-
function descendantOf_DOM(element) {
2121+
function descendantOf_DOM(element, ancestor) {
21192122
element = $(element);
21202123
while (element = element.parentNode)
21212124
if (element === ancestor) return true;
@@ -2124,6 +2127,8 @@
21242127

21252128
function descendantOf_contains(element, ancestor) {
21262129
element = $(element), ancestor = $(ancestor);
2130+
// Some nodes, like `document`, don't have the "contains" method.
2131+
if (!ancestor.contains) return descendantOf_DOM(element, ancestor);
21272132
return ancestor.contains(element) && ancestor !== element;
21282133
}
21292134

@@ -2135,7 +2140,7 @@
21352140
var descendantOf;
21362141
if (DIV.compareDocumentPosition) {
21372142
descendantOf = descendantOf_compareDocumentPosition;
2138-
} else if (DIV.contains && typeof DIV.contains === 'function') {
2143+
} else if (DIV.contains) {
21392144
descendantOf = descendantOf_contains;
21402145
} else {
21412146
descendantOf = descendantOf_DOM;
@@ -2311,6 +2316,20 @@
23112316
return element.getAttribute(attribute);
23122317
}
23132318

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+
23142333

23152334
/**
23162335
* Element.writeAttribute(@element, attribute[, value = true]) -> Element
@@ -2659,15 +2678,16 @@
26592678

26602679
// STYLES
26612680
function normalizeStyleName(style) {
2662-
if (style === 'float') return 'cssFloat';
2681+
if (style === 'float' || style === 'styleFloat')
2682+
return 'cssFloat';
26632683
return style.camelize();
26642684
}
26652685

26662686
function normalizeStyleName_IE(style) {
2667-
if (style === 'float') return 'styleFloat';
2687+
if (style === 'float' || style === 'cssFloat')
2688+
return 'styleFloat';
26682689
return style.camelize();
26692690
}
2670-
26712691

26722692
/**
26732693
* Element.setStyle(@element, styles) -> Element
@@ -2855,7 +2875,7 @@
28552875
}
28562876

28572877
function stripAlphaFromFilter_IE(filter) {
2858-
return filter.replace(/alpha\([^\)]*\)/gi, '');
2878+
return (filter || '').replace(/alpha\([^\)]*\)/gi, '');
28592879
}
28602880

28612881
function hasLayout_IE(element) {
@@ -2894,17 +2914,17 @@
28942914
}
28952915

28962916
function setOpacity_IE(element, value) {
2897-
element = hasLayout($(element));
2917+
element = hasLayout_IE($(element));
28982918
var filter = Element.getStyle(element, 'filter'),
2899-
style = element.style;
2919+
style = element.style;
29002920

29012921
if (value == 1 || value === '') {
29022922
// Remove the `alpha` filter from IE's `filter` CSS property. If there
29032923
// is anything left after removal, put it back where it was; otherwise
29042924
// remove the property.
29052925
filter = stripAlphaFromFilter_IE(filter);
29062926
if (filter) style.filter = filter;
2907-
else style.removeAttribute('filter');
2927+
else style.removeAttribute('filter');
29082928
return element;
29092929
}
29102930

@@ -2928,6 +2948,7 @@
29282948

29292949
function getOpacity_IE(element) {
29302950
var filter = Element.getStyle(element, 'filter');
2951+
if (filter.length === 0) return 1.0;
29312952
var match = (filter || '').match(/alpha\(opacity=(.*)\)/);
29322953
if (match[1]) return parseFloat(match[1]) / 100;
29332954
return 1.0;
@@ -2946,28 +2967,29 @@
29462967
methods.setOpacity = setOpacity_IE;
29472968
methods.getOpacity = getOpacity_IE;
29482969
}
2949-
2950-
29512970

29522971
// STORAGE
29532972
var UID = 0;
29542973

2955-
GLOBAL.Element.Storage = {};
2974+
GLOBAL.Element.Storage = { UID: 0 };
29562975

29572976
function getUniqueElementID(element) {
29582977
if (element === window) return 0;
29592978

29602979
// Need to use actual `typeof` operator to prevent errors in some
29612980
// environments when accessing node expandos.
29622981
if (typeof element._prototypeUID === 'undefined')
2963-
element._prototypeUID = UID++;
2982+
element._prototypeUID = Element.Storage.UID++;
29642983
return element._prototypeUID;
29652984
}
29662985

29672986
// In Internet Explorer, DOM nodes have a `uniqueID` property. Saves us
29682987
// from inventing our own.
29692988
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;
29712993
}
29722994

29732995
var HAS_UNIQUE_ID_PROPERTY = ('uniqueID' in DIV);
@@ -3139,9 +3161,12 @@
31393161

31403162
return element;
31413163
}
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+
}
31453170

31463171
function addMethodsToTagName(tagName, methods) {
31473172
tagName = tagName.toUpperCase();

0 commit comments

Comments
 (0)