From 74584371bdb1391afb3655b8c3113f5cda5afe0f Mon Sep 17 00:00:00 2001 From: Simone Manganelli Date: Sun, 3 May 2009 05:28:29 +0800 Subject: [PATCH] Re-added feature to change opacity of parent, but with additional checks 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 --- Plugin/Plugin.m | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/Plugin/Plugin.m b/Plugin/Plugin.m index 4acff275..4605d39e 100644 --- a/Plugin/Plugin.m +++ b/Plugin/Plugin.m @@ -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"]; } @@ -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; } @@ -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;