2022-02-14 17:09:29 +01:00
|
|
|
let log = Format.printf
|
|
|
|
|
|
|
|
|
|
(* called by clicking post_id *)
|
|
|
|
|
(* insert id into reply form *)
|
2022-02-18 18:31:55 +01:00
|
|
|
let insert_quote post_id _event =
|
2022-02-14 17:09:29 +01:00
|
|
|
log "quote@.";
|
2022-02-18 01:37:25 +01:00
|
|
|
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 )
|
2022-02-18 20:17:24 +01:00
|
|
|
Jv.(find global "reply-comment");
|
2022-02-18 01:37:25 +01:00
|
|
|
Jv.undefined
|
2022-02-14 17:09:29 +01:00
|
|
|
|
2022-02-18 18:31:55 +01:00
|
|
|
let () =
|
|
|
|
|
log "add inser_quote event on post links@.";
|
|
|
|
|
let document = Jv.get Jv.global "document" in
|
|
|
|
|
let quote_links =
|
|
|
|
|
Jv.to_jv_list
|
2022-02-18 20:17:24 +01:00
|
|
|
@@ Jv.call document "getElementsByClassName" [| Jv.of_string "quote-link" |]
|
2022-02-18 18:31:55 +01:00
|
|
|
in
|
|
|
|
|
log "quote_links leng %d@." (List.length quote_links);
|
|
|
|
|
let add_click quote_link =
|
|
|
|
|
let post_id =
|
|
|
|
|
Jv.call quote_link "getAttribute" [| Jv.of_string "data-id" |]
|
|
|
|
|
in
|
|
|
|
|
ignore
|
|
|
|
|
@@ Jv.call quote_link "addEventListener"
|
|
|
|
|
[| Jv.of_string "click"; Jv.repr (insert_quote post_id) |]
|
|
|
|
|
in
|
|
|
|
|
List.iter add_click quote_links
|
2022-02-14 17:09:29 +01:00
|
|
|
|
|
|
|
|
(* make image description field visible when a file is selected*)
|
|
|
|
|
let make_visible el _event =
|
|
|
|
|
let el_style = Jv.get el "style" in
|
2022-02-18 01:37:25 +01:00
|
|
|
ignore @@ Jv.set el_style "display" (Jv.of_string "block")
|
2022-02-14 17:09:29 +01:00
|
|
|
|
|
|
|
|
let () =
|
|
|
|
|
log "change image description visibility@.";
|
2022-02-18 01:37:25 +01:00
|
|
|
Option.iter
|
|
|
|
|
(fun file_input ->
|
|
|
|
|
let alt_input = Jv.get Jv.global "alt" in
|
2022-02-18 20:17:24 +01:00
|
|
|
let alt_label = Jv.get Jv.global "alt-label" in
|
2022-02-18 01:37:25 +01:00
|
|
|
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")
|