aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/genpass/components/input.cljc5
-rw-r--r--src/genpass/core.cljs17
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))]]])