mxEvent.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473
  1. /**
  2. * Copyright (c) 2006-2015, JGraph Ltd
  3. * Copyright (c) 2006-2015, Gaudenz Alder
  4. */
  5. var mxEvent =
  6. {
  7. /**
  8. * Class: mxEvent
  9. *
  10. * Cross-browser DOM event support. For internal event handling,
  11. * <mxEventSource> and the graph event dispatch loop in <mxGraph> are used.
  12. *
  13. * Memory Leaks:
  14. *
  15. * Use this class for adding and removing listeners to/from DOM nodes. The
  16. * <removeAllListeners> function is provided to remove all listeners that
  17. * have been added using <addListener>. The function should be invoked when
  18. * the last reference is removed in the JavaScript code, typically when the
  19. * referenced DOM node is removed from the DOM.
  20. *
  21. * Function: addListener
  22. *
  23. * Binds the function to the specified event on the given element. Use
  24. * <mxUtils.bind> in order to bind the "this" keyword inside the function
  25. * to a given execution scope.
  26. */
  27. addListener: function()
  28. {
  29. var updateListenerList = function(element, eventName, funct)
  30. {
  31. if (element.mxListenerList == null)
  32. {
  33. element.mxListenerList = [];
  34. }
  35. var entry = {name: eventName, f: funct};
  36. element.mxListenerList.push(entry);
  37. };
  38. if (window.addEventListener)
  39. {
  40. return function(element, eventName, funct)
  41. {
  42. element.addEventListener(eventName, funct, false);
  43. updateListenerList(element, eventName, funct);
  44. };
  45. }
  46. else
  47. {
  48. return function(element, eventName, funct)
  49. {
  50. element.attachEvent('on' + eventName, funct);
  51. updateListenerList(element, eventName, funct);
  52. };
  53. }
  54. }(),
  55. /**
  56. * Function: removeListener
  57. *
  58. * Removes the specified listener from the given element.
  59. */
  60. removeListener: function()
  61. {
  62. var updateListener = function(element, eventName, funct)
  63. {
  64. if (element.mxListenerList != null)
  65. {
  66. var listenerCount = element.mxListenerList.length;
  67. for (var i = 0; i < listenerCount; i++)
  68. {
  69. var entry = element.mxListenerList[i];
  70. if (entry.f == funct)
  71. {
  72. element.mxListenerList.splice(i, 1);
  73. break;
  74. }
  75. }
  76. if (element.mxListenerList.length == 0)
  77. {
  78. element.mxListenerList = null;
  79. }
  80. }
  81. };
  82. if (window.removeEventListener)
  83. {
  84. return function(element, eventName, funct)
  85. {
  86. element.removeEventListener(eventName, funct, false);
  87. updateListener(element, eventName, funct);
  88. };
  89. }
  90. else
  91. {
  92. return function(element, eventName, funct)
  93. {
  94. element.detachEvent('on' + eventName, funct);
  95. updateListener(element, eventName, funct);
  96. };
  97. }
  98. }(),
  99. /**
  100. * Function: removeAllListeners
  101. *
  102. * Removes all listeners from the given element.
  103. */
  104. removeAllListeners: function(element)
  105. {
  106. var list = element.mxListenerList;
  107. if (list != null)
  108. {
  109. while (list.length > 0)
  110. {
  111. var entry = list[0];
  112. mxEvent.removeListener(element, entry.name, entry.f);
  113. }
  114. }
  115. },
  116. /**
  117. * Function: addGestureListeners
  118. *
  119. * Adds the given listeners for touch, mouse and/or pointer events. If
  120. * <mxClient.IS_POINTER> is true then pointer events will be registered,
  121. * else the respective mouse events will be registered. If <mxClient.IS_POINTER>
  122. * is false and <mxClient.IS_TOUCH> is true then the respective touch events
  123. * will be registered as well as the mouse events.
  124. */
  125. addGestureListeners: function(node, startListener, moveListener, endListener)
  126. {
  127. if (startListener != null)
  128. {
  129. mxEvent.addListener(node, (mxClient.IS_POINTER) ? 'pointerdown' : 'mousedown', startListener);
  130. }
  131. if (moveListener != null)
  132. {
  133. mxEvent.addListener(node, (mxClient.IS_POINTER) ? 'pointermove' : 'mousemove', moveListener);
  134. }
  135. if (endListener != null)
  136. {
  137. mxEvent.addListener(node, (mxClient.IS_POINTER) ? 'pointerup' : 'mouseup', endListener);
  138. }
  139. if (!mxClient.IS_POINTER && mxClient.IS_TOUCH)
  140. {
  141. if (startListener != null)
  142. {
  143. mxEvent.addListener(node, 'touchstart', startListener);
  144. }
  145. if (moveListener != null)
  146. {
  147. mxEvent.addListener(node, 'touchmove', moveListener);
  148. }
  149. if (endListener != null)
  150. {
  151. mxEvent.addListener(node, 'touchend', endListener);
  152. }
  153. }
  154. },
  155. /**
  156. * Function: removeGestureListeners
  157. *
  158. * Removes the given listeners from mousedown, mousemove, mouseup and the
  159. * respective touch events if <mxClient.IS_TOUCH> is true.
  160. */
  161. removeGestureListeners: function(node, startListener, moveListener, endListener)
  162. {
  163. if (startListener != null)
  164. {
  165. mxEvent.removeListener(node, (mxClient.IS_POINTER) ? 'pointerdown' : 'mousedown', startListener);
  166. }
  167. if (moveListener != null)
  168. {
  169. mxEvent.removeListener(node, (mxClient.IS_POINTER) ? 'pointermove' : 'mousemove', moveListener);
  170. }
  171. if (endListener != null)
  172. {
  173. mxEvent.removeListener(node, (mxClient.IS_POINTER) ? 'pointerup' : 'mouseup', endListener);
  174. }
  175. if (!mxClient.IS_POINTER && mxClient.IS_TOUCH)
  176. {
  177. if (startListener != null)
  178. {
  179. mxEvent.removeListener(node, 'touchstart', startListener);
  180. }
  181. if (moveListener != null)
  182. {
  183. mxEvent.removeListener(node, 'touchmove', moveListener);
  184. }
  185. if (endListener != null)
  186. {
  187. mxEvent.removeListener(node, 'touchend', endListener);
  188. }
  189. }
  190. },
  191. /**
  192. * Function: redirectMouseEvents
  193. *
  194. * Redirects the mouse events from the given DOM node to the graph dispatch
  195. * loop using the event and given state as event arguments. State can
  196. * either be an instance of <mxCellState> or a function that returns an
  197. * <mxCellState>. The down, move, up and dblClick arguments are optional
  198. * functions that take the trigger event as arguments and replace the
  199. * default behaviour.
  200. */
  201. redirectMouseEvents: function(node, graph, state, down, move, up, dblClick)
  202. {
  203. var getState = function(evt)
  204. {
  205. return (typeof(state) == 'function') ? state(evt) : state;
  206. };
  207. mxEvent.addGestureListeners(node, function (evt)
  208. {
  209. if (down != null)
  210. {
  211. down(evt);
  212. }
  213. else if (!mxEvent.isConsumed(evt))
  214. {
  215. graph.fireMouseEvent(mxEvent.MOUSE_DOWN, new mxMouseEvent(evt, getState(evt)));
  216. }
  217. },
  218. function (evt)
  219. {
  220. if (move != null)
  221. {
  222. move(evt);
  223. }
  224. else if (!mxEvent.isConsumed(evt))
  225. {
  226. graph.fireMouseEvent(mxEvent.MOUSE_MOVE, new mxMouseEvent(evt, getState(evt)));
  227. }
  228. },
  229. function (evt)
  230. {
  231. if (up != null)
  232. {
  233. up(evt);
  234. }
  235. else if (!mxEvent.isConsumed(evt))
  236. {
  237. graph.fireMouseEvent(mxEvent.MOUSE_UP, new mxMouseEvent(evt, getState(evt)));
  238. }
  239. });
  240. mxEvent.addListener(node, 'dblclick', function (evt)
  241. {
  242. if (dblClick != null)
  243. {
  244. dblClick(evt);
  245. }
  246. else if (!mxEvent.isConsumed(evt))
  247. {
  248. var tmp = getState(evt);
  249. graph.dblClick(evt, (tmp != null) ? tmp.cell : null);
  250. }
  251. });
  252. },
  253. /**
  254. * Function: release
  255. *
  256. * Removes the known listeners from the given DOM node and its descendants.
  257. *
  258. * Parameters:
  259. *
  260. * element - DOM node to remove the listeners from.
  261. */
  262. release: function(element)
  263. {
  264. try
  265. {
  266. if (element != null)
  267. {
  268. mxEvent.removeAllListeners(element);
  269. var children = element.childNodes;
  270. if (children != null)
  271. {
  272. var childCount = children.length;
  273. for (var i = 0; i < childCount; i += 1)
  274. {
  275. mxEvent.release(children[i]);
  276. }
  277. }
  278. }
  279. }
  280. catch (e)
  281. {
  282. // ignores errors as this is typically called in cleanup code
  283. }
  284. },
  285. /**
  286. * Function: addMouseWheelListener
  287. *
  288. * Installs the given function as a handler for mouse wheel events. The
  289. * function has two arguments: the mouse event and a boolean that specifies
  290. * if the wheel was moved up or down.
  291. *
  292. * This has been tested with IE 6 and 7, Firefox (all versions), Opera and
  293. * Safari. It does currently not work on Safari for Mac.
  294. *
  295. * Example:
  296. *
  297. * (code)
  298. * mxEvent.addMouseWheelListener(function (evt, up, pinch)
  299. * {
  300. * mxLog.show();
  301. * mxLog.debug('mouseWheel: up='+up);
  302. * });
  303. *(end)
  304. *
  305. * Parameters:
  306. *
  307. * funct - Handler function that takes the event argument, a boolean argument
  308. * for the mousewheel direction and a boolean to specify if the underlying
  309. * event was a pinch gesture on a touch device.
  310. * target - Target for installing the listener in Google Chrome. See
  311. * https://www.chromestatus.com/features/6662647093133312.
  312. */
  313. addMouseWheelListener: function(funct, target)
  314. {
  315. if (funct != null)
  316. {
  317. var wheelHandler = function(evt)
  318. {
  319. // IE does not give an event object but the
  320. // global event object is the mousewheel event
  321. // at this point in time.
  322. if (evt == null)
  323. {
  324. evt = window.event;
  325. }
  326. //To prevent window zoom on trackpad pinch
  327. if (evt.ctrlKey)
  328. {
  329. evt.preventDefault();
  330. }
  331. var delta = -evt.deltaY;
  332. // Handles the event using the given function
  333. if (Math.abs(evt.deltaX) > 0.5 || Math.abs(evt.deltaY) > 0.5)
  334. {
  335. funct(evt, (evt.deltaY == 0) ? -evt.deltaX > 0 : -evt.deltaY > 0);
  336. }
  337. };
  338. target = target != null ? target : window;
  339. if (mxClient.IS_SF && !mxClient.IS_TOUCH)
  340. {
  341. var scale = 1;
  342. mxEvent.addListener(target, 'gesturestart', function(evt)
  343. {
  344. mxEvent.consume(evt);
  345. scale = 1;
  346. });
  347. mxEvent.addListener(target, 'gesturechange', function(evt)
  348. {
  349. mxEvent.consume(evt);
  350. var diff = scale - evt.scale;
  351. if (Math.abs(diff) > 0.2)
  352. {
  353. funct(evt, diff < 0, true);
  354. scale = evt.scale;
  355. }
  356. });
  357. mxEvent.addListener(target, 'gestureend', function(evt)
  358. {
  359. mxEvent.consume(evt);
  360. });
  361. }
  362. else
  363. {
  364. var evtCache = [];
  365. var dx0 = 0;
  366. var dy0 = 0;
  367. // Adds basic listeners for graph event dispatching
  368. mxEvent.addGestureListeners(target, mxUtils.bind(this, function(evt)
  369. {
  370. if (!mxEvent.isMouseEvent(evt) && evt.pointerId != null)
  371. {
  372. evtCache.push(evt);
  373. }
  374. }),
  375. mxUtils.bind(this, function(evt)
  376. {
  377. if (!mxEvent.isMouseEvent(evt) && evtCache.length == 2)
  378. {
  379. // Find this event in the cache and update its record with this event
  380. for (var i = 0; i < evtCache.length; i++)
  381. {
  382. if (evt.pointerId == evtCache[i].pointerId)
  383. {
  384. evtCache[i] = evt;
  385. break;
  386. }
  387. }
  388. // Calculate the distance between the two pointers
  389. var dx = Math.abs(evtCache[0].clientX - evtCache[1].clientX);
  390. var dy = Math.abs(evtCache[0].clientY - evtCache[1].clientY);
  391. var tx = Math.abs(dx - dx0);
  392. var ty = Math.abs(dy - dy0);
  393. if (tx > mxEvent.PINCH_THRESHOLD || ty > mxEvent.PINCH_THRESHOLD)
  394. {
  395. var cx = evtCache[0].clientX + (evtCache[1].clientX - evtCache[0].clientX) / 2;
  396. var cy = evtCache[0].clientY + (evtCache[1].clientY - evtCache[0].clientY) / 2;
  397. funct(evtCache[0], (tx > ty) ? dx > dx0 : dy > dy0, true, cx, cy);
  398. // Cache the distance for the next move event
  399. dx0 = dx;
  400. dy0 = dy;
  401. }
  402. }
  403. }),
  404. mxUtils.bind(this, function(evt)
  405. {
  406. evtCache = [];
  407. dx0 = 0;
  408. dy0 = 0;
  409. }));
  410. }
  411. mxEvent.addListener(target, 'wheel', wheelHandler);
  412. }
  413. },
  414. /**
  415. * Function: disableContextMenu
  416. *
  417. * Disables the context menu for the given element.
  418. */
  419. disableContextMenu: function(element)
  420. {
  421. mxEvent.addListener(element, 'contextmenu', function(evt)
  422. {
  423. if (evt.preventDefault)
  424. {
  425. evt.preventDefault();
  426. }
  427. return false;
  428. });
  429. },
  430. /**
  431. * Function: getSource
  432. *
  433. * Returns the event's target or srcElement depending on the browser.
  434. */
  435. getSource: function(evt)
  436. {
  437. return (evt.srcElement != null) ? evt.srcElement : evt.target;
  438. },
  439. /**
  440. * Function: isConsumed
  441. *
  442. * Returns true if the event has been consumed using <consume>.
  443. */
  444. isConsumed: function(evt)
  445. {
  446. return evt.isConsumed != null && evt.isConsumed;
  447. },
  448. /**
  449. * Function: isTouchEvent
  450. *
  451. * Returns true if the event was generated using a touch device (not a pen or mouse).
  452. */
  453. isTouchEvent: function(evt)
  454. {
  455. return (evt.pointerType != null) ? (evt.pointerType == 'touch' || evt.pointerType ===
  456. evt.MSPOINTER_TYPE_TOUCH) : ((evt.mozInputSource != null) ?
  457. evt.mozInputSource == 5 : evt.type.indexOf('touch') == 0);
  458. },
  459. /**
  460. * Function: isPenEvent
  461. *
  462. * Returns true if the event was generated using a pen (not a touch device or mouse).
  463. */
  464. isPenEvent: function(evt)
  465. {
  466. return (evt.pointerType != null) ? (evt.pointerType == 'pen' || evt.pointerType ===
  467. evt.MSPOINTER_TYPE_PEN) : ((evt.mozInputSource != null) ?
  468. evt.mozInputSource == 2 : evt.type.indexOf('pen') == 0);
  469. },
  470. /**
  471. * Function: isMultiTouchEvent
  472. *
  473. * Returns true if the event was generated using a touch device (not a pen or mouse).
  474. */
  475. isMultiTouchEvent: function(evt)
  476. {
  477. return (evt.type != null && evt.type.indexOf('touch') == 0 && evt.touches != null && evt.touches.length > 1);
  478. },
  479. /**
  480. * Function: isMouseEvent
  481. *
  482. * Returns true if the event was generated using a mouse (not a pen or touch device).
  483. */
  484. isMouseEvent: function(evt)
  485. {
  486. return (evt.pointerType != null) ? (evt.pointerType == 'mouse' || evt.pointerType ===
  487. evt.MSPOINTER_TYPE_MOUSE) : ((evt.mozInputSource != null) ?
  488. evt.mozInputSource == 1 : evt.type.indexOf('mouse') == 0);
  489. },
  490. /**
  491. * Function: isLeftMouseButton
  492. *
  493. * Returns true if the left mouse button is pressed for the given event.
  494. * To check if a button is pressed during a mouseMove you should use the
  495. * <mxGraph.isMouseDown> property. Note that this returns true in Firefox
  496. * for control+left-click on the Mac.
  497. */
  498. isLeftMouseButton: function(evt)
  499. {
  500. // Special case for mousemove and mousedown we check the buttons
  501. // if it exists because which is 0 even if no button is pressed
  502. if ('buttons' in evt && (evt.type == 'mousedown' || evt.type == 'mousemove'))
  503. {
  504. return evt.buttons == 1;
  505. }
  506. else if ('which' in evt)
  507. {
  508. return evt.which === 1;
  509. }
  510. else
  511. {
  512. return evt.button === 1;
  513. }
  514. },
  515. /**
  516. * Function: isMiddleMouseButton
  517. *
  518. * Returns true if the middle mouse button is pressed for the given event.
  519. * To check if a button is pressed during a mouseMove you should use the
  520. * <mxGraph.isMouseDown> property.
  521. */
  522. isMiddleMouseButton: function(evt)
  523. {
  524. if ('which' in evt)
  525. {
  526. return evt.which === 2;
  527. }
  528. else
  529. {
  530. return evt.button === 4;
  531. }
  532. },
  533. /**
  534. * Function: isRightMouseButton
  535. *
  536. * Returns true if the right mouse button was pressed. Note that this
  537. * button might not be available on some systems. For handling a popup
  538. * trigger <isPopupTrigger> should be used.
  539. */
  540. isRightMouseButton: function(evt)
  541. {
  542. if ('which' in evt)
  543. {
  544. return evt.which === 3;
  545. }
  546. else
  547. {
  548. return evt.button === 2;
  549. }
  550. },
  551. /**
  552. * Function: isPopupTrigger
  553. *
  554. * Returns true if the event is a popup trigger. This implementation
  555. * returns true if the right button or the left button and control was
  556. * pressed on a Mac.
  557. */
  558. isPopupTrigger: function(evt)
  559. {
  560. return mxEvent.isRightMouseButton(evt) || (mxClient.IS_MAC && mxEvent.isControlDown(evt) &&
  561. !mxEvent.isShiftDown(evt) && !mxEvent.isMetaDown(evt) && !mxEvent.isAltDown(evt));
  562. },
  563. /**
  564. * Function: isShiftDown
  565. *
  566. * Returns true if the shift key is pressed for the given event.
  567. */
  568. isShiftDown: function(evt)
  569. {
  570. return (evt != null) ? evt.shiftKey : false;
  571. },
  572. /**
  573. * Function: isAltDown
  574. *
  575. * Returns true if the alt key is pressed for the given event.
  576. */
  577. isAltDown: function(evt)
  578. {
  579. return (evt != null) ? evt.altKey : false;
  580. },
  581. /**
  582. * Function: isControlDown
  583. *
  584. * Returns true if the control key is pressed for the given event.
  585. */
  586. isControlDown: function(evt)
  587. {
  588. return (evt != null) ? evt.ctrlKey : false;
  589. },
  590. /**
  591. * Function: isMetaDown
  592. *
  593. * Returns true if the meta key is pressed for the given event.
  594. */
  595. isMetaDown: function(evt)
  596. {
  597. return (evt != null) ? evt.metaKey : false;
  598. },
  599. /**
  600. * Function: getMainEvent
  601. *
  602. * Returns the touch or mouse event that contains the mouse coordinates.
  603. */
  604. getMainEvent: function(e)
  605. {
  606. if ((e.type == 'touchstart' || e.type == 'touchmove') && e.touches != null && e.touches[0] != null)
  607. {
  608. e = e.touches[0];
  609. }
  610. else if (e.type == 'touchend' && e.changedTouches != null && e.changedTouches[0] != null)
  611. {
  612. e = e.changedTouches[0];
  613. }
  614. return e;
  615. },
  616. /**
  617. * Function: getClientX
  618. *
  619. * Returns true if the meta key is pressed for the given event.
  620. */
  621. getClientX: function(e)
  622. {
  623. return mxEvent.getMainEvent(e).clientX;
  624. },
  625. /**
  626. * Function: getClientY
  627. *
  628. * Returns true if the meta key is pressed for the given event.
  629. */
  630. getClientY: function(e)
  631. {
  632. return mxEvent.getMainEvent(e).clientY;
  633. },
  634. /**
  635. * Function: consume
  636. *
  637. * Consumes the given event.
  638. *
  639. * Parameters:
  640. *
  641. * evt - Native event to be consumed.
  642. * preventDefault - Optional boolean to prevent the default for the event.
  643. * Default is true.
  644. * stopPropagation - Option boolean to stop event propagation. Default is
  645. * true.
  646. */
  647. consume: function(evt, preventDefault, stopPropagation)
  648. {
  649. preventDefault = (preventDefault != null) ? preventDefault : true;
  650. stopPropagation = (stopPropagation != null) ? stopPropagation : true;
  651. if (preventDefault)
  652. {
  653. if (evt.preventDefault)
  654. {
  655. if (stopPropagation)
  656. {
  657. evt.stopPropagation();
  658. }
  659. evt.preventDefault();
  660. }
  661. else if (stopPropagation)
  662. {
  663. evt.cancelBubble = true;
  664. }
  665. }
  666. // Opera
  667. evt.isConsumed = true;
  668. // Other browsers
  669. if (!evt.preventDefault)
  670. {
  671. evt.returnValue = false;
  672. }
  673. },
  674. //
  675. // Special handles in mouse events
  676. //
  677. /**
  678. * Variable: LABEL_HANDLE
  679. *
  680. * Index for the label handle in an mxMouseEvent. This should be a negative
  681. * value that does not interfere with any possible handle indices. Default
  682. * is -1.
  683. */
  684. LABEL_HANDLE: -1,
  685. /**
  686. * Variable: ROTATION_HANDLE
  687. *
  688. * Index for the rotation handle in an mxMouseEvent. This should be a
  689. * negative value that does not interfere with any possible handle indices.
  690. * Default is -2.
  691. */
  692. ROTATION_HANDLE: -2,
  693. /**
  694. * Variable: CUSTOM_HANDLE
  695. *
  696. * Start index for the custom handles in an mxMouseEvent. This should be a
  697. * negative value and is the start index which is decremented for each
  698. * custom handle. Default is -100.
  699. */
  700. CUSTOM_HANDLE: -100,
  701. /**
  702. * Variable: VIRTUAL_HANDLE
  703. *
  704. * Start index for the virtual handles in an mxMouseEvent. This should be a
  705. * negative value and is the start index which is decremented for each
  706. * virtual handle. Default is -100000. This assumes that there are no more
  707. * than VIRTUAL_HANDLE - CUSTOM_HANDLE custom handles.
  708. *
  709. */
  710. VIRTUAL_HANDLE: -100000,
  711. //
  712. // Event names
  713. //
  714. /**
  715. * Variable: MOUSE_DOWN
  716. *
  717. * Specifies the event name for mouseDown.
  718. */
  719. MOUSE_DOWN: 'mouseDown',
  720. /**
  721. * Variable: MOUSE_MOVE
  722. *
  723. * Specifies the event name for mouseMove.
  724. */
  725. MOUSE_MOVE: 'mouseMove',
  726. /**
  727. * Variable: MOUSE_UP
  728. *
  729. * Specifies the event name for mouseUp.
  730. */
  731. MOUSE_UP: 'mouseUp',
  732. /**
  733. * Variable: ACTIVATE
  734. *
  735. * Specifies the event name for activate.
  736. */
  737. ACTIVATE: 'activate',
  738. /**
  739. * Variable: RESIZE_START
  740. *
  741. * Specifies the event name for resizeStart.
  742. */
  743. RESIZE_START: 'resizeStart',
  744. /**
  745. * Variable: RESIZE
  746. *
  747. * Specifies the event name for resize.
  748. */
  749. RESIZE: 'resize',
  750. /**
  751. * Variable: RESIZE_END
  752. *
  753. * Specifies the event name for resizeEnd.
  754. */
  755. RESIZE_END: 'resizeEnd',
  756. /**
  757. * Variable: MOVE_START
  758. *
  759. * Specifies the event name for moveStart.
  760. */
  761. MOVE_START: 'moveStart',
  762. /**
  763. * Variable: MOVE
  764. *
  765. * Specifies the event name for move.
  766. */
  767. MOVE: 'move',
  768. /**
  769. * Variable: MOVE_END
  770. *
  771. * Specifies the event name for moveEnd.
  772. */
  773. MOVE_END: 'moveEnd',
  774. /**
  775. * Variable: PAN_START
  776. *
  777. * Specifies the event name for panStart.
  778. */
  779. PAN_START: 'panStart',
  780. /**
  781. * Variable: PAN
  782. *
  783. * Specifies the event name for pan.
  784. */
  785. PAN: 'pan',
  786. /**
  787. * Variable: PAN_END
  788. *
  789. * Specifies the event name for panEnd.
  790. */
  791. PAN_END: 'panEnd',
  792. /**
  793. * Variable: MINIMIZE
  794. *
  795. * Specifies the event name for minimize.
  796. */
  797. MINIMIZE: 'minimize',
  798. /**
  799. * Variable: NORMALIZE
  800. *
  801. * Specifies the event name for normalize.
  802. */
  803. NORMALIZE: 'normalize',
  804. /**
  805. * Variable: MAXIMIZE
  806. *
  807. * Specifies the event name for maximize.
  808. */
  809. MAXIMIZE: 'maximize',
  810. /**
  811. * Variable: HIDE
  812. *
  813. * Specifies the event name for hide.
  814. */
  815. HIDE: 'hide',
  816. /**
  817. * Variable: SHOW
  818. *
  819. * Specifies the event name for show.
  820. */
  821. SHOW: 'show',
  822. /**
  823. * Variable: CLOSE
  824. *
  825. * Specifies the event name for close.
  826. */
  827. CLOSE: 'close',
  828. /**
  829. * Variable: DESTROY
  830. *
  831. * Specifies the event name for destroy.
  832. */
  833. DESTROY: 'destroy',
  834. /**
  835. * Variable: REFRESH
  836. *
  837. * Specifies the event name for refresh.
  838. */
  839. REFRESH: 'refresh',
  840. /**
  841. * Variable: SIZE
  842. *
  843. * Specifies the event name for size.
  844. */
  845. SIZE: 'size',
  846. /**
  847. * Variable: SELECT
  848. *
  849. * Specifies the event name for select.
  850. */
  851. SELECT: 'select',
  852. /**
  853. * Variable: FIRED
  854. *
  855. * Specifies the event name for fired.
  856. */
  857. FIRED: 'fired',
  858. /**
  859. * Variable: FIRE_MOUSE_EVENT
  860. *
  861. * Specifies the event name for fireMouseEvent.
  862. */
  863. FIRE_MOUSE_EVENT: 'fireMouseEvent',
  864. /**
  865. * Variable: GESTURE
  866. *
  867. * Specifies the event name for gesture.
  868. */
  869. GESTURE: 'gesture',
  870. /**
  871. * Variable: TAP_AND_HOLD
  872. *
  873. * Specifies the event name for tapAndHold.
  874. */
  875. TAP_AND_HOLD: 'tapAndHold',
  876. /**
  877. * Variable: GET
  878. *
  879. * Specifies the event name for get.
  880. */
  881. GET: 'get',
  882. /**
  883. * Variable: RECEIVE
  884. *
  885. * Specifies the event name for receive.
  886. */
  887. RECEIVE: 'receive',
  888. /**
  889. * Variable: CONNECT
  890. *
  891. * Specifies the event name for connect.
  892. */
  893. CONNECT: 'connect',
  894. /**
  895. * Variable: DISCONNECT
  896. *
  897. * Specifies the event name for disconnect.
  898. */
  899. DISCONNECT: 'disconnect',
  900. /**
  901. * Variable: SUSPEND
  902. *
  903. * Specifies the event name for suspend.
  904. */
  905. SUSPEND: 'suspend',
  906. /**
  907. * Variable: RESUME
  908. *
  909. * Specifies the event name for suspend.
  910. */
  911. RESUME: 'resume',
  912. /**
  913. * Variable: MARK
  914. *
  915. * Specifies the event name for mark.
  916. */
  917. MARK: 'mark',
  918. /**
  919. * Variable: ROOT
  920. *
  921. * Specifies the event name for root.
  922. */
  923. ROOT: 'root',
  924. /**
  925. * Variable: POST
  926. *
  927. * Specifies the event name for post.
  928. */
  929. POST: 'post',
  930. /**
  931. * Variable: OPEN
  932. *
  933. * Specifies the event name for open.
  934. */
  935. OPEN: 'open',
  936. /**
  937. * Variable: SAVE
  938. *
  939. * Specifies the event name for open.
  940. */
  941. SAVE: 'save',
  942. /**
  943. * Variable: BEFORE_ADD_VERTEX
  944. *
  945. * Specifies the event name for beforeAddVertex.
  946. */
  947. BEFORE_ADD_VERTEX: 'beforeAddVertex',
  948. /**
  949. * Variable: ADD_VERTEX
  950. *
  951. * Specifies the event name for addVertex.
  952. */
  953. ADD_VERTEX: 'addVertex',
  954. /**
  955. * Variable: AFTER_ADD_VERTEX
  956. *
  957. * Specifies the event name for afterAddVertex.
  958. */
  959. AFTER_ADD_VERTEX: 'afterAddVertex',
  960. /**
  961. * Variable: DONE
  962. *
  963. * Specifies the event name for done.
  964. */
  965. DONE: 'done',
  966. /**
  967. * Variable: EXECUTE
  968. *
  969. * Specifies the event name for execute.
  970. */
  971. EXECUTE: 'execute',
  972. /**
  973. * Variable: EXECUTED
  974. *
  975. * Specifies the event name for executed.
  976. */
  977. EXECUTED: 'executed',
  978. /**
  979. * Variable: BEGIN_UPDATE
  980. *
  981. * Specifies the event name for beginUpdate.
  982. */
  983. BEGIN_UPDATE: 'beginUpdate',
  984. /**
  985. * Variable: START_EDIT
  986. *
  987. * Specifies the event name for startEdit.
  988. */
  989. START_EDIT: 'startEdit',
  990. /**
  991. * Variable: END_UPDATE
  992. *
  993. * Specifies the event name for endUpdate.
  994. */
  995. END_UPDATE: 'endUpdate',
  996. /**
  997. * Variable: END_EDIT
  998. *
  999. * Specifies the event name for endEdit.
  1000. */
  1001. END_EDIT: 'endEdit',
  1002. /**
  1003. * Variable: BEFORE_UNDO
  1004. *
  1005. * Specifies the event name for beforeUndo.
  1006. */
  1007. BEFORE_UNDO: 'beforeUndo',
  1008. /**
  1009. * Variable: UNDO
  1010. *
  1011. * Specifies the event name for undo.
  1012. */
  1013. UNDO: 'undo',
  1014. /**
  1015. * Variable: REDO
  1016. *
  1017. * Specifies the event name for redo.
  1018. */
  1019. REDO: 'redo',
  1020. /**
  1021. * Variable: CHANGE
  1022. *
  1023. * Specifies the event name for change.
  1024. */
  1025. CHANGE: 'change',
  1026. /**
  1027. * Variable: NOTIFY
  1028. *
  1029. * Specifies the event name for notify.
  1030. */
  1031. NOTIFY: 'notify',
  1032. /**
  1033. * Variable: LAYOUT_CELLS
  1034. *
  1035. * Specifies the event name for layoutCells.
  1036. */
  1037. LAYOUT_CELLS: 'layoutCells',
  1038. /**
  1039. * Variable: CLICK
  1040. *
  1041. * Specifies the event name for click.
  1042. */
  1043. CLICK: 'click',
  1044. /**
  1045. * Variable: SCALE
  1046. *
  1047. * Specifies the event name for scale.
  1048. */
  1049. SCALE: 'scale',
  1050. /**
  1051. * Variable: TRANSLATE
  1052. *
  1053. * Specifies the event name for translate.
  1054. */
  1055. TRANSLATE: 'translate',
  1056. /**
  1057. * Variable: SCALE_AND_TRANSLATE
  1058. *
  1059. * Specifies the event name for scaleAndTranslate.
  1060. */
  1061. SCALE_AND_TRANSLATE: 'scaleAndTranslate',
  1062. /**
  1063. * Variable: UP
  1064. *
  1065. * Specifies the event name for up.
  1066. */
  1067. UP: 'up',
  1068. /**
  1069. * Variable: DOWN
  1070. *
  1071. * Specifies the event name for down.
  1072. */
  1073. DOWN: 'down',
  1074. /**
  1075. * Variable: ADD
  1076. *
  1077. * Specifies the event name for add.
  1078. */
  1079. ADD: 'add',
  1080. /**
  1081. * Variable: REMOVE
  1082. *
  1083. * Specifies the event name for remove.
  1084. */
  1085. REMOVE: 'remove',
  1086. /**
  1087. * Variable: CLEAR
  1088. *
  1089. * Specifies the event name for clear.
  1090. */
  1091. CLEAR: 'clear',
  1092. /**
  1093. * Variable: ADD_CELLS
  1094. *
  1095. * Specifies the event name for addCells.
  1096. */
  1097. ADD_CELLS: 'addCells',
  1098. /**
  1099. * Variable: CELLS_ADDED
  1100. *
  1101. * Specifies the event name for cellsAdded.
  1102. */
  1103. CELLS_ADDED: 'cellsAdded',
  1104. /**
  1105. * Variable: MOVE_CELLS
  1106. *
  1107. * Specifies the event name for moveCells.
  1108. */
  1109. MOVE_CELLS: 'moveCells',
  1110. /**
  1111. * Variable: CELLS_MOVED
  1112. *
  1113. * Specifies the event name for cellsMoved.
  1114. */
  1115. CELLS_MOVED: 'cellsMoved',
  1116. /**
  1117. * Variable: RESIZE_CELLS
  1118. *
  1119. * Specifies the event name for resizeCells.
  1120. */
  1121. RESIZE_CELLS: 'resizeCells',
  1122. /**
  1123. * Variable: CELLS_RESIZED
  1124. *
  1125. * Specifies the event name for cellsResized.
  1126. */
  1127. CELLS_RESIZED: 'cellsResized',
  1128. /**
  1129. * Variable: TOGGLE_CELLS
  1130. *
  1131. * Specifies the event name for toggleCells.
  1132. */
  1133. TOGGLE_CELLS: 'toggleCells',
  1134. /**
  1135. * Variable: CELLS_TOGGLED
  1136. *
  1137. * Specifies the event name for cellsToggled.
  1138. */
  1139. CELLS_TOGGLED: 'cellsToggled',
  1140. /**
  1141. * Variable: ORDER_CELLS
  1142. *
  1143. * Specifies the event name for orderCells.
  1144. */
  1145. ORDER_CELLS: 'orderCells',
  1146. /**
  1147. * Variable: CELLS_ORDERED
  1148. *
  1149. * Specifies the event name for cellsOrdered.
  1150. */
  1151. CELLS_ORDERED: 'cellsOrdered',
  1152. /**
  1153. * Variable: REMOVE_CELLS
  1154. *
  1155. * Specifies the event name for removeCells.
  1156. */
  1157. REMOVE_CELLS: 'removeCells',
  1158. /**
  1159. * Variable: CELLS_REMOVED
  1160. *
  1161. * Specifies the event name for cellsRemoved.
  1162. */
  1163. CELLS_REMOVED: 'cellsRemoved',
  1164. /**
  1165. * Variable: GROUP_CELLS
  1166. *
  1167. * Specifies the event name for groupCells.
  1168. */
  1169. GROUP_CELLS: 'groupCells',
  1170. /**
  1171. * Variable: UNGROUP_CELLS
  1172. *
  1173. * Specifies the event name for ungroupCells.
  1174. */
  1175. UNGROUP_CELLS: 'ungroupCells',
  1176. /**
  1177. * Variable: REMOVE_CELLS_FROM_PARENT
  1178. *
  1179. * Specifies the event name for removeCellsFromParent.
  1180. */
  1181. REMOVE_CELLS_FROM_PARENT: 'removeCellsFromParent',
  1182. /**
  1183. * Variable: FOLD_CELLS
  1184. *
  1185. * Specifies the event name for foldCells.
  1186. */
  1187. FOLD_CELLS: 'foldCells',
  1188. /**
  1189. * Variable: CELLS_FOLDED
  1190. *
  1191. * Specifies the event name for cellsFolded.
  1192. */
  1193. CELLS_FOLDED: 'cellsFolded',
  1194. /**
  1195. * Variable: ALIGN_CELLS
  1196. *
  1197. * Specifies the event name for alignCells.
  1198. */
  1199. ALIGN_CELLS: 'alignCells',
  1200. /**
  1201. * Variable: LABEL_CHANGED
  1202. *
  1203. * Specifies the event name for labelChanged.
  1204. */
  1205. LABEL_CHANGED: 'labelChanged',
  1206. /**
  1207. * Variable: CONNECT_CELL
  1208. *
  1209. * Specifies the event name for connectCell.
  1210. */
  1211. CONNECT_CELL: 'connectCell',
  1212. /**
  1213. * Variable: CELL_CONNECTED
  1214. *
  1215. * Specifies the event name for cellConnected.
  1216. */
  1217. CELL_CONNECTED: 'cellConnected',
  1218. /**
  1219. * Variable: SPLIT_EDGE
  1220. *
  1221. * Specifies the event name for splitEdge.
  1222. */
  1223. SPLIT_EDGE: 'splitEdge',
  1224. /**
  1225. * Variable: FLIP_EDGE
  1226. *
  1227. * Specifies the event name for flipEdge.
  1228. */
  1229. FLIP_EDGE: 'flipEdge',
  1230. /**
  1231. * Variable: START_EDITING
  1232. *
  1233. * Specifies the event name for startEditing.
  1234. */
  1235. START_EDITING: 'startEditing',
  1236. /**
  1237. * Variable: EDITING_STARTED
  1238. *
  1239. * Specifies the event name for editingStarted.
  1240. */
  1241. EDITING_STARTED: 'editingStarted',
  1242. /**
  1243. * Variable: EDITING_STOPPED
  1244. *
  1245. * Specifies the event name for editingStopped.
  1246. */
  1247. EDITING_STOPPED: 'editingStopped',
  1248. /**
  1249. * Variable: ADD_OVERLAY
  1250. *
  1251. * Specifies the event name for addOverlay.
  1252. */
  1253. ADD_OVERLAY: 'addOverlay',
  1254. /**
  1255. * Variable: REMOVE_OVERLAY
  1256. *
  1257. * Specifies the event name for removeOverlay.
  1258. */
  1259. REMOVE_OVERLAY: 'removeOverlay',
  1260. /**
  1261. * Variable: UPDATE_CELL_SIZE
  1262. *
  1263. * Specifies the event name for updateCellSize.
  1264. */
  1265. UPDATE_CELL_SIZE: 'updateCellSize',
  1266. /**
  1267. * Variable: ESCAPE
  1268. *
  1269. * Specifies the event name for escape.
  1270. */
  1271. ESCAPE: 'escape',
  1272. /**
  1273. * Variable: DOUBLE_CLICK
  1274. *
  1275. * Specifies the event name for doubleClick.
  1276. */
  1277. DOUBLE_CLICK: 'doubleClick',
  1278. /**
  1279. * Variable: START
  1280. *
  1281. * Specifies the event name for start.
  1282. */
  1283. START: 'start',
  1284. /**
  1285. * Variable: RESET
  1286. *
  1287. * Specifies the event name for reset.
  1288. */
  1289. RESET: 'reset',
  1290. /**
  1291. * Variable: PINCH_THRESHOLD
  1292. *
  1293. * Threshold for pinch gestures to fire a mouse wheel event.
  1294. * Default value is 10.
  1295. */
  1296. PINCH_THRESHOLD: 10
  1297. };
  1298. __mxOutput.mxEvent = typeof mxEvent !== 'undefined' ? mxEvent : undefined;