Simplify setting element opacity.

This simplifies setElementOpacity by removing support for the
obsolete, IE-only element.filters property. Also removes a variable
that previously leaked into the global scope.
This commit is contained in:
Ventero 2013-06-07 00:34:09 +02:00
parent e5643bf22f
commit 0093153e4e

View File

@ -1013,8 +1013,7 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){
*/ */
setElementOpacity: function( element, opacity, usesAlpha ) { setElementOpacity: function( element, opacity, usesAlpha ) {
var previousFilter, var ieOpacity,
ieOpacity,
ieFilter; ieFilter;
element = $.getElement( element ); element = $.getElement( element );
@ -1023,31 +1022,16 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){
opacity = Math.round( opacity ); opacity = Math.round( opacity );
} }
if ( opacity < 1 ) { if ( $.Browser.opacity ) {
element.style.opacity = opacity; element.style.opacity = opacity < 1 ? opacity : "";
} else { } else {
element.style.opacity = ""; if ( opacity < 1 ) {
} ieOpacity = Math.round( 100 * opacity );
ieFilter = "alpha(opacity=" + ieOpacity + ")";
if ( opacity == 1 ) { element.style.filter = ieFilter;
prevFilter = element.style.filter || "";
element.style.filter = prevFilter.replace(/alpha\(.*?\)/g, "");
return;
}
ieOpacity = Math.round( 100 * opacity );
ieFilter = " alpha(opacity=" + ieOpacity + ") ";
//TODO: find out why this uses a try/catch instead of a predetermined
// routine or at least an if/elseif/else
try {
if ( element.filters && element.filters.alpha ) {
element.filters.alpha.opacity = ieOpacity;
} else { } else {
element.style.filter += ieFilter; element.style.filter = "";
} }
} catch ( e ) {
element.style.filter += ieFilter;
} }
}, },
@ -1630,6 +1614,12 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){
) )
); );
//determine if this browser supports element.style.opacity
$.Browser.opacity = !(
$.Browser.vendor == $.BROWSERS.IE &&
$.Browser.version < 9
);
})(); })();