mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-25 06:36:11 +03:00
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:
parent
e5643bf22f
commit
0093153e4e
@ -1013,8 +1013,7 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){
|
||||
*/
|
||||
setElementOpacity: function( element, opacity, usesAlpha ) {
|
||||
|
||||
var previousFilter,
|
||||
ieOpacity,
|
||||
var ieOpacity,
|
||||
ieFilter;
|
||||
|
||||
element = $.getElement( element );
|
||||
@ -1023,31 +1022,16 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){
|
||||
opacity = Math.round( opacity );
|
||||
}
|
||||
|
||||
if ( opacity < 1 ) {
|
||||
element.style.opacity = opacity;
|
||||
if ( $.Browser.opacity ) {
|
||||
element.style.opacity = opacity < 1 ? opacity : "";
|
||||
} else {
|
||||
element.style.opacity = "";
|
||||
}
|
||||
|
||||
if ( opacity == 1 ) {
|
||||
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;
|
||||
if ( opacity < 1 ) {
|
||||
ieOpacity = Math.round( 100 * opacity );
|
||||
ieFilter = "alpha(opacity=" + ieOpacity + ")";
|
||||
element.style.filter = ieFilter;
|
||||
} 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
|
||||
);
|
||||
|
||||
})();
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user