diff options
author | Jay Freeman (saurik) <saurik@saurik.com> | 2011-02-17 01:45:59 -0800 |
---|---|---|
committer | Jay Freeman (saurik) <saurik@saurik.com> | 2011-02-17 02:21:53 -0800 |
commit | f196b921bfe9e90d63869d060ae3e102dc82408a (patch) | |
tree | e8c3544eeb6598058fcb959f27f54e216b23b9a0 /UICaboodle | |
parent | 0893a034f90f80629c5b634b564bdd4977c48369 (diff) |
Use document.dispatchEvent() for UIViewController events.
Diffstat (limited to 'UICaboodle')
-rw-r--r-- | UICaboodle/BrowserView.h | 2 | ||||
-rw-r--r-- | UICaboodle/BrowserView.mm | 43 |
2 files changed, 45 insertions, 0 deletions
diff --git a/UICaboodle/BrowserView.h b/UICaboodle/BrowserView.h index f6d689a..692704a 100644 --- a/UICaboodle/BrowserView.h +++ b/UICaboodle/BrowserView.h @@ -126,4 +126,6 @@ - (void) close; +- (void) dispatchEvent:(NSString *)event; + @end diff --git a/UICaboodle/BrowserView.mm b/UICaboodle/BrowserView.mm index 956e359..bdb5753 100644 --- a/UICaboodle/BrowserView.mm +++ b/UICaboodle/BrowserView.mm @@ -1174,4 +1174,47 @@ static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *se return 980; } +- (void) dispatchEvent:(NSString *)event { + WebThreadLocked lock; + + NSString *script([NSString stringWithFormat:@ + "(function() {" + "var event = this.document.createEvent('Events');" + "event.initEvent('%@', false, false);" + "this.document.dispatchEvent(event);" + "})();" + , event]); + + NSMutableArray *frames([NSMutableArray arrayWithObjects: + [[[webview_ _documentView] webView] mainFrame] + , nil]); + + while (WebFrame *frame = [frames lastObject]) { + WebScriptObject *object([frame windowObject]); + [object evaluateWebScript:script]; + [frames removeLastObject]; + [frames addObjectsFromArray:[frame childFrames]]; + } +} + +- (void) viewWillAppear:(BOOL)animated { + [self dispatchEvent:@"CydiaViewWillAppear"]; + [super viewWillAppear:animated]; +} + +- (void) viewDidAppear:(BOOL)animated { + [self dispatchEvent:@"CydiaViewDidAppear"]; + [super viewDidAppear:animated]; +} + +- (void) viewWillDisappear:(BOOL)animated { + [self dispatchEvent:@"CydiaViewWillDisappear"]; + [super viewWillDisappear:animated]; +} + +- (void) viewDidDisappear:(BOOL)animated { + [self dispatchEvent:@"CydiaViewDidDisappear"]; + [super viewDidDisappear:animated]; +} + @end |