PageSourceSearch

https://networkdepo.com/Scripts/js/wl_Slider.js

js networkdepo.com collected 2026-10-06 22:52:04 UTC 12,658 bytes, 399 lines download raw bytes

1/*----------------------------------------------------------------------*/
2/* wl_Slider
3/* description: 
4/* dependency: jquery UI Slider, mousewheel plugin
5/*----------------------------------------------------------------------*/
6
7$.fn.wl_Slider = function (method) {
8
9	var args = arguments;
10	return this.each(function () {
11
12		var $this = $(this);
13
14		if ($.fn.wl_Slider.methods[method]) {
15			return $.fn.wl_Slider.methods[method].apply(this, Array.prototype.slice.call(args, 1));
16		} else if (typeof method === 'object' || !method) {
17			if ($this.data('wl_Slider')) {
18				var opts = $.extend({}, $this.data('wl_Slider'), method);
19			} else {
20				var opts = $.extend({}, $.fn.wl_Slider.defaults, method, $this.data());
21			}
22		} else {
23			try {
24				return $this.slider(method, args[1], args[2]);
25			} catch (e) {
26				$.error('Method "' + method + '" does not exist');
27			}
28		}
29
30		if (!$this.data('wl_Slider')) {
31
32			$this.data('wl_Slider', {});
33
34			
35			//bind mousewheel events
36			$this.bind('mousewheel.wl_Slider', function (event, delta) {
37				if (opts.mousewheel) {
38					
39					//delta must be 1 or -1 (different on macs and with shiftkey pressed)
40					delta = (delta < 0) ? -1 : 1;
41					event.preventDefault();
42
43					//slider with one handler
44					if ($this.data('range') !== true) {
45						var _value = $this.slider('value');
46						$.fn.wl_Slider.methods.values.call($this[0], _value + (delta * opts.step));
47						
48						//update the tooltip
49						if (opts.tooltip){
50							var _handle = $this.find('a');
51
52							_handle.tipsy('setTitel',opts.tooltipPattern.replace('%n', _value + (delta * opts.step)));
53							_handle.tipsy('update');	
54						} 
55						
56					//slider with two handlers
57					} else {
58						var _values = $this.slider('values');
59						var _handler = $this.find('a'),
60							_h1 = _handler.eq(0).offset(),
61							_h2 = _handler.eq(1).offset();
62							
63						//callculate the affected handler depending on the mouseposition
64						if (opts.orientation == 'horizontal') {
65							if (_h1.left + (_h2.left - _h1.left) / 2 > event.clientX) {
66								$.fn.wl_Slider.methods.values.call($this[0], Math.min(_values[0] + (delta * opts.step), _values[1]), _values[1]);
67							} else {
68								$.fn.wl_Slider.methods.values.call($this[0], _values[0], Math.max(_values[1] + (delta * opts.step), _values[0]));
69							}
70						} else if (opts.orientation == 'vertical') {
71							if (_h2.top + (_h1.top - _h2.top) / 2 < event.pageY) {
72								$.fn.wl_Slider.methods.values.call($this[0], Math.min(_values[0] + (delta * opts.step), _values[1]), _values[1]);
73							} else {
74								$.fn.wl_Slider.methods.values.call($this[0], _values[0], Math.max(_values[1] + (delta * opts.step), _values[0]));
75							}
76						}
77						//update the tooltip
78						if (opts.tooltip){
79							_handler.eq(0).tipsy('setTitel',opts.tooltipPattern.replace('%n', _values[0] + (delta * opts.step)));
80							_handler.eq(0).tipsy('update');
81							_handler.eq(1).tipsy('setTitel',opts.tooltipPattern.replace('%n', _values[0] + (delta * opts.step)));
82							_handler.eq(1).tipsy('update');
83						} 
84					}
85					$.fn.wl_Slider.methods.slide.call($this[0]);
86				}
87			});
88		} else {
89			//destroy it
90			$this.unbind('slide slidechange').slider('destroy');
91		}
92
93
94		//call the jQuery UI slider plugin and add callbacks
95		$this.slider(opts).bind('slide', function (event, ui) {
96			$.fn.wl_Slider.methods.slide.call($this[0], ui.value);
97		}).bind('slidechange', function (event, ui) {
98			$.fn.wl_Slider.methods.change.call($this[0], ui.value);
99		});
100
101		//slider is connected to an input field
102		if (opts.connect) {
103			
104			//single slider
105			if ($this.data('range') !== true) {
106				var _input = $('#' + opts.connect),
107					_value = _input.val() || $this.data('value') || opts.min;
108					
109				if(!_input.data('wl_Number')) _input.wl_Number();
110
111				$this.unbind('slide slidechange').slider('value', _value);
112				
113				//set callbacks on slide to change input fields
114				$this.bind('slide', function (event, ui) {
115					_input.val(ui.value);
116					$.fn.wl_Slider.methods.slide.call($this[0], ui.value);
117				}).bind('slidechange', function (event, ui) {
118					_input.val(ui.value);
119					$.fn.wl_Slider.methods.change.call($this[0], ui.value);
120				});
121				_input.val(_value).wl_Number('set', $.extend({}, opts, {
122					onChange: function (value) {
123						$this.slider('value', value);
124						$this.wl_Slider('slide');
125						$this.wl_Slider('change');
126					}
127				}));
128				
129			//range slider with two handlers
130			} else {
131				var _input = $.parseData(opts.connect, true),
132					_input1 = $('#' + _input[0]),
133					_input2 = $('#' + _input[1]),
134					_value1 = _input1.val() || $this.data('values')[0] || opts.min,
135					_value2 = _input2.val() || $this.data('values')[1] || opts.max;
136
137				if(!_input1.data('wl_Number')) _input1.wl_Number();
138				if(!_input2.data('wl_Number')) _input2.wl_Number();
139				
140				//set callbacks on slide to change input fields
141				$this.unbind('slide slidechange').slider('option', 'values', [_value1, _value2]).bind('slide', function (event, ui) {
142					_input1.val(ui.values[0]);
143					_input2.val(ui.values[1]);
144					$.fn.wl_Slider.methods.slide.call($this[0], ui.values);
145				}).bind('slidechange', function (event, ui) {
146					_input1.val(ui.values[0]);
147					_input2.val(ui.values[1]);
148					$.fn.wl_Slider.methods.change.call($this[0], ui.values);
149				});
150
151				//set callbacks to the connected input fields
152				_input1.wl_Number('set', $.extend({}, opts, {
153					onChange: function (value) {
154						$this.slider('option', 'values', [value, _input2.val()]);
155						_input2.wl_Number('set', 'min', parseFloat(value));
156						$this.wl_Slider('slide');
157						$this.wl_Slider('change');
158					},
159					min: opts.min,
160					max: _input2.val() || _value2
161				})).val(_value1);
162
163				_input2.wl_Number('set', $.extend({}, opts, {
164					onChange: function (value) {
165						$this.slider('option', 'values', [_input1.val(), value]);
166						_input1.wl_Number('set', 'max', parseFloat(value));
167						$this.wl_Slider('slide');
168						$this.wl_Slider('change');
169					},
170					min: _input1.val() || _value1,
171					max: opts.max
172				})).val(_value2);
173			}
174		}
175		
176		//activate tooltip
177		if(opts.tooltip){
178			
179			var e = $this.find('.ui-slider-handle');
180			var gravity, handles = [];
181			
182			//set the gravity
183			if($.isArray(opts.tooltipGravity)){
184				if(opts.orientation == 'horizontal'){
185					gravity = opts.tooltipGravity[0];
186				}else if(opts.orientation == 'vertical'){
187					gravity = opts.tooltipGravity[1];
188				}
189			}else{
190				gravity = opts.tooltipGravity;
191			}
192			
193			//for each handle (e)
194			$.each(e, function(i,handle){
195				
196				var value;
197				
198				handles.push($(handle));
199				
200				//get the value as array. set it to zero if undefined (required for init)
201				if(opts.values){
202					value = opts.values;
203				}else if(opts.value){
204					value = [opts.value];
205				}else{
206					value = [0,0];	
207				}
208				
209				//use tipsy for a tooltip
210				handles[i].tipsy($.extend({}, config.tooltip, {
211					trigger: 'manual',
212					gravity: gravity,
213					html: true,
214					fallback: opts.tooltipPattern.replace('%n',value[i]),
215					appendTo: handles[i]
216				}));
217				
218				//prevent the tooltip to wrap
219				var tip = handles[i].tipsy('tip');
220				tip.find('.tipsy-inner').css('white-space','nowrap');
221				
222				//bind events to the handler(s)
223				handles[i].bind({
224					'mouseenter.wl_Slider touchstart.wl_Slider':function(){handles[i].tipsy('show');},
225					'mouseleave.wl_Slider touchend.wl_Slider':function(){handles[i].tipsy('hide');},
226					'mouseenter touchstart':function(){handles[i].data('mouseIsOver',true);},
227					'mouseleave touchend':function(){handles[i].data('mouseIsOver',false);}
228				});
229				
230			});
231			
232			
233			$this
234			//unbind events if the slider starts (prevents flickering if the cursor leaves the handle)
235			.bind('slidestart', function (event, ui) {
236				$(ui.handle).unbind('mouseleave.wl_Slider touchstart.wl_Slider mouseenter.wl_Slider touchend.wl_Slider');
237			})
238			//rebind them again on slidestop
239			.bind('slidestop', function (event, ui) {
240				var handle = $(ui.handle);
241				handle.bind({
242					'mouseenter.wl_Slider touchstart.wl_Slider':function(){handle.tipsy('show');},
243					'mouseleave.wl_Slider touchend.wl_Slider':function(){handle.tipsy('hide');}
244				});
245				//hide the tooltip if the mouse isn't over the handle
246				if(!handle.data('mouseIsOver'))handle.tipsy('hide');
247			})
248			
249			//update the tooltip on the slide event
250			.bind('slide', function (event, ui) {
251				var handle = $(ui.handle);
252				handle.tipsy('setTitel',opts.tooltipPattern.replace('%n',ui.value));
253				handle.tipsy('update');
254			});
255			
256			
257		}
258
259		//disable if set
260		if (opts.disabled) {
261			$this.fn.wl_Slider.methods.disable.call($this[0]);
262		}
263
264		if (opts) $.extend($this.data('wl_Slider'), opts);
265	});
266
267};
268
269$.fn.wl_Slider.defaults = {
270	min: 0,
271	max: 100,
272	step: 1,
273	animate: false,
274	disabled: false,
275	orientation: 'horizontal',
276	range: false,
277	mousewheel: true,
278	connect: null,
279	tooltip: false,
280	tooltipGravity: ['s','w'],
281	tooltipPattern: '%n',
282	onSlide: function (value) {},
283	onChange: function (value) {}
284};
285$.fn.wl_Slider.version = '1.1.1';
286
287
288$.fn.wl_Slider.methods = {
289	disable: function () {
290		var $this = $(this),
291			opts = $this.data('wl_Slider');
292		
293		//disable slider
294		$this.slider('disable');
295		
296		//disable connected input fields
297		if (opts.connect) {
298			if ($this.data('range') !== true) {
299				$('#' + opts.connect).prop('disabled', true);
300			} else {
301				var _input = $.parseData(opts.connect, true),
302					_input1 = $('#' + _input[0]),
303					_input2 = $('#' + _input[1]);
304				_input1.attr('disabled', true);
305				_input2.attr('disabled', true);
306			}
307		}
308		$this.data('wl_Slider').disabled = true;
309	},
310	enable: function () {
311		var $this = $(this),
312			opts = $this.data('wl_Slider');
313		
314		//enable slider
315		$this.slider('enable');
316		
317		//enable connected input fields
318		if ($this.data('wl_Slider').connect) {
319			if ($this.data('range') !== true) {
320				$('#' + opts.connect).prop('disabled', false);
321			} else {
322				var _input = $.parseData(opts.connect, true),
323					_input1 = $('#' + _input[0]),
324					_input2 = $('#' + _input[1]);
325				_input1.removeAttr('disabled');
326				_input2.removeAttr('disabled');
327			}
328		}
329		$this.data('wl_Slider').disabled = false;
330	},
331	change: function (value) {
332		var $this = $(this),
333			opts = $this.data('wl_Slider');
334		if ($this.data('range') !== true) {
335			opts.onChange.call(this, value || $this.slider('value'));
336		} else {
337			opts.onChange.call(this, value || $this.slider('values'));
338		}
339	},
340	slide: function (value) {
341		var $this = $(this),
342			opts = $this.data('wl_Slider');
343		if ($this.data('range') !== true) {
344			opts.onSlide.call(this, value || $this.slider('value'));
345		} else {
346			opts.onSlide.call(this, value || $this.slider('values'));
347		}
348	},
349	value: function () {
350		var $this = $(this),
351			opts = $this.data('wl_Slider');
352		if (opts.range !== true) {
353			$this.slider('value', arguments[0]);
354		}
355	},
356	values: function () {
357		var $this = $(this),
358			opts = $this.data('wl_Slider');
359		if (opts.range === true) {
360			if (typeof arguments[0] === 'object') {
361				$this.slider('values', 0, arguments[0][0]);
362				$this.slider('values', 1, arguments[0][1]);
363			} else {
364				$this.slider('values', 0, arguments[0]);
365				$this.slider('values', 1, arguments[1]);
366			}
367		} else {
368			$.fn.wl_Slider.methods.value.call(this, arguments[0]);
369		}
370	},
371	set: function () {
372		var $this = $(this),
373			options = {};
374		if (typeof arguments[0] === 'object') {
375			options = arguments[0];
376		} else if (arguments[0] && arguments[1] !== undefined) {
377			options[arguments[0]] = arguments[1];
378		}
379		if ($this.data('wl_Slider').connect) {
380			if ($this.data('range') !== true) {
381				var _input1 = $('#' + $this.data('wl_Slider').connect);
382			} else {
383				var _input = $.parseData($this.data('wl_Slider').connect, true),
384					_input1 = $('#' + _input[0]),
385					_input2 = $('#' + _input[1]);
386			}
387		}
388		$.each(options, function (key, value) {
389			if ($.fn.wl_Slider.defaults[key] !== undefined || $.fn.wl_Slider.defaults[key] == null) {
390				$this.slider('option', key, value).data('wl_Slider')[key] = value;
391				if (_input1) _input1.data(key, value).trigger('change');
392				if (_input2) _input2.data(key, value).trigger('change');
393			} else {
394				$.error('Key "' + key + '" is not defined');
395			}
396		});
397
398	}
399};

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.