mxEventObject.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**
  2. * Copyright (c) 2006-2015, JGraph Ltd
  3. * Copyright (c) 2006-2015, Gaudenz Alder
  4. */
  5. /**
  6. * Class: mxEventObject
  7. *
  8. * The mxEventObject is a wrapper for all properties of a single event.
  9. * Additionally, it also offers functions to consume the event and check if it
  10. * was consumed as follows:
  11. *
  12. * (code)
  13. * evt.consume();
  14. * INV: evt.isConsumed() == true
  15. * (end)
  16. *
  17. * Constructor: mxEventObject
  18. *
  19. * Constructs a new event object with the specified name. An optional
  20. * sequence of key, value pairs can be appended to define properties.
  21. *
  22. * Example:
  23. *
  24. * (code)
  25. * new mxEventObject("eventName", key1, val1, .., keyN, valN)
  26. * (end)
  27. */
  28. function mxEventObject(name)
  29. {
  30. this.name = name;
  31. this.properties = [];
  32. for (var i = 1; i < arguments.length; i += 2)
  33. {
  34. if (arguments[i + 1] != null)
  35. {
  36. this.properties[arguments[i]] = arguments[i + 1];
  37. }
  38. }
  39. };
  40. /**
  41. * Variable: name
  42. *
  43. * Holds the name.
  44. */
  45. mxEventObject.prototype.name = null;
  46. /**
  47. * Variable: properties
  48. *
  49. * Holds the properties as an associative array.
  50. */
  51. mxEventObject.prototype.properties = null;
  52. /**
  53. * Variable: consumed
  54. *
  55. * Holds the consumed state. Default is false.
  56. */
  57. mxEventObject.prototype.consumed = false;
  58. /**
  59. * Function: getName
  60. *
  61. * Returns <name>.
  62. */
  63. mxEventObject.prototype.getName = function()
  64. {
  65. return this.name;
  66. };
  67. /**
  68. * Function: getProperties
  69. *
  70. * Returns <properties>.
  71. */
  72. mxEventObject.prototype.getProperties = function()
  73. {
  74. return this.properties;
  75. };
  76. /**
  77. * Function: getProperty
  78. *
  79. * Returns the property for the given key.
  80. */
  81. mxEventObject.prototype.getProperty = function(key)
  82. {
  83. return this.properties[key];
  84. };
  85. /**
  86. * Function: isConsumed
  87. *
  88. * Returns true if the event has been consumed.
  89. */
  90. mxEventObject.prototype.isConsumed = function()
  91. {
  92. return this.consumed;
  93. };
  94. /**
  95. * Function: consume
  96. *
  97. * Consumes the event.
  98. */
  99. mxEventObject.prototype.consume = function()
  100. {
  101. this.consumed = true;
  102. };