package ojs_base

  1. Overview
  2. Docs

JS utilities

module SMap : Map.S with type key = string
val (+=) : 'a SMap.t ref -> (string * 'a) -> unit

Replace a referenced map by the same map with an additional binding.

val (-=) : 'a SMap.t ref -> string -> unit

Replace a referenced map by the same map minus a binding.

type id = string
val log : string -> unit

Log to JS console.

val mk_msg_of_wsdata : (Yojson.Safe.t -> ('a, string) result) -> string -> 'a option

Helper function to read a messsage from a websocket frame data, using the given (json to msg) function.

val class_ : string -> string

Used to create ojs specific classes. class_ str returns "ojs-"^str.

val setup_ws : string -> (string -> 'a option) -> onopen:(Js_of_ocaml.WebSockets.webSocket Js_of_ocaml.Js.t -> 'c) -> onmessage:(Js_of_ocaml.WebSockets.webSocket Js_of_ocaml.Js.t -> 'a -> 'd) -> Js_of_ocaml.WebSockets.webSocket Js_of_ocaml.Js.t option

setup_ws url msg_of_data ~onopen ~onmessage opens a websocket connection to the given url, using msg_of_data to read messages and pass them to the onmessage handler. onopen is called when the websocket is open.

val send_msg : Js_of_ocaml.WebSockets.webSocket Js_of_ocaml.Js.t -> string -> unit

Send data on the given websocket.

val clear_children : Js_of_ocaml.Dom.node Js_of_ocaml.Js.t -> unit

Remove all children of a DOM node.

Get a DOM node by its id.

  • raises Failure

    if the node could not be found.

val gen_id : unit -> id

gen_id() returns a new id prefixed by "ojsid". This is useful to create unique node ids when creating nodes in the DOM.

set_onclick node f sets f as callback to "onclick" event on node.

val split_string : ?keep_empty:bool -> string -> char list -> string list

Separate the given string according to the given list of characters.

  • author Maxence Guesdon
  • version 1.2
  • parameter keep_empty

    is false by default. If set to true, the empty strings between separators are kept. @cgname String.split_string

val get_classes : Js_of_ocaml.Dom_html.element Js_of_ocaml.Js.t -> string list

get_classes node returns the list of classes associated to this element (by splitting on spaces in the class attribute).

val node_unset_class : Js_of_ocaml.Dom_html.element Js_of_ocaml.Js.t -> string -> unit

node_unset_class node cl removes the given class cl from the given DOM element.

val node_set_class : Js_of_ocaml.Dom_html.element Js_of_ocaml.Js.t -> string -> unit

node_set_class node cl adds the given class cl from the given DOM element, if it is not present yet.

val unset_class : id:string -> string -> unit

unset_class ~id cl is the same as node_unset_class but use the given id to retrieve the element.

val set_class : id:string -> string -> unit

set_class ~id cl is the same as node_set_class but use the given id to retrieve the element.

val display_message : ?timeout:float -> ?cl:id -> id -> Js_of_ocaml.Dom.node Js_of_ocaml.Js.t list -> unit
val display_error : id -> Js_of_ocaml.Dom.node Js_of_ocaml.Js.t list -> unit
val display_text_message : ?timeout:float -> ?cl:id -> id -> id -> unit
val display_text_error : id -> id -> unit
OCaml

Innovation. Community. Security.