1 /*----------------------------------------------------------------------------\
3 |-----------------------------------------------------------------------------|
4 | Created by Erik Arvidsson |
5 | (http://webfx.eae.net/contact.html#erik) |
6 | For WebFX (http://webfx.eae.net/) |
7 |-----------------------------------------------------------------------------|
8 | Used to model the data used when working with sliders, scrollbars and |
9 | progress bars. Based on the ideas of the javax.swing.BoundedRangeModel |
10 | interface defined by Sun for Java; http://java.sun.com/products/jfc/ |
11 | swingdoc-api-1.0.3/com/sun/java/swing/BoundedRangeModel.html |
12 |-----------------------------------------------------------------------------|
13 | Copyright (c) 2002, 2005, 2006 Erik Arvidsson |
14 |-----------------------------------------------------------------------------|
15 | Licensed under the Apache License, Version 2.0 (the "License"); you may not |
16 | use this file except in compliance with the License. You may obtain a copy |
17 | of the License at http://www.apache.org/licenses/LICENSE-2.0 |
18 | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
19 | Unless required by applicable law or agreed to in writing, software |
20 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
21 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
22 | License for the specific language governing permissions and limitations |
23 | under the License. |
24 |-----------------------------------------------------------------------------|
25 | 2002-10-14 | Original version released |
26 | 2005-10-27 | Use Math.round instead of Math.floor |
27 | 2006-05-28 | Changed license to Apache Software License 2.0. |
28 |-----------------------------------------------------------------------------|
29 | Created 2002-10-14 | All changes are in the log above. | Updated 2006-05-28 |
30 \----------------------------------------------------------------------------*/
39 this._isChanging = false;
42 Range.prototype.setValue = function (value) {
43 value = Math.round(parseFloat(value));
44 if (isNaN(value)) return;
45 if (this._value != value) {
46 if (value + this._extent > this._maximum)
47 this._value = this._maximum - this._extent;
48 else if (value < this._minimum)
49 this._value = this._minimum;
52 if (!this._isChanging && typeof this.onchange == "function")
57 Range.prototype.getValue = function () {
61 Range.prototype.setExtent = function (extent) {
62 if (this._extent != extent) {
65 else if (this._value + extent > this._maximum)
66 this._extent = this._maximum - this._value;
68 this._extent = extent;
69 if (!this._isChanging && typeof this.onchange == "function")
74 Range.prototype.getExtent = function () {
78 Range.prototype.setMinimum = function (minimum) {
79 if (this._minimum != minimum) {
80 var oldIsChanging = this._isChanging;
81 this._isChanging = true;
83 this._minimum = minimum;
85 if (minimum > this._value)
86 this.setValue(minimum);
87 if (minimum > this._maximum) {
89 this.setMaximum(minimum);
90 this.setValue(minimum)
92 if (minimum + this._extent > this._maximum)
93 this._extent = this._maximum - this._minimum;
95 this._isChanging = oldIsChanging;
96 if (!this._isChanging && typeof this.onchange == "function")
101 Range.prototype.getMinimum = function () {
102 return this._minimum;
105 Range.prototype.setMaximum = function (maximum) {
106 if (this._maximum != maximum) {
107 var oldIsChanging = this._isChanging;
108 this._isChanging = true;
110 this._maximum = maximum;
112 if (maximum < this._value)
113 this.setValue(maximum - this._extent);
114 if (maximum < this._minimum) {
116 this.setMinimum(maximum);
117 this.setValue(this._maximum);
119 if (maximum < this._minimum + this._extent)
120 this._extent = this._maximum - this._minimum;
121 if (maximum < this._value + this._extent)
122 this._extent = this._maximum - this._value;
124 this._isChanging = oldIsChanging;
125 if (!this._isChanging && typeof this.onchange == "function")
130 Range.prototype.getMaximum = function () {
131 return this._maximum;