LabelFactory.js
1.15 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
'use strict';
/**
* The label factory provides a label entry. For the label text
* it expects either a string provided by the options.labelText
* parameter or it could be generated programmatically using a
* function passed as the options.get parameter.
*
* @param {Object} options
* @param {string} options.id
* @param {string} [options.labelText]
* @param {Function} [options.get]
* @param {Function} [options.showLabel]
* @param {Boolean} [options.divider] adds a divider at the top of the label if true; default: false
*/
var label = function(options) {
return {
id: options.id,
html: '<label data-value="label" ' +
'data-show="showLabel" ' +
'class="entry-label' + (options.divider ? ' divider' : '') + '">' +
'</label>',
get: function(element, node) {
if (typeof options.get === 'function') {
return options.get(element, node);
}
return { label: options.labelText };
},
showLabel: function(element, node) {
if (typeof options.showLabel === 'function') {
return options.showLabel(element, node);
}
return true;
}
};
};
module.exports = label;