diff options
author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-05-08 12:35:41 -0700 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-05-08 12:35:41 -0700 |
commit | 8594e17f2b07976c006bca1c5531e56ead9b065a (patch) | |
tree | 0a123b99f45ef614193dd591e2e0a5254fb8f875 /ext/mac-ui-macgap1-wrapper/src/MacGap/Classes/JSEventHelper.m | |
parent | a40192a40bdf81b9d2a78ae69e059e41d78604ea (diff) | |
download | infinitytier-8594e17f2b07976c006bca1c5531e56ead9b065a.tar.gz infinitytier-8594e17f2b07976c006bca1c5531e56ead9b065a.zip |
Move mac-ui into src/
Diffstat (limited to 'ext/mac-ui-macgap1-wrapper/src/MacGap/Classes/JSEventHelper.m')
-rw-r--r-- | ext/mac-ui-macgap1-wrapper/src/MacGap/Classes/JSEventHelper.m | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/ext/mac-ui-macgap1-wrapper/src/MacGap/Classes/JSEventHelper.m b/ext/mac-ui-macgap1-wrapper/src/MacGap/Classes/JSEventHelper.m new file mode 100644 index 00000000..65406b3c --- /dev/null +++ b/ext/mac-ui-macgap1-wrapper/src/MacGap/Classes/JSEventHelper.m @@ -0,0 +1,41 @@ +// +// Helper.m +// MacGap +// +// Created by Liam Kaufman Simpkins on 12-01-22. +// Copyright (c) 2012 Twitter. All rights reserved. +// + +#import "JSEventHelper.h" + +@implementation JSEventHelper + ++ (void) triggerEvent:(NSString *)event forWebView:(WebView *)webView { + [self triggerEvent:event withArgs:[NSMutableDictionary dictionary] forObject:@"document" forWebView:webView]; +} + ++ (void) triggerEvent:(NSString *)event withArgs:(NSDictionary *)args forWebView:(WebView *)webView { + [self triggerEvent:event withArgs:args forObject:@"document" forWebView:webView]; +} + ++ (void) triggerEvent:(NSString *)event withArgs:(NSDictionary *)args forObject:(NSString *)objName forWebView:(WebView *)webView { + + // Convert args Dictionary to JSON. + NSString* jsonString = [[Utils sharedInstance] convertDictionaryToJSON:args]; + + // Create the event JavaScript and run it. + NSString * str = [NSString stringWithFormat:@"var e = document.createEvent('Events'); e.initEvent('%@', true, false); e.data=%@; %@.dispatchEvent(e); ", event, jsonString, objName]; + [webView stringByEvaluatingJavaScriptFromString:str]; +} + ++ (void) triggerEvent:(NSString *)event forDetail:(NSString *)detail forWebView:(WebView *)webView { + [self triggerEvent:event forDetail:detail forObject:@"document" forWebView:webView]; +} + ++ (void) triggerEvent:(NSString *)event forDetail:(NSString *)detail forObject:(NSString *)objName forWebView:(WebView *)webView { + NSString *detailEscaped = [detail stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]; + NSString *str = [NSString stringWithFormat:@"var e = new CustomEvent('%@', { 'detail': decodeURIComponent(\"%@\") }); %@.dispatchEvent(e); ", event, detailEscaped, objName]; + [webView stringByEvaluatingJavaScriptFromString:str]; +} + +@end |