diff options
author | Robert Speicher <rspeicher@gmail.com> | 2016-02-12 16:28:53 -0500 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2016-03-02 15:11:15 -0500 |
commit | 76ed2afcfc2ae2b6ab3d3419a1183374a39022cc (patch) | |
tree | 9f102ebcd4ec208938898529782317029e304d61 /app/assets/javascripts | |
parent | b5738edadeb7e77fa152fc3776f652d94156681c (diff) | |
download | gitlab-ce-76ed2afcfc2ae2b6ab3d3419a1183374a39022cc.tar.gz |
Change `js-quick-submit` behavior to expect the class on the form
Now it will work on any field inside that form, and it's easier to scope
new behavior, which is what we're adding next!
Diffstat (limited to 'app/assets/javascripts')
-rw-r--r-- | app/assets/javascripts/behaviors/quick_submit.js.coffee | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/app/assets/javascripts/behaviors/quick_submit.js.coffee b/app/assets/javascripts/behaviors/quick_submit.js.coffee index 4ec8531d580..5d771180219 100644 --- a/app/assets/javascripts/behaviors/quick_submit.js.coffee +++ b/app/assets/javascripts/behaviors/quick_submit.js.coffee @@ -1,23 +1,30 @@ # Quick Submit behavior # -# When an input field with the `js-quick-submit` class receives a "Meta+Enter" -# (Mac) or "Ctrl+Enter" (Linux/Windows) key combination, its parent form is -# submitted. +# When a child field of a form with a `js-quick-submit` class receives a +# "Meta+Enter" (Mac) or "Ctrl+Enter" (Linux/Windows) key combination, the form +# is submitted. # #= require extensions/jquery # # ### Example Markup # -# <form action="/foo"> -# <input type="text" class="js-quick-submit" /> -# <textarea class="js-quick-submit"></textarea> +# <form action="/foo" class="js-quick-submit"> +# <input type="text" /> +# <textarea></textarea> +# <input type="submit" value="Submit" /> # </form> # +isMac = -> + navigator.userAgent.match(/Macintosh/) + +keyCodeIs = (e, keyCode) -> + return false if (e.originalEvent && e.originalEvent.repeat) || e.repeat + return e.keyCode == keyCode + $(document).on 'keydown.quick_submit', '.js-quick-submit', (e) -> - return if (e.originalEvent && e.originalEvent.repeat) || e.repeat - return unless e.keyCode == 13 # Enter + return unless keyCodeIs(e, 13) # Enter - if navigator.userAgent.match(/Macintosh/) + if isMac() return unless (e.metaKey && !e.altKey && !e.ctrlKey && !e.shiftKey) else return unless (e.ctrlKey && !e.altKey && !e.metaKey && !e.shiftKey) |