/lenasys/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/lenasys/trunk

« back to all changes in this revision

Viewing changes to Widget Library/sliders.js

  • Committer: Gustav Hartvigsson
  • Date: 2013-04-12 17:00:09 UTC
  • mfrom: (23.1.4 lenasys)
  • Revision ID: gustav.hartvigsson@gmail.com-20130412170009-gla04s3anpjep68p
Merging implementation group one's team bnanch in to trunk.
This is also end of this cycle.

Good work guys.

20130412.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 
5
5
*/
6
6
 
 
7
// Fixes css3 for IE
 
8
function attachPIE() {
 
9
        $('*').each(function() {
 
10
                PIE.attach(this);
 
11
        });
 
12
}
 
13
 
 
14
// Creates a demo
 
15
function createDemoSliders() {
 
16
        str = "";
 
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;
 
24
        attachPIE();
 
25
 
 
26
}
 
27
 
7
28
// Recursive Pos of div in document - should work in most browsers
8
29
function findPos(obj) {
9
30
        var curLeft = curTop = 0;
10
 
        if(obj.offsetParent) {
 
31
        if (obj.offsetParent) {
11
32
                curLeft = obj.offsetLeft
12
33
                curTop = obj.offsetTop
13
 
                while(obj = obj.offsetParent) {
 
34
                while (obj = obj.offsetParent) {
14
35
                        curLeft += obj.offsetLeft
15
36
                        curTop += obj.offsetTop
16
37
                }
29
50
 
30
51
function readSlider(sliderId) {
31
52
        var value = parseFloat(document.getElementById(sliderId + "box").value);
32
 
        if(isNaN(value)) {
 
53
        if (isNaN(value)) {
33
54
                value = 0.0;
34
55
        }
35
56
        return value;
37
58
 
38
59
function readBinary(binaryId) {
39
60
        lf = document.getElementById(binaryId + "marker").style.left;
40
 
        if(lf == "2px") {
 
61
        if (lf == "2px") {
41
62
                return 0;
42
63
        } else {
43
64
                return 1;
52
73
 
53
74
// The idea is to have a few functions like this one and minimum javascript intervention                
54
75
function updateBinary(event, binaryId) {
55
 
        if(mb) {
 
76
        if (mb) {
56
77
                coords = findPos(event.currentTarget);
57
78
                coords.x = event.clientX - coords.x;
58
79
                coords.y = event.clientY - coords.y;
68
89
 
69
90
// The idea is to have a few functions like this one and minimum javascript intervention                
70
91
function updateSlider(event, kind, min, max, length, sliderId, boxId) {
71
 
        if(mb) {
 
92
        if (mb) {
72
93
                coords = findPos(event.currentTarget);
73
94
                coords.x = event.clientX - coords.x;
74
95
                coords.y = event.clientY - coords.y;
75
96
                cx = coords.x / length;
76
97
                sd = max - min;
77
98
                value = min + (sd * cx);        
78
 
                if(value > max) value = max;
79
 
                if(kind == 0) {
 
99
                if (value > max) value = max;
 
100
                if (kind == 0) {
80
101
                        value = Math.round(value);
81
102
                }
82
 
                if(kind == 1) {
 
103
                if (kind == 1) {
83
104
                        value = Math.round(value * 10.0) / 10.0;
84
105
                }
85
 
                if(kind == 2) {
 
106
                if (kind == 2) {
86
107
                        value = Math.round(value * 100.0) / 100.0;
87
108
                }
88
 
                if(kind == 3) {
 
109
                if (kind == 3) {
89
110
                        value = Math.round(value * 1000.0) / 1000.0;
90
111
                }
91
112
                document.getElementById(boxId).value = value;                           
94
115
}
95
116
                
96
117
function sliderPosition(value, min, max, length) {
97
 
                if(value < min) {
 
118
                if (value < min) {
98
119
                        value = min;
99
120
                }
100
 
                if(value > max) {
 
121
                if (value > max) {
101
122
                        value = max;
102
123
                }
103
124
                pos = Math.round(((value - min) / (max - min)) * length);
106
127
 
107
128
function changeSlider(value, sliderId, kind, min, max, length) {
108
129
                value = parseFloat(value);              
109
 
                if(isNaN(value)) {
 
130
                if (isNaN(value)) {
110
131
                        value = 0.0;
111
132
                }
112
 
                if(value < min) {
 
133
                if (value < min) {
113
134
                        value = min;
114
135
                }
115
 
                if(value > max) {
 
136
                if (value > max) {
116
137
                        value = max;
117
138
                }
118
 
                if(kind == 0) {
 
139
                if (kind == 0) {
119
140
                        value = Math.round(value);
120
141
                }
121
 
                if(kind == 1) {
 
142
                if (kind == 1) {
122
143
                        value = Math.round(value * 10.0) / 10.0;
123
144
                }
124
 
                if(kind == 2) {
 
145
                if (kind == 2) {
125
146
                        value = Math.round(value * 100.0) / 100.0;
126
147
                }
127
 
                if(kind == 3) {
 
148
                if (kind == 3) {
128
149
                        value = Math.round(value * 1000.0) / 1000.0;
129
150
                }
130
151
                pos = sliderPosition(value, min, max, length);
158
179
function makeSlider(sliderId, kind, minValue, maxValue, midValue, sliderWidth, defaultValue) {
159
180
        s = "";
160
181
        defaultPosition = sliderPosition(defaultValue, minValue, maxValue, sliderWidth);
161
 
        if(defaultValue < minValue) {
 
182
        if (defaultValue < minValue) {
162
183
                defaultValue = minValue;
163
184
        }
164
 
        if(defaultValue > maxValue) {
 
185
        if (defaultValue > maxValue) {
165
186
                defaultValue = maxValue;
166
187
        }                                       
167
188
        s += "<input id='" + sliderId + "box' value='" + defaultValue + "' type='text' class='sliderBox' onBlur='changeSlider(this.value,\"" + sliderId + "\"," + kind + "," + minValue + "," + maxValue + "," + sliderWidth + ");'>";
178
199
 
179
200
function makeBinary(binaryId, defaultValue) {
180
201
        s = "";
181
 
        if(defaultValue == 1) {
 
202
        if (defaultValue == 1) {
182
203
                defaultPosition = 20;
183
204
                defaultColor = "#ddd";
184
205
        } else {