Warning: Reason support is experimental. We are looking for beta-tester and contributors.

Module Eliom_content_core.Html.Custom_data

module Custom_data : sig..end

Type-safe custom data for HTML5. See the examples in the manual .


type 'a t

Custom data with values of type 'a.

val create : 
  name:string ->
  ?default:'a ->
  to_string:('a -> string) ->
  of_string:(string -> 'a) ->
  unit -> 'a t

Create a custom data field by providing string conversion functions. If the default is provided, calls to Eliom_content.Html.Custom_data.get_dom return that instead of throwing an exception Not_found.

val create_json : 
  name:string ->
  ?default:'a ->
  'a Deriving_Json.t -> 'a t

Create a custom data from a Json-deriving type.

val attrib : 
  'a t ->
  'a -> [> `User_data ] Eliom_content_core.Html.attrib

attrib my_data value creates a HTML5 attribute for the custom-data type my_data with value value for injecting it into an a HTML5 tree (Eliom_content.Html.elt ).

val get_dom : 
  Js_of_ocaml.Dom_html.element Js_of_ocaml.Js.t ->
  'a t -> 'a

get_dom element custom_data gets the custom_data from a JavaScript element (Js_of_ocaml.Dom_html.element ). Raises Not_found if the element does not contain the respective custom data attribute and the custom_data was created without default.
Returns The value encoded in the respective custom data attribute of element, or the default value, if any.

val set_dom : 
  Js_of_ocaml.Dom_html.element Js_of_ocaml.Js.t ->
  'a t -> 'a -> unit

set_dom element custom_data value sets the custom data attribute for custom_data of an JavaScript element (Js_of_ocaml.Dom_html.element ) to value.