Created
June 29, 2012 19:53
-
-
Save kolmodin/3020266 to your computer and use it in GitHub Desktop.
Looking for idiomatic version of something like this
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; part of my 100 first lines of clojure/clojurescript | |
;; not finished... not working. | |
(defn withHints [editor hints] | |
(defn insert [str] (.replaceRange editor str (.-from result) (.-to result))) | |
(let [completions (.-list hints)] | |
(cond | |
(= 1 (.-length completions)) (insert (first completions))) | |
(let [complete (.createElement js/document "div") | |
pos (.cursorCoords editor)] | |
(set! (.-class complete) "goog-menu") | |
(set! (.-id complete) "menu") | |
(set! (-> complete .-style .-left) (str (.-x pos) "px")) | |
(set! (-> complete .-style .-top) (str (.-yBot pos) "px")) | |
(set! (-> complete .-style .-position) "absolute") | |
(doseq [i completions] | |
(let [e (.createElement js/document "div")] | |
(set! (.-innerHTML e) (str i)) | |
(set! (.-class e) "goog-menuitem") | |
(set! (-> e .-style .-color) "red") | |
(.appendChild complete e) | |
) | |
) | |
(.appendChild (.-body js/document) complete) | |
(let [m (js/goog.ui.Menu. )] | |
(.decorate m complete)) | |
) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment