click them all!

This commit is contained in:
Swrup 2022-02-21 04:11:25 +01:00
parent 05c997a409
commit d66f81ddad
2 changed files with 29 additions and 5 deletions

View file

@ -26,8 +26,9 @@ let image_click post_image event =
ignore
@@ Jv.call post_image "setAttribute"
[| Jv.of_string "class"; Jv.of_string new_class |];
(*prevent opening image in new tab*)
ignore @@ Jv.call event "preventDefault" [||]
(*prevent redirect to /img/:img*)
ignore @@ Jv.call event "preventDefault" [||];
ignore @@ Jv.call event "stopPropagation" [||]
let render_time date_span =
log "render time@\n";
@ -43,6 +44,14 @@ let render_time date_span =
in
ignore @@ Jv.set date_span "innerHTML" (Jv.of_string date)
(* make threads preview clickable to get to thread *)
let preview_click thread_id _event =
log "preview_click@\n";
let url = Format.sprintf "/thread/%s" thread_id in
let window = Jv.get Jv.global "window" in
let location = Jv.get window "location" in
ignore @@ Jv.set location "href" (Jv.of_string url)
let make_pretty _event =
log "make pretty@\n";
let document = Jv.get Jv.global "document" in
@ -64,7 +73,22 @@ let make_pretty _event =
[| Jv.of_string "click"; Jv.repr (image_click el) |]
in
List.iter add_click post_images;
()
log "make_pretty_catalog@\n";
let previews =
Jv.to_jv_list
@@ Jv.call document "getElementsByClassName"
[| Jv.of_string "thread-preview" |]
in
let add_preview_click el =
let thread_id =
Jv.to_string @@ Jv.call el "getAttribute" [| Jv.of_string "data-id" |]
in
ignore
@@ Jv.call el "addEventListener"
[| Jv.of_string "click"; Jv.repr (preview_click thread_id) |]
in
List.iter add_preview_click previews
(*make pretty after page load*)
let () =

View file

@ -127,11 +127,11 @@ let pp_thread_preview fmt op =
let thread_preview =
Format.fprintf fmt
{|
<div class="thread-preview">
<div class="thread-preview" data-id="%s" >
%a
</div>
|}
pp_post
post.id pp_post
(Op (thread_data, post))
in
thread_preview