diff --git a/lms/static/coffee/fixtures/calculator.html b/lms/static/coffee/fixtures/calculator.html
index 61c6f5e153..0001715707 100644
--- a/lms/static/coffee/fixtures/calculator.html
+++ b/lms/static/coffee/fixtures/calculator.html
@@ -4,14 +4,14 @@
diff --git a/lms/static/coffee/src/calculator.coffee b/lms/static/coffee/src/calculator.coffee
index 788081ebd6..c1f5ae96b5 100644
--- a/lms/static/coffee/src/calculator.coffee
+++ b/lms/static/coffee/src/calculator.coffee
@@ -3,25 +3,55 @@ class @Calculator
$('.calc').click @toggle
$('form#calculator').submit(@calculate).submit (e) ->
e.preventDefault()
- $('div.help-wrapper a').hover(@helpToggle).click (e) ->
- e.preventDefault()
+ $('div.help-wrapper a')
+ .focus($.proxy @helpOnFocus, @)
+ .blur($.proxy @helpOnBlur, @)
+ .hover(
+ $.proxy(@helpShow, @),
+ $.proxy(@helpHide, @)
+ )
+ .click (e) ->
+ e.preventDefault()
toggle: (event) ->
event.preventDefault()
+ $calc = $('.calc')
+ $calcWrapper = $('#calculator_wrapper')
+
$('div.calc-main').toggleClass 'open'
- if $('.calc.closed').length
- $('.calc').attr 'aria-label', 'Open Calculator'
+ if $calc.hasClass('closed')
+ $calc.attr 'aria-label', 'Open Calculator'
+ $calcWrapper
+ .find('input, a')
+ .attr 'tabindex', -1
else
- $('.calc').attr 'aria-label', 'Close Calculator'
+ $calc.attr 'aria-label', 'Close Calculator'
+ $calcWrapper
+ .find('input, a')
+ .attr 'tabindex', null
# TODO: Investigate why doing this without the timeout causes it to jump
# down to the bottom of the page. I suspect it's because it's putting the
# focus on the text field before it transitions onto the page.
- setTimeout (-> $('#calculator_wrapper #calculator_input').focus()), 100
+ setTimeout (-> $calcWrapper.find('#calculator_input').focus()), 100
- $('.calc').toggleClass 'closed'
+ $calc.toggleClass 'closed'
- helpToggle: ->
- $('.help').toggleClass 'shown'
+ helpOnFocus: (e) ->
+ e.preventDefault()
+ @isFocusedHelp = true
+ @helpShow()
+
+ helpOnBlur: (e) ->
+ e.preventDefault()
+ @isFocusedHelp = false
+ @helpHide()
+
+ helpShow: ->
+ $('.help').addClass 'shown'
+
+ helpHide: ->
+ if not @isFocusedHelp
+ $('.help').removeClass 'shown'
calculate: ->
$.getWithPrefix '/calculate', { equation: $('#calculator_input').val() }, (data) ->