-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
73 lines (57 loc) · 1.5 KB
/
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
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
/**
* Module dependencies.
*/
var spin = require('spin');
var classes = require('classes');
/**
* Module expose.
*/
module.exports = LoadingLock;
/**
* Return new `LoadingLock` instance.
*
* @param {DOMNode} el Document Object Model Node Element
* @param {Object} options Options object.
* @return {LoadingLock} `LoadingLock` instance.
* @api public
*/
function LoadingLock (el, options) {
if (!(this instanceof LoadingLock)) {
return new LoadingLock(el, options);
}
this.el = el;
this.classes = classes(el);
this.classes.add('loading-lock');
// create lock screen element
// with proper css classes
this.lockScreen = document.createElement('span');
classes(this.lockScreen).add('lock-spinner');
// insert lock screen element for
// `spin` height a width refs
this.el.appendChild(this.lockScreen);
// set size of spinner from el's size or options
// defaults to `25`
this.size = options.size || Math.min(this.el.offsetWidth / 5, this.el.offsetHeight / 5) || 25;
}
/**
* Locks element adding 'locked' class
*
* @return {LoadingLock} `LoadingLock` instance.
* @api public
*/
LoadingLock.prototype.lock = function() {
this.classes.add('locked');
this.spinner = spin(this.lockScreen, { delay: 1, size: this.size });
return this;
}
/**
* Unlocks element removing 'locked' class
*
* @return {LoadingLock} `LoadingLock` instance.
* @api public
*/
LoadingLock.prototype.unlock = function() {
this.classes.remove('locked');
this.spinner.remove();
return this;
}