2016-08-11 07:26:39 -04:00
import { Plugin , CordovaInstance } from './plugin' ;
2016-09-21 15:04:46 -05:00
import { Observable } from 'rxjs/Observable' ;
2016-08-31 18:02:15 -03:00
2016-08-11 07:26:39 -04:00
declare var cordova : any ;
2016-07-17 19:56:52 +02:00
2017-02-15 16:57:16 -05:00
export interface InAppBrowserOptions {
/** Set to yes or no to ruen the InAppBrowser's location bar on or off. */
location ? : 'yes' | 'no' ;
/ * * S e t t o y e s t o c r e a t e t h e b r o w s e r a n d l o a d t h e p a g e , b u t n o t s h o w i t . T h e l o a d s t o p e v e n t f i r e s w h e n l o a d i n g i s c o m p l e t e .
* Omit or set to no ( default ) to have the browser open and load normally . * /
hidden ? : 'yes' | 'no' ;
/** Set to yes to have the browser's cookie cache cleared before the new window is opened. */
clearcache ? : 'yes' ;
/** Set to yes to have the session cookie cache cleared before the new window is opened. */
clearsessioncache ? : 'yes' ;
/** (Android Only) set to yes to show Android browser's zoom controls, set to no to hide them. Default value is yes. */
zoom ? : 'yes' | 'no' ;
/ * * S e t t o y e s t o u s e t h e h a r d w a r e b a c k b u t t o n t o n a v i g a t e b a c k w a r d s t h r o u g h t h e I n A p p B r o w s e r ' s h i s t o r y .
* If there is no previous page , the InAppBrowser will close . The default value is yes , so you must set it to no if you want the back button to simply close the InAppBrowser . * /
hardwareback ? : 'yes' | 'no' ;
/** Set to yes to prevent HTML5 audio or video from autoplaying (defaults to no). */
mediaPlaybackRequiresUserAction ? : 'yes' | 'no' ;
/** (Android Only) Set to yes to make InAppBrowser WebView to pause/resume with the app to stop background audio (this may be required to avoid Google Play issues) */
shouldPauseOnSuspend ? : 'yes' | 'no' ;
/** (iOS Only) Set to a string to use as the Done button's caption. Note that you need to localize this value yourself. */
closebuttoncaption? : string ;
/** (iOS Only) Set to yes or no (default is no). Turns on/off the UIWebViewBounce property. */
disallowoverscroll ? : 'yes' | 'no' ;
/** (iOS Only) Set to yes or no to turn the toolbar on or off for the InAppBrowser (defaults to yes) */
toolbar ? : 'yes' | 'no' ;
/** (iOS Only) Set to yes or no to prevent viewport scaling through a meta tag (defaults to no). */
enableViewportScale ? : 'yes' | 'no' ;
/ * * ( i O S O n l y ) S e t t o y e s o r n o t o a l l o w i n - l i n e H T M L 5 m e d i a p l a y b a c k , d i s p l a y i n g w i t h i n t h e b r o w s e r w i n d o w r a t h e r t h a n a d e v i c e - s p e c i f i c p l a y b a c k i n t e r f a c e .
* The HTML ' s video element must also include the webkit - playsinline attribute ( defaults to no ) * /
allowInlineMediaPlayback ? : 'yes' | 'no' ;
/** (iOS Only) Set to yes or no to open the keyboard when form elements receive focus via JavaScript's focus() call (defaults to yes). */
keyboardDisplayRequiresUserAction ? : 'yes' | 'no' ;
/** (iOS Only) Set to yes or no to wait until all new view content is received before being rendered (defaults to no). */
suppressesIncrementalRendering ? : 'yes' | 'no' ;
/** (iOS Only) Set to pagesheet, formsheet or fullscreen to set the presentation style (defaults to fullscreen). */
presentationstyle ? : 'pagesheet' | 'formsheet' | 'fullscreen' ;
/** (iOS Only) Set to fliphorizontal, crossdissolve or coververtical to set the transition style (defaults to coververtical). */
transitionstyle ? : 'fliphorizontal' | 'crossdissolve' | 'coververtical' ;
/** (iOS Only) Set to top or bottom (default is bottom). Causes the toolbar to be at the top or bottom of the window. */
toolbarposition ? : 'top' | 'bottom' ;
/ * * ( W i n d o w s o n l y ) S e t t o y e s t o c r e a t e t h e b r o w s e r c o n t r o l w i t h o u t a b o r d e r a r o u n d i t .
* Please note that if location = no is also specified , there will be no control presented to user to close IAB window . * /
fullscreen ? : 'yes' ;
}
2016-07-17 19:56:52 +02:00
export interface InAppBrowserEvent extends Event {
/** the eventname, either loadstart, loadstop, loaderror, or exit. */
type : string ;
/** the URL that was loaded. */
url : string ;
/** the error code, only in the case of loaderror. */
code : number ;
/** the error message, only in the case of loaderror. */
message : string ;
}
2016-08-11 07:26:39 -04:00
/ * *
* @name InAppBrowser
* @description Launches in app Browser
* @usage
* ` ` ` typescript
* import { InAppBrowser } from 'ionic-native' ;
*
*
* . . .
*
*
* let browser = new InAppBrowser ( 'https://ionic.io' , '_system' ) ;
* browser . executeScript ( . . . ) ;
* browser . insertCSS ( . . . ) ;
* browser . close ( ) ;
* ` ` `
2016-12-06 09:18:37 -05:00
* @interfaces
* InAppBrowserEvent
2017-02-23 04:29:33 -05:00
* InAppBrowserOptions
2016-08-11 07:26:39 -04:00
* /
@Plugin ( {
2016-10-27 12:48:50 -05:00
pluginName : 'InAppBrowser' ,
2016-08-11 07:26:39 -04:00
plugin : 'cordova-plugin-inappbrowser' ,
pluginRef : 'cordova.InAppBrowser' ,
repo : 'https://github.com/apache/cordova-plugin-inappbrowser'
} )
export class InAppBrowser {
2016-07-17 19:56:52 +02:00
2016-08-11 07:26:39 -04:00
private _objectInstance : any ;
2016-07-17 19:56:52 +02:00
/ * *
2016-08-11 07:26:39 -04:00
* Opens a URL in a new InAppBrowser instance , the current browser instance , or the system browser .
* @param url The URL to load .
* @param target The target in which to load the URL , an optional parameter that defaults to _self .
* @param options Options for the InAppBrowser . Optional , defaulting to : location = yes .
* The options string must not contain any blank space , and each feature ' s
* name / value pairs must be separated by a comma . Feature names are case insensitive .
2016-07-17 19:56:52 +02:00
* /
2017-02-15 16:57:16 -05:00
constructor ( url : string , target? : string , options? : InAppBrowserOptions ) ;
constructor ( url : string , target? : string , options? : string ) ;
constructor ( url : string , target? : string , options? : string | InAppBrowserOptions ) {
2016-08-11 07:26:39 -04:00
try {
2017-02-15 16:57:16 -05:00
if ( options && typeof options !== 'string' )
options = Object . keys ( options ) . map ( key = > ` ${ key } = ${ options [ key ] } ` ) . join ( ',' ) ;
2016-08-11 07:26:39 -04:00
this . _objectInstance = cordova . InAppBrowser . open ( url , target , options ) ;
} catch ( e ) {
window . open ( url ) ;
console . warn ( 'Native: InAppBrowser is not installed or you are running on a browser. Falling back to window.open, all instance methods will NOT work.' ) ;
}
}
2016-07-17 19:56:52 +02:00
/ * *
* Displays an InAppBrowser window that was opened hidden . Calling this has no effect
* if the InAppBrowser was already visible .
* /
2017-02-15 16:57:16 -05:00
@CordovaInstance ( { sync : true } )
2016-08-11 07:26:39 -04:00
show ( ) : void { }
/ * *
* Closes the InAppBrowser window .
* /
2017-02-15 16:57:16 -05:00
@CordovaInstance ( { sync : true } )
2016-08-11 07:26:39 -04:00
close ( ) : void { }
2016-07-17 19:56:52 +02:00
2017-02-01 07:42:07 +01:00
/ * *
* Hides an InAppBrowser window that is currently shown . Calling this has no effect
* if the InAppBrowser was already hidden .
* /
2017-02-15 16:57:16 -05:00
@CordovaInstance ( { sync : true } )
2017-02-01 07:42:07 +01:00
hide ( ) : void { }
2016-07-17 19:56:52 +02:00
/ * *
* Injects JavaScript code into the InAppBrowser window .
2017-01-07 05:44:38 -05:00
* @param script { Object } Details of the script to run , specifying either a file or code key .
2016-11-29 16:40:50 -06:00
* @returns { Promise < any > }
2016-07-17 19:56:52 +02:00
* /
2016-08-11 07:26:39 -04:00
@CordovaInstance ( )
2017-02-15 16:57:16 -05:00
executeScript ( script : { file? : string , code? : string } ) : Promise < any > { return ; }
2016-07-17 19:56:52 +02:00
/ * *
* Injects CSS into the InAppBrowser window .
2017-01-07 05:44:38 -05:00
* @param css { Object } Details of the script to run , specifying either a file or code key .
2016-11-29 16:40:50 -06:00
* @returns { Promise < any > }
2016-07-17 19:56:52 +02:00
* /
2016-08-11 07:26:39 -04:00
@CordovaInstance ( )
2017-02-15 16:57:16 -05:00
insertCSS ( css : { file? : string , code? : string } ) : Promise < any > { return ; }
2016-07-17 19:56:52 +02:00
/ * *
2016-08-11 07:26:39 -04:00
* A method that allows you to listen to events happening in the browser .
2016-11-29 16:40:50 -06:00
* @param { string } name of the event
* @returns { Observable < InAppBrowserEvent > } Returns back an observable that will listen to the event on subscribe , and will stop listening to the event on unsubscribe .
2016-07-17 19:56:52 +02:00
* /
2016-08-11 07:26:39 -04:00
on ( event : string ) : Observable < InAppBrowserEvent > {
return new Observable < InAppBrowserEvent > ( ( observer ) = > {
2016-08-13 11:30:52 -04:00
this . _objectInstance . addEventListener ( event , observer . next . bind ( observer ) ) ;
2016-08-13 11:19:46 -04:00
return ( ) = > this . _objectInstance . removeEventListener ( event , observer . next . bind ( observer ) ) ;
2016-08-11 07:26:39 -04:00
} ) ;
}
2016-12-06 09:18:37 -05:00
2016-07-17 19:56:52 +02:00
}