blob: 3313d7050aea3594ecf81c1d9ccd5097404bbdc1 [file] [log] [blame]
Akron9905e2a2016-05-10 16:06:44 +02001define({
2
3 /**
4 * Create new prefix object.
5 */
6 create : function () {
7 return Object.create(this)._init();
8 },
9
Akron6b24b202016-05-17 23:04:36 +020010 _mousemove : function (e) {
11
12 var offset = parseInt(
13 (
14 (e.clientY - this._event.init)
15 / this._rulerHeight
16 ) * this._screens
17 );
18
19 this.offset(offset);
20
21 e.halt();
22 /*
23 isTouch?e.touches[0]:e
24 ,offset = horizontal?client.clientX - lastClient.clientX:client.clientY - lastClient.clientY
25 ,barPos = Math.min(Math.max(orgBarPos + offset,0),dir.viewportSize-dir.barSize)
26 ;
27 //
28 inst.viewport[getScroll(horizontal)] = (barPos/dir.viewportSize)*dir.viewportScrollSize;
29 */
30 },
31
32 _mouseup : function (e) {
33
34 window.removeEventListener('mousemove', this._event.mov);
35 window.removeEventListener('mouseup', this._event.up);
36 },
37
38 _mousedown : function (e) {
39 // Bind drag handler
40 var ev = this._event;
41 ev.init = e.clientY;
42 ev.mov = this._mousemove.bind(this);
43 ev.up = this._mouseup.bind(this);
44
45 this._rulerHeight = this._element.clientHeight; // offsetHeight?
46
47 window.addEventListener('mousemove', ev.mov);
48 window.addEventListener('mouseup', ev.up);
49
50 e.halt();
51 },
52
Akron9905e2a2016-05-10 16:06:44 +020053 // Initialize prefix object
54 _init : function () {
55
Akronf86eaea2016-05-13 18:02:27 +020056 this._offset = 0;
Akron6b24b202016-05-17 23:04:36 +020057 this._event = {};
Akronf86eaea2016-05-13 18:02:27 +020058
Akron9905e2a2016-05-10 16:06:44 +020059 this._element = document.createElement('div');
60 this._element.setAttribute('class', 'ruler');
61
62 this._slider = this._element.appendChild(
63 document.createElement('span')
64 );
65
Akron6b24b202016-05-17 23:04:36 +020066 // TODO: Support touch!
67 this._slider.addEventListener('mousedown', this._mousedown.bind(this), false);
68
Akron9905e2a2016-05-10 16:06:44 +020069 this._element.appendChild(document.createElement('div'));
Akron9905e2a2016-05-10 16:06:44 +020070 return this;
71 },
72
Akronf86eaea2016-05-13 18:02:27 +020073 _initSize : function () {
74 this._height = ((this._limit / this._length) * 100);
Akron6b24b202016-05-17 23:04:36 +020075 this._screens = this._length - this._limit;
76 this._step = (100 - this._height) / this._screens;
Akronf86eaea2016-05-13 18:02:27 +020077 },
78
Akron9905e2a2016-05-10 16:06:44 +020079 show : function (i) {
Akronf86eaea2016-05-13 18:02:27 +020080 this._slider.style.height = this._height + '%';
Akron9905e2a2016-05-10 16:06:44 +020081 },
82
83 length : function (i) {
84 this._length = i;
Akronf86eaea2016-05-13 18:02:27 +020085 this._initSize();
Akron9905e2a2016-05-10 16:06:44 +020086 },
87
88 limit : function (i) {
89 this._limit = i;
Akronf86eaea2016-05-13 18:02:27 +020090 this._initSize();
91 },
92
93 offset : function (off) {
94 if (off === undefined)
95 return this._offset;
96
Akron6b24b202016-05-17 23:04:36 +020097 if (off === this._offset || off > this._screens || off < 0)
98 return;
99
Akronf86eaea2016-05-13 18:02:27 +0200100 this._offset = off;
101 this._slider.style.top = (this._step * off) + '%';
Akron9905e2a2016-05-10 16:06:44 +0200102 },
103
104 element : function () {
105 return this._element;
106 }
107});