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 ignore
@@ Jv.call post_image "setAttribute" @@ Jv.call post_image "setAttribute"
[| Jv.of_string "class"; Jv.of_string new_class |]; [| Jv.of_string "class"; Jv.of_string new_class |];
(*prevent opening image in new tab*) (*prevent redirect to /img/:img*)
ignore @@ Jv.call event "preventDefault" [||] ignore @@ Jv.call event "preventDefault" [||];
ignore @@ Jv.call event "stopPropagation" [||]
let render_time date_span = let render_time date_span =
log "render time@\n"; log "render time@\n";
@ -43,6 +44,14 @@ let render_time date_span =
in in
ignore @@ Jv.set date_span "innerHTML" (Jv.of_string date) 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 = let make_pretty _event =
log "make pretty@\n"; log "make pretty@\n";
let document = Jv.get Jv.global "document" in 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) |] [| Jv.of_string "click"; Jv.repr (image_click el) |]
in in
List.iter add_click post_images; 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*) (*make pretty after page load*)
let () = let () =

View file

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