From 12d2c47c9f8d1cb0d1a26232034789e5b4b39485 Mon Sep 17 00:00:00 2001 From: polesye Date: Fri, 11 Oct 2013 12:13:49 +0300 Subject: [PATCH] Fix BLD-165. --- lms/static/coffee/fixtures/calculator.html | 8 ++-- lms/static/coffee/src/calculator.coffee | 48 ++++++++++++++++++---- 2 files changed, 43 insertions(+), 13 deletions(-) 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 @@
- +
- Hints +
- - + +
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) ->