9
$('*').each(function() {
15
function createDemoSliders() {
17
str += makePanel(250, 200);
18
str += makeLabel("Slider");
19
str += makeSlider("slider", 1, 2, 7, 4.5, 160, 5);
20
str += makeLabel("Binary");
21
str += makeBinary("binary", 0);
22
str += makePanelEnd();
23
document.getElementById("container").innerHTML = str;
28
// Recursive Pos of div in document - should work in most browsers
29
function findPos(obj) {
30
var curLeft = curTop = 0;
31
if (obj.offsetParent) {
32
curLeft = obj.offsetLeft
33
curTop = obj.offsetTop
34
while (obj = obj.offsetParent) {
35
curLeft += obj.offsetLeft
36
curTop += obj.offsetTop
47
ui read widget functions
51
function readSlider(sliderId) {
52
var value = parseFloat(document.getElementById(sliderId + "box").value);
59
function readBinary(binaryId) {
60
lf = document.getElementById(binaryId + "marker").style.left;
70
ui change widget functions
74
// The idea is to have a few functions like this one and minimum javascript intervention
75
function updateBinary(event, binaryId) {
77
coords = findPos(event.currentTarget);
78
coords.x = event.clientX - coords.x;
79
coords.y = event.clientY - coords.y;
81
document.getElementById(binaryId + "marker").style.left = 20 + "px";
82
document.getElementById(binaryId).style.backgroundColor = "#ddd";
83
}else if(coords.x < 16) {
84
document.getElementById(binaryId + "marker").style.left = 2 + "px";
85
document.getElementById(binaryId).style.backgroundColor = "#777";
90
// The idea is to have a few functions like this one and minimum javascript intervention
91
function updateSlider(event, kind, min, max, length, sliderId, boxId) {
93
coords = findPos(event.currentTarget);
94
coords.x = event.clientX - coords.x;
95
coords.y = event.clientY - coords.y;
96
cx = coords.x / length;
98
value = min + (sd * cx);
99
if (value > max) value = max;
101
value = Math.round(value);
104
value = Math.round(value * 10.0) / 10.0;
107
value = Math.round(value * 100.0) / 100.0;
110
value = Math.round(value * 1000.0) / 1000.0;
112
document.getElementById(boxId).value = value;
113
document.getElementById(sliderId).style.left = Math.ceil((length) * ((value - min) / sd)) + "px";
117
function sliderPosition(value, min, max, length) {
124
pos = Math.round(((value - min) / (max - min)) * length);
128
function changeSlider(value, sliderId, kind, min, max, length) {
129
value = parseFloat(value);
140
value = Math.round(value);
143
value = Math.round(value * 10.0) / 10.0;
146
value = Math.round(value * 100.0) / 100.0;
149
value = Math.round(value * 1000.0) / 1000.0;
151
pos = sliderPosition(value, min, max, length);
152
document.getElementById(sliderId + "box").value = value;
153
document.getElementById(sliderId + "marker").style.left = pos + "px";
158
ui make widget functions
162
function makeLabel(name) {
164
s += "<div class='label'>" + name + "</div>";
168
function makePanel(width, height) {
170
s += "<div class='panel' style='height: " + height + "px; width: " + width + "px;'>";
174
function makePanelEnd() {
179
function makeSlider(sliderId, kind, minValue, maxValue, midValue, sliderWidth, defaultValue) {
181
defaultPosition = sliderPosition(defaultValue, minValue, maxValue, sliderWidth);
182
if (defaultValue < minValue) {
183
defaultValue = minValue;
185
if (defaultValue > maxValue) {
186
defaultValue = maxValue;
188
s += "<input id='" + sliderId + "box' value='" + defaultValue + "' type='text' class='sliderBox' onBlur='changeSlider(this.value,\"" + sliderId + "\"," + kind + "," + minValue + "," + maxValue + "," + sliderWidth + ");'>";
189
s += "<div id='" + sliderId + "' class='sliderLine' style='width:" + sliderWidth + "px;'";
190
s += " onmousemove='updateSlider(event," + kind + "," + minValue + "," + maxValue + "," + sliderWidth + ",\"" + sliderId + "marker\",\"" + sliderId + "box\");'";
191
s += " onmouseup='updateSlider(event," + kind + "," + minValue + "," + maxValue + "," + sliderWidth + ",\"" + sliderId + "marker\",\"" + sliderId + "box\");'>";
192
s += " <div id='" + sliderId + "marker' class='sliderMarker' style='left:" + defaultPosition + "px;'></div>";
194
s += "<div class='slidermidValue' style='width:" + sliderWidth + "px;'>" + midValue;
195
s += "<div class='sliderminValue'>" + minValue + "</div>";
196
s += "<div class='slidermaxValue'>" + maxValue + "</div></div>";
200
function makeBinary(binaryId, defaultValue) {
202
if (defaultValue == 1) {
203
defaultPosition = 20;
204
defaultColor = "#ddd";
207
defaultColor = "#777";
209
s += "<div id='" + binaryId + "' class='binaryLine' style='background-color:" + defaultColor + ";' onmousemove='updateBinary(event,\"" + binaryId + "\");' onmouseup='updateBinary(event,\"" + binaryId + "\");'>";
210
s += "<div id='" + binaryId + "marker' class='binaryMarker' style='left:" + defaultPosition + "px;'></div>";
217
function mbPress(event) {
221
function mbRelease(event) {
b'\\ No newline at end of file'