2010-04-16 23:41:16 +02:00
//
// ViewDelegate . m
// Twittia 2
//
// Created by Jeena on 15.04 .10 .
// Licence : BSD ( see attached LICENCE . txt file ) .
//
# import "ViewDelegate.h"
@ implementation ViewDelegate
2011-09-19 23:07:26 +02:00
@ synthesize timelineView , mentionsView , twittiaOauthView ;
2010-04-16 23:41:16 +02:00
2010-04-25 13:16:55 +02:00
- ( void ) webView : ( WebView * ) sender addMessageToConsole : ( NSDictionary * ) message ; {
2010-04-17 02:16:50 +02:00
2010-04-16 23:41:16 +02:00
if ( ! [ message isKindOfClass : [ NSDictionary class ] ] ) return ;
2011-09-19 23:07:26 +02:00
NSString * viewName = @ "TimelineView" ;
if ( sender = = mentionsView ) viewName = @ "MentionsView" ;
if ( sender = = twittiaOauthView ) viewName = @ "TwittiaOauthView" ;
NSLog ( @ "js<%@>: %@:%@: %@" ,
viewName ,
2010-04-16 23:41:16 +02:00
[ [ message objectForKey : @ "sourceURL" ] lastPathComponent ] ,
[ message objectForKey : @ "lineNumber" ] ,
[ message objectForKey : @ "message" ]
) ;
}
- ( void ) webView : ( WebView * ) sender runJavaScriptAlertPanelWithMessage : ( NSString * ) message initiatedByFrame : ( WebFrame * ) frame {
2011-09-19 23:07:26 +02:00
NSString * viewName = @ "TimelineView" ;
if ( sender = = mentionsView ) viewName = @ "MentionsView" ;
if ( sender = = twittiaOauthView ) viewName = @ "TwittiaOauthView" ;
NSLog ( @ "jsa<%@>: %@" , viewName , message ) ;
2010-04-16 23:41:16 +02:00
}
- ( void ) webView : ( WebView * ) sender decidePolicyForNavigationAction : ( NSDictionary * ) actionInformation request : ( NSURLRequest * ) request frame : ( WebFrame * ) frame decisionListener : ( id < WebPolicyDecisionListener > ) listener {
[ listener ignore ] ;
[ [ NSWorkspace sharedWorkspace ] openURL : [ request URL ] ] ;
}
2010-04-25 13:16:55 +02:00
- ( void ) webView : ( WebView * ) sender didFinishLoadForFrame : ( WebFrame * ) frame {
2011-09-19 23:07:26 +02:00
if ( sender = = twittiaOauthView ) {
[ twittiaOauthView stringByEvaluatingJavaScriptFromString : @ "setTimeout( function() { twittia_oauth = new TwittiaOauth(); }, 2);" ] ;
} else {
NSString * action = @ "home_timeline" ;
NSString * delay = @ "1" ;
if ( sender = = mentionsView ) {
action = @ "mentions" ;
delay = @ "1000" ;
}
[ sender stringByEvaluatingJavaScriptFromString : [ NSString stringWithFormat :
@ " setTimeout ( function ( ) { twittia_instance = new Twittia ( ' % @ ' ) ; \
document . getElementsByTagName ( ' body ' ) [ 0 ] . appendChild ( twittia_instance . body ) ; \
setTimeout ( function ( ) { loadPlugin ( controller . pluginURL ( ) ) } , 1 ) ; } , % @ ) ; " , action , delay ] ] ;
}
2010-04-25 13:16:55 +02:00
}
2010-04-16 23:41:16 +02:00
@ end