Skip to content

Commit

Permalink
Re-added feature to change opacity of parent, but with additional che…
Browse files Browse the repository at this point in the history
…cks that prevent style from being reapplied indefinitely, since changing the style seems to reload the view in older versions of Safari (thanks @lapcat)

Signed-off-by: Jonathan 'Wolf' Rentzsch <jwr.git@redshed.net>
  • Loading branch information
Simone Manganelli authored and rentzsch committed May 2, 2009
1 parent 7503af2 commit 7458437
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions Plugin/Plugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,21 @@ - (id) initWithArguments:(NSDictionary *)arguments
// Should we apply this to the parent?
// That seems to be problematic.

// well, in my experience w/CSS, to get a layout to work a lot of the
// time, you need to create parent objects and apply styles to parents,
// so it seemed reasonable to check both self and parent for potential
// problems with opacity

NSMutableDictionary *originalOpacityDict = [NSMutableDictionary dictionary];
NSString *opacityResetString = @"; opacity: 1.000 !important; -moz-opacity: 1 !important; filter: alpha(opacity=1) !important;";

NSString *originalWmode = [self.container getAttribute:@"wmode"];
NSString *originalStyle = [self.container getAttribute:@"style"];
NSString *originalParentWmode = [(DOMElement *)[self.container parentNode] getAttribute:@"wmode"];
NSString *originalParentStyle = [(DOMElement *)[self.container parentNode] getAttribute:@"style"];

if (originalWmode != nil && [originalWmode length] > 0u && ![originalWmode isEqualToString:@"opaque"]) {
[originalOpacityDict setObject:originalWmode forKey:@"wmode"];
[originalOpacityDict setObject:originalWmode forKey:@"self-wmode"];
[self.container setAttribute:@"wmode" value:@"opaque"];
}

Expand All @@ -287,6 +294,16 @@ - (id) initWithArguments:(NSDictionary *)arguments
[self.container setAttribute:@"style" value:[originalStyle stringByAppendingString:opacityResetString]];
}

if (originalParentWmode != nil && [originalParentWmode length] > 0u && ![originalParentWmode isEqualToString:@"opaque"]) {
[originalOpacityDict setObject:originalParentWmode forKey:@"parent-wmode"];
[(DOMElement *)[self.container parentNode] setAttribute:@"wmode" value:@"opaque"];
}

if (originalParentStyle != nil && [originalParentStyle length] > 0u && ![originalParentStyle hasSuffix:opacityResetString]) {
[originalOpacityDict setObject:originalParentStyle forKey:@"parent-style"];
[(DOMElement *)[self.container parentNode] setAttribute:@"style" value:[originalParentStyle stringByAppendingString:opacityResetString]];
}

self.originalOpacityAttributes = originalOpacityDict;
}

Expand Down Expand Up @@ -937,15 +954,25 @@ - (void) _prepareForConversion

- (void) _revertToOriginalOpacityAttributes
{
NSString *wmode = [self.originalOpacityAttributes objectForKey:@"wmode"];
if (wmode != nil ) {
[self.container setAttribute:@"wmode" value:wmode];
NSString *selfWmode = [self.originalOpacityAttributes objectForKey:@"self-wmode"];
if (selfWmode != nil ) {
[self.container setAttribute:@"wmode" value:selfWmode];
}

NSString *selfStyle = [self.originalOpacityAttributes objectForKey:@"self-style"];
if (selfStyle != nil ) {
[self.container setAttribute:@"style" value:selfStyle];
}

NSString *parentWmode = [self.originalOpacityAttributes objectForKey:@"parent-wmode"];
if (parentWmode != nil ) {
[(DOMElement *)[self.container parentNode] setAttribute:@"wmode" value:parentWmode];
}

NSString *parentStyle = [self.originalOpacityAttributes objectForKey:@"parent-style"];
if (parentStyle != nil ) {
[(DOMElement *)[self.container parentNode] setAttribute:@"style" value:parentStyle];
}
}

@synthesize webView = _webView;
Expand Down

0 comments on commit 7458437

Please sign in to comment.