LabelFactory.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. /**
  3. * The label factory provides a label entry. For the label text
  4. * it expects either a string provided by the options.labelText
  5. * parameter or it could be generated programmatically using a
  6. * function passed as the options.get parameter.
  7. *
  8. * @param {Object} options
  9. * @param {string} options.id
  10. * @param {string} [options.labelText]
  11. * @param {Function} [options.get]
  12. * @param {Function} [options.showLabel]
  13. * @param {Boolean} [options.divider] adds a divider at the top of the label if true; default: false
  14. */
  15. var label = function(options) {
  16. return {
  17. id: options.id,
  18. html: '<label data-value="label" ' +
  19. 'data-show="showLabel" ' +
  20. 'class="entry-label' + (options.divider ? ' divider' : '') + '">' +
  21. '</label>',
  22. get: function(element, node) {
  23. if (typeof options.get === 'function') {
  24. return options.get(element, node);
  25. }
  26. return { label: options.labelText };
  27. },
  28. showLabel: function(element, node) {
  29. if (typeof options.showLabel === 'function') {
  30. return options.showLabel(element, node);
  31. }
  32. return true;
  33. }
  34. };
  35. };
  36. module.exports = label;