-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
47 lines (38 loc) · 975 Bytes
/
index.js
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
/**
* Module dependencies.
*/
var domify = require('domify')
, events = require('event')
, wrap = require('wrap');
/**
* Magnified search input.
*/
module.exports = function(el) {
var handle = domify('<div class="magnifier '+el.className+'">')
, width = el.style.width;
// Need to wrap input to add the handle
el.className = 'magnifier-input';
wrap(el, handle);
// Events
function onfocus() {
var parentWidth = getComputedStyle(this.parentNode.parentNode).width;
handle.classList.add('focus');
el.style.width = parentWidth;
}
function onblur() {
if (el.value == '') {
handle.classList.remove('focus');
el.style.width = width;
}
}
function keyup(e) {
if (13 == e.keyCode) {
handle.classList.remove('focus');
handle.classList.add('spin');
el.style.width = width;
}
}
events.bind(el, 'focus', onfocus);
events.bind(el, 'blur', onblur);
events.bind(el, 'keyup', keyup);
}