mxEvent.js 29 KB

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