Skip to content

Commit

Permalink
adding functions to access 'InAppBrowserEvent' properties + README up…
Browse files Browse the repository at this point in the history
…dated
  • Loading branch information
Thibaut committed Jul 5, 2021
1 parent 14f4e5c commit a4f89b6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,33 @@ Cordova_in_app_browser.ai_clear_cache true] in
(* Opens in the Cordova WebView if the URL is in the white list *)
i#open_ "https://ocaml.org" (Cordova_in_app_browser.target_self) opt
```

The function "open_t" is hte same as "open" but it return a "typed"
result: an object of type "inAppBrowser" that can be used later. An
"inAppBrowser" object is te only way to to call the function
"addEventListener" and "close" of this ibrary for example

```OCaml
let popup =
Cordova_in_app_browser.open_t
~url:"https://www.google.com" ~tgt:Blank
~option:"location=yes"
in
Cordova_in_app_browser.addEventListener popup ~eventname:"loadstop"
~f:(fun evt ->
ignore (print_endline "Hello World");
Cordova_in_app_browser.close popup)
```

You can access the 5 properties of the argument of an added
"EventListener" with this functions:
°Cordova_in_app_browser.type: either "loadstart",
"loadstop", "loaderror", "message", or "exit"
°Cordova_in_app_browser.url: not available for every
event type (not for "exit").
°Cordova_in_app_browser.code: only available for event
with an error code.
°Cordova_in_app_browser.message: only available for
"loaderror" event type
°Cordova_in_app_browser.data: onlys available for
"message event type
17 changes: 16 additions & 1 deletion src/cordova_in_app_browser.mli
Original file line number Diff line number Diff line change
Expand Up @@ -235,16 +235,31 @@ type inAppBrowser
val open_t : url:string -> tgt:target -> option:string -> inAppBrowser
[@@js.global "cordova.InAppBrowser.open"]

type inAppBrowserEvent

val addEventListener :
inAppBrowser ->
(*Where to add the listener*)
eventname:string ->
(*The event name*)
f:(Ojs.t -> unit) ->
f:(inAppBrowserEvent -> unit) ->
(*The call_back*)
unit
[@@js.call]

(*Getting access to the "InAppBrowserEvent" properties*)

val type_ : inAppBrowserEvent -> string [@@js.get "type"]

val url : inAppBrowserEvent -> string [@@js.get "url"]

val code : inAppBrowserEvent -> int [@@js.get "code"]

val message : inAppBrowserEvent -> string [@@js.get "message"]

val data : inAppBrowserEvent -> string [@@js.get "data"]

(*Indicate to close an open InAppBrowser object*)
val close : inAppBrowser -> unit [@@js.call]

(*That function indicate if the plugin "cordova-InAppBrowser" is currently available*)
Expand Down

0 comments on commit a4f89b6

Please sign in to comment.