Akron | 9905e2a | 2016-05-10 16:06:44 +0200 | [diff] [blame] | 1 | define({ |
| 2 | |
| 3 | /** |
| 4 | * Create new prefix object. |
| 5 | */ |
| 6 | create : function () { |
| 7 | return Object.create(this)._init(); |
| 8 | }, |
| 9 | |
| 10 | // Initialize prefix object |
| 11 | _init : function () { |
| 12 | |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame^] | 13 | this._offset = 0; |
| 14 | |
Akron | 9905e2a | 2016-05-10 16:06:44 +0200 | [diff] [blame] | 15 | this._element = document.createElement('div'); |
| 16 | this._element.setAttribute('class', 'ruler'); |
| 17 | |
| 18 | this._slider = this._element.appendChild( |
| 19 | document.createElement('span') |
| 20 | ); |
| 21 | |
| 22 | this._element.appendChild(document.createElement('div')); |
| 23 | |
| 24 | /* |
| 25 | this._string = ''; |
| 26 | |
| 27 | // Add prefix span |
| 28 | this._element = document.createElement('span'); |
| 29 | this._element.classList.add('pref'); |
| 30 | // Connect action |
| 31 | |
| 32 | if (this["onclick"] !== undefined) |
| 33 | this._element["onclick"] = this.onclick.bind(this); |
| 34 | |
| 35 | */ |
| 36 | return this; |
| 37 | }, |
| 38 | |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame^] | 39 | _initSize : function () { |
| 40 | this._height = ((this._limit / this._length) * 100); |
| 41 | this._step = (100 - this._height) / (this._length - this._limit); |
| 42 | }, |
| 43 | |
Akron | 9905e2a | 2016-05-10 16:06:44 +0200 | [diff] [blame] | 44 | show : function (i) { |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame^] | 45 | this._slider.style.height = this._height + '%'; |
Akron | 9905e2a | 2016-05-10 16:06:44 +0200 | [diff] [blame] | 46 | }, |
| 47 | |
| 48 | length : function (i) { |
| 49 | this._length = i; |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame^] | 50 | this._initSize(); |
Akron | 9905e2a | 2016-05-10 16:06:44 +0200 | [diff] [blame] | 51 | }, |
| 52 | |
| 53 | limit : function (i) { |
| 54 | this._limit = i; |
Akron | f86eaea | 2016-05-13 18:02:27 +0200 | [diff] [blame^] | 55 | this._initSize(); |
| 56 | }, |
| 57 | |
| 58 | offset : function (off) { |
| 59 | if (off === undefined) |
| 60 | return this._offset; |
| 61 | |
| 62 | this._offset = off; |
| 63 | this._slider.style.top = (this._step * off) + '%'; |
Akron | 9905e2a | 2016-05-10 16:06:44 +0200 | [diff] [blame] | 64 | }, |
| 65 | |
| 66 | element : function () { |
| 67 | return this._element; |
| 68 | } |
| 69 | }); |