/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: galaxyAbstractor
  • Date: 2013-04-04 16:19:07 UTC
  • mto: (12.2.4 lenasys) (19.1.4 lenasys)
  • mto: This revision was merged to the branch mainline in revision 17.
  • Revision ID: galaxyabstractor@gmail.com-20130404161907-eo1wnb7ac2rnizg8
Started implementation of a new codeviewer using Ace

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