Index: trunk/parsers/wikidom/lib/es/es.Range.js |
— | — | @@ -4,8 +4,31 @@ |
5 | 5 | * @param start {Integer} Starting point |
6 | 6 | * @param end {Integer} Ending point |
7 | 7 | * @returns {es.Range} |
| 8 | + * @property to {Integer} |
| 9 | + * @property from {Integer} |
| 10 | + * @property start {Integer} |
| 11 | + * @property end {Integer} |
8 | 12 | */ |
9 | | -es.Range = function( start, end ) { |
10 | | - this.start = start || null; |
11 | | - this.end = end || null; |
| 13 | +es.Range = function( from, to ) { |
| 14 | + this.set( from, to ); |
| 15 | +}; |
| 16 | + |
| 17 | +es.Range.prototype.set = function( from, to ) { |
| 18 | + this.from = from || 0; |
| 19 | + this.to = to || from; |
| 20 | + this.normalize(); |
12 | 21 | } |
| 22 | + |
| 23 | +es.Range.prototype.getLength = function() { |
| 24 | + return Math.abs( this.from - this.to ); |
| 25 | +}; |
| 26 | + |
| 27 | +es.Range.prototype.normalize = function() { |
| 28 | + if ( this.from < this.to ) { |
| 29 | + this.start = this.from; |
| 30 | + this.end = this.to; |
| 31 | + } else { |
| 32 | + this.start = this.to; |
| 33 | + this.end = this.from; |
| 34 | + } |
| 35 | +}; |