geochan/src/js/js_post_form.ml

56 lines
1.8 KiB
OCaml
Raw Normal View History

let log = Format.printf
(* called by clicking post_id *)
2022-03-23 04:34:54 +01:00
(* insert emojid into reply form *)
let insert_quote emojid _event =
2022-02-19 00:59:01 +01:00
log "quote@\n";
2022-02-18 01:37:25 +01:00
Option.iter
2022-02-26 14:36:44 +01:00
(fun textarea ->
let content = Jv.to_string @@ Jv.get textarea "value" in
2022-02-18 01:37:25 +01:00
let new_content =
2022-02-26 14:36:44 +01:00
if String.ends_with ~suffix:"\n" content || String.length content = 0
2022-03-23 04:34:54 +01:00
then (* don't skip a line *)
Format.sprintf "%s[%s] " content emojid
else Format.sprintf "%s@\n[%s] " content emojid
2022-02-18 01:37:25 +01:00
in
2022-02-26 14:36:44 +01:00
ignore @@ Jv.set textarea "value" (Jv.of_string new_content) )
Jv.(find global "reply-comment")
2022-02-18 18:31:55 +01:00
let () =
2022-02-19 00:59:01 +01:00
log "add inser_quote event on post links@\n";
2022-02-18 18:31:55 +01:00
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
2022-02-19 00:59:01 +01:00
log "quote_links leng %d@\n" (List.length quote_links);
2022-02-18 18:31:55 +01:00
let add_click quote_link =
2022-03-23 04:34:54 +01:00
let emojid =
2022-02-26 14:36:44 +01:00
Jv.to_string
2022-03-23 04:34:54 +01:00
@@ Jv.call quote_link "getAttribute" [| Jv.of_string "data-emojid" |]
2022-02-18 18:31:55 +01:00
in
ignore
@@ Jv.call quote_link "addEventListener"
2022-03-23 04:34:54 +01:00
[| Jv.of_string "click"; Jv.repr (insert_quote emojid) |]
2022-02-18 18:31:55 +01:00
in
List.iter add_click quote_links
(* 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")
let () =
2022-02-19 00:59:01 +01:00
log "change image description visibility@\n";
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")