2022-04-18 03:11:31 +02:00
|
|
|
open Brr
|
|
|
|
|
open Utils
|
|
|
|
|
|
|
|
|
|
(* called by clicking post_id *)
|
|
|
|
|
(* insert emojid into reply form *)
|
|
|
|
|
let insert_quote el _event =
|
|
|
|
|
log "quote@\n";
|
|
|
|
|
let emojid =
|
|
|
|
|
match El.at (Jstr.of_string "data-emojid") el with
|
|
|
|
|
| None -> "no data-emojid on element"
|
|
|
|
|
| Some emojid -> Jstr.to_string emojid
|
|
|
|
|
in
|
|
|
|
|
let textarea = find_by_id "reply-comment" in
|
|
|
|
|
let inner_html = El.Prop.jstr (Jstr.of_string "innerHTML") in
|
|
|
|
|
let content = Jstr.to_string @@ El.prop inner_html textarea in
|
|
|
|
|
let new_content =
|
|
|
|
|
if String.ends_with ~suffix:"\n" content || String.length content = 0 then
|
|
|
|
|
(* don't skip a line *)
|
|
|
|
|
Format.sprintf "%s[>%s] " content emojid
|
|
|
|
|
else Format.sprintf "%s@\n[>%s] " content emojid
|
|
|
|
|
in
|
2022-04-18 03:21:56 +02:00
|
|
|
El.set_prop inner_html (Jstr.of_string new_content) textarea;
|
|
|
|
|
El.set_has_focus true textarea
|
2022-04-18 03:11:31 +02:00
|
|
|
|
|
|
|
|
let () =
|
|
|
|
|
log "add inser_quote event on post links@\n";
|
|
|
|
|
add_event_to_class Ev.click "quote-link" insert_quote
|
|
|
|
|
|
|
|
|
|
(* make image description field visible when a file is selected*)
|
|
|
|
|
let make_visible el _event = El.set_class (Jstr.of_string "off") false el
|
|
|
|
|
|
|
|
|
|
let () =
|
|
|
|
|
log "add event to change image description visibility@\n";
|
|
|
|
|
match find_by_id_opt "file" with
|
|
|
|
|
| None -> log "no file element found, not logged in?@\n"
|
|
|
|
|
| Some file_input ->
|
|
|
|
|
let alt_input = find_by_id "alt" in
|
|
|
|
|
let alt_label = find_by_id "alt-label" in
|
|
|
|
|
let change = Ev.Type.create (Jstr.of_string "change") in
|
|
|
|
|
let (_ : Ev.listener) =
|
|
|
|
|
Ev.listen change (make_visible alt_input) (El.as_target file_input)
|
|
|
|
|
in
|
|
|
|
|
let (_ : Ev.listener) =
|
|
|
|
|
Ev.listen change (make_visible alt_label) (El.as_target file_input)
|
|
|
|
|
in
|
|
|
|
|
()
|