-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjquery.ui.dial.js
88 lines (73 loc) · 1.95 KB
/
jquery.ui.dial.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* jQuery UI Dial 0.1.0
*
* Copyright 2010 Emil Loer (http://koffietijd.net)
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*
* https://github.com/thedjinn/jquery-ui-dial
*
* Depends:
* jquery.ui.core.js
* jquery.ui.widget.js
* jquery.ui.mouse.js
* jquery.ui.draggable.js
*/
(function($, undefined) {
$.widget("ui.dial", {
options: {
min: -100,
max: 100,
value: 0,
unitsPerPixel: 1,
numImages: 10,
imageWidth: 32
},
_create: function() {
this._value = this.options.value;
this._origValue = this._value;
var self = this;
this.element.addClass("ui-dial");
this.element.draggable({
axis: 'y',
helper: 'original',
scroll: false,
cursor: 'row-resize',
addClasses: false,
drag: function(event, ui) {
var val = (self._origValue + (ui.position.top - ui.originalPosition.top) * -self.options.unitsPerPixel);
ui.position = ui.originalPosition;
self.value(val);
self._trigger("change", event, {value: self._value});
},
start: function(event, ui) {
self._origValue = self._value;
self._trigger("start", event, {value: self._value});
},
stop: function(event, ui) {
self._trigger("stop", event, {value: self._value});
}
});
this._update();
},
destroy: function() {
$.Widget.prototype.destroy.apply(this, arguments);
},
value: function(newValue) {
if (newValue === undefined) {
return this._value;
}
if (typeof newValue === "number") {
this._value = newValue;
this._value = Math.max(this._value, this.options.min);
this._value = Math.min(this._value, this.options.max);
this._update();
}
return this;
},
_update: function() {
var pos = Math.round((this._value - this.options.min) / (this.options.max - this.options.min) * (this.options.numImages - 1)) * this.options.imageWidth;
this.element.css("background-position", "-" + pos + "px 0");
}
});
})(jQuery);