moved qdb here because matt is lazy
[public/www-new.git] / pub / qdb / res / themes / default / js / slider / range.js
1 /*----------------------------------------------------------------------------\\r
2 |                                Range Class                                  |\r
3 |-----------------------------------------------------------------------------|\r
4 |                         Created by Erik Arvidsson                           |\r
5 |                  (http://webfx.eae.net/contact.html#erik)                   |\r
6 |                      For WebFX (http://webfx.eae.net/)                      |\r
7 |-----------------------------------------------------------------------------|\r
8 | Used to  model the data  used  when working  with  sliders,  scrollbars and |\r
9 | progress bars.  Based  on  the  ideas of  the javax.swing.BoundedRangeModel |\r
10 | interface  defined  by  Sun  for  Java;   http://java.sun.com/products/jfc/ |\r
11 | swingdoc-api-1.0.3/com/sun/java/swing/BoundedRangeModel.html                |\r
12 |-----------------------------------------------------------------------------|\r
13 |                Copyright (c) 2002, 2005, 2006 Erik Arvidsson                |\r
14 |-----------------------------------------------------------------------------|\r
15 | Licensed under the Apache License, Version 2.0 (the "License"); you may not |\r
16 | use this file except in compliance with the License.  You may obtain a copy |\r
17 | of the License at http://www.apache.org/licenses/LICENSE-2.0                |\r
18 | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |\r
19 | Unless  required  by  applicable law or  agreed  to  in  writing,  software |\r
20 | distributed under the License is distributed on an  "AS IS" BASIS,  WITHOUT |\r
21 | WARRANTIES OR  CONDITIONS OF ANY KIND,  either express or implied.  See the |\r
22 | License  for the  specific language  governing permissions  and limitations |\r
23 | under the License.                                                          |\r
24 |-----------------------------------------------------------------------------|\r
25 | 2002-10-14 | Original version released                                      |\r
26 | 2005-10-27 | Use Math.round instead of Math.floor                           |\r
27 | 2006-05-28 | Changed license to Apache Software License 2.0.                |\r
28 |-----------------------------------------------------------------------------|\r
29 | Created 2002-10-14 | All changes are in the log above. | Updated 2006-05-28 |\r
30 \----------------------------------------------------------------------------*/\r
31 \r
32 \r
33 function Range() {\r
34         this._value = 0;\r
35         this._minimum = 0;\r
36         this._maximum = 100;\r
37         this._extent = 0;\r
38 \r
39         this._isChanging = false;\r
40 }\r
41 \r
42 Range.prototype.setValue = function (value) {\r
43         value = Math.round(parseFloat(value));\r
44         if (isNaN(value)) return;\r
45         if (this._value != value) {\r
46                 if (value + this._extent > this._maximum)\r
47                         this._value = this._maximum - this._extent;\r
48                 else if (value < this._minimum)\r
49                         this._value = this._minimum;\r
50                 else\r
51                         this._value = value;\r
52                 if (!this._isChanging && typeof this.onchange == "function")\r
53                          this.onchange();\r
54         }\r
55 };\r
56 \r
57 Range.prototype.getValue = function () {\r
58         return this._value;\r
59 };\r
60 \r
61 Range.prototype.setExtent = function (extent) {\r
62         if (this._extent != extent) {\r
63                 if (extent < 0)\r
64                         this._extent = 0;\r
65                 else if (this._value + extent > this._maximum)\r
66                         this._extent = this._maximum - this._value;\r
67                 else\r
68                         this._extent = extent;\r
69                 if (!this._isChanging && typeof this.onchange == "function")\r
70                         this.onchange();\r
71         }\r
72 };\r
73 \r
74 Range.prototype.getExtent = function () {\r
75         return this._extent;\r
76 };\r
77 \r
78 Range.prototype.setMinimum = function (minimum) {\r
79         if (this._minimum != minimum) {\r
80                 var oldIsChanging = this._isChanging;\r
81                 this._isChanging = true;\r
82 \r
83                 this._minimum = minimum;\r
84 \r
85                 if (minimum > this._value)\r
86                         this.setValue(minimum);\r
87                 if (minimum > this._maximum) {\r
88                         this._extent = 0;\r
89                         this.setMaximum(minimum);\r
90                         this.setValue(minimum)\r
91                 }\r
92                 if (minimum + this._extent > this._maximum)\r
93                         this._extent = this._maximum - this._minimum;\r
94 \r
95                 this._isChanging = oldIsChanging;\r
96                 if (!this._isChanging && typeof this.onchange == "function")\r
97                         this.onchange();\r
98         }\r
99 };\r
100 \r
101 Range.prototype.getMinimum = function () {\r
102         return this._minimum;\r
103 };\r
104 \r
105 Range.prototype.setMaximum = function (maximum) {\r
106         if (this._maximum != maximum) {\r
107                 var oldIsChanging = this._isChanging;\r
108                 this._isChanging = true;\r
109 \r
110                 this._maximum = maximum;\r
111 \r
112                 if (maximum < this._value)\r
113                         this.setValue(maximum - this._extent);\r
114                 if (maximum < this._minimum) {\r
115                         this._extent = 0;\r
116                         this.setMinimum(maximum);\r
117                         this.setValue(this._maximum);\r
118                 }\r
119                 if (maximum < this._minimum + this._extent)\r
120                         this._extent = this._maximum - this._minimum;\r
121                 if (maximum < this._value + this._extent)\r
122                         this._extent = this._maximum - this._value;\r
123 \r
124                 this._isChanging = oldIsChanging;\r
125                 if (!this._isChanging && typeof this.onchange == "function")\r
126                         this.onchange();\r
127         }\r
128 };\r
129 \r
130 Range.prototype.getMaximum = function () {\r
131         return this._maximum;\r
132 };\r