fix textarea not found
This commit is contained in:
parent
d090934183
commit
778a03ae88
2 changed files with 28 additions and 24 deletions
|
|
@ -7,32 +7,30 @@ 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"
|
||||
| None -> failwith "no data-emojid on element"
|
||||
| Some emojid -> Jstr.to_string emojid
|
||||
in
|
||||
let textarea = find_by_id "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
|
||||
El.set_prop inner_html (Jstr.of_string new_content) 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
|
||||
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 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
|
||||
El.set_prop inner_html (Jstr.of_string new_content) textarea;
|
||||
El.set_has_focus true textarea
|
||||
|
||||
(* 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";
|
||||
let add_events _load =
|
||||
log "add post_form events @\n";
|
||||
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 ->
|
||||
let alt_input = find_by_id "alt" in
|
||||
let alt_label = find_by_id "alt-label" in
|
||||
|
|
@ -43,4 +41,12 @@ let () =
|
|||
let (_ : Ev.listener) =
|
||||
Ev.listen change (make_visible alt_label) (El.as_target file_input)
|
||||
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
|
||||
()
|
||||
|
|
|
|||
|
|
@ -188,9 +188,8 @@ let make_pretty _event =
|
|||
let () = add_event_to_class Ev.mouseout "reply-link" on_mouse_out in
|
||||
|
||||
(* add fragment listener to mark as selected the linked post *)
|
||||
let hashchange = Ev.Type.create (Jstr.of_string "hashchange") in
|
||||
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
|
||||
(* call hashchange on page load too *)
|
||||
on_hashchange ()
|
||||
|
|
@ -198,8 +197,7 @@ let make_pretty _event =
|
|||
(*make pretty after page load*)
|
||||
let () =
|
||||
log "add load eventlistener to make pretty@\n";
|
||||
let load = Ev.Type.create (Jstr.of_string "load") in
|
||||
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
|
||||
()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue