Updated Branches: refs/heads/master 510468d88 -> 24e37235d
Support window.alert, window.prompt, window.confirm Project: http://git-wip-us.apache.org/repos/asf/cordova-osx/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-osx/commit/24e37235 Tree: http://git-wip-us.apache.org/repos/asf/cordova-osx/tree/24e37235 Diff: http://git-wip-us.apache.org/repos/asf/cordova-osx/diff/24e37235 Branch: refs/heads/master Commit: 24e37235d41d160697b5316e57f5c39cb4b21a76 Parents: 510468d Author: Shazron Abdullah <[email protected]> Authored: Fri Apr 12 16:59:06 2013 -0700 Committer: Shazron Abdullah <[email protected]> Committed: Fri Apr 12 16:59:06 2013 -0700 ---------------------------------------------------------------------- .../CordovaFramework/Classes/CDVWebViewDelegate.m | 70 ++++++++++++++- .../Resources/en.lproj/MainViewController.xib | 10 ++- 2 files changed, 76 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/24e37235/CordovaFramework/CordovaFramework/Classes/CDVWebViewDelegate.m ---------------------------------------------------------------------- diff --git a/CordovaFramework/CordovaFramework/Classes/CDVWebViewDelegate.m b/CordovaFramework/CordovaFramework/Classes/CDVWebViewDelegate.m index 144c8fd..04fbd86 100644 --- a/CordovaFramework/CordovaFramework/Classes/CDVWebViewDelegate.m +++ b/CordovaFramework/CordovaFramework/Classes/CDVWebViewDelegate.m @@ -26,7 +26,7 @@ @synthesize console; -- (void) webView:(WebView*)webView windowScriptObjectAvailable:(WebScriptObject*)windowScriptObject +- (void)webView:(WebView*)webView didClearWindowObject:(WebScriptObject*)windowScriptObject forFrame:(WebFrame*)frame { if (self.console == nil) { self.console = [CDVConsole new]; @@ -39,14 +39,13 @@ [windowScriptObject setValue:self.bridge forKey:@"cordovabridge"]; } -- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame +- (void)webView:(WebView*)sender didFinishLoadForFrame:(WebFrame*)frame { id win = [sender windowScriptObject]; NSString* nativeReady = @"try{cordova.require('cordova/channel').onNativeReady.fire();}catch(e){window._nativeReady = true;}"; [win evaluateWebScript:nativeReady]; } -/* This logs all errors from Javascript, nifty */ - (void) webView:(WebView*)webView addMessageToConsole:(NSDictionary*)message { if (![message isKindOfClass:[NSDictionary class]]) { @@ -84,4 +83,69 @@ } +#pragma mark WebUIDelegate + +- (BOOL)webView:(WebView*)sender runBeforeUnloadConfirmPanelWithMessage:(NSString*)message initiatedByFrame:(WebFrame*)frame +{ + return [self webView:sender runJavaScriptConfirmPanelWithMessage:message initiatedByFrame:frame]; +} + +- (void)webView:(WebView *)sender runOpenPanelForFileButtonWithResultListener:(id < WebOpenPanelResultListener >)resultListener allowMultipleFiles:(BOOL)allowMultipleFiles +{ + NSOpenPanel* dialog = [NSOpenPanel openPanel]; + + [dialog setCanChooseFiles:YES]; + [dialog setAllowsMultipleSelection:allowMultipleFiles]; + [dialog setCanChooseDirectories:YES]; + + if ([dialog runModal] == NSOKButton) { + [resultListener chooseFilenames:[[dialog URLs] valueForKey:@"relativePath"]]; + } +} + +- (void)webView:(WebView*)sender runOpenPanelForFileButtonWithResultListener:(id<WebOpenPanelResultListener>)resultListener +{ + [self webView:sender runOpenPanelForFileButtonWithResultListener:resultListener allowMultipleFiles:NO]; +} + +- (void)webView:(WebView*)sender runJavaScriptAlertPanelWithMessage:(NSString*)message initiatedByFrame:(WebFrame*)frame +{ + NSAlert* alert = [[NSAlert alloc] init]; + [alert addButtonWithTitle:NSLocalizedString(@"OK", @"")]; + [alert setMessageText:message]; + + [alert runModal]; +} + +- (BOOL)webView:(WebView*)sender runJavaScriptConfirmPanelWithMessage:(NSString*)message initiatedByFrame:(WebFrame*)frame +{ + NSAlert* alert = [[NSAlert alloc] init]; + [alert addButtonWithTitle:NSLocalizedString(@"OK", @"")]; + [alert addButtonWithTitle:NSLocalizedString(@"Cancel", @"")]; + [alert setMessageText:message]; + + return ([alert runModal] == NSAlertFirstButtonReturn); +} + +- (NSString*)webView:(WebView*)sender runJavaScriptTextInputPanelWithPrompt:(NSString*)prompt defaultText:(NSString*)defaultText initiatedByFrame:(WebFrame*)frame +{ + NSAlert* alert = [NSAlert alertWithMessageText:prompt + defaultButton:NSLocalizedString(@"OK", @"") + alternateButton:NSLocalizedString(@"Cancel", @"") + otherButton:nil + informativeTextWithFormat:@""]; + + NSTextField* input = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 300, 24)]; + [input setStringValue:defaultText]; + [alert setAccessoryView:input]; + + NSInteger button = [alert runModal]; + if (button == NSAlertDefaultReturn) { + [input validateEditing]; + return [input stringValue]; + } + + return nil; +} + @end http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/24e37235/bin/templates/project/__TESTING__/Resources/en.lproj/MainViewController.xib ---------------------------------------------------------------------- diff --git a/bin/templates/project/__TESTING__/Resources/en.lproj/MainViewController.xib b/bin/templates/project/__TESTING__/Resources/en.lproj/MainViewController.xib index e1eb83f..e80658d 100644 --- a/bin/templates/project/__TESTING__/Resources/en.lproj/MainViewController.xib +++ b/bin/templates/project/__TESTING__/Resources/en.lproj/MainViewController.xib @@ -2098,6 +2098,14 @@ </object> <object class="IBConnectionRecord"> <object class="IBOutletConnection" key="connection"> + <string key="label">UIDelegate</string> + <reference key="source" ref="286545035"/> + <reference key="destination" ref="898714931"/> + </object> + <int key="connectionID">752</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> <string key="label">webView</string> <reference key="source" ref="382806442"/> <reference key="destination" ref="286545035"/> @@ -3417,7 +3425,7 @@ <nil key="activeLocalization"/> <dictionary class="NSMutableDictionary" key="localizations"/> <nil key="sourceID"/> - <int key="maxID">751</int> + <int key="maxID">752</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <array class="NSMutableArray" key="referencedPartialClassDescriptions">
