Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

hand.js 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * WHITEBOPHIR
  3. *********************************************************
  4. * @licstart The following is the entire license notice for the
  5. * JavaScript code in this page.
  6. *
  7. * Copyright (C) 2013 Ophir LOJKINE
  8. *
  9. *
  10. * The JavaScript code in this page is free software: you can
  11. * redistribute it and/or modify it under the terms of the GNU
  12. * General Public License (GNU GPL) as published by the Free Software
  13. * Foundation, either version 3 of the License, or (at your option)
  14. * any later version. The code is distributed WITHOUT ANY WARRANTY;
  15. * without even the implied warranty of MERCHANTABILITY or FITNESS
  16. * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
  17. *
  18. * As additional permission under GNU GPL version 3 section 7, you
  19. * may distribute non-source (e.g., minimized or compacted) forms of
  20. * that code without the copy of the GNU GPL normally required by
  21. * section 4, provided you include this license notice and a URL
  22. * through which recipients can access the Corresponding Source.
  23. *
  24. * @licend
  25. */
  26. (function () { //Code isolation
  27. var orig = { x: 0, y: 0 };
  28. var pressed = false;
  29. function press(x, y, evt, isTouchEvent) {
  30. if (!isTouchEvent) {
  31. pressed = true;
  32. orig.x = document.documentElement.scrollLeft + evt.clientX;
  33. orig.y = document.documentElement.scrollTop + evt.clientY;
  34. }
  35. }
  36. function move(x, y, evt, isTouchEvent) {
  37. if (pressed && !isTouchEvent) { //Let the browser handle touch to scroll
  38. window.scrollTo(orig.x - evt.clientX, orig.y - evt.clientY);
  39. }
  40. }
  41. function release() {
  42. pressed = false;
  43. }
  44. Tools.add({ //The new tool
  45. "name": "Hand",
  46. "shortcut": "h",
  47. "listeners": {
  48. "press": press,
  49. "move": move,
  50. "release": release
  51. },
  52. "icon": "tools/hand/icon.svg",
  53. "mouseCursor": "move",
  54. "showMarker": true,
  55. });
  56. //The hand tool is selected by default
  57. Tools.change("Hand");
  58. })(); //End of code isolation