add class; todo more brr
This commit is contained in:
parent
3b7dabd7f3
commit
efc8b2224b
2 changed files with 76 additions and 26 deletions
|
|
@ -43,6 +43,14 @@ blockquote.blockquote {
|
||||||
display: table;
|
display: table;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.post + .selected {
|
||||||
|
background-color: #9dd162;
|
||||||
|
margin: 5px 5px 5px 5px;
|
||||||
|
border: 2px solid #FFB300;
|
||||||
|
padding: 2px;
|
||||||
|
display: table;
|
||||||
|
}
|
||||||
|
|
||||||
.post-info {
|
.post-info {
|
||||||
display: block;
|
display: block;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
let log = Format.printf
|
let log = Format.printf
|
||||||
|
|
||||||
|
(* TODO do like in render_time everywhere *)
|
||||||
|
let inner_html = Brr.El.Prop.jstr (Jstr.of_string "innerHTML")
|
||||||
|
|
||||||
type image_size =
|
type image_size =
|
||||||
| Big
|
| Big
|
||||||
| Small
|
| Small
|
||||||
|
|
@ -45,21 +48,55 @@ let image_click post_image event =
|
||||||
|
|
||||||
let render_time date_span =
|
let render_time date_span =
|
||||||
log "render time@\n";
|
log "render time@\n";
|
||||||
let t =
|
let data_time =
|
||||||
Jv.to_float
|
match Brr.El.at (Jstr.of_string "data-time") date_span with
|
||||||
(Jv.call date_span "getAttribute" [| Jv.of_string "data-time" |])
|
| None -> failwith "no attribute data-time for date element"
|
||||||
|
| Some data_time -> Jstr.to_float data_time
|
||||||
in
|
in
|
||||||
let t = Unix.localtime t in
|
(*
|
||||||
|
let t =
|
||||||
|
Jv.to_float
|
||||||
|
(Jv.call date_span "getAttribute" [| Jv.of_string "data-time" |])
|
||||||
|
in
|
||||||
|
*)
|
||||||
|
let t = Unix.localtime data_time in
|
||||||
let date =
|
let date =
|
||||||
Format.sprintf "%02d-%02d-%02d %02d:%02d" (1900 + t.tm_year) (1 + t.tm_mon)
|
Format.sprintf "%02d-%02d-%02d %02d:%02d" (1900 + t.tm_year) (1 + t.tm_mon)
|
||||||
t.tm_mday t.tm_hour t.tm_min
|
t.tm_mday t.tm_hour t.tm_min
|
||||||
in
|
in
|
||||||
ignore @@ Jv.set date_span "innerHTML" (Jv.of_string date)
|
Brr.El.set_prop inner_html (Jstr.of_string date) date_span
|
||||||
|
|
||||||
let preview_ref = ref None
|
let preview_ref = ref None
|
||||||
|
|
||||||
let highlighted_ref = ref None
|
let highlighted_ref = ref None
|
||||||
|
|
||||||
|
let selected_ref = ref None
|
||||||
|
|
||||||
|
(* todo use brr *)
|
||||||
|
let add_class name el =
|
||||||
|
let class_list = Jv.get el "classList" in
|
||||||
|
ignore @@ Jv.call class_list "add" [| Jv.of_string name |]
|
||||||
|
|
||||||
|
let remove_class name el =
|
||||||
|
let class_list = Jv.get el "classList" in
|
||||||
|
ignore @@ Jv.call class_list "remove" [| Jv.of_string name |]
|
||||||
|
|
||||||
|
let on_hashchange _event =
|
||||||
|
log "on hashchange";
|
||||||
|
let frag =
|
||||||
|
Jstr.to_string @@ Brr.Uri.fragment @@ Brr.Window.location Brr.G.window
|
||||||
|
in
|
||||||
|
match Jv.find Jv.global frag with
|
||||||
|
| None -> log "fragment not found on the page"
|
||||||
|
| Some reply ->
|
||||||
|
let () =
|
||||||
|
match !selected_ref with
|
||||||
|
| None -> ()
|
||||||
|
| Some item -> remove_class "selected" item
|
||||||
|
in
|
||||||
|
let () = add_class "selected" reply in
|
||||||
|
selected_ref := Some reply
|
||||||
|
|
||||||
let on_mouse_over el _event =
|
let on_mouse_over el _event =
|
||||||
log "on mouse over@\n";
|
log "on mouse over@\n";
|
||||||
(*get id of reply *)
|
(*get id of reply *)
|
||||||
|
|
@ -134,31 +171,37 @@ let on_mouse_out _el _event =
|
||||||
let make_pretty _event =
|
let make_pretty _event =
|
||||||
log "make pretty@\n";
|
log "make pretty@\n";
|
||||||
|
|
||||||
let get_class name =
|
|
||||||
Jv.to_jv_list
|
|
||||||
@@ Jv.call document "getElementsByClassName" [| Jv.of_string name |]
|
|
||||||
in
|
|
||||||
|
|
||||||
let add_event_to_class ~name ~event handler =
|
let add_event_to_class ~name ~event handler =
|
||||||
(* TODO use brr? *)
|
(* TODO use brr? *)
|
||||||
let add_event el =
|
let event = Brr.Ev.Type.create (Jstr.of_string event) in
|
||||||
ignore
|
let el_list = Brr.El.find_by_class (Jstr.of_string name) in
|
||||||
@@ Jv.call el "addEventListener"
|
List.iter
|
||||||
[| Jv.of_string event; Jv.repr (handler el) |]
|
(fun el ->
|
||||||
|
(* TODO handler should take Brr.El. ? *)
|
||||||
|
Brr.Ev.listen event (handler el) (Brr.El.as_target el) )
|
||||||
|
el_list
|
||||||
|
in
|
||||||
|
|
||||||
|
let dates = Brr.El.find_by_class (Jstr.of_string "date") in
|
||||||
|
List.iter render_time dates;
|
||||||
|
|
||||||
|
(*(*add event image_click to all postImage*)
|
||||||
|
let () = add_event_to_class ~name:"post-image" ~event:"click" image_click in
|
||||||
|
|
||||||
|
(*add event mouse_over/out to all reply-link *)
|
||||||
|
let () =
|
||||||
|
add_event_to_class ~name:"reply-link" ~event:"mouseover" on_mouse_over
|
||||||
in
|
in
|
||||||
List.iter add_event (get_class name)
|
*)
|
||||||
in
|
|
||||||
|
|
||||||
List.iter render_time (get_class "date");
|
|
||||||
|
|
||||||
(*add event image_click to all postImage*)
|
|
||||||
let () = add_event_to_class ~name:"post-image" ~event:"click" image_click in
|
|
||||||
|
|
||||||
(*add event mouse_over/out to all reply-link *)
|
|
||||||
let () =
|
let () =
|
||||||
add_event_to_class ~name:"reply-link" ~event:"mouseover" on_mouse_over
|
add_event_to_class ~name:"reply-link" ~event:"mouseout" on_mouse_out
|
||||||
in
|
in
|
||||||
add_event_to_class ~name:"reply-link" ~event:"mouseout" on_mouse_out
|
|
||||||
|
(* add fragment listener to mark as selected the linked post *)
|
||||||
|
let window = Jv.get Jv.global "window" in
|
||||||
|
ignore
|
||||||
|
@@ Jv.call window "addEventListener"
|
||||||
|
[| Jv.of_string "hashchange"; Jv.repr on_hashchange |]
|
||||||
|
|
||||||
(*make pretty after page load*)
|
(*make pretty after page load*)
|
||||||
let () =
|
let () =
|
||||||
|
|
@ -168,7 +211,6 @@ let () =
|
||||||
@@ Jv.call window "addEventListener"
|
@@ Jv.call window "addEventListener"
|
||||||
[| Jv.of_string "load"; Jv.repr make_pretty |]
|
[| Jv.of_string "load"; Jv.repr make_pretty |]
|
||||||
|
|
||||||
(* TODO add event with Brr etc*)
|
|
||||||
(* TODO add a selected class for post clicked / in fragment *)
|
(* TODO add a selected class for post clicked / in fragment *)
|
||||||
(* see https://developer.mozilla.org/en-US/docs/Web/API/Window/hashchange_event *)
|
(* see https://developer.mozilla.org/en-US/docs/Web/API/Window/hashchange_event *)
|
||||||
(* TODO reply can be in another thread, how to display it? if displaying it on mouseover we need to fetch it. and display it in special color. need to change pp_post in pp_babillard *)
|
(* TODO reply can be in another thread, how to display it? if displaying it on mouseover we need to fetch it. and display it in special color. need to change pp_post in pp_babillard *)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue