ToggleButtonViewModel.js 1.7 KB

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