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";
|
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
|
||||||
let inner_html = El.Prop.jstr (Jstr.of_string "innerHTML") in
|
| None -> log "element `comment` not found, not logged in?@\n"
|
||||||
let content = Jstr.to_string @@ El.prop inner_html textarea in
|
| Some textarea ->
|
||||||
let new_content =
|
let inner_html = El.Prop.jstr (Jstr.of_string "innerHTML") in
|
||||||
if String.ends_with ~suffix:"\n" content || String.length content = 0 then
|
let content = Jstr.to_string @@ El.prop inner_html textarea in
|
||||||
(* don't skip a line *)
|
let new_content =
|
||||||
Format.sprintf "%s[>%s] " content emojid
|
if String.ends_with ~suffix:"\n" content || String.length content = 0 then
|
||||||
else Format.sprintf "%s@\n[>%s] " content emojid
|
(* don't skip a line *)
|
||||||
in
|
Format.sprintf "%s[>%s] " content emojid
|
||||||
El.set_prop inner_html (Jstr.of_string new_content) textarea;
|
else Format.sprintf "%s@\n[>%s] " content emojid
|
||||||
El.set_has_focus true textarea
|
in
|
||||||
|
El.set_prop inner_html (Jstr.of_string new_content) textarea;
|
||||||
let () =
|
El.set_has_focus true textarea
|
||||||
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
|
||||||
|
()
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
()
|
()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue