From 8c716d495a5bf1d31c316da16635a32a291a34c0 Mon Sep 17 00:00:00 2001 From: Gabriel Giovanini Date: Sun, 23 Jun 2019 20:57:07 +0200 Subject: Move from input to span --- src/genpass/components/input.cljc | 5 ++++- src/genpass/core.cljs | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) (limited to 'src') 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))]]]) -- cgit v1.2.3