diff options
author | Robert Speicher <rspeicher@gmail.com> | 2016-02-13 00:29:41 +0300 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2016-03-02 23:11:44 +0300 |
commit | 97c909bd01da334007599be8216d595307dceeda (patch) | |
tree | 51adb90a10b3da11df504c9ee46392451c8aca84 /app/assets/javascripts/behaviors | |
parent | 76ed2afcfc2ae2b6ab3d3419a1183374a39022cc (diff) |
Contextually teach the user about the quick submit hotkey
When a user tabs to the submit button (i.e., the "wrong" way), we
display a tooltip with the quick submit hotkey so they can learn the
"right" way.
Diffstat (limited to 'app/assets/javascripts/behaviors')
-rw-r--r-- | app/assets/javascripts/behaviors/quick_submit.js.coffee | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/app/assets/javascripts/behaviors/quick_submit.js.coffee b/app/assets/javascripts/behaviors/quick_submit.js.coffee index 5d771180219..61c2e4f698c 100644 --- a/app/assets/javascripts/behaviors/quick_submit.js.coffee +++ b/app/assets/javascripts/behaviors/quick_submit.js.coffee @@ -34,3 +34,22 @@ $(document).on 'keydown.quick_submit', '.js-quick-submit', (e) -> $form = $(e.target).closest('form') $form.find('input[type=submit], button[type=submit]').disable() $form.submit() + +# If the user tabs to a submit button on a `js-quick-submit` form, display a +# tooltip to let them know they could've used the hotkey +$(document).on 'keyup.quick_submit', '.js-quick-submit input[type=submit], .js-quick-submit button[type=submit]', (e) -> + return unless keyCodeIs(e, 9) # Tab + + if isMac() + title = "You can also press ⌘-Enter" + else + title = "You can also press Ctrl-Enter" + + $this = $(@) + $this.tooltip( + container: 'body' + html: 'true' + placement: 'auto top' + title: title + trigger: 'manual' + ).tooltip('show').one('blur', -> $this.tooltip('hide')) |