From e6707af6675cbbedacb1251d2a3656f708a3f81c Mon Sep 17 00:00:00 2001 From: scottjehl Date: Tue, 21 Sep 2010 16:43:07 -0400 Subject: [PATCH] added aria support --- js/jQuery.mobile.forms.slider.js | 38 ++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/js/jQuery.mobile.forms.slider.js b/js/jQuery.mobile.forms.slider.js index 6b960831..bea01ec2 100644 --- a/js/jQuery.mobile.forms.slider.js +++ b/js/jQuery.mobile.forms.slider.js @@ -8,18 +8,31 @@ $.fn.slider = function(options){ return $(this).each(function(){ var input = $(this), - label = $('[for='+ input.attr('id') +']'), - slider = $('
'), - handle = $('').appendTo(slider).buttonMarkup({corners: true}), + inputID = input.attr('id'), + labelID = inputID + '-label', + label = $('[for='+ inputID +']').attr('id',labelID), + val = input.val(), + min = parseFloat(input.attr('min')), + max = parseFloat(input.attr('max')), + percent = val / (max - min) * 100, + slider = $('
'), + handle = $('') + .appendTo(slider) + .buttonMarkup({corners: true}) + .attr({ + 'role': 'slider', + 'aria-valuemin': min, + 'aria-valuemax': max, + 'aria-valuenow': val, + 'aria-valuetext': val, + 'title': val, + 'aria-labelledby': labelID + }), dragging = false, supportTouch = $.support.touch, touchStartEvent = supportTouch ? "touchstart" : "mousedown", touchStopEvent = supportTouch ? "touchend" : "mouseup", - touchMoveEvent = supportTouch ? "touchmove" : "mousemove", - val = input.val(), - min = input.attr('min'), - max = input.attr('max'), - percent = val / (max - min) * 100; + touchMoveEvent = supportTouch ? "touchmove" : "mousemove"; function slideUpdate(event, val){ if(!val){ @@ -39,7 +52,14 @@ $.fn.slider = function(options){ } var newval = Math.round( (percent/100) * max ); if( newval < min ){ newval = min; } - handle.css('left', percent + '%'); + if( newval > max ){ newval = max; } + handle + .css('left', percent + '%') + .attr({ + 'aria-valuenow': newval, + 'aria-valuetext': newval, + 'title': newval + }); input.val(newval); }