Last active
August 29, 2015 14:13
-
-
Save remvee/76566d1ecd0f300e067e to your computer and use it in GitHub Desktop.
Detect on screen keyboard
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
(defn detect-keyboard-on-screen! | |
"Try to detect keyboard going on and off screen and toggle class on | |
the element when applicable." | |
[el class] | |
(let [former-height (atom (.-innerHeight js/window))] | |
(.addEventListener | |
js/window "resize" | |
#(let [focus (.-activeElement js/document) | |
height (.-innerHeight js/window)] | |
(gclasses/enable el class | |
(and (#{"INPUT" "TEXTAREA"} (.-tagName focus)) | |
(< height @former-height))) | |
(reset! former-height height))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment