Last active
December 14, 2015 12:28
-
-
Save arthuredelstein/5086009 to your computer and use it in GitHub Desktop.
User choosers a folder; browser reads files (in cljs)
This file contains 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
;; uses hiccups/render-html | |
(defn new-window-document [] | |
(.. js/window open -document)) | |
(defn folder-chooser [id] | |
[:input {:id id | |
:type "file" | |
:webkitdirectory "" | |
:mozdirectory "" | |
:directory ""}]) | |
(defn page-html [] | |
(render-html [:html [:head [:title "Multiple files"]] | |
[:body [:p (folder-chooser "file_input")]]])) | |
(defn create-page [] | |
(doto (new-window-document) | |
(.writeln (page-html)))) | |
(defn respond-to-folder-choice [input callback] | |
(.addEventListener input "change" | |
#(-> % .-target .-files callback) false)) | |
(defn show-page [callback] | |
(let [doc (create-page)] | |
(respond-to-folder-choice (.getElementById doc "file_input") | |
callback))) | |
(defn print-files [file-list] | |
(dotimes [i (.-length file-list)] | |
(println (-> file-list (.item i) .-name)))) | |
(defn run-experiment [] | |
(show-page print-files)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment