Commit a02101bd by ahsan-ul-haq

Merge pull request #6928 from edx/ahsan/tnl-944-calculator-UI-difficult-access

Calculator UI difficulit to access
parents c72cc5dc 6536ab84
...@@ -8,6 +8,14 @@ ...@@ -8,6 +8,14 @@
<div class="help-wrapper"> <div class="help-wrapper">
<a id="calculator_hint" href="#" role="button" aria-haspopup="true" tabindex="-1">Hints</a> <a id="calculator_hint" href="#" role="button" aria-haspopup="true" tabindex="-1">Hints</a>
<ul id="calculator_input_help" class="help" aria-activedescendant="hint-integers" role="tooltip" aria-hidden="true"> <ul id="calculator_input_help" class="help" aria-activedescendant="hint-integers" role="tooltip" aria-hidden="true">
<li class="hint-item" id="hint-moreinfo" tabindex="-1">
<p>
<span class="bold">For detailed information, see
<a id="hint-link-first" href="http://edx-guide-for-students.readthedocs.org/en/latest/SFD_mathformatting.html">Entering Mathematical and Scientific Expressions</a>in the
<a id="hint-link-second" href="http://edx-guide-for-students.readthedocs.org/en/latest/index.html">edX Guide for Students </a> format
</span>
</p>
</li>
<li class="hint-item" id="hint-integers" tabindex="-1"><p><span class="bold">Integers:</span> 2520</p></li> <li class="hint-item" id="hint-integers" tabindex="-1"><p><span class="bold">Integers:</span> 2520</p></li>
<li class="hint-item" id="hint-decimals" tabindex="-1"><p><span class="bold">Decimals:</span> 3.14 or .98</p></li> <li class="hint-item" id="hint-decimals" tabindex="-1"><p><span class="bold">Decimals:</span> 3.14 or .98</p></li>
</ul> </ul>
......
...@@ -19,16 +19,12 @@ describe 'Calculator', -> ...@@ -19,16 +19,12 @@ describe 'Calculator', ->
it 'bind the calculator button', -> it 'bind the calculator button', ->
expect($('.calc')).toHandleWith 'click', @calculator.toggle expect($('.calc')).toHandleWith 'click', @calculator.toggle
it 'bind the help button', -> it 'bind key up on calculator', ->
# These events are bind by $.hover() expect($('#calculator_wrapper')).toHandle 'keyup', @calculator.handleKeyUpOnHint
expect($('#calculator_hint')).toHandle 'mouseover'
expect($('#calculator_hint')).toHandle 'mouseout'
expect($('#calculator_hint')).toHandle 'keydown'
it 'prevent default behavior on help button', -> it 'bind the help button', ->
$('#calculator_hint').click (e) -> # This events is bind by $.click()
expect(e.isDefaultPrevented()).toBeTruthy() expect($('#calculator_hint')).toHandle 'click'
$('#calculator_hint').click()
it 'bind the calculator submit', -> it 'bind the calculator submit', ->
expect($('form#calculator')).toHandleWith 'submit', @calculator.calculate expect($('form#calculator')).toHandleWith 'submit', @calculator.calculate
...@@ -75,6 +71,12 @@ describe 'Calculator', -> ...@@ -75,6 +71,12 @@ describe 'Calculator', ->
expect($('.help')).not.toHaveClass('shown') expect($('.help')).not.toHaveClass('shown')
expect($('.help')).toHaveAttr('aria-hidden', 'true') expect($('.help')).toHaveAttr('aria-hidden', 'true')
describe 'handleClickOnHintButton', ->
it 'on click hint button hint popup becomes visible ', ->
e = jQuery.Event('click');
$('#calculator_hint').trigger(e);
expect($('.help')).toHaveClass 'shown'
describe 'handleClickOnDocument', -> describe 'handleClickOnDocument', ->
it 'on click out of the hint popup it becomes hidden', -> it 'on click out of the hint popup it becomes hidden', ->
@calculator.showHint() @calculator.showHint()
...@@ -82,6 +84,13 @@ describe 'Calculator', -> ...@@ -82,6 +84,13 @@ describe 'Calculator', ->
$(document).trigger(e); $(document).trigger(e);
expect($('.help')).not.toHaveClass 'shown' expect($('.help')).not.toHaveClass 'shown'
describe 'handleClickOnHintPopup', ->
it 'on click of hint popup it remains visible', ->
@calculator.showHint()
e = jQuery.Event('click');
$('#calculator_input_help').trigger(e);
expect($('.help')).toHaveClass 'shown'
describe 'selectHint', -> describe 'selectHint', ->
it 'select correct hint item', -> it 'select correct hint item', ->
spyOn($.fn, 'focus') spyOn($.fn, 'focus')
...@@ -108,7 +117,7 @@ describe 'Calculator', -> ...@@ -108,7 +117,7 @@ describe 'Calculator', ->
expect(@calculator.activeHint.attr('id')).toBe($('.hint-item').eq(0).attr('id')) expect(@calculator.activeHint.attr('id')).toBe($('.hint-item').eq(0).attr('id'))
it 'Prev hint item is selected', -> it 'if this was the second item, select the first one', ->
@calculator.activeHint = $('.hint-item').eq(1) @calculator.activeHint = $('.hint-item').eq(1)
@calculator.prevHint() @calculator.prevHint()
...@@ -118,20 +127,32 @@ describe 'Calculator', -> ...@@ -118,20 +127,32 @@ describe 'Calculator', ->
@calculator.activeHint = $('.hint-item').eq(0) @calculator.activeHint = $('.hint-item').eq(0)
@calculator.prevHint() @calculator.prevHint()
expect(@calculator.activeHint.attr('id')).toBe($('.hint-item').eq(2).attr('id'))
it 'if this was the last item, select the second last', ->
@calculator.activeHint = $('.hint-item').eq(2)
@calculator.prevHint()
expect(@calculator.activeHint.attr('id')).toBe($('.hint-item').eq(1).attr('id')) expect(@calculator.activeHint.attr('id')).toBe($('.hint-item').eq(1).attr('id'))
describe 'nextHint', -> describe 'nextHint', ->
it 'Next hint item is selected', -> it 'if this was the first item, select the second one', ->
@calculator.activeHint = $('.hint-item').eq(0) @calculator.activeHint = $('.hint-item').eq(0)
@calculator.nextHint() @calculator.nextHint()
expect(@calculator.activeHint.attr('id')).toBe($('.hint-item').eq(1).attr('id')) expect(@calculator.activeHint.attr('id')).toBe($('.hint-item').eq(1).attr('id'))
it 'If this was the last item, select the first one', -> it 'If this was the second item, select the last one', ->
@calculator.activeHint = $('.hint-item').eq(1) @calculator.activeHint = $('.hint-item').eq(1)
@calculator.nextHint() @calculator.nextHint()
expect(@calculator.activeHint.attr('id')).toBe($('.hint-item').eq(2).attr('id'))
it 'If this was the last item, select the first one', ->
@calculator.activeHint = $('.hint-item').eq(2)
@calculator.nextHint()
expect(@calculator.activeHint.attr('id')).toBe($('.hint-item').eq(0).attr('id')) expect(@calculator.activeHint.attr('id')).toBe($('.hint-item').eq(0).attr('id'))
describe 'handleKeyDown', -> describe 'handleKeyDown', ->
...@@ -264,14 +285,6 @@ describe 'Calculator', -> ...@@ -264,14 +285,6 @@ describe 'Calculator', ->
not_called: not_called:
'nextHint': calc 'nextHint': calc
tab:
returnedValue: true
event:
keyCode: KEY.TAB
shiftKey: false
called:
'hideHint': calc
esc: esc:
returnedValue: false returnedValue: false
event: event:
......
...@@ -22,16 +22,17 @@ class @Calculator ...@@ -22,16 +22,17 @@ class @Calculator
$('form#calculator').submit(@calculate).submit (e) -> $('form#calculator').submit(@calculate).submit (e) ->
e.preventDefault() e.preventDefault()
@hintButton @hintButton
.hover( .click(($.proxy(@handleClickOnHintButton, @)))
$.proxy(@showHint, @),
$.proxy(@hideHint, @) @hintPopup
) .click(($.proxy(@handleClickOnHintPopup, @)))
.keydown($.proxy(@handleKeyDown, @))
.click (e) -> e.preventDefault()
@hintPopup @hintPopup
.keydown($.proxy(@handleKeyDownOnHint, @)) .keydown($.proxy(@handleKeyDownOnHint, @))
$('#calculator_wrapper')
.keyup($.proxy(@handleKeyUpOnHint, @))
@handleClickOnDocument = $.proxy(@handleClickOnDocument, @) @handleClickOnDocument = $.proxy(@handleClickOnDocument, @)
KEY: KEY:
...@@ -140,9 +141,6 @@ class @Calculator ...@@ -140,9 +141,6 @@ class @Calculator
return true return true
switch e.keyCode switch e.keyCode
when @KEY.TAB
# hide popup with hints
@hideHint()
when @KEY.ESC when @KEY.ESC
# hide popup with hints # hide popup with hints
...@@ -175,11 +173,27 @@ class @Calculator ...@@ -175,11 +173,27 @@ class @Calculator
# allow the event to propagate # allow the event to propagate
return true return true
handleKeyUpOnHint: (e) ->
switch e.keyCode
when @KEY.TAB
# move focus to hint links and hide hint once focus is out of hint pop up
@active_element = document.activeElement
if not $(@active_element).parents().is(@hintPopup)
@hideHint()
handleClickOnDocument: (e) -> handleClickOnDocument: (e) ->
@hideHint() @hideHint()
# allow the event to propagate handleClickOnHintButton: (e) ->
return true; e.stopPropagation()
if @hintPopup.hasClass 'shown'
@hideHint()
else
@showHint()
@activeHint.focus()
handleClickOnHintPopup: (e) ->
e.stopPropagation()
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