This commit is contained in:
Swrup 2022-02-18 01:37:25 +01:00
parent 812133d0ad
commit 30ea27d40a
8 changed files with 132 additions and 143 deletions

View file

@ -91,8 +91,7 @@ module Leaflet = struct
let () =
log "add on (move/zoom)end event@.";
ignore @@ Jv.call map "on" [| Jv.of_string "moveend"; Jv.repr on_moveend |];
ignore @@ Jv.call map "on" [| Jv.of_string "zoomend"; Jv.repr on_zoomend |];
()
ignore @@ Jv.call map "on" [| Jv.of_string "zoomend"; Jv.repr on_zoomend |]
end
module Geolocalize = struct
@ -106,14 +105,12 @@ module Geolocalize = struct
let latlng =
Jv.call Leaflet.leaflet "latLng" [| Jv.of_float lat; Jv.of_float lng |]
in
ignore @@ Jv.call Leaflet.map "setView" [| latlng; Jv.of_int 13 |];
()
ignore @@ Jv.call Leaflet.map "setView" [| latlng; Jv.of_int 13 |]
let geolocalize () =
log "geolocalize@.";
let l = Brr_io.Geolocation.of_navigator Brr.G.navigator in
ignore @@ Fut.await (Brr_io.Geolocation.get l) update_location;
()
ignore @@ Fut.await (Brr_io.Geolocation.get l) update_location
let () = Jv.set Jv.global "geolocalize" (Jv.repr geolocalize)
end
@ -141,8 +138,7 @@ module Marker = struct
@@ Jv.call layer "on"
[| Jv.of_string "click"
; Jv.repr (marker_on_click thread_preview thread_id)
|];
()
|]
let handle_geojson geojson =
log "handle_geojson@.";
@ -162,14 +158,12 @@ module Marker = struct
let markers_handle_response response =
log "markers_handle_response@.";
let geo_json_list_futur = Jv.call response "json" [||] in
ignore @@ Jv.call geo_json_list_futur "then" [| Jv.repr handle_geojson |];
()
ignore @@ Jv.call geo_json_list_futur "then" [| Jv.repr handle_geojson |]
let () =
log "fetch thread geojson@.";
let window = Jv.get Jv.global "window" in
let link = Jv.of_string "/babillard/markers" in
let fetchfutur = Jv.call window "fetch" [| link |] in
ignore @@ Jv.call fetchfutur "then" [| Jv.repr markers_handle_response |];
()
ignore @@ Jv.call fetchfutur "then" [| Jv.repr markers_handle_response |]
end

View file

@ -27,8 +27,7 @@ let on_click e =
let newthread_div = Jv.get Jv.global "newthread" in
ignore
@@ Jv.call newthread_div "setAttribute"
[| Jv.of_string "style"; Jv.of_string "visibility:hidden" |];
()
[| Jv.of_string "style"; Jv.of_string "visibility:hidden" |]
(*add on_click callback to map*)
let () =

View file

@ -4,37 +4,34 @@ let log = Format.printf
(* insert id into reply form *)
let insert_quote post_id =
log "quote@.";
match Jv.(find global "replyComment") with
| None -> Jv.undefined
| Some comment_textarea ->
let content = Jv.get comment_textarea "value" in
let new_content =
Jv.call content "concat"
[| Jv.of_string "\n>>"; post_id; Jv.of_string " " |]
in
ignore @@ Jv.set comment_textarea "value" new_content;
Jv.undefined
Option.iter
(fun comment_textarea ->
let content = Jv.get comment_textarea "value" in
let new_content =
Jv.call content "concat"
[| Jv.of_string "\n>>"; post_id; Jv.of_string " " |]
in
ignore @@ Jv.set comment_textarea "value" new_content )
Jv.(find global "replyComment");
Jv.undefined
let () = Jv.set Jv.global "insert_quote" (Jv.repr insert_quote)
(* make image description field visible when a file is selected*)
let make_visible el _event =
let el_style = Jv.get el "style" in
ignore @@ Jv.set el_style "display" (Jv.of_string "block");
()
ignore @@ Jv.set el_style "display" (Jv.of_string "block")
let () =
log "change image description visibility@.";
let file_input = Jv.find Jv.global "file" in
match file_input with
| None -> () (*not post form on the page, not logged in*)
| Some file_input ->
let alt_input = Jv.get Jv.global "alt" in
let alt_label = Jv.get Jv.global "altLabel" in
ignore
@@ Jv.call file_input "addEventListener"
[| Jv.of_string "change"; Jv.repr (make_visible alt_input) |];
ignore
@@ Jv.call file_input "addEventListener"
[| Jv.of_string "change"; Jv.repr (make_visible alt_label) |];
()
Option.iter
(fun file_input ->
let alt_input = Jv.get Jv.global "alt" in
let alt_label = Jv.get Jv.global "altLabel" in
ignore
@@ Jv.call file_input "addEventListener"
[| Jv.of_string "change"; Jv.repr (make_visible alt_input) |];
ignore
@@ Jv.call file_input "addEventListener"
[| Jv.of_string "change"; Jv.repr (make_visible alt_label) |] )
Jv.(find global "file")

View file

@ -1,5 +1,18 @@
let log = Format.printf
type image_size =
| Big
| Small
let of_string = function
| "postImage" -> Some Small
| "postImageBig" -> Some Big
| _ -> None
let to_string = function
| Small -> "postImage"
| Big -> "postImageBig"
(*change postImage class to make it bigger/smaller on click*)
let image_click post_image event =
log "image_click@.";
@ -7,17 +20,19 @@ let image_click post_image event =
Jv.to_string @@ Jv.call post_image "getAttribute" [| Jv.of_string "class" |]
in
let new_class =
match current_class with
| "postImage" -> "postImageBig"
| "postImageBig" -> "postImage"
| _ -> failwith "invalid image class name"
match of_string current_class with
| Some image_size ->
to_string
( match image_size with
| Big -> Small
| Small -> Big )
| None -> failwith "invalid image class name"
in
ignore
@@ Jv.call post_image "setAttribute"
[| Jv.of_string "class"; Jv.of_string new_class |];
(*prevent opening image in new tab*)
ignore @@ Jv.call event "preventDefault" [||];
()
ignore @@ Jv.call event "preventDefault" [||]
let render_time date_span =
log "render time@.";
@ -39,8 +54,7 @@ let render_time date_span =
let date_string =
Format.sprintf "%02d-%02d-%02d %02d:%02d" year month day hour min
in
ignore @@ Jv.set date_span "innerHTML" (Jv.of_string date_string);
()
ignore @@ Jv.set date_span "innerHTML" (Jv.of_string date_string)
let make_pretty _ =
log "make pretty@.";
@ -71,5 +85,4 @@ let () =
let window = Jv.get Jv.global "window" in
ignore
@@ Jv.call window "addEventListener"
[| Jv.of_string "load"; Jv.repr make_pretty |];
()
[| Jv.of_string "load"; Jv.repr make_pretty |]