ToggleButtonViewModel.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import defaultValue from '../Core/defaultValue.js';
  2. import defined from '../Core/defined.js';
  3. import defineProperties from '../Core/defineProperties.js';
  4. import DeveloperError from '../Core/DeveloperError.js';
  5. import knockout from '../ThirdParty/knockout.js';
  6. /**
  7. * A view model which exposes the properties of a toggle button.
  8. * @alias ToggleButtonViewModel
  9. * @constructor
  10. *
  11. * @param {Command} command The command which will be executed when the button is toggled.
  12. * @param {Object} [options] Object with the following properties:
  13. * @param {Boolean} [options.toggled=false] A boolean indicating whether the button should be initially toggled.
  14. * @param {String} [options.tooltip=''] A string containing the button's tooltip.
  15. */
  16. function ToggleButtonViewModel(command, options) {
  17. //>>includeStart('debug', pragmas.debug);
  18. if (!defined(command)) {
  19. throw new DeveloperError('command is required.');
  20. }
  21. //>>includeEnd('debug');
  22. this._command = command;
  23. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  24. /**
  25. * Gets or sets whether the button is currently toggled. This property is observable.
  26. * @type {Boolean}
  27. * @default false
  28. */
  29. this.toggled = defaultValue(options.toggled, false);
  30. /**
  31. * Gets or sets the button's tooltip. This property is observable.
  32. * @type {String}
  33. * @default ''
  34. */
  35. this.tooltip = defaultValue(options.tooltip, '');
  36. knockout.track(this, ['toggled', 'tooltip']);
  37. }
  38. defineProperties(ToggleButtonViewModel.prototype, {
  39. /**
  40. * Gets the command which will be executed when the button is toggled.
  41. * @memberof ToggleButtonViewModel.prototype
  42. * @type {Command}
  43. */
  44. command : {
  45. get : function() {
  46. return this._command;
  47. }
  48. }
  49. });
  50. export default ToggleButtonViewModel;