This repository was archived by the owner on Apr 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
74 lines (60 loc) · 1.17 KB
/
Copy pathindex.js
File metadata and controls
74 lines (60 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* dependencies
*/
var direction = require('directionality')
, events = require('events')
, trim = require('trim');
/**
* Export `Direction`
*/
module.exports = Direction;
/**
* Initialize `Direction` with `el`.
*
* @param {Element} el
*/
function Direction(el){
if (!(this instanceof Direction)) return new Direction(el);
if (!el) throw new TypeError('expected element');
this.events = events(el, this);
this.el = el;
this.bind();
}
/**
* Bind internal events.
*
* @return {Direction}
*/
Direction.prototype.bind = function(){
this.events.bind('keyup');
this.events.bind('blur');
return this;
};
/**
* Unbind internal events.
*
* @return {Direction}
*/
Direction.prototype.unbind = function(){
this.events.unbind();
return this;
};
/**
* onkeyup
*/
Direction.prototype.onkeyup = function(e){
if (1 <= this.el.value.length) {
var val = trim.left(this.el.value);
this.el.style.direction = direction(val);
} else if (0 == this.el.value.length) {
this.el.style.direction = null;
}
};
/**
* onblur
*/
Direction.prototype.onblur = function(){
if (0 == this.el.value.length) {
this.el.style.direction = null;
}
};