Skip to content

Commit 7458437

Browse files
Simone Manganellirentzsch
Simone Manganelli
authored andcommitted
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 <[email protected]>
1 parent 7503af2 commit 7458437

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

Plugin/Plugin.m

+31-4
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,21 @@ - (id) initWithArguments:(NSDictionary *)arguments
271271
// Should we apply this to the parent?
272272
// That seems to be problematic.
273273

274+
// well, in my experience w/CSS, to get a layout to work a lot of the
275+
// time, you need to create parent objects and apply styles to parents,
276+
// so it seemed reasonable to check both self and parent for potential
277+
// problems with opacity
278+
274279
NSMutableDictionary *originalOpacityDict = [NSMutableDictionary dictionary];
275280
NSString *opacityResetString = @"; opacity: 1.000 !important; -moz-opacity: 1 !important; filter: alpha(opacity=1) !important;";
276281

277282
NSString *originalWmode = [self.container getAttribute:@"wmode"];
278283
NSString *originalStyle = [self.container getAttribute:@"style"];
284+
NSString *originalParentWmode = [(DOMElement *)[self.container parentNode] getAttribute:@"wmode"];
285+
NSString *originalParentStyle = [(DOMElement *)[self.container parentNode] getAttribute:@"style"];
279286

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

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

297+
if (originalParentWmode != nil && [originalParentWmode length] > 0u && ![originalParentWmode isEqualToString:@"opaque"]) {
298+
[originalOpacityDict setObject:originalParentWmode forKey:@"parent-wmode"];
299+
[(DOMElement *)[self.container parentNode] setAttribute:@"wmode" value:@"opaque"];
300+
}
301+
302+
if (originalParentStyle != nil && [originalParentStyle length] > 0u && ![originalParentStyle hasSuffix:opacityResetString]) {
303+
[originalOpacityDict setObject:originalParentStyle forKey:@"parent-style"];
304+
[(DOMElement *)[self.container parentNode] setAttribute:@"style" value:[originalParentStyle stringByAppendingString:opacityResetString]];
305+
}
306+
290307
self.originalOpacityAttributes = originalOpacityDict;
291308
}
292309

@@ -937,15 +954,25 @@ - (void) _prepareForConversion
937954

938955
- (void) _revertToOriginalOpacityAttributes
939956
{
940-
NSString *wmode = [self.originalOpacityAttributes objectForKey:@"wmode"];
941-
if (wmode != nil ) {
942-
[self.container setAttribute:@"wmode" value:wmode];
957+
NSString *selfWmode = [self.originalOpacityAttributes objectForKey:@"self-wmode"];
958+
if (selfWmode != nil ) {
959+
[self.container setAttribute:@"wmode" value:selfWmode];
943960
}
944961

945962
NSString *selfStyle = [self.originalOpacityAttributes objectForKey:@"self-style"];
946963
if (selfStyle != nil ) {
947964
[self.container setAttribute:@"style" value:selfStyle];
948965
}
966+
967+
NSString *parentWmode = [self.originalOpacityAttributes objectForKey:@"parent-wmode"];
968+
if (parentWmode != nil ) {
969+
[(DOMElement *)[self.container parentNode] setAttribute:@"wmode" value:parentWmode];
970+
}
971+
972+
NSString *parentStyle = [self.originalOpacityAttributes objectForKey:@"parent-style"];
973+
if (parentStyle != nil ) {
974+
[(DOMElement *)[self.container parentNode] setAttribute:@"style" value:parentStyle];
975+
}
949976
}
950977

951978
@synthesize webView = _webView;

0 commit comments

Comments
 (0)