diff --git a/index.html b/index.html deleted file mode 100644 index be9e687..0000000 --- a/index.html +++ /dev/null @@ -1,188 +0,0 @@ - - - - - OCaml toplevel - - - - - - - -
-

-      
-
- - -
-
-
-

OpLevel

-

A programming system based on a compiler from OCaml bytecode to Javascript.

-
- -

See the generated javascript code

-
-      
-
- - diff --git a/oplevel.ml b/oplevel.ml index e11a0a7..a98338b 100644 --- a/oplevel.ml +++ b/oplevel.ml @@ -15,7 +15,7 @@ let resize ~container ~textbox () = textbox##.style##.height := Js.string "auto"; textbox##.style##.height := Js.string (Printf.sprintf "%dpx" (max 18 textbox##.scrollHeight)); - container##.scrollTop := container##.scrollHeight; + (* container##.scrollTop := container##.scrollHeight; *) Lwt.return () let appendchild ~container html = @@ -37,7 +37,7 @@ let _ = [ txt "starting..." ]; ]); let textbox : 'a Js.t = - by_id_coerce "userinput" Dom_html.CoerceTo.textarea + by_id_coerce "code" Dom_html.CoerceTo.textarea in let rootrepo = Store.test_pull () in rootrepo >>= fun (_upstream, t) -> @@ -65,11 +65,11 @@ let _ = (* setup handlers *) textbox##.onkeyup := Dom_html.handler (fun _ -> - Lwt.async (resize ~container ~textbox); + (* Lwt.async (resize ~container ~textbox); *) Js._true); textbox##.onchange := Dom_html.handler (fun _ -> - Lwt.async (resize ~container ~textbox); + (* Lwt.async (resize ~container ~textbox); *) Js._true); textbox##.onkeydown := Dom_html.handler diff --git a/toplevel.ml b/toplevel.ml index 5bf36fd..e84d0e5 100644 --- a/toplevel.ml +++ b/toplevel.ml @@ -225,75 +225,13 @@ let rec iter_on_sharp ~f x = | None -> () | Some n -> iter_on_sharp ~f n -let setup_share_button ~output = - do_by_id "btn-share" (fun e -> +let setup_run_button ~execute = + do_by_id "btn-run" (fun e -> e##.style##.display := Js.string "block"; e##.onclick := Dom_html.handler (fun _ -> - (* get all ocaml code *) - let code = ref [] in - Js.Opt.iter output##.firstChild - (iter_on_sharp ~f:(fun e -> - code := - Js.Opt.case e##.textContent - (fun () -> "") - Js.to_string - :: !code)); - let code_encoded = - B64.encode (String.concat "" (List.rev !code)) - in - let url, is_file = - match Url.Current.get () with - | Some (Url.Http url) -> - (Url.Http { url with Url.hu_fragment = "" }, false) - | Some (Url.Https url) -> - (Url.Https { url with Url.hu_fragment = "" }, false) - | Some (Url.File url) -> - (Url.File { url with Url.fu_fragment = "" }, true) - | _ -> assert false - in - let frag = - let frags = parse_hash () in - let frags = - List.remove_assoc "code" frags - @ [ ("code", code_encoded) ] - in - Url.encode_arguments frags - in - let uri = Url.string_of_url url ^ "#" ^ frag in - let append_url str = - let dom = - Tyxml_js.Html.( - p - [ - txt "Share this url : "; - a ~a:[ a_href str ] [ txt str ]; - ]) - in - Dom.appendChild output (Tyxml_js.To_dom.of_element dom) - in - Lwt.async (fun () -> - Lwt.catch - (fun () -> - if is_file then - failwith "Cannot shorten url with file scheme" - else - let uri = - Printf.sprintf - "http://is.gd/create.php?format=json&url=%s" - (Url.urlencode uri) - in - Lwt.bind (Js_of_ocaml_lwt.Jsonp.call uri) - (fun o -> - let str = Js.to_string o##.shorturl in - append_url str; - Lwt.return_unit)) - (fun exn -> - Format.eprintf - "Could not generate short url. reason: %s@." - (Printexc.to_string exn); - append_url uri; - Lwt.return_unit)); + let textbox = by_id "code" in + execute (Js.to_string textbox##.innerText##trim); Js._false)) let setup_js_preview () = @@ -383,7 +321,7 @@ let run ~init ~output () : let container = by_id "toplevel-container" in let textbox : 'a Js.t = - by_id_coerce "userinput" Dom_html.CoerceTo.textarea + by_id_coerce "code" Dom_html.CoerceTo.textarea in let sharp_chan = open_out "/dev/null0" in let sharp_ppf = Format.formatter_of_out_channel sharp_chan in @@ -402,7 +340,6 @@ let run ~init ~output () : else content in current_position := output##.childNodes##.length; - textbox##.value := Js.string ""; History.push content; JsooTop.execute true ~pp_code ~highlight_location caml_ppf content'; @@ -443,7 +380,7 @@ let run ~init ~output () : (fun s -> Js.to_string s ^ "\n") in Sys_js.set_channel_filler stdin readline; - setup_share_button ~output; + setup_run_button ~execute; (* setup_examples ~container ~textbox; *) setup_pseudo_fs ~load_cmis_from_server:false; setup_toplevel ();