fix
This commit is contained in:
parent
dec7d3f7fe
commit
277f0edad0
8 changed files with 88 additions and 86 deletions
|
|
@ -2,63 +2,70 @@ open Js_map
|
|||
include Js_post_form
|
||||
|
||||
module Visibility = struct
|
||||
let is_in_new_thread_mode () =
|
||||
log "is_in_new_thread_mode?@\n";
|
||||
let new_thread_div = Jv.get Jv.global "new-thread" in
|
||||
let class_list = Jv.get new_thread_div "classList" in
|
||||
Jv.to_bool @@ Jv.call class_list "contains" [| Jv.of_string "on" |]
|
||||
let new_thread_div = Jv.get Jv.global "new-thread"
|
||||
|
||||
let set visible el =
|
||||
log "set (un)visible@\n";
|
||||
let thread_preview_div = Jv.get Jv.global "thread-preview"
|
||||
|
||||
let return_button = Jv.get Jv.global "return-button"
|
||||
|
||||
(* new-thread-button is new-thread-button-redirect if not logged in *)
|
||||
let new_thread_button = Jv.find Jv.global "new-thread-button"
|
||||
|
||||
let is_in_new_thread_mode = ref false
|
||||
|
||||
let set_visible el =
|
||||
log "set_visible@\n";
|
||||
let class_list = Jv.get el "classList" in
|
||||
if visible then
|
||||
ignore
|
||||
@@ Jv.call class_list "replace"
|
||||
[| Jv.of_string "off"; Jv.of_string "on" |]
|
||||
else
|
||||
ignore
|
||||
@@ Jv.call class_list "replace"
|
||||
[| Jv.of_string "on"; Jv.of_string "off" |]
|
||||
ignore
|
||||
@@ Jv.call class_list "replace" [| Jv.of_string "off"; Jv.of_string "on" |]
|
||||
|
||||
let change_page_mode ~form_visibility _event =
|
||||
let set_invisible el =
|
||||
log "set_invisible@\n";
|
||||
let class_list = Jv.get el "classList" in
|
||||
ignore
|
||||
@@ Jv.call class_list "replace" [| Jv.of_string "on"; Jv.of_string "off" |]
|
||||
|
||||
let to_new_thread_mode _event =
|
||||
log "change_page_mode@\n";
|
||||
let new_thread_div = Jv.get Jv.global "new-thread" in
|
||||
let thread_preview_div = Jv.get Jv.global "thread-preview" in
|
||||
let new_thread_button = Jv.get Jv.global "new-thread-button" in
|
||||
let return_button = Jv.get Jv.global "return-button" in
|
||||
let () = set form_visibility new_thread_div in
|
||||
let () = set form_visibility return_button in
|
||||
let () = set (not form_visibility) thread_preview_div in
|
||||
let () = set (not form_visibility) new_thread_button in
|
||||
is_in_new_thread_mode := true;
|
||||
set_visible new_thread_div;
|
||||
set_visible return_button;
|
||||
set_invisible thread_preview_div;
|
||||
Option.iter set_invisible new_thread_button;
|
||||
ignore @@ Jv.call Leaflet.map "closePopup" [||]
|
||||
|
||||
let to_babillard_mode _event =
|
||||
log "change_page_mode@\n";
|
||||
is_in_new_thread_mode := false;
|
||||
set_invisible new_thread_div;
|
||||
set_invisible return_button;
|
||||
set_visible thread_preview_div;
|
||||
Option.iter set_visible new_thread_button;
|
||||
ignore @@ Jv.call Leaflet.map "closePopup" [||]
|
||||
|
||||
let () =
|
||||
log "add events on return/new thread button@\n";
|
||||
let return_button = Jv.get Jv.global "return-button" in
|
||||
ignore
|
||||
@@ Jv.call return_button "addEventListener"
|
||||
[| Jv.of_string "click"
|
||||
; Jv.repr (change_page_mode ~form_visibility:false)
|
||||
|];
|
||||
(* new-thread-button is new-thread-button-redirect if not logged in *)
|
||||
let opt = Jv.find Jv.global "new-thread-button" in
|
||||
if Option.is_some opt then
|
||||
let new_thread_button = Option.get opt in
|
||||
ignore
|
||||
@@ Jv.call new_thread_button "addEventListener"
|
||||
[| Jv.of_string "click"
|
||||
; Jv.repr (change_page_mode ~form_visibility:true)
|
||||
|]
|
||||
[| Jv.of_string "click"; Jv.repr to_babillard_mode |];
|
||||
Option.iter
|
||||
(fun button ->
|
||||
ignore
|
||||
@@ Jv.call button "addEventListener"
|
||||
[| Jv.of_string "click"; Jv.repr to_new_thread_mode |] )
|
||||
new_thread_button
|
||||
end
|
||||
|
||||
module Marker = struct
|
||||
let window = Jv.get Jv.global "window"
|
||||
|
||||
let thread_preview_div = Jv.get Jv.global "thread-preview"
|
||||
|
||||
let marker_on_click thread_preview _e =
|
||||
log "marker_on_click@\n";
|
||||
if not (Visibility.is_in_new_thread_mode ()) then (
|
||||
let thread_preview_div = Jv.get Jv.global "thread-preview" in
|
||||
if not !Visibility.is_in_new_thread_mode then
|
||||
ignore @@ Jv.set thread_preview_div "innerHTML" thread_preview;
|
||||
let _ = Js_pretty_post.make_pretty () in
|
||||
() )
|
||||
Js_pretty_post.make_pretty ()
|
||||
|
||||
let on_each_feature feature layer =
|
||||
log "on_each_feature@\n";
|
||||
|
|
@ -70,8 +77,6 @@ module Marker = struct
|
|||
|
||||
let handle_geojson geojson =
|
||||
log "handle_geojson@\n";
|
||||
log "feed geojson to leaflet@\n";
|
||||
(* make markers unresponsive on*)
|
||||
let dict = Jv.obj [| ("onEachFeature", Jv.repr on_each_feature) |] in
|
||||
let layer = Jv.call Leaflet.leaflet "geoJSON" [| geojson; dict |] in
|
||||
let _marker_layer = Jv.call layer "addTo" [| Leaflet.map |] in
|
||||
|
|
@ -84,16 +89,21 @@ module Marker = struct
|
|||
|
||||
let () =
|
||||
log "fetch thread geojson@\n";
|
||||
let window = Jv.get Jv.global "window" in
|
||||
let link = Jv.of_string "/markers" in
|
||||
let fetchfutur = Jv.call window "fetch" [| link |] in
|
||||
ignore @@ Jv.call fetchfutur "then" [| Jv.repr markers_handle_response |]
|
||||
end
|
||||
|
||||
let lat_input = Jv.get Jv.global "lat-input"
|
||||
|
||||
let lng_input = Jv.get Jv.global "lng-input"
|
||||
|
||||
let button = Jv.get Jv.global "submit-new-thread-button"
|
||||
|
||||
(* set input lat/lng when clicked*)
|
||||
let on_click_set_latlng e =
|
||||
log "on_click_set_latlng@\n";
|
||||
if Visibility.is_in_new_thread_mode () then (
|
||||
if !Visibility.is_in_new_thread_mode then (
|
||||
let lat_lng = Jv.get e "latlng" in
|
||||
ignore @@ Jv.call Leaflet.popup "setLatLng" [| lat_lng |];
|
||||
ignore
|
||||
|
|
@ -103,13 +113,9 @@ let on_click_set_latlng e =
|
|||
|
||||
let lat = Jv.get lat_lng "lat" in
|
||||
let lng = Jv.get lat_lng "lng" in
|
||||
let lat_input = Jv.get Jv.global "lat-input" in
|
||||
let lng_input = Jv.get Jv.global "lng-input" in
|
||||
ignore @@ Jv.call lat_input "setAttribute" [| Jv.of_string "value"; lat |];
|
||||
ignore @@ Jv.call lng_input "setAttribute" [| Jv.of_string "value"; lng |];
|
||||
|
||||
log "on_click_set_latlng: disableb disabled@\n";
|
||||
let button = Jv.get Jv.global "submit-new-thread-button" in
|
||||
ignore @@ Jv.call button "removeAttribute" [| Jv.of_string "disabled" |] )
|
||||
|
||||
(*add on_click callback to map*)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue