From bdf41c6964e5b5f7ed865c89d87bfcd08e69ed5b Mon Sep 17 00:00:00 2001 From: Nicholas Kariniemi Date: Sun, 12 Jan 2014 19:32:37 +0200 Subject: [PATCH] Fix: detect enter on other browsers than Chrome --- src/cljs/grub/view/dom.cljs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/cljs/grub/view/dom.cljs b/src/cljs/grub/view/dom.cljs index b6d0d89..071e289 100644 --- a/src/cljs/grub/view/dom.cljs +++ b/src/cljs/grub/view/dom.cljs @@ -15,6 +15,8 @@ (dommy/listen! el type push-fn) {:chan out :unlisten unlisten}))) +(def ENTER-KEYCODE 13) + (defn listen-once ([el type] (listen el type nil)) ([el type f] (listen el type f (chan))) @@ -34,14 +36,14 @@ (listen elem :click)) (defn get-enters [elem] - (let [{c :chan unlisten :unlisten} - (listen elem :keyup)] + (let [{c :chan unlisten :unlisten} (listen elem :keyup) + filtered-chan (a/filter< #(= (.-which %) ENTER-KEYCODE) c)] {:unlisten unlisten - :chan (a/filter< #(= (.-keyIdentifier %) "Enter") c)})) + :chan filtered-chan})) (defn get-ctrl-enters [] (let [{c :chan unlisten :unlisten} (listen (sel1 :body) :keyup) - filtered-chan (a/filter< #(and (= (.-keyIdentifier %) "Enter") + filtered-chan (a/filter< #(and (= (.-which %) ENTER-KEYCODE) (.-ctrlKey %)) c)] {:chan filtered-chan :unlisten unlisten}))