-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
42 lines (35 loc) · 988 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
'use strict';
var get = require('get-value');
module.exports = function(options) {
return function(breakdance) {
// overrides the built-in `input` handler
breakdance.set('input', function(node) {
var type = get(node, 'attribs.type');
var prefix = '';
if (get(node.attribs, 'checked') === '') {
type = 'checkbox checked';
}
if (!this.isInside(node.parent, 'li')) {
prefix = '* ';
var cls = get(node, 'parent.attribs.class');
var m = /checkbox\s*(checked|active|enabled)?/.exec(cls);
if (m) {
type = m[1] ? 'checkbox checked' : 'checkbox';
}
}
switch (type) {
case 'checkbox checked':
case 'checkbox active':
this.emit(prefix + '[x] ', node);
break;
case 'checkbox':
this.emit(prefix + '[ ] ', node);
break;
default: {
this.emit('', node);
break;
}
}
});
};
};