Commit 12d2c47c by polesye

Fix BLD-165.

parent f00f9001
...@@ -4,14 +4,14 @@ ...@@ -4,14 +4,14 @@
<div id="calculator_wrapper"> <div id="calculator_wrapper">
<form id="calculator"> <form id="calculator">
<div class="input-wrapper"> <div class="input-wrapper">
<input type="text" id="calculator_input" /> <input type="text" id="calculator_input" tabindex="-1" />
<div class="help-wrapper"> <div class="help-wrapper">
<a href="#">Hints</a> <a href="#" aria-expanded="false" tabindex="-1">Hints</a>
<dl class="help"></dl> <dl class="help"></dl>
</div> </div>
</div> </div>
<input id="calculator_button" type="submit" value="="/> <input id="calculator_button" type="submit" value="=" tabindex="-1" />
<input type="text" id="calculator_output" readonly /> <input type="text" id="calculator_output" readonly tabindex="-1" />
</form> </form>
</div> </div>
</li> </li>
......
...@@ -3,25 +3,55 @@ class @Calculator ...@@ -3,25 +3,55 @@ class @Calculator
$('.calc').click @toggle $('.calc').click @toggle
$('form#calculator').submit(@calculate).submit (e) -> $('form#calculator').submit(@calculate).submit (e) ->
e.preventDefault() e.preventDefault()
$('div.help-wrapper a').hover(@helpToggle).click (e) -> $('div.help-wrapper a')
.focus($.proxy @helpOnFocus, @)
.blur($.proxy @helpOnBlur, @)
.hover(
$.proxy(@helpShow, @),
$.proxy(@helpHide, @)
)
.click (e) ->
e.preventDefault() e.preventDefault()
toggle: (event) -> toggle: (event) ->
event.preventDefault() event.preventDefault()
$calc = $('.calc')
$calcWrapper = $('#calculator_wrapper')
$('div.calc-main').toggleClass 'open' $('div.calc-main').toggleClass 'open'
if $('.calc.closed').length if $calc.hasClass('closed')
$('.calc').attr 'aria-label', 'Open Calculator' $calc.attr 'aria-label', 'Open Calculator'
$calcWrapper
.find('input, a')
.attr 'tabindex', -1
else 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 # 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 # 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. # 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'
helpOnFocus: (e) ->
e.preventDefault()
@isFocusedHelp = true
@helpShow()
helpOnBlur: (e) ->
e.preventDefault()
@isFocusedHelp = false
@helpHide()
$('.calc').toggleClass 'closed' helpShow: ->
$('.help').addClass 'shown'
helpToggle: -> helpHide: ->
$('.help').toggleClass 'shown' if not @isFocusedHelp
$('.help').removeClass 'shown'
calculate: -> calculate: ->
$.getWithPrefix '/calculate', { equation: $('#calculator_input').val() }, (data) -> $.getWithPrefix '/calculate', { equation: $('#calculator_input').val() }, (data) ->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment