├── .gitignore ├── META ├── examples ├── snake │ ├── .depend │ ├── Makefile │ ├── style.css │ ├── index.html │ ├── utils.mli │ ├── utils.ml │ └── snake.ml ├── test.ml ├── test.html └── Makefile ├── .depend ├── README.md ├── tools.mli ├── Makefile ├── tools.ml ├── effects.mli ├── effects.ml ├── jQuery.mli └── jQuery.ml /.gitignore: -------------------------------------------------------------------------------- 1 | *.cm[oixa] 2 | *~ -------------------------------------------------------------------------------- /META: -------------------------------------------------------------------------------- 1 | version = "0.1" 2 | description = "Js_of_ocaml bindings for jQuery" 3 | archive(byte) = "oquery.cma" 4 | archive(byte, plugin) = "oquery.cma" 5 | exists_if = "oquery.cma" 6 | -------------------------------------------------------------------------------- /examples/snake/.depend: -------------------------------------------------------------------------------- 1 | utils.cmo: utils.cmi 2 | utils.cmx: utils.cmi 3 | snake.cmo: utils.cmi ../../jQuery.cmi ../../effects.cmi 4 | snake.cmx: utils.cmx ../../jQuery.cmx ../../effects.cmx 5 | -------------------------------------------------------------------------------- /.depend: -------------------------------------------------------------------------------- 1 | effects.cmo: effects.cmi 2 | effects.cmx: effects.cmi 3 | examples/test.cmo: tools.cmi jQuery.cmi 4 | examples/test.cmx: tools.cmx jQuery.cmx 5 | jQuery.cmo: tools.cmi effects.cmi jQuery.cmi 6 | jQuery.cmx: tools.cmx effects.cmx jQuery.cmi 7 | tools.cmo: tools.cmi 8 | tools.cmx: tools.cmi 9 | effects.cmi: 10 | jQuery.cmi: tools.cmi effects.cmi 11 | tools.cmi: 12 | -------------------------------------------------------------------------------- /examples/test.ml: -------------------------------------------------------------------------------- 1 | open Js 2 | open JQuery 3 | open Effects 4 | 5 | module D = Dom_html 6 | let d = D.document 7 | 8 | let jss = Js.string 9 | let _ = (jQ "div.foo")##css (jss "color", jss "red") 10 | 11 | let _ = 12 | (jQ "#clickme")##click (some (wrap_callback (fun _ -> 13 | (jQ "#square")##slideDown (some (of_duration Slow), null, some (wrap_callback (fun _ -> 14 | Dom_html.window##alert(Js.string "Done sliding"))))))) 15 | 16 | -------------------------------------------------------------------------------- /examples/test.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | First Test OQuery 5 | 8 | 9 | 10 | 11 |
Should be red
12 |
13 | Click here 14 |
15 |
17 |
18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Requirements 2 | 3 | * Findlib 4 | * Js_of_ocaml (http://ocsigen.org/js_of_ocaml/) : a compiler from OCaml 5 | bytecode programs to Javascript 6 | 7 | # Usage 8 | 9 | * run {{{make}}} to compile the library 10 | * run {{{make examples}}} to compile the examples (optionnal) 11 | 12 | # Others Makefile rules: 13 | 14 | * run {{{make depend}} to calculate dependencies in the library 15 | * run {{{make clean}}} to delete generated files 16 | * you can also run {{{make}}} and {{{make clean}}} directly in examples/ 17 | 18 | # Examples 19 | 20 | In the "examples/" directory, you will find some examples of this bindings like the snake games. 21 | -------------------------------------------------------------------------------- /examples/Makefile: -------------------------------------------------------------------------------- 1 | SRC=$(wildcard *.ml) 2 | EXECS=$(SRC:.ml=.byte) 3 | TARGETS=$(SRC:.ml=.js) 4 | OQUERY=oquery.cma 5 | LIB=-package js_of_ocaml $(OQUERY) 6 | OCAMLFLAGS=-package js_of_ocaml.syntax -syntax camlp4o -I $(LIBDIR) 7 | OCAMLLFLAGS= 8 | LIBDIR=.. 9 | all: $(TARGETS) 10 | 11 | %.byte: %.ml $(LIBDIR)/$(OQUERY) 12 | @echo "[CC]" $@ 13 | ocamlfind ocamlc -linkpkg -o $@ $(OCAMLFLAGS) $(LIB) $< 14 | 15 | %.js: %.byte 16 | js_of_ocaml $^ -pretty 17 | 18 | ocamldep: 19 | ocamlfind ocamldep -I $(LIBDIR) $(OCAMLFLAGS) $(SRC) 20 | 21 | clean: 22 | @echo "[CLEAN]" 23 | -rm -f *.cmo *.cmi $(TARGETS) $(EXECS) 24 | 25 | var: 26 | @echo $(TARGETS) 27 | @echo $(EXECS) 28 | -------------------------------------------------------------------------------- /examples/snake/Makefile: -------------------------------------------------------------------------------- 1 | SRC=utils.ml snake.ml 2 | EXECS=snake.byte 3 | TARGETS=snake.js 4 | OQUERY=oquery.cma 5 | LIB=utils.cmo -package js_of_ocaml $(OQUERY) 6 | OCAMLFLAGS=-package js_of_ocaml.syntax -syntax camlp4o -I $(LIBDIR) 7 | OCAMLLFLAGS= 8 | OCAMLFIND=ocamlfind 9 | OCAMLC=ocamlc 10 | LIBDIR=../.. 11 | 12 | all: utils.cmi utils.cmo $(TARGETS) 13 | 14 | %.cmo: %.ml 15 | $(OCAMLFIND) $(OCAMLC) $(OCAMLFLAGS) -c $< 16 | 17 | %.cmi: %.mli 18 | $(OCAMLFIND) $(OCAMLC) $(OCAMLFLAGS) -c $< 19 | 20 | %.byte: %.ml $(LIBDIR)/$(OQUERY) 21 | @echo "[CC]" $@ 22 | ocamlfind ocamlc -linkpkg -o $@ $(OCAMLFLAGS) $(LIB) $< 23 | 24 | %.js: %.byte 25 | js_of_ocaml $^ -pretty 26 | 27 | depend: 28 | ocamlfind ocamldep -I $(LIBDIR) $(OCAMLFLAGS) $(SRC) > .depend 29 | 30 | clean: 31 | @echo "[CLEAN]" 32 | -rm -f *.cmo *.cmi *.cmt* $(TARGETS) $(EXECS) 33 | 34 | var: 35 | @echo $(TARGETS) 36 | @echo $(EXECS) 37 | -------------------------------------------------------------------------------- /examples/snake/style.css: -------------------------------------------------------------------------------- 1 | *{margin:0;padding:0;font-family:trebuchet ms;} 2 | body{width:900px;position:realtive;margin:0 auto;} 3 | table{margin:0 auto 10px auto;border:1px solid #ccc;box-shadow:3px 3px 10px #999;} 4 | td{width:6px;height:6px;border:1px solid #fff;cellpadding:0;cellspacing:0;} 5 | td.snakeCell{background:#000;-moz-border-radius:5px;border:1px solid #000;box-shadow:1px 1px 1px #aaa;} 6 | td.snakeHead{background:red;-moz-border-radius:5px;border:1px solid red;} 7 | td.fruitCell{background:green;-moz-border-radius:5px;border:1px solid green;box-shadow:1px 1px 1px #aaa;} 8 | 9 | #scoreBoard{text-shadow:2px 2px 1px #fff;box-shadow:0 -3px 5px #aaa;width:482px;margin:50px auto 0 auto;border:1px solid #ccc;background:#eee;font-weight:bold;padding:10px;} 10 | .gameOver{font-weight:bold;text-shadow:2px 2px 1px #fff;position:absolute;top:0;left:550px;background:#eee;color:red;width:70px;border:50px solid #eee;text-align:center;-moz-border-radius:90px;-webkit-border-radius:90px;border-radius:90px;box-shadow:3px 3px 10px #999;} -------------------------------------------------------------------------------- /examples/snake/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Snake Game- built with js_of_ocaml and ocaml-jquery bindings 5 | 6 | 7 | 8 | 9 | 10 | 11 |

Snake Game - built with js_of_ocaml and ocaml-jquery 12 | bindings

13 | 18 |
19 | 20 |
Your Score : 0
21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /tools.mli: -------------------------------------------------------------------------------- 1 | (* 2 | * JQuery binding for Js_of_ocaml - 2011-2012 3 | * Tools module 4 | * 5 | * 2011 Gabriel Cardoso - gcardoso.w@gmail.com 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, with linking exception; 10 | * either version 2.1 of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 | *) 21 | 22 | module Choice3 : sig 23 | type (+'a, +'b, +'c) t 24 | val i1 : 'a -> ('a, 'b, 'c) t 25 | val i2 : 'b -> ('a, 'b, 'c) t 26 | val i3 : 'c -> ('a, 'b, 'c) t 27 | end 28 | 29 | module Choice4 : sig 30 | type (+'a, +'b, +'c, +'d) t 31 | val i1 : 'a -> ('a, 'b, 'c, 'd) t 32 | val i2 : 'b -> ('a, 'b, 'c, 'd) t 33 | val i3 : 'c -> ('a, 'b, 'c, 'd) t 34 | val i4 : 'd -> ('a, 'b, 'c, 'd) t 35 | end 36 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | JS_OF_OCAML?=$(shell ocamlfind query js_of_ocaml) 2 | LIB=$(JS_OF_OCAML_PATH)/lib 3 | 4 | OCAMLFLAGS=$(INCLUDES) -package js_of_ocaml.syntax -syntax camlp4o 5 | OCAMLIFLAGS=$(INCLUDES) -package js_of_ocaml -pp "cpp -traditional-cpp" 6 | OQUERY=oquery.cma 7 | LIBRARY=oquery 8 | MLS=$(shell find * -name "*.ml") 9 | MLIS=$(shell find * -name "*.mli") 10 | OCAMLFIND=ocamlfind 11 | OCAMLDOC=ocamldoc 12 | CMOS=tools.cmo effects.cmo jQuery.cmo 13 | CMIS=tools.cmi effects.cmi jQuery.cmi 14 | 15 | all: $(OQUERY) 16 | 17 | examples: all 18 | @(${MAKE} -C examples); 19 | 20 | 21 | -include .depend 22 | 23 | $(OQUERY): $(CMOS) 24 | $(OCAMLFIND) ocamlc -a -o $@ $^ 25 | 26 | .SECONDEXPANSION: 27 | 28 | %.cmo: %.ml 29 | @echo "[CC] $@" 30 | $(OCAMLFIND) ocamlc $(OCAMLFLAGS) -c $< 31 | 32 | %.cmi: %.mli 33 | $(OCAMLFIND) ocamlc $(OCAMLIFLAGS) -c $< 34 | 35 | depend: ocamldep 36 | 37 | ocamldep: 38 | ($(OCAMLFIND) ocamldep $(OCAMLFLAGS) $(MLS); \ 39 | $(OCAMLFIND) ocamldep $(OCAMLIFLAGS) $(MLIS)) > .depend 40 | 41 | cleanall: clean 42 | -rm -f .depend 43 | 44 | clean: 45 | @echo "[CLEAN]" 46 | -rm -f $(OQUERY) 47 | -find . -name "*.cm[oix]" -exec rm {} \; 48 | -find . -name "*.cm[t]" -exec rm {} \; 49 | -find . -name "*.cmt[i]" -exec rm {} \; 50 | ${MAKE} -C examples clean 51 | 52 | install: 53 | ocamlfind install jquery META oquery.cma $(CMIS) $(MLIS) 54 | 55 | uninstall: 56 | ocamlfind remove jquery 57 | -------------------------------------------------------------------------------- /tools.ml: -------------------------------------------------------------------------------- 1 | (* 2 | * JQuery binding for Js_of_ocaml - 2011-2012 3 | * Tools module 4 | * 5 | * 2011 Gabriel Cardoso - gcardoso.w@gmail.com 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, with linking exception; 10 | * either version 2.1 of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 | *) 21 | 22 | module Choice3 = struct 23 | type (+'a, +'b, +'c) t 24 | let i1 : 'a -> ('a, 'b, 'c) t = Obj.magic 25 | let i2 : 'b -> ('a, 'b, 'c) t = Obj.magic 26 | let i3 : 'c -> ('a, 'b, 'c) t = Obj.magic 27 | end 28 | 29 | module Choice4 = struct 30 | type (+'a, +'b, +'c, +'d) t 31 | let i1 : 'a -> ('a, 'b, 'c, 'd) t = Obj.magic 32 | let i2 : 'b -> ('a, 'b, 'c, 'd) t = Obj.magic 33 | let i3 : 'c -> ('a, 'b, 'c, 'd) t = Obj.magic 34 | let i4 : 'd -> ('a, 'b, 'c, 'd) t = Obj.magic 35 | end 36 | -------------------------------------------------------------------------------- /effects.mli: -------------------------------------------------------------------------------- 1 | (* 2 | * JQuery binding for Js_of_ocaml - 2011-2012 3 | * Effects module 4 | * 5 | * 2011 Gabriel Cardoso - gcardoso.w@gmail.com 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, with linking exception; 10 | * either version 2.1 of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 | *) 21 | 22 | open Js 23 | 24 | type duration = Value of int | Slow | Fast 25 | type duration_pre 26 | val of_duration : duration -> duration_pre 27 | 28 | type easing = 29 | | Def 30 | | Jswing 31 | | Easeinquad 32 | | Easeoutquad 33 | | Easeinoutquad 34 | | Easeincubic 35 | | Easeoutcubic 36 | | Easeinoutcubic 37 | | Easeinquart 38 | | Easeoutquart 39 | | Easeinoutquart 40 | | Easeinsine 41 | | Easeoutsine 42 | | Easeinoutsine 43 | | Easeinexpo 44 | | Easeoutexpo 45 | | Easeinoutexpo 46 | | Easeinquint 47 | | Easeoutquint 48 | | Easeinoutquint 49 | | Easeincirc 50 | | Easeoutcirc 51 | | Easeinoutcirc 52 | | Easeinelastic 53 | | Easeoutelastic 54 | | Easeinoutelastic 55 | | Easeinback 56 | | Easeoutback 57 | | Easeinoutback 58 | | Easeinbounce 59 | | Easeoutbounce 60 | | Easeinoutbounce 61 | 62 | type easing_pre 63 | val of_easing : easing -> easing_pre 64 | -------------------------------------------------------------------------------- /examples/snake/utils.mli: -------------------------------------------------------------------------------- 1 | (* 2 | * Utils module from https://github.com/OCamlPro/tryocaml/blob/master/ocp-jslib/utils.mli 3 | * http://www.ocamlpro.com - OCamlPro SAS 4 | * 5 | * (C) 2012 Fabrice Le Fessant - fabrice.le_fessant@inria.fr 6 | * (C) 2012 Cagdas Bozman - cagdas.bozman@ocamlpro.com 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, with linking exception; 11 | * either version 2.1 of the License, or (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21 | *) 22 | 23 | (** {1 Useful functions and alias} *) 24 | val doc : Dom_html.document Js.t 25 | 26 | val window : Dom_html.window Js.t 27 | 28 | val loc : Dom_html.location Js.t 29 | 30 | val _s : string -> Js.js_string Js.t 31 | 32 | val _f : ('a -> 'b) -> ('c, 'a -> 'b) Js.meth_callback 33 | 34 | val set_div_by_id : string -> string -> unit 35 | 36 | val set_by_id : string -> string -> unit 37 | 38 | val get_element_by_id : string -> Dom_html.element Js.t 39 | 40 | val get_by_id : string -> string 41 | 42 | val get_by_name : string -> string 43 | 44 | (** {2 Constructors} *) 45 | 46 | (** [jsnew0] is a function to build an object using contructor [constr] 47 | without arguments. *) 48 | val jsnew0 : 'a Js.t Js.constr -> unit -> 'a Js.t 49 | 50 | (** [jsnew1] is a function to build an object using contructor [constr] 51 | and argument [a].*) 52 | val jsnew1 : ('a -> 'b Js.t) Js.constr -> 'a -> 'b Js.t 53 | 54 | (** [jsnew2] is a function to build an object using contructor [constr] 55 | and arguments [a] and [b].*) 56 | val jsnew2 : ('a -> 'b -> 'c Js.t) Js.constr -> 'a * 'b -> 'c Js.t 57 | 58 | (** [jsnew3] is a function to build an object using contructor [constr] 59 | and arguments [a], [b] and [c].*) 60 | val jsnew3 : ('a -> 'b -> 'c -> 'd Js.t) Js.constr -> 'a * 'b * 'c -> 'd Js.t 61 | 62 | val setIntervalUntilFalse : (unit -> bool) -> float -> unit 63 | val setInterval : (unit -> unit) -> float -> (unit -> unit) 64 | val setTimeout : (unit -> unit) -> float -> (unit -> unit) 65 | -------------------------------------------------------------------------------- /examples/snake/utils.ml: -------------------------------------------------------------------------------- 1 | (* 2 | * Utils module from https://github.com/OCamlPro/tryocaml/blob/master/ocp-jslib/utils.ml 3 | * http://www.ocamlpro.com - OCamlPro SAS 4 | * 5 | * (C) 2012 Fabrice Le Fessant - fabrice.le_fessant@inria.fr 6 | * (C) 2012 Cagdas Bozman - cagdas.bozman@ocamlpro.com 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, with linking exception; 11 | * either version 2.1 of the License, or (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21 | *) 22 | 23 | let doc = Dom_html.document 24 | 25 | let window = Dom_html.window 26 | 27 | let loc = Js.Unsafe.variable "location" 28 | 29 | let _s s = Js.string s 30 | 31 | let _f f = Js.wrap_callback f 32 | 33 | let get_element_by_id id = 34 | Js.Opt.get (doc##getElementById (Js.string id)) (fun () -> assert false) 35 | 36 | let set_by_id id s = 37 | let div = get_element_by_id id in 38 | div##innerHTML <- Js.string s 39 | 40 | let set_div_by_id id s = 41 | try 42 | set_by_id id s 43 | with _ -> () 44 | 45 | let get_by_id id = 46 | let div = get_element_by_id id in 47 | Js.to_string div##innerHTML 48 | 49 | let get_by_name id = 50 | let div = 51 | List.hd (Dom.list_of_nodeList (doc##getElementsByTagName (Js.string id))) in 52 | Js.to_string div##innerHTML 53 | 54 | let jsnew0 (constr : 'a Js.t Js.constr) () = 55 | (Js.Unsafe.new_obj constr [| |] : 'a Js.t) 56 | 57 | let jsnew1 (constr : ('a -> 'z Js.t) Js.constr) (a) = 58 | (Js.Unsafe.new_obj constr [| 59 | Js.Unsafe.inject (a : 'a) 60 | |] : 'z Js.t) 61 | 62 | let jsnew2 (constr : ('a -> 'b -> 'z Js.t) Js.constr) (a,b) = 63 | (Js.Unsafe.new_obj constr [| 64 | Js.Unsafe.inject (a : 'a); 65 | Js.Unsafe.inject (b : 'b); 66 | |] : 'z Js.t) 67 | 68 | let jsnew3 (constr : ('a -> 'b -> 'c -> 'z Js.t) Js.constr) (a,b,c) = 69 | (Js.Unsafe.new_obj constr [| 70 | Js.Unsafe.inject (a : 'a); 71 | Js.Unsafe.inject (b : 'b); 72 | Js.Unsafe.inject (c : 'c); 73 | |] : 'z Js.t) 74 | 75 | let setIntervalUntilFalse f time = 76 | let interval_id = ref None in 77 | let f () = 78 | if not (f ()) then 79 | match !interval_id with 80 | None -> () 81 | | Some interval_id -> 82 | window##clearInterval (interval_id) 83 | in 84 | interval_id := Some (window##setInterval (_f f, time)) 85 | 86 | let setInterval f time = 87 | let interval_id = window##setInterval (_f f, time) in 88 | (fun _ -> window##clearInterval (interval_id)) 89 | 90 | let setTimeout f time = 91 | let interval_id = window##setTimeout (_f f, time) in 92 | (fun _ -> window##clearTimeout (interval_id)) 93 | -------------------------------------------------------------------------------- /effects.ml: -------------------------------------------------------------------------------- 1 | (* 2 | * JQuery binding for Js_of_ocaml - 2011-2012 3 | * Effects module 4 | * 5 | * 2011 Gabriel Cardoso - gcardoso.w@gmail.com 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, with linking exception; 10 | * either version 2.1 of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 | *) 21 | 22 | open Js 23 | 24 | type duration = Value of int | Slow | Fast 25 | type duration_pre 26 | 27 | let of_duration = function 28 | | Value i -> (Obj.magic i : duration_pre) 29 | | Slow -> (Obj.magic (Js.string "slow") : duration_pre) 30 | | Fast -> (Obj.magic (Js.string "fast") : duration_pre) 31 | 32 | type easing = 33 | | Def 34 | | Jswing 35 | | Easeinquad 36 | | Easeoutquad 37 | | Easeinoutquad 38 | | Easeincubic 39 | | Easeoutcubic 40 | | Easeinoutcubic 41 | | Easeinquart 42 | | Easeoutquart 43 | | Easeinoutquart 44 | | Easeinsine 45 | | Easeoutsine 46 | | Easeinoutsine 47 | | Easeinexpo 48 | | Easeoutexpo 49 | | Easeinoutexpo 50 | | Easeinquint 51 | | Easeoutquint 52 | | Easeinoutquint 53 | | Easeincirc 54 | | Easeoutcirc 55 | | Easeinoutcirc 56 | | Easeinelastic 57 | | Easeoutelastic 58 | | Easeinoutelastic 59 | | Easeinback 60 | | Easeoutback 61 | | Easeinoutback 62 | | Easeinbounce 63 | | Easeoutbounce 64 | | Easeinoutbounce 65 | 66 | type easing_pre = js_string t 67 | 68 | let of_easing = function 69 | | Def -> Js.string "def" 70 | | Jswing -> Js.string "jswing" 71 | | Easeinquad -> Js.string "easeinquad" 72 | | Easeoutquad -> Js.string "easeoutquad" 73 | | Easeinoutquad -> Js.string "easeinoutquad" 74 | | Easeincubic -> Js.string "easeincubic" 75 | | Easeoutcubic -> Js.string "easeoutcubic" 76 | | Easeinoutcubic -> Js.string "easeinoutcubic" 77 | | Easeinquart -> Js.string "easeinquart" 78 | | Easeoutquart -> Js.string "easeoutquart" 79 | | Easeinoutquart -> Js.string "easeinoutquart" 80 | | Easeinsine -> Js.string "easeinsine" 81 | | Easeoutsine -> Js.string "easeoutsine" 82 | | Easeinoutsine -> Js.string "easeinoutsine" 83 | | Easeinexpo -> Js.string "easeinexpo" 84 | | Easeoutexpo -> Js.string "easeoutexpo" 85 | | Easeinoutexpo -> Js.string "easeinoutexpo" 86 | | Easeinquint -> Js.string "easeinquint" 87 | | Easeoutquint -> Js.string "easeoutquint" 88 | | Easeinoutquint -> Js.string "easeinoutquint" 89 | | Easeincirc -> Js.string "easeincirc" 90 | | Easeoutcirc -> Js.string "easeoutcirc" 91 | | Easeinoutcirc -> Js.string "easeinoutcirc" 92 | | Easeinelastic -> Js.string "easeinelastic" 93 | | Easeoutelastic -> Js.string "easeoutelastic" 94 | | Easeinoutelastic -> Js.string "easeinoutelastic" 95 | | Easeinback -> Js.string "easeinback" 96 | | Easeoutback -> Js.string "easeoutback" 97 | | Easeinoutback -> Js.string "easeinoutback" 98 | | Easeinbounce -> Js.string "easeinbounce" 99 | | Easeoutbounce -> Js.string "easeoutbounce" 100 | | Easeinoutbounce -> Js.string "easeinoutbounce" 101 | -------------------------------------------------------------------------------- /jQuery.mli: -------------------------------------------------------------------------------- 1 | (* 2 | * JQuery binding for Js_of_ocaml - 2011-2012 3 | * jQuery module 4 | * 5 | * 2011 Gabriel Cardoso - gcardoso.w@gmail.com 6 | * 2012 Cagdas Bozman - cagdas.bozman@ocamlpro.com 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, with linking exception; 11 | * either version 2.1 of the License, or (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21 | *) 22 | 23 | open Js 24 | open Effects 25 | 26 | class type jQuery = object 27 | method add : js_string t -> jQuery t meth 28 | method add_element : #Dom_html.element t -> jQuery t meth 29 | method add_jquery : jQuery t -> jQuery t meth 30 | method addClass : js_string t -> jQuery t meth 31 | method addClass_ : (int -> js_string t -> js_string t) callback 32 | -> jQuery t meth 33 | method after : (js_string t, #Dom_html.element t, jQuery t) Tools.Choice3.t 34 | -> jQuery t meth 35 | method after_fun : 36 | (int -> (js_string t, #Dom_html.element t, jQuery t) Tools.Choice3.t) 37 | -> jQuery t meth 38 | method ajaxComplete : 39 | (#Dom_html.event t -> #XmlHttpRequest.xmlHttpRequest t -> 'a) callback 40 | -> jQuery t meth 41 | method animate : Dom_html.cssStyleDeclaration t -> duration_pre opt 42 | -> easing_pre opt -> ('a, 'b) meth_callback opt -> jQuery t meth 43 | method append : js_string t -> jQuery t meth 44 | method appendTo : js_string t -> jQuery t meth 45 | method appendTo_jquery : jQuery t -> jQuery t meth 46 | method attr : js_string t -> js_string t optdef meth 47 | method attr_set : js_string t -> js_string t -> jQuery t meth 48 | method before : (js_string t, #Dom_html.element t, jQuery t) Tools.Choice3.t 49 | -> jQuery t meth 50 | method bind : js_string t -> ('a, 'b) meth_callback opt -> jQuery t meth 51 | method blur : ('a, 'b) meth_callback opt -> jQuery t meth 52 | method change : ('a, 'b) meth_callback opt -> jQuery t meth 53 | method clearQueue : js_string t opt -> jQuery t meth 54 | method click : ('a, 'b) meth_callback opt -> jQuery t meth 55 | method css_get : js_string t -> js_string t meth 56 | method css : js_string t -> js_string t -> jQuery t meth 57 | method delay : int -> js_string t opt -> jQuery t meth 58 | method dequeue : js_string t opt -> jQuery t meth 59 | method each : (int -> #Dom_html.element t -> 'a) callback -> jQuery t meth 60 | method eq : int -> jQuery t meth 61 | method fadeIn : duration_pre opt -> easing_pre opt -> ('a, 'b) meth_callback opt 62 | -> jQuery t meth 63 | method fadeOut : duration_pre opt -> easing_pre opt -> ('a, 'b) meth_callback opt 64 | -> jQuery t meth 65 | method fadeTo : duration_pre opt -> easing_pre opt -> ('a, 'b) meth_callback opt 66 | -> jQuery t meth 67 | method fadeToggle : duration_pre opt -> easing_pre opt -> ('a, 'b) meth_callback opt 68 | -> jQuery t meth 69 | method find : jQuery t -> jQuery t meth 70 | method focus : ('a, 'b) meth_callback opt -> jQuery t meth 71 | method has : js_string t -> jQuery t meth 72 | method hasClass : js_string t -> bool t meth 73 | method height : int meth 74 | method height_set : int -> jQuery t meth 75 | method hide : duration_pre opt -> easing_pre opt -> ('a, 'b) meth_callback opt 76 | -> jQuery t meth 77 | method hover : ('a, 'b) meth_callback -> ('a, 'b) meth_callback opt -> jQuery t meth 78 | method html : js_string t meth 79 | method html_set : js_string t -> jQuery t meth 80 | method insertAfter : (js_string t, #Dom_html.element t, jQuery t) 81 | Tools.Choice3.t -> jQuery t meth 82 | method insertBefore : (js_string t, #Dom_html.element t, jQuery t) 83 | Tools.Choice3.t -> jQuery t meth 84 | method length : int readonly_prop 85 | method live : 'a Dom.Event.typ -> ('a, 'b) meth_callback -> jQuery t meth 86 | method prepend : js_string t -> unit meth 87 | method queue : js_string t opt -> js_string t js_array t meth 88 | method ready : ('a, 'b) meth_callback -> jQuery t meth 89 | method remove : unit meth 90 | method removeClass : js_string t opt -> jQuery t meth 91 | method removeClass_ : (int -> js_string t -> js_string t) callback 92 | -> jQuery t meth 93 | method select : ('a, 'b) meth_callback opt -> jQuery t meth 94 | method serialize : unit -> js_string meth 95 | method show : duration_pre opt -> easing_pre opt -> ('a, 'b) meth_callback opt 96 | -> jQuery t meth 97 | method size : int meth 98 | method slideDown : duration_pre opt -> easing_pre opt -> ('a, 'b) meth_callback opt 99 | -> jQuery t meth 100 | method slideToggle : duration_pre opt -> easing_pre opt -> ('a, 'b) meth_callback opt 101 | -> jQuery t meth 102 | method slideUp : duration_pre opt -> easing_pre opt -> ('a, 'b) meth_callback opt 103 | -> jQuery t meth 104 | method stop : bool t opt -> bool t opt -> jQuery t meth 105 | method submit : ('a, 'b) meth_callback opt -> jQuery t meth 106 | method toggle : bool t -> jQuery t meth 107 | method toggleClass : js_string t -> jQuery t meth 108 | method toggle_ : duration_pre opt -> easing_pre opt -> ('a, 'b) meth_callback opt 109 | -> jQuery t meth 110 | method text : js_string t meth 111 | method text_set : js_string t -> jQuery t meth 112 | method unbind : js_string t -> jQuery t meth 113 | method val_ : string_array t meth 114 | method val_set : js_string t -> jQuery t meth 115 | method width : int meth 116 | method width_set : int -> jQuery t meth 117 | method tableFilter : unit meth 118 | method tableFilterApplyFilterValues : unit meth 119 | end 120 | 121 | (** Easy way to call the jQuery object jQ "#foo" <=> $("#foo") **) 122 | val jQ : string -> jQuery t 123 | 124 | (** Call the jQuery object i.e. "$" in jQuery **) 125 | val jQuery : (js_string t, #Dom_html.element t, #Dom_html.element t js_array t, 126 | jQuery t) Tools.Choice4.t -> 127 | (#Dom_html.element t, #Dom_html.document, 128 | jQuery t) Tools.Choice3.t opt -> jQuery t 129 | 130 | 131 | val ajax : js_string t -> unit 132 | val param : Unsafe.any t -> bool t opt -> js_string t 133 | -------------------------------------------------------------------------------- /examples/snake/snake.ml: -------------------------------------------------------------------------------- 1 | (* Snake Game 2 | * http://www.ocsigen.org/js_of_ocaml/ 3 | * https://github.com/gabriel-cardoso/ocaml-jquery 4 | * http://www.ocamlpro.com 5 | * 6 | * (C) 2012 Cagdas Bozman - cagdas.bozman@ocamlpro.com 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, with linking exception; 11 | * either version 2.1 of the License, or (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21 | *) 22 | 23 | open JQuery 24 | open Effects 25 | open Utils 26 | 27 | module Html = Dom_html 28 | 29 | let direction = ref "right" 30 | let speed = ref 100 31 | let ticker : Html.interval_id ref = 32 | ref (Html.window##setInterval ((Js.wrap_callback (fun _ -> ())), 10.)) 33 | let fruit_cell : (int * int ) ref = ref (15, 15) 34 | let score = ref 0 35 | let size = 40 36 | 37 | let snake_cells = 38 | let arr = jsnew Js.array_empty () in 39 | ignore (arr##push ((10, 14))); 40 | ignore (arr##push ((10, 13))); 41 | ignore (arr##push ((10, 12))); 42 | ignore (arr##push ((10, 11))); 43 | ignore (arr##push ((10, 10))); 44 | ignore (arr##push ((10, 9))); 45 | ignore (arr##push ((10, 8))); 46 | ignore (arr##push ((10, 7 ))); 47 | arr 48 | 49 | let snake_head = ref (10, 14) 50 | 51 | let render_snake () = 52 | let _ = 53 | (jQ "td")##removeClass (Js.some (_s "snakeCell")) in 54 | let _ = 55 | (jQ "td")##removeClass (Js.some (_s "snakeHead")) in 56 | for i = 0 to (snake_cells##length - 1) do 57 | let cell = Js.Optdef.to_option (Js.array_get snake_cells i) in 58 | let cell = 59 | match cell with 60 | | None -> assert false 61 | | Some t -> t in 62 | let fst, snd = fst cell, snd cell in 63 | ignore (((((jQ "tr")##eq (fst))##find (jQ "td"))##eq (snd))##addClass (_s "snakeCell")) 64 | done; 65 | ignore (((((jQ "tr")##eq (fst !snake_head))##find (jQ "td"))##eq (snd !snake_head))##addClass (_s "snakeHead")) 66 | 67 | let get_random_number limit = 68 | int_of_float ((Js.to_float (Js.math##random ())) *. (float_of_int (limit mod limit))) 69 | 70 | let get_fruit_cell () = 71 | fruit_cell := ( 72 | Random.int ((jQ "tr")##length), 73 | Random.int ((jQ "tr:eq(0)>td")##length) 74 | ) 75 | 76 | let game_over () = 77 | let fast = Js.some (of_duration Fast) and 78 | slow = Js.some (of_duration Slow) in 79 | let _ = 80 | (jQ "div.gameOver")##show (fast, Js.null, Js.some 81 | (Js.wrap_callback (fun _ -> 82 | let this = get_element_by_id "gameOver" in 83 | this##style##top <- _s "250"; 84 | (jQ "this")##animate (this##style, slow, Js.null, Js.null)))) in 85 | window##clearInterval (!ticker); 86 | failwith ("Game Over") 87 | 88 | let render_fruit_cell () = 89 | ignore ((jQ "td")##removeClass (Js.some (_s "fruitCell"))); 90 | ignore (((((jQ "tr")##eq (fst !fruit_cell)##find ((jQ "td")))##eq ( 91 | snd !fruit_cell))##addClass ( _s "fruitCell"))) 92 | 93 | let rec start_game () = 94 | ticker := window##setInterval (Js.wrap_callback (fun () -> update_snake_cell ()), 95 | float_of_int !speed) 96 | 97 | and update_snake_cell () = 98 | let snake_new_head = ref (0, 0) in 99 | let () = 100 | match !direction with 101 | | "left" -> 102 | snake_new_head := fst !snake_head, (snd !snake_head) - 1 103 | | "up" -> 104 | snake_new_head := (fst !snake_head) - 1, snd !snake_head 105 | | "right" -> 106 | snake_new_head := fst !snake_head, (snd !snake_head) + 1 107 | | "down" -> 108 | snake_new_head := (fst !snake_head) + 1, snd !snake_head 109 | | _ -> () in 110 | let () = 111 | if fst !snake_new_head < 0 || snd !snake_new_head < 0 then 112 | game_over () 113 | else if fst !snake_new_head >= size || snd !snake_new_head >= size then 114 | game_over () 115 | else () in 116 | let new_cell = (((jQ "tr")##eq (fst !snake_new_head))##find (jQ "td"))##eq ( 117 | snd !snake_new_head) in 118 | if new_cell##length = 0 then game_over () 119 | else begin 120 | if (Js.to_bool (new_cell##hasClass (_s "snakeCell"))) then 121 | game_over () 122 | else begin 123 | if (Js.to_bool (new_cell##hasClass (_s "fruitCell"))) then begin 124 | get_fruit_cell (); 125 | render_fruit_cell (); 126 | score := !score + 100; 127 | let score_board = get_element_by_id "scoreBoard" in 128 | score_board##innerHTML <- _s (Printf.sprintf "Your score : %d\n" !score); 129 | speed := if !speed - 10 > 5 then !speed - 10 else !speed; 130 | window##clearInterval (!ticker); 131 | start_game () 132 | end; 133 | 134 | for i = (snake_cells##length - 1) downto 1 do 135 | let value = 136 | match Js.Optdef.to_option (Js.array_get snake_cells (i - 1)) with 137 | | None -> assert false 138 | | Some t -> t in 139 | Js.array_set snake_cells i value 140 | done; 141 | 142 | Js.array_set snake_cells 0 (!snake_new_head); 143 | snake_head := !snake_new_head; 144 | render_snake () 145 | end 146 | end 147 | 148 | let get_new_direction keyCode = 149 | let codes = function 150 | | 37 -> "left" 151 | | 38 -> "up" 152 | | 39 -> "right" 153 | | 40 -> "down" 154 | | _ -> "" in 155 | let new_direction = codes keyCode and 156 | change_direction = ref true in 157 | let () = 158 | match !direction with 159 | | "left" -> 160 | change_direction := new_direction <> "right" 161 | | "up" -> 162 | change_direction := new_direction <> "down" 163 | | "right" -> 164 | change_direction := new_direction <> "left" 165 | | "down" -> 166 | change_direction := new_direction <> "up" 167 | | _ -> () in 168 | direction := if !change_direction then new_direction else !direction 169 | 170 | let render_board () = 171 | let rowhtml = ref "" in 172 | for i = 0 to size do 173 | rowhtml := !rowhtml ^ "" 174 | done; 175 | let html = jsnew Js.array_empty () in 176 | for i = 0 to size do 177 | ignore (html##push (_s ("" ^ !rowhtml ^""))) 178 | done; 179 | ignore ((jQ "body")##append ((_s "")##concat_2 (html##join (_s "\n"), _s "
"))); 180 | get_fruit_cell () 181 | 182 | 183 | let main () = 184 | (jQ "document")##ready (Js.wrap_callback (fun _ -> 185 | render_board (); 186 | render_fruit_cell (); 187 | Html.document##onkeydown <- 188 | (Html.handler (fun e -> get_new_direction (e##keyCode); Js._true)); 189 | start_game ())) 190 | 191 | let _ = 192 | main () 193 | 194 | 195 | 196 | 197 | 198 | -------------------------------------------------------------------------------- /jQuery.ml: -------------------------------------------------------------------------------- 1 | (* 2 | * JQuery binding for Js_of_ocaml - 2011-2012 3 | * jQuery module 4 | * 5 | * 2011 Gabriel Cardoso - gcardoso.w@gmail.com 6 | * 2012 Cagdas Bozman - cagdas.bozman@ocamlpro.com 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation, with linking exception; 11 | * either version 2.1 of the License, or (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21 | *) 22 | 23 | open Js 24 | open Effects 25 | 26 | class type jQuery = object 27 | method add : js_string t -> jQuery t meth 28 | method add_element : #Dom_html.element t -> jQuery t meth 29 | method add_jquery : jQuery t -> jQuery t meth 30 | method addClass : js_string t -> jQuery t meth 31 | method addClass_ : (int -> js_string t -> js_string t) callback 32 | -> jQuery t meth 33 | method after : (js_string t, #Dom_html.element t, jQuery t) Tools.Choice3.t 34 | -> jQuery t meth 35 | method after_fun : 36 | (int -> (js_string t, #Dom_html.element t, jQuery t) Tools.Choice3.t) 37 | -> jQuery t meth 38 | method ajaxComplete : 39 | (#Dom_html.event t -> #XmlHttpRequest.xmlHttpRequest t -> 'a) callback 40 | -> jQuery t meth 41 | method animate : Dom_html.cssStyleDeclaration t -> duration_pre opt 42 | -> easing_pre opt -> ('a, 'b) meth_callback opt -> jQuery t meth 43 | method append : js_string t -> jQuery t meth 44 | method appendTo : js_string t -> jQuery t meth 45 | method appendTo_jquery : jQuery t -> jQuery t meth 46 | method attr : js_string t -> js_string t optdef meth 47 | method attr_set : js_string t -> js_string t -> jQuery t meth 48 | method before : (js_string t, #Dom_html.element t, jQuery t) Tools.Choice3.t 49 | -> jQuery t meth 50 | method bind : js_string t -> ('a, 'b) meth_callback opt -> jQuery t meth 51 | method blur : ('a, 'b) meth_callback opt -> jQuery t meth 52 | method change : ('a, 'b) meth_callback opt -> jQuery t meth 53 | method clearQueue : js_string t opt -> jQuery t meth 54 | method click : ('a, 'b) meth_callback opt -> jQuery t meth 55 | method css_get : js_string t -> js_string t meth 56 | method css : js_string t -> js_string t -> jQuery t meth 57 | method delay : int -> js_string t opt -> jQuery t meth 58 | method dequeue : js_string t opt -> jQuery t meth 59 | method each : (int -> #Dom_html.element t -> 'a) callback -> jQuery t meth 60 | method eq : int -> jQuery t meth 61 | method fadeIn : duration_pre opt -> easing_pre opt -> ('a, 'b) meth_callback opt 62 | -> jQuery t meth 63 | method fadeOut : duration_pre opt -> easing_pre opt -> ('a, 'b) meth_callback opt 64 | -> jQuery t meth 65 | method fadeTo : duration_pre opt -> easing_pre opt -> ('a, 'b) meth_callback opt 66 | -> jQuery t meth 67 | method fadeToggle : duration_pre opt -> easing_pre opt -> ('a, 'b) meth_callback opt 68 | -> jQuery t meth 69 | method find : jQuery t -> jQuery t meth 70 | method focus : ('a, 'b) meth_callback opt -> jQuery t meth 71 | method has : js_string t -> jQuery t meth 72 | method hasClass : js_string t -> bool t meth 73 | method height : int meth 74 | method height_set : int -> jQuery t meth 75 | method hide : duration_pre opt -> easing_pre opt -> ('a, 'b) meth_callback opt 76 | -> jQuery t meth 77 | method hover : ('a, 'b) meth_callback -> ('a, 'b) meth_callback opt -> jQuery t meth 78 | method html : js_string t meth 79 | method html_set : js_string t -> jQuery t meth 80 | method insertAfter : (js_string t, #Dom_html.element t, jQuery t) 81 | Tools.Choice3.t -> jQuery t meth 82 | method insertBefore : (js_string t, #Dom_html.element t, jQuery t) 83 | Tools.Choice3.t -> jQuery t meth 84 | method length : int readonly_prop 85 | method live : 'a Dom.Event.typ-> ('a, 'b) meth_callback -> jQuery t meth 86 | method prepend : js_string t -> unit meth 87 | method queue : js_string t opt -> js_string t js_array t meth 88 | method ready : ('a, 'b) meth_callback -> jQuery t meth 89 | method remove : unit meth 90 | method removeClass : js_string t opt -> jQuery t meth 91 | method removeClass_ : (int -> js_string t -> js_string t) callback 92 | -> jQuery t meth 93 | method select : ('a, 'b) meth_callback opt -> jQuery t meth 94 | method serialize : unit -> js_string meth 95 | method show : duration_pre opt -> easing_pre opt -> ('a, 'b) meth_callback opt 96 | -> jQuery t meth 97 | method size : int meth 98 | method slideDown : duration_pre opt -> easing_pre opt -> ('a, 'b) meth_callback opt 99 | -> jQuery t meth 100 | method slideToggle : duration_pre opt -> easing_pre opt -> ('a, 'b) meth_callback opt 101 | -> jQuery t meth 102 | method slideUp : duration_pre opt -> easing_pre opt -> ('a, 'b) meth_callback opt 103 | -> jQuery t meth 104 | method stop : bool t opt -> bool t opt -> jQuery t meth 105 | method submit : ('a, 'b) meth_callback opt -> jQuery t meth 106 | method toggle : bool t -> jQuery t meth 107 | method toggle_ : duration_pre opt -> easing_pre opt -> ('a, 'b) meth_callback opt 108 | -> jQuery t meth 109 | method toggleClass : js_string t -> jQuery t meth 110 | method text : js_string t meth 111 | method text_set : js_string t -> jQuery t meth 112 | method unbind : js_string t -> jQuery t meth 113 | method val_ : string_array t meth 114 | method val_set : js_string t -> jQuery t meth 115 | method width : int meth 116 | method width_set : int -> jQuery t meth 117 | method tableFilter : unit meth 118 | method tableFilterApplyFilterValues : unit meth 119 | 120 | 121 | (* TODO : implement the right types for these methods c.f. jQuery API 122 | method ajaxError 123 | method ajaxSend 124 | method ajaxStart 125 | method ajaxStop 126 | method ajaxSuccess 127 | method andSelf 128 | method change 129 | method children 130 | method click 131 | method clone 132 | method closest 133 | method contents 134 | method context 135 | method data 136 | method dblclick 137 | method delegate 138 | method die 139 | method each 140 | method empty 141 | method end_ 142 | method error 143 | method filter 144 | method first 145 | method focusin 146 | method focusout 147 | method get 148 | method has 149 | method hasClass 150 | method height 151 | method hover 152 | method index 153 | method innerHeight 154 | method innerWidth 155 | method is 156 | method jquery 157 | method keydown 158 | method keypress 159 | method keyup 160 | method last 161 | method live 162 | method load 163 | method load 164 | method map 165 | method mousedown 166 | method mouseenter 167 | method mouseleave 168 | method mousemove 169 | method mouseout 170 | method mouseover 171 | method mouseup 172 | method next 173 | method nextAll 174 | method nextUntil 175 | method not 176 | method offset 177 | method offsetParent 178 | method one 179 | method outerHeight 180 | method outerWidth 181 | method parent 182 | method parents 183 | method parentsUntil 184 | method position 185 | method prependTo 186 | method prev 187 | method prevAll 188 | method prevUntil 189 | method promise 190 | method prop 191 | method pushStack 192 | method ready 193 | method removeAttr 194 | method removeData 195 | method removeProp 196 | method replaceAll 197 | method replaceWith 198 | method resize 199 | method scroll 200 | method scrollLeft 201 | method scrollTop 202 | method serializeArray 203 | method siblings 204 | method size 205 | method slice 206 | method toArray 207 | method trigger 208 | method triggerHandler 209 | method undelegate 210 | method unload 211 | method unwrap 212 | method width 213 | method wrap 214 | method wrapAll 215 | method wrapInner*) 216 | end 217 | 218 | let jQ s = Unsafe.fun_call 219 | (Unsafe.variable "jQuery") [|Unsafe.inject (Js.string s)|] 220 | 221 | let jQuery 222 | (selector : (js_string t, 223 | #Dom_html.element t, 224 | #Dom_html.element t js_array t, 225 | jQuery t) Tools.Choice4.t) 226 | (context_opt : (#Dom_html.element t, 227 | #Dom_html.document, 228 | jQuery t) Tools.Choice3.t opt) : jQuery t = 229 | Unsafe.fun_call 230 | (Unsafe.variable "jQuery") 231 | [|Unsafe.inject selector; Unsafe.inject context_opt|] 232 | 233 | let ajax : js_string t -> unit = Unsafe.variable "jQuery.ajax" 234 | (* TODO implement these values as in the jQuery API *) 235 | (*let ajaxPrefilter = Unsafe.variable "jQuery.ajaxPrefilter" 236 | let ajaxSetup = Unsafe.variable "jQuery.ajaxSetup" 237 | let boxModel = Unsafe.variable "jQuery.boxModel" 238 | let browser = Unsafe.variable "jQuery.browser" 239 | module Deferred = struct 240 | let always = Unsafe.variable "jQuery.deferred.always" 241 | let done_ = Unsafe.variable "jQuery.deferred.done" 242 | let fail = Unsafe.variable "jQuery.deferred.fail" 243 | let isRejected = Unsafe.variable "jQuery.deferred.isRejected" 244 | let isResolved = Unsafe.variable "jQuery.deferred.isResolved" 245 | let pipe = Unsafe.variable "jQuery.deferred.pipe" 246 | let promise = Unsafe.variable "jQuery.deferred.promise" 247 | let reject = Unsafe.variable "jQuery.deferred.reject" 248 | let rejectWith = Unsafe.variable "jQuery.deferred.rejectWith" 249 | let resolve = Unsafe.variable "jQuery.deferred.resolve" 250 | let resolveWith = Unsafe.variable "jQuery.deferred.resolveWith" 251 | let then_ = Unsafe.variable "jQuery.deferred.then" 252 | end 253 | let dequeue = Unsafe.variable "jQuery.browser" 254 | let each = Unsafe.variable "jQuery.each" 255 | let error = Unsafe.variable "jQuery.error" 256 | module Event = struct 257 | let currentTarget = Unsafe.variable "jQuery.event.currentTarget" 258 | let data = Unsafe.variable "jQuery.event.data" 259 | let isDefaultPrevented = Unsafe.variable "jQuery.event.isDefaultPrevented" 260 | let preventDefault = Unsafe.variable "jQuery.event.preventDefault" 261 | let isImmediatePropagationStopped = 262 | Unsafe.variable "jQuery.event.isImmediatePropagationStopped" 263 | let stopImmediatePropagation = 264 | Unsafe.variable "jQuery.event.stopImmediatePropagation" 265 | let isPropagationStopped = 266 | Unsafe.variable "jQuery.event.isPropagationStopped" 267 | let stopPropagation = Unsafe.variable "jQuery.event.stopPropagation" 268 | let namespace = Unsafe.variable "jQuery.event.namespace" 269 | let pageX = Unsafe.variable "jQuery.event.pageX" 270 | let pageY = Unsafe.variable "jQuery.event.pageY" 271 | let preventDefault = Unsafe.variable "jQuery.event.preventDefault" 272 | let relatedTarget = Unsafe.variable "jQuery.event.relatedTarget" 273 | let result = Unsafe.variable "jQuery.event.result" 274 | let stopImmediatePropagation = 275 | Unsafe.variable "jQuery.event.stopImmediatePropagation" 276 | let stopPropagation = Unsafe.variable "jQuery.event.stopPropagation" 277 | let target = Unsafe.variable "jQuery.event.target" 278 | let timeStamp = Unsafe.variable "jQuery.event.timeStamp" 279 | let type_ = Unsafe.variable "jQuery.event.type" 280 | let which = Unsafe.variable "jQuery.event.which" 281 | end 282 | let extend = Unsafe.variable "jQuery.extend" 283 | module Fx = struct 284 | let interval = Unsafe.variable "jQuery.fx.interval" 285 | let off = Unsafe.variable "jQuery.fx.off" 286 | end 287 | let get = Unsafe.variable "jQuery.get" 288 | let getJSON = Unsafe.variable "jQuery.getJSON" 289 | let getScript = Unsafe.variable "jQuery.getScript" 290 | let globalEval = Unsafe.variable "jQuery.globalEval" 291 | let grep = Unsafe.variable "jQuery.grep" 292 | let hasData = Unsafe.variable "jQuery.hasData" 293 | let holdReady = Unsafe.variable "jQuery.holdReady" 294 | let inArray = Unsafe.variable "jQuery.inArray" 295 | let isArray = Unsafe.variable "jQuery.isArray" 296 | let isEmptyObject = Unsafe.variable "jQuery.isEmptyObject" 297 | let isFunction = Unsafe.variable "jQuery.isFunction" 298 | let isPlainObject = Unsafe.variable "jQuery.isPlainObject" 299 | let isWindow = Unsafe.variable "jQuery.isWindow" 300 | let isXMLDoc = Unsafe.variable "jQuery.isXMLDoc" 301 | let makeArray = Unsafe.variable "jQuery.makeArray" 302 | let map = Unsafe.variable "jQuery.map" 303 | let merge = Unsafe.variable "jQuery.merge" 304 | let noConflict = Unsafe.variable "jQuery.noConflict" 305 | let noop = Unsafe.variable "jQuery.noop" 306 | let now = Unsafe.variable "jQuery.now"*) 307 | let param : Unsafe.any t -> bool t opt -> js_string t = 308 | Unsafe.variable "jQuery.param" 309 | (*let parseJSON = Unsafe.variable "jQuery.parseJSON" 310 | let parseXML = Unsafe.variable "jQuery.parseXML" 311 | let post = Unsafe.variable "jQuery.post" 312 | let proxy = Unsafe.variable "jQuery.proxy" 313 | let queue = Unsafe.variable "jQuery.queue" 314 | let removeData = Unsafe.variable "jQuery.removeData" 315 | let sub = Unsafe.variable "jQuery.sub" 316 | let suppo = Unsafe.variable "jQuery.suppo" 317 | let trim = Unsafe.variable "jQuery.trim" 318 | let type_ = Unsafe.variable "jQuery.type" 319 | let unique = Unsafe.variable "jQuery.unique" 320 | let when_ = Unsafe.variable "jQuery.when" 321 | *) 322 | --------------------------------------------------------------------------------