Show:

File: doc/api/util-api.js

  1. /**
  2. * A set of helper methods for use by jsPlumb.
  3. * @class jsPlumbUtil
  4. * @static
  5. */
  6.  
  7. /**
  8. * Returns whether the given object is an Array.
  9. * @method isArray
  10. * @static
  11. * @param {Object} obj Object to test
  12. * @return {Boolean} True if the object is an Array, false otherwise.
  13. */
  14.  
  15. /**
  16. * Returns whether the given object is a String.
  17. * @method isString
  18. * @static
  19. * @param {Object} obj Object to test
  20. * @return {Boolean} True if the object is a String, false otherwise.
  21. */
  22.  
  23. /**
  24. * Returns whether the given object is a Boolean.
  25. * @method isBoolean
  26. * @static
  27. * @param {Object} obj Object to test
  28. * @return {Boolean} True if the object is a Boolean, false otherwise.
  29. */
  30.  
  31. /**
  32. * Returns whether the given object is null.
  33. * @method isNull
  34. * @static
  35. * @param {Object} obj Object to test
  36. * @return {Boolean} True if the object is null, false otherwise.
  37. */
  38.  
  39. /**
  40. * Returns whether the given object is an Object.
  41. * @method isObject
  42. * @static
  43. * @param {Object} obj Object to test
  44. * @return {Boolean} True if the object is an Object, false otherwise.
  45. */
  46. /**
  47. * Returns whether the given object is a Date.
  48. * @method isDate
  49. * @static
  50. * @param {Object} obj Object to test
  51. * @return {Boolean} True if the object is a Date, false otherwise.
  52. */
  53. /**
  54. * Returns whether the given object is a Function.
  55. * @method isFunction
  56. * @static
  57. * @param {Object} obj Object to test
  58. * @return {Boolean} True if the object is a Function, false otherwise.
  59. */
  60. /**
  61. * Returns whether the given object (an Object or Array) is empty.
  62. * @method isEmpty
  63. * @static
  64. * @param {Object} obj Object to test
  65. * @return {Boolean} True if the object is empty, false otherwise.
  66. */
  67. /**
  68. * Returns whether the given object is a Number.
  69. * @method isNumber
  70. * @static
  71. * @param {Object} obj Object to test
  72. * @return {Boolean} True if the object is a Number, false otherwise.
  73. */
  74.  
  75. /**
  76. * Merges one object into another, optionally folding individual values into arrays.
  77. * @method merge
  78. * @static
  79. * @param {Object} a Object to merge into
  80. * @param {Object} b Object to merge from.
  81. * @param [String[]] [collations] Optional list of parameter keys for values that, if present in both 'a' and 'b', should result in an array with values from each (rather than the default behaviour of overwriting a's value with b's)
  82. */
  83.  
  84. /**
  85. * Provides event bind/fire functionality.
  86. * @class jsPlumbUtil.EventGenerator
  87. */
  88.  
  89. /**
  90. * Binds a listener to one or more events.
  91. * @method bind
  92. * @param {String|String[]} event Name(s) of the event(s) to bind to. Note that if you provide multiple event names they all are bound with the same function.
  93. * @param {Function} listener Function to execute.
  94. * @param {Boolean} [insertAtStart=false] Whether or not to insert this listener at the start of the listener list, so it is fired before the other currently registered listeners.
  95. */
  96.  
  97. /**
  98. * Fires an update for the given event.
  99. * @method fire
  100. * @private
  101. * @param {String} event Event to fire
  102. * @param {Object} value Value to pass to the event listener(s).
  103. * @param {Event} originalEvent The original event from the browser
  104. */
  105.  
  106. /**
  107. * Clears either all listeners, or listeners for some specific event, or just some listener. You can call this method
  108. * with zero, one or two arguments: with zero arguments, all listeners are cleared. With one argument that is a string, all listeners for
  109. * the specified event type are cleared. With one argument that is a function, it is removed from the appropriate event list.
  110. * With two arguments, the first is an event type, and the second is a function to be unbound. In fact this is perhaps unnecessary
  111. * given that you can unbind a function just by passing it.
  112. * @method unbind
  113. * @param {String|Function} [eventOrListener] If a string, constrains the clear to just listeners for the event identified by the string. If a Function, unbinds this function wherever it may have been bound.
  114. * @param {Function} [listener] If provided, removes just this listener for the given event.
  115. */
  116. /**
  117. * Sets whether or not events are suspended.
  118. * @method setSuspendEvents
  119. * @param {Boolean} val Whether or not to suspend events.
  120. */
  121. /**
  122. * Checks whether or not events are currently suspended.
  123. * @method isSuspendEvents
  124. * @return {Boolean} True if events are suspended, false otherwise.
  125. */
  126. /**
  127. * Removes all listeners.
  128. * @method cleanupListeners
  129. */
  130.  
  131. /**
  132. * Replaces values inside some JS object according to a given path spec. A path spec is a string in dotted notation,
  133. * with each component optionally declaring an array index. Some examples are:
  134. *
  135. * foo.bar
  136. * foo.baz[2]
  137. * foo.qux[3].baz[3].shwee
  138. *
  139. * The function fails gracefully if the path identifies a non-existent object.
  140. *
  141. * @method jsPlumbUtil.replace
  142. * @param {Object} inObj Object to perform replacements inside.
  143. * @param {String} path Path to use for replacements
  144. * @param {Object} value Value to set.
  145. */