File: mutationObserver.mli

package info (click to toggle)
js-of-ocaml 6.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,932 kB
  • sloc: ml: 135,957; javascript: 58,364; ansic: 437; makefile: 422; sh: 12; perl: 4
file content (108 lines) | stat: -rw-r--r-- 3,584 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
(* Js_of_ocaml library
 * http://www.ocsigen.org/js_of_ocaml/
 * Copyright (C) 2015 Stéphane Legrand
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, with linking exception;
 * either version 2.1 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *)

(** MutationObserver API

  A code example:
  {[
    if (MutationObserver.is_supported()) then
      let doc = Dom_html.document in
      let target =
        Js.Opt.get (doc##getElementById (Js.string "observed"))
          (fun () -> assert false)
      in
      let node = (target :> Dom.node Js.t) in
      let f records observer =
        Console.console##debug records ;
        Console.console##debug observer
      in
      MutationObserver.observe ~node ~f
        ~attributes:true ~child_list:true ~character_data:true
        ()
  ]}

  @see <https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver> for API documentation.
  @see <https://dom.spec.whatwg.org/#mutation-observers> for the Web Hypertext Application Technology Working Group (WHATWG) spec. *)

class type mutationObserverInit = object
  method childList : bool Js.writeonly_prop

  method attributes : bool Js.writeonly_prop

  method characterData : bool Js.writeonly_prop

  method subtree : bool Js.writeonly_prop

  method attributeOldValue : bool Js.writeonly_prop

  method characterDataOldValue : bool Js.writeonly_prop

  method attributeFilter : Js.js_string Js.t Js.js_array Js.t Js.writeonly_prop
end

class type mutationRecord = object
  method _type : Js.js_string Js.t Js.readonly_prop

  method target : Dom.node Js.t Js.readonly_prop

  method addedNodes : Dom.node Dom.nodeList Js.t Js.readonly_prop

  method removedNodes : Dom.node Dom.nodeList Js.t Js.readonly_prop

  method previousSibling : Dom.node Js.t Js.opt Js.readonly_prop

  method nextSibling : Dom.node Js.t Js.opt Js.readonly_prop

  method attributeName : Js.js_string Js.t Js.opt Js.readonly_prop

  method attributeNamespace : Js.js_string Js.t Js.opt Js.readonly_prop

  method oldValue : Js.js_string Js.t Js.opt Js.readonly_prop
end

class type mutationObserver = object
  method observe : #Dom.node Js.t -> mutationObserverInit Js.t -> unit Js.meth

  method disconnect : unit Js.meth

  method takeRecords : mutationRecord Js.t Js.js_array Js.t Js.meth
end

val empty_mutation_observer_init : unit -> mutationObserverInit Js.t

val mutationObserver :
  (   (mutationRecord Js.t Js.js_array Js.t -> mutationObserver Js.t -> unit) Js.callback
   -> mutationObserver Js.t)
  Js.constr

val is_supported : unit -> bool

val observe :
     node:#Dom.node Js.t
  -> f:(mutationRecord Js.t Js.js_array Js.t -> mutationObserver Js.t -> unit)
  -> ?child_list:bool
  -> ?attributes:bool
  -> ?character_data:bool
  -> ?subtree:bool
  -> ?attribute_old_value:bool
  -> ?character_data_old_value:bool
  -> ?attribute_filter:Js.js_string Js.t list
  -> unit
  -> mutationObserver Js.t
(** Helper to create a new observer and connect it to a node *)