Skip to content

Commit b0e5be5

Browse files
Second pass on rewrite. All tests pass in Safari. Lots of failures still in IE.
1 parent 09aff1e commit b0e5be5

File tree

3 files changed

+611
-59
lines changed

3 files changed

+611
-59
lines changed

src/dom/dom.js

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282

8383

8484
// Define the DOM Level 2 node type constants if they're missing.
85-
if (!Node) GLOBAL.Node = {};
85+
if (!GLOBAL.Node) GLOBAL.Node = {};
8686

8787
if (!GLOBAL.Node.ELEMENT_NODE) {
8888
Object.extend(GLOBAL.Node, {
@@ -2112,10 +2112,10 @@
21122112
}
21132113

21142114
var descendantOf;
2115-
if (DIV.contains && typeof DIV.contains === 'function') {
2116-
descendantOf = descendantOf_contains;
2117-
} else if (DIV.compareDocumentPosition) {
2115+
if (DIV.compareDocumentPosition) {
21182116
descendantOf = descendantOf_compareDocumentPosition;
2117+
} else if (DIV.contains && typeof DIV.contains === 'function') {
2118+
descendantOf = descendantOf_contains;
21192119
} else {
21202120
descendantOf = descendantOf_DOM;
21212121
}
@@ -2703,7 +2703,7 @@
27032703

27042704
for (var property in styles) {
27052705
if (property === 'opacity') {
2706-
Element.setOpacity(styles[property]);
2706+
Element.setOpacity(element, styles[property]);
27072707
} else {
27082708
var value = styles[property];
27092709
if (property === 'float' || property === 'cssFloat') {
@@ -2820,7 +2820,7 @@
28202820
}
28212821

28222822
if (style === 'opacity')
2823-
return interpretOpacityValue_IE(element, opacity);
2823+
return getOpacity_IE(element);
28242824

28252825
if (value === 'auto') {
28262826
// If we need a dimension, return null for hidden elements, but return
@@ -2833,9 +2833,14 @@
28332833
return value;
28342834
}
28352835

2836+
function stripAlphaFromFilter_IE(filter) {
2837+
return filter.replace(/alpha\([^\)]*\)/gi, '');
2838+
}
28362839

2837-
function interpretOpacityValue_IE(element, opacity) {
2838-
2840+
function hasLayout_IE(element) {
2841+
if (!element.currentStyle.hasLayout)
2842+
element.style.zoom = 1;
2843+
return element;
28392844
}
28402845

28412846

@@ -2859,14 +2864,38 @@
28592864
* element.setStyle({ opacity: 0.5 });
28602865
* element.setStyle("opacity: 0.5");
28612866
**/
2862-
function setOpacity(element, opacity) {
2867+
function setOpacity(element, value) {
28632868
element = $(element);
28642869
if (value == 1 || value === '') value = '';
2870+
else if (value < 0.00001) value = 0;
2871+
element.style.opacity = value;
2872+
return element;
2873+
}
2874+
2875+
function setOpacity_IE(element, value) {
2876+
element = hasLayout($(element));
2877+
var filter = Element.getStyle(element, 'filter'),
2878+
style = element.style;
2879+
2880+
if (value == 1 || value === '') {
2881+
// Remove the `alpha` filter from IE's `filter` CSS property. If there
2882+
// is anything left after removal, put it back where it was; otherwise
2883+
// remove the property.
2884+
filter = stripAlphaFromFilter_IE(filter);
2885+
if (filter) style.filter = filter;
2886+
else style.removeAttribute('filter');
2887+
return element;
2888+
}
2889+
28652890
if (value < 0.00001) value = 0;
2866-
element.style.opacity = value;
2891+
2892+
style.filter = stripAlphaFromFilter_IE(filter) +
2893+
'alpha(opacity=' + (value * 100) + ')';
2894+
28672895
return element;
28682896
}
28692897

2898+
28702899
/**
28712900
* Element.getOpacity(@element) -> String | null
28722901
*
@@ -2876,13 +2905,28 @@
28762905
return Element.getStyle(element, 'opacity');
28772906
}
28782907

2908+
function getOpacity_IE(element) {
2909+
var filter = Element.getStyle(element, 'filter');
2910+
var match = (filter || '').match(/alpha\(opacity=(.*)\)/);
2911+
if (match[1]) return parseFloat(match[1]) / 100;
2912+
return 1.0;
2913+
}
2914+
2915+
28792916
Object.extend(methods, {
28802917
setStyle: setStyle,
28812918
getStyle: getStyle,
28822919
setOpacity: setOpacity,
28832920
getOpacity: getOpacity
28842921
});
28852922

2923+
if ('styleFloat' in DIV.style) {
2924+
methods.getStyle = getStyle_IE;
2925+
methods.setOpacity = setOpacity_IE;
2926+
methods.getOpacity = getOpacity_IE;
2927+
}
2928+
2929+
28862930

28872931
// STORAGE
28882932
var UID = 0;
@@ -3326,10 +3370,4 @@
33263370

33273371
Element.addMethods(methods);
33283372

3329-
// TODO: move dimensions stuff to layout
3330-
// getHeight, getWidth, getDimensions, scrollTo,
3331-
// makePositioned, undoPositioned, makeClipping, undoClipping,
3332-
// clonePosition
3333-
// document.viewport
3334-
33353373
})(this);

0 commit comments

Comments
 (0)