fix textarea not found

This commit is contained in:
Swrup 2022-04-19 00:54:36 +02:00
parent 4a5361c61a
commit a820fe1823
2 changed files with 28 additions and 24 deletions

View file

@ -7,10 +7,12 @@ let insert_quote el _event =
log "quote@\n"; log "quote@\n";
let emojid = let emojid =
match El.at (Jstr.of_string "data-emojid") el with match El.at (Jstr.of_string "data-emojid") el with
| None -> "no data-emojid on element" | None -> failwith "no data-emojid on element"
| Some emojid -> Jstr.to_string emojid | Some emojid -> Jstr.to_string emojid
in in
let textarea = find_by_id "comment" in match find_by_id_opt "comment" with
| None -> log "element `comment` not found, not logged in?@\n"
| Some textarea ->
let inner_html = El.Prop.jstr (Jstr.of_string "innerHTML") in let inner_html = El.Prop.jstr (Jstr.of_string "innerHTML") in
let content = Jstr.to_string @@ El.prop inner_html textarea in let content = Jstr.to_string @@ El.prop inner_html textarea in
let new_content = let new_content =
@ -22,17 +24,13 @@ let insert_quote el _event =
El.set_prop inner_html (Jstr.of_string new_content) textarea; El.set_prop inner_html (Jstr.of_string new_content) textarea;
El.set_has_focus true textarea El.set_has_focus true textarea
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*) (* 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 make_visible el _event = El.set_class (Jstr.of_string "off") false el
let () = let add_events _load =
log "add event to change image description visibility@\n"; log "add post_form events @\n";
match find_by_id_opt "file" with match find_by_id_opt "file" with
| None -> log "no file element found, not logged in?@\n" | None -> log "element `file` not found, not logged in?@\n"
| Some file_input -> | Some file_input ->
let alt_input = find_by_id "alt" in let alt_input = find_by_id "alt" in
let alt_label = find_by_id "alt-label" in let alt_label = find_by_id "alt-label" in
@ -43,4 +41,12 @@ let () =
let (_ : Ev.listener) = let (_ : Ev.listener) =
Ev.listen change (make_visible alt_label) (El.as_target file_input) Ev.listen change (make_visible alt_label) (El.as_target file_input)
in in
log "add inser_quote event on post links@\n";
add_event_to_class Ev.click "quote-link" insert_quote
(*make events after page load*)
let () =
let (_ : Ev.listener) =
Ev.listen Ev.load add_events (Window.as_target G.window)
in
() ()

View file

@ -188,9 +188,8 @@ let make_pretty _event =
let () = add_event_to_class Ev.mouseout "reply-link" on_mouse_out in let () = add_event_to_class Ev.mouseout "reply-link" on_mouse_out in
(* add fragment listener to mark as selected the linked post *) (* add fragment listener to mark as selected the linked post *)
let hashchange = Ev.Type.create (Jstr.of_string "hashchange") in
let (_ : Ev.listener) = let (_ : Ev.listener) =
Ev.listen hashchange on_hashchange (Window.as_target G.window) Ev.listen Ev.hashchange on_hashchange (Window.as_target G.window)
in in
(* call hashchange on page load too *) (* call hashchange on page load too *)
on_hashchange () on_hashchange ()
@ -198,8 +197,7 @@ let make_pretty _event =
(*make pretty after page load*) (*make pretty after page load*)
let () = let () =
log "add load eventlistener to make pretty@\n"; log "add load eventlistener to make pretty@\n";
let load = Ev.Type.create (Jstr.of_string "load") in
let (_ : Ev.listener) = let (_ : Ev.listener) =
Ev.listen load make_pretty (Window.as_target G.window) Ev.listen Ev.load make_pretty (Window.as_target G.window)
in in
() ()