jquery-ui-sliderAccess.js (3076B)
1 /* 2 * jQuery UI Slider Access 3 * By: Trent Richardson [http://trentrichardson.com] 4 * Version 0.3 5 * Last Modified: 10/20/2012 6 * 7 * Copyright 2011 Trent Richardson 8 * Dual licensed under the MIT and GPL licenses. 9 * http://trentrichardson.com/Impromptu/GPL-LICENSE.txt 10 * http://trentrichardson.com/Impromptu/MIT-LICENSE.txt 11 * 12 */ 13 (function($){ 14 15 $.fn.extend({ 16 sliderAccess: function(options){ 17 options = options || {}; 18 options.touchonly = options.touchonly !== undefined? options.touchonly : true; // by default only show it if touch device 19 20 if(options.touchonly === true && !("ontouchend" in document)){ 21 return $(this); 22 } 23 24 return $(this).each(function(i,obj){ 25 var $t = $(this), 26 o = $.extend({},{ 27 where: 'after', 28 step: $t.slider('option','step'), 29 upIcon: 'ui-icon-plus', 30 downIcon: 'ui-icon-minus', 31 text: false, 32 upText: '+', 33 downText: '-', 34 buttonset: true, 35 buttonsetTag: 'span', 36 isRTL: false 37 }, options), 38 $buttons = $('<'+ o.buttonsetTag +' class="ui-slider-access">'+ 39 '<button data-icon="'+ o.downIcon +'" data-step="'+ (o.isRTL? o.step : o.step*-1) +'">'+ o.downText +'</button>'+ 40 '<button data-icon="'+ o.upIcon +'" data-step="'+ (o.isRTL? o.step*-1 : o.step) +'">'+ o.upText +'</button>'+ 41 '</'+ o.buttonsetTag +'>'); 42 43 $buttons.children('button').each(function(j, jobj){ 44 var $jt = $(this); 45 $jt.button({ 46 text: o.text, 47 icons: { primary: $jt.data('icon') } 48 }) 49 .click(function(e){ 50 var step = $jt.data('step'), 51 curr = $t.slider('value'), 52 newval = curr += step*1, 53 minval = $t.slider('option','min'), 54 maxval = $t.slider('option','max'), 55 slidee = $t.slider("option", "slide") || function(){}, 56 stope = $t.slider("option", "stop") || function(){}; 57 58 e.preventDefault(); 59 60 if(newval < minval || newval > maxval){ 61 return; 62 } 63 64 $t.slider('value', newval); 65 66 slidee.call($t, null, { value: newval }); 67 stope.call($t, null, { value: newval }); 68 }); 69 }); 70 71 // before or after 72 $t[o.where]($buttons); 73 74 if(o.buttonset){ 75 $buttons.removeClass('ui-corner-right').removeClass('ui-corner-left').buttonset(); 76 $buttons.eq(0).addClass('ui-corner-left'); 77 $buttons.eq(1).addClass('ui-corner-right'); 78 } 79 80 // adjust the width so we don't break the original layout 81 var bOuterWidth = $buttons.css({ 82 marginLeft: ((o.where === 'after' && !o.isRTL) || (o.where === 'before' && o.isRTL)? 10:0), 83 marginRight: ((o.where === 'before' && !o.isRTL) || (o.where === 'after' && o.isRTL)? 10:0) 84 }).outerWidth(true) + 5; 85 var tOuterWidth = $t.outerWidth(true); 86 $t.css('display','inline-block').width(tOuterWidth-bOuterWidth); 87 }); 88 } 89 }); 90 91 })(jQuery);