diff options
author | Trent Richardson <trentdrichardson@gmail.com> | 2012-07-01 18:51:06 -0400 |
---|---|---|
committer | Trent Richardson <trentdrichardson@gmail.com> | 2012-07-01 18:51:06 -0400 |
commit | 7b9ba9a5111fcb716c5eacafe922b6be484eae49 (patch) | |
tree | 6f95f43900629ae8d858045e40a78a6f400eac1a /jquery-ui-sliderAccess.js | |
parent | 2050b7b6a1baad681b868828e3ec83589f5e304c (diff) | |
parent | c73678c2374a61294f3cad568d327d02711b5106 (diff) | |
download | jQuery-Timepicker-Addon-7b9ba9a5111fcb716c5eacafe922b6be484eae49.zip jQuery-Timepicker-Addon-7b9ba9a5111fcb716c5eacafe922b6be484eae49.tar.gz jQuery-Timepicker-Addon-7b9ba9a5111fcb716c5eacafe922b6be484eae49.tar.bz2 |
Merge dev branch v1.0.1
Diffstat (limited to 'jquery-ui-sliderAccess.js')
-rw-r--r-- | jquery-ui-sliderAccess.js | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/jquery-ui-sliderAccess.js b/jquery-ui-sliderAccess.js new file mode 100644 index 0000000..4c96bd5 --- /dev/null +++ b/jquery-ui-sliderAccess.js @@ -0,0 +1,85 @@ +/* + * jQuery UI Slider Access + * By: Trent Richardson [http://trentrichardson.com] + * Version 0.2 + * Last Modified: 12/02/2011 + * + * Copyright 2011 Trent Richardson + * Dual licensed under the MIT and GPL licenses. + * http://trentrichardson.com/Impromptu/GPL-LICENSE.txt + * http://trentrichardson.com/Impromptu/MIT-LICENSE.txt + * + */ + (function($){ + + $.fn.extend({ + sliderAccess: function(options){ + options = options || {}; + options.touchonly = options.touchonly !== undefined? options.touchonly : true; // by default only show it if touch device + + if(options.touchonly === true && !("ontouchend" in document)) + return $(this); + + return $(this).each(function(i,obj){ + var $t = $(this), + o = $.extend({},{ + where: 'after', + step: $t.slider('option','step'), + upIcon: 'ui-icon-plus', + downIcon: 'ui-icon-minus', + text: false, + upText: '+', + downText: '-', + buttonset: true, + buttonsetTag: 'span' + }, options), + $buttons = $('<'+ o.buttonsetTag +' class="ui-slider-access">'+ + '<button data-icon="'+ o.downIcon +'" data-step="-'+ o.step +'">'+ o.downText +'</button>'+ + '<button data-icon="'+ o.upIcon +'" data-step="'+ o.step +'">'+ o.upText +'</button>'+ + '</'+ o.buttonsetTag +'>'); + + $buttons.children('button').each(function(j, jobj){ + var $jt = $(this); + $jt.button({ + text: o.text, + icons: { primary: $jt.data('icon') } + }) + .click(function(e){ + var step = $jt.data('step'), + curr = $t.slider('value'), + newval = curr += step*1, + minval = $t.slider('option','min'), + maxval = $t.slider('option','max'); + + e.preventDefault(); + + if(newval < minval || newval > maxval) + return; + + $t.slider('value', newval); + + $t.slider("option", "slide").call($t, null, { value: newval }); + }); + }); + + // before or after + $t[o.where]($buttons); + + if(o.buttonset){ + $buttons.removeClass('ui-corner-right').removeClass('ui-corner-left').buttonset(); + $buttons.eq(0).addClass('ui-corner-left'); + $buttons.eq(1).addClass('ui-corner-right'); + } + + // adjust the width so we don't break the original layout + var bOuterWidth = $buttons.css({ + marginLeft: (o.where == 'after'? 10:0), + marginRight: (o.where == 'before'? 10:0) + }).outerWidth(true) + 5; + var tOuterWidth = $t.outerWidth(true); + $t.css('display','inline-block').width(tOuterWidth-bOuterWidth); + }); + } + }); + +})(jQuery);
\ No newline at end of file |