package ojs_base

  1. Overview
  2. Docs

Module Ojs_jsSource

JS utilities

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

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

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

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

Sourcetype id = string
Sourceval log : string -> unit

Log to JS console.

Sourceval 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.

Sourceval class_ : string -> string

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

Sourceval 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.

Send data on the given websocket.

Sourceval 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.

Sourceval 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.

Sourceval 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

Sourceval 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).

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

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

Innovation. Community. Security.