[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 /*----------------------------------------------------------------------------\ 2 | Range Class | 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 \----------------------------------------------------------------------------*/ 31 32 33 function Range() { 34 this._value = 0; 35 this._minimum = 0; 36 this._maximum = 100; 37 this._extent = 0; 38 39 this._isChanging = false; 40 } 41 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; 50 else 51 this._value = value; 52 if (!this._isChanging && typeof this.onchange == "function") 53 this.onchange(); 54 } 55 }; 56 57 Range.prototype.getValue = function () { 58 return this._value; 59 }; 60 61 Range.prototype.setExtent = function (extent) { 62 if (this._extent != extent) { 63 if (extent < 0) 64 this._extent = 0; 65 else if (this._value + extent > this._maximum) 66 this._extent = this._maximum - this._value; 67 else 68 this._extent = extent; 69 if (!this._isChanging && typeof this.onchange == "function") 70 this.onchange(); 71 } 72 }; 73 74 Range.prototype.getExtent = function () { 75 return this._extent; 76 }; 77 78 Range.prototype.setMinimum = function (minimum) { 79 if (this._minimum != minimum) { 80 var oldIsChanging = this._isChanging; 81 this._isChanging = true; 82 83 this._minimum = minimum; 84 85 if (minimum > this._value) 86 this.setValue(minimum); 87 if (minimum > this._maximum) { 88 this._extent = 0; 89 this.setMaximum(minimum); 90 this.setValue(minimum) 91 } 92 if (minimum + this._extent > this._maximum) 93 this._extent = this._maximum - this._minimum; 94 95 this._isChanging = oldIsChanging; 96 if (!this._isChanging && typeof this.onchange == "function") 97 this.onchange(); 98 } 99 }; 100 101 Range.prototype.getMinimum = function () { 102 return this._minimum; 103 }; 104 105 Range.prototype.setMaximum = function (maximum) { 106 if (this._maximum != maximum) { 107 var oldIsChanging = this._isChanging; 108 this._isChanging = true; 109 110 this._maximum = maximum; 111 112 if (maximum < this._value) 113 this.setValue(maximum - this._extent); 114 if (maximum < this._minimum) { 115 this._extent = 0; 116 this.setMinimum(maximum); 117 this.setValue(this._maximum); 118 } 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; 123 124 this._isChanging = oldIsChanging; 125 if (!this._isChanging && typeof this.onchange == "function") 126 this.onchange(); 127 } 128 }; 129 130 Range.prototype.getMaximum = function () { 131 return this._maximum; 132 };
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Mar 17 22:47:18 2015 | Cross-referenced by PHPXref 0.7.1 |