diff options
author | Gabriel Giovanini <gabrielg.desouza@gmail.com> | 2019-06-23 20:57:07 +0200 |
---|---|---|
committer | Gabriel Giovanini <gabrielg.desouza@gmail.com> | 2019-06-23 20:57:07 +0200 |
commit | 8c716d495a5bf1d31c316da16635a32a291a34c0 (patch) | |
tree | 379b1b1697317d3a8191f7ff583f75d0a51fc6ec | |
parent | 000b0d243f454ee17f09fc99ad4bed3d879cff6b (diff) | |
download | genpass-8c716d495a5bf1d31c316da16635a32a291a34c0.tar.gz genpass-8c716d495a5bf1d31c316da16635a32a291a34c0.tar.bz2 genpass-8c716d495a5bf1d31c316da16635a32a291a34c0.zip |
Move from input to span
-rw-r--r-- | src/genpass/components/input.cljc | 5 | ||||
-rw-r--r-- | src/genpass/core.cljs | 17 |
2 files changed, 19 insertions, 3 deletions
diff --git a/src/genpass/components/input.cljc b/src/genpass/components/input.cljc index a5ae437..a4b8499 100644 --- a/src/genpass/components/input.cljc +++ b/src/genpass/components/input.cljc @@ -1,5 +1,6 @@ (ns genpass.components.input) + (defn input-primary ([text] (input-primary text #())) @@ -7,4 +8,6 @@ [:input.input.is-primary {:type "text" :value text - :on-click fn}]))
\ No newline at end of file + :on-click fn}])) + + diff --git a/src/genpass/core.cljs b/src/genpass/core.cljs index 5e17143..f6e1b68 100644 --- a/src/genpass/core.cljs +++ b/src/genpass/core.cljs @@ -8,14 +8,27 @@ (def size (r/atom 12)) (def password (r/atom (genpwd @size))) +(defn magic-selection-trick-took-from-so [e] + (let [this (.-target e)] + (if (and (.getSelection js/window) (.createRange js/document)) + (let [selection (.getSelection js/window) + range (.createRange js/document)] + (.selectNodeContents range this) + (.-romoveAllRange js/document) + (.addRange selection range)) + (if (and (.-selection js/document) (-> js/document .-body .createTextRange)) + (let [range (-> js/document .-body .creatTextRange)] + (.moveToElementText range) + (.select range this)))))) + (defn update-pwd [arg] (reset! size arg) (reset! password (genpwd @size))) (defn main-section [] [:div - [:div.field - (input-primary @password #(-> % .-target .select))] + [:div.field.has-text-centered + [:span.title.is-2 {:on-click magic-selection-trick-took-from-so} @password]] [:div.field.is-grouped.is-grouped-centered [:div.control (button-primary "Generate" #(update-pwd @size))]]]) |