mirror of
https://github.com/ZeroTier/ZeroTierOne
synced 2025-07-10 15:23:06 -07:00
41 lines
1.8 KiB
Objective-C
41 lines
1.8 KiB
Objective-C
//
|
|
// 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
|