Last active
August 29, 2015 14:07
-
-
Save maximkoretskiy/191c49fb7c361bdac3b4 to your computer and use it in GitHub Desktop.
Textarea start editing prevention
This file contains hidden or 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
| # demo: http://jsfiddle.net/q173wuoy/1/ | |
| KEY_DELETE = [8, 46] | |
| KEY_NAV = [33..40] | |
| $( -> | |
| inputPreventer = (e)-> | |
| length = 10 | |
| cursorPos = e.currentTarget?.selectionStart | |
| return if e.keyCode in KEY_NAV | |
| border = if e.keyCode in KEY_DELETE then length+1 else length | |
| e.preventDefault() if 0 < cursorPos < border | |
| ($ 'textarea').on 'keydown', inputPreventer | |
| ) |
This file contains hidden or 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
| <textarea class='ta' name="" id="" cols="30" rows="10">Жуй тебе, дружок</textarea> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment