fix insert_quote

This commit is contained in:
Swrup 2022-02-26 14:36:44 +01:00
parent 66839885ff
commit b863c719c3

View file

@ -5,15 +5,15 @@ let log = Format.printf
let insert_quote post_id _event = let insert_quote post_id _event =
log "quote@\n"; log "quote@\n";
Option.iter Option.iter
(fun comment_textarea -> (fun textarea ->
let content = Jv.get comment_textarea "value" in let content = Jv.to_string @@ Jv.get textarea "value" in
let new_content = let new_content =
Jv.call content "concat" if String.ends_with ~suffix:"\n" content || String.length content = 0
[| Jv.of_string "\n>>"; post_id; Jv.of_string " " |] then Format.sprintf "%s>>%s " content post_id
else Format.sprintf "%s\n>>%s " content post_id
in in
ignore @@ Jv.set comment_textarea "value" new_content ) ignore @@ Jv.set textarea "value" (Jv.of_string new_content) )
Jv.(find global "reply-comment"); Jv.(find global "reply-comment")
Jv.undefined
let () = let () =
log "add inser_quote event on post links@\n"; log "add inser_quote event on post links@\n";
@ -25,7 +25,8 @@ let () =
log "quote_links leng %d@\n" (List.length quote_links); log "quote_links leng %d@\n" (List.length quote_links);
let add_click quote_link = let add_click quote_link =
let post_id = let post_id =
Jv.call quote_link "getAttribute" [| Jv.of_string "data-id" |] Jv.to_string
@@ Jv.call quote_link "getAttribute" [| Jv.of_string "data-id" |]
in in
ignore ignore
@@ Jv.call quote_link "addEventListener" @@ Jv.call quote_link "addEventListener"