1/*----------------------------------------------------------------------*/ 2/* wl_Slider v 1.0 by revaxarts.com 3/* description: 4/* dependency: jquery UI Slider, mousewheel plugin 5/*----------------------------------------------------------------------*/ 6 7 8$.fn.wl_Slider = function (method) { 9 10 var args = arguments; 11 return this.each(function () { 12 13 var $this = $(this); 14 15 if ($.fn.wl_Slider.methods[method]) { 16 return $.fn.wl_Slider.methods[method].apply(this, Array.prototype.slice.call(args, 1)); 17 } else if (typeof method === 'object' || !method) { 18 if ($this.data('wl_Slider')) { 19 var opts = $.extend({}, $this.data('wl_Slider'), method); 20 } else { 21 var opts = $.extend({}, $.fn.wl_Slider.defaults, method, $this.data()); 22 } 23 } else { 24 try { 25 return $this.slider(method, args[1], args[2]); 26 } catch (e) { 27 $.error('Method "' + method + '" does not exist'); 28 } 29 } 30 31 if (!$this.data('wl_Slider')) { 32 33 $this.data('wl_Slider', {}); 34 35 36 //bind mousewheel events 37 $this.bind('mousewheel.wl_Slider', function (event, delta) { 38 if (opts.mousewheel) { 39 40 //delta must be 1 or -1 (different on macs and with shiftkey pressed) 41 delta = (delta < 0) ? -1 : 1; 42 event.preventDefault(); 43 44 //slider with one handler 45 if ($this.data('range') !== true) { 46 var _value = $this.slider('value'); 47 $.fn.wl_Slider.methods.values.call($this[0], _value + (delta * opts.step)); 48 49 //slider with two handlers 50 } else { 51 var _values = $this.slider('values'); 52 var _handler = $this.find('a'), 53 _h1 = _handler.eq(0).offset(), 54 _h2 = _handler.eq(1).offset(); 55 56 //callculate the affected handler depending on the mouseposition 57 if (opts.orientation == 'horizontal') { 58 if (_h1.left + (_h2.left - _h1.left) / 2 > event.clientX) { 59 $.fn.wl_Slider.methods.values.call($this[0], Math.min(_values[0] + (delta * opts.step), _values[1]), _values[1]); 60 } else { 61 $.fn.wl_Slider.methods.values.call($this[0], _values[0], Math.max(_values[1] + (delta * opts.step), _values[0])); 62 } 63 } else if (opts.orientation == 'vertical') { 64 if (_h2.top + (_h1.top - _h2.top) / 2 < event.pageY) { 65 $.fn.wl_Slider.methods.values.call($this[0], Math.min(_values[0] + (delta * opts.step), _values[1]), _values[1]); 66 } else { 67 $.fn.wl_Slider.methods.values.call($this[0], _values[0], Math.max(_values[1] + (delta * opts.step), _values[0])); 68 } 69 } 70 } 71 $.fn.wl_Slider.methods.slide.call($this[0]); 72 } 73 }); 74 } else { 75 //destroy it 76 $this.unbind('slide slidechange').slider('destroy'); 77 } 78 79 80 //call the jQuery UI slider plugin and add callbacks 81 $this.slider(opts).bind('slide', function (event, ui) { 82 $.fn.wl_Slider.methods.slide.call($this[0], ui.value); 83 }).bind('slidechange', function (event, ui) { 84 $.fn.wl_Slider.methods.change.call($this[0], ui.value); 85 }); 86 87 88 //slider is connected to an input field 89 if (opts.connect) { 90 91 //single slider 92 if ($this.data('range') !== true) { 93 var _input = $('#' + opts.connect), 94 _value = _input.val() || $this.data('value') || opts.min; 95 96 if(!_input.data('wl_Number')) _input.wl_Number(); 97 98 $this.unbind('slide slidechange').slider('value', _value); 99 100 //set callbacks on slide to change input fields 101 $this.bind('slide', function (event, ui) { 102 _input.val(ui.value); 103 $.fn.wl_Slider.methods.slide.call($this[0], ui.value); 104 }).bind('slidechange', function (event, ui) { 105 _input.val(ui.value); 106 $.fn.wl_Slider.methods.change.call($this[0], ui.value); 107 }); 108 _input.val(_value).wl_Number('set', $.extend({}, opts, { 109 onChange: function (value) { 110 $this.slider('value', value); 111 $this.wl_Slider('slide'); 112 $this.wl_Slider('change'); 113 } 114 })); 115 116 //range slider with two handlers 117 } else { 118 var _input = $.parseData(opts.connect, true), 119 _input1 = $('#' + _input[0]), 120 _input2 = $('#' + _input[1]), 121 _value1 = _input1.val() || $this.data('values')[0] || opts.min, 122 _value2 = _input2.val() || $this.data('values')[1] || opts.max; 123 124 if(!_input1.data('wl_Number')) _input1.wl_Number(); 125 if(!_input2.data('wl_Number')) _input2.wl_Number(); 126 127 //set callbacks on slide to change input fields 128 $this.unbind('slide slidechange').slider('option', 'values', [_value1, _value2]).bind('slide', function (event, ui) { 129 _input1.val(ui.values[0]); 130 _input2.val(ui.values[1]); 131 $.fn.wl_Slider.methods.slide.call($this[0], ui.values); 132 }).bind('slidechange', function (event, ui) { 133 _input1.val(ui.values[0]); 134 _input2.val(ui.values[1]); 135 $.fn.wl_Slider.methods.change.call($this[0], ui.values); 136 }); 137 138 //set callbacks to the connected input fields 139 _input1.wl_Number('set', $.extend({}, opts, { 140 onChange: function (value) { 141 $this.slider('option', 'values', [value, _input2.val()]); 142 _input2.wl_Number('set', 'min', parseFloat(value)); 143 $this.wl_Slider('slide'); 144 $this.wl_Slider('change'); 145 }, 146 min: opts.min, 147 max: _input2.val() || _value2 148 })).val(_value1); 149 150 _input2.wl_Number('set', $.extend({}, opts, { 151 onChange: function (value) { 152 $this.slider('option', 'values', [_input1.val(), value]); 153 _input1.wl_Number('set', 'max', parseFloat(value)); 154 $this.wl_Slider('slide'); 155 $this.wl_Slider('change'); 156 }, 157 min: _input1.val() || _value1,
158 max: opts.max 159 })).val(_value2); 160 } 161 } 162 163 //disable if set 164 if (opts.disabled) { 165 $this.fn.wl_Slider.methods.disable.call($this[0]); 166 } 167 168 if (opts) $.extend($this.data('wl_Slider'), opts); 169 }); 170 171}; 172 173$.fn.wl_Slider.defaults = { 174 min: 0, 175 max: 100, 176 step: 1, 177 animate: false, 178 disabled: false, 179 orientation: 'horizontal', 180 range: false, 181 mousewheel: true, 182 connect: null, 183 onSlide: function (value) {}, 184 onChange: function (value) {} 185}; 186$.fn.wl_Slider.version = '1.0'; 187 188 189$.fn.wl_Slider.methods = { 190 disable: function () { 191 var $this = $(this), 192 opts = $this.data('wl_Slider'); 193 194 //disable slider 195 $this.slider('disable'); 196 197 //disable connected input fields 198 if (opts.connect) { 199 if ($this.data('range') !== true) { 200 $('#' + opts.connect).prop('disabled', true); 201 } else { 202 var _input = $.parseData(opts.connect, true), 203 _input1 = $('#' + _input[0]), 204 _input2 = $('#' + _input[1]); 205 _input1.attr('disabled', true); 206 _input2.attr('disabled', true); 207 } 208 } 209 $this.data('wl_Slider').disabled = true; 210 }, 211 enable: function () { 212 var $this = $(this), 213 opts = $this.data('wl_Slider'); 214 215 //enable slider 216 $this.slider('enable'); 217 218 //enable connected input fields 219 if ($this.data('wl_Slider').connect) { 220 if ($this.data('range') !== true) { 221 $('#' + opts.connect).prop('disabled', false); 222 } else { 223 var _input = $.parseData(opts.connect, true), 224 _input1 = $('#' + _input[0]), 225 _input2 = $('#' + _input[1]); 226 _input1.removeAttr('disabled'); 227 _input2.removeAttr('disabled'); 228 } 229 } 230 $this.data('wl_Slider').disabled = false; 231 }, 232 change: function (value) { 233 var $this = $(this), 234 opts = $this.data('wl_Slider'); 235 if ($this.data('range') !== true) { 236 opts.onChange.call(this, value || $this.slider('value')); 237 } else { 238 opts.onChange.call(this, value || $this.slider('values')); 239 } 240 }, 241 slide: function (value) { 242 var $this = $(this), 243 opts = $this.data('wl_Slider'); 244 if ($this.data('range') !== true) { 245 opts.onSlide.call(this, value || $this.slider('value')); 246 } else { 247 opts.onSlide.call(this, value || $this.slider('values')); 248 } 249 }, 250 value: function () { 251 var $this = $(this), 252 opts = $this.data('wl_Slider'); 253 if (opts.range !== true) { 254 $this.slider('value', arguments[0]); 255 } 256 }, 257 values: function () { 258 var $this = $(this), 259 opts = $this.data('wl_Slider'); 260 if (opts.range === true) { 261 if (typeof arguments[0] === 'object') { 262 $this.slider('values', 0, arguments[0][0]); 263 $this.slider('values', 1, arguments[0][1]); 264 } else { 265 $this.slider('values', 0, arguments[0]); 266 $this.slider('values', 1, arguments[1]); 267 } 268 } else { 269 $.fn.wl_Slider.methods.value.call(this, arguments[0]); 270 } 271 }, 272 set: function () { 273 var $this = $(this), 274 options = {}; 275 if (typeof arguments[0] === 'object') { 276 options = arguments[0]; 277 } else if (arguments[0] && arguments[1] !== undefined) { 278 options[arguments[0]] = arguments[1]; 279 } 280 if ($this.data('wl_Slider').connect) { 281 if ($this.data('range') !== true) { 282 var _input1 = $('#' + $this.data('wl_Slider').connect); 283 } else { 284 var _input = $.parseData($this.data('wl_Slider').connect, true), 285 _input1 = $('#' + _input[0]), 286 _input2 = $('#' + _input[1]); 287 } 288 } 289 $.each(options, function (key, value) { 290 if ($.fn.wl_Slider.defaults[key] !== undefined || $.fn.wl_Slider.defaults[key] == null) { 291 $this.slider('option', key, value).data('wl_Slider')[key] = value; 292 if (_input1) _input1.data(key, value).trigger('change'); 293 if (_input2) _input2.data(key, value).trigger('change'); 294 } else { 295 $.error('Key "' + key + '" is not defined'); 296 } 297 }); 298 299 } 300};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.