mxDefaultKeyHandlerCodec.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * Copyright (c) 2006-2015, JGraph Ltd
  3. * Copyright (c) 2006-2015, Gaudenz Alder
  4. */
  5. mxCodecRegistry.register(function()
  6. {
  7. /**
  8. * Class: mxDefaultKeyHandlerCodec
  9. *
  10. * Custom codec for configuring <mxDefaultKeyHandler>s. This class is created
  11. * and registered dynamically at load time and used implicitly via
  12. * <mxCodec> and the <mxCodecRegistry>. This codec only reads configuration
  13. * data for existing key handlers, it does not encode or create key handlers.
  14. */
  15. var codec = new mxObjectCodec(new mxDefaultKeyHandler());
  16. /**
  17. * Function: encode
  18. *
  19. * Returns null.
  20. */
  21. codec.encode = function(enc, obj)
  22. {
  23. return null;
  24. };
  25. /**
  26. * Function: decode
  27. *
  28. * Reads a sequence of the following child nodes
  29. * and attributes:
  30. *
  31. * Child Nodes:
  32. *
  33. * add - Binds a keystroke to an actionname.
  34. *
  35. * Attributes:
  36. *
  37. * as - Keycode.
  38. * action - Actionname to execute in editor.
  39. * control - Optional boolean indicating if
  40. * the control key must be pressed.
  41. *
  42. * Example:
  43. *
  44. * (code)
  45. * <mxDefaultKeyHandler as="keyHandler">
  46. * <add as="88" control="true" action="cut"/>
  47. * <add as="67" control="true" action="copy"/>
  48. * <add as="86" control="true" action="paste"/>
  49. * </mxDefaultKeyHandler>
  50. * (end)
  51. *
  52. * The keycodes are for the x, c and v keys.
  53. *
  54. * See also: <mxDefaultKeyHandler.bindAction>,
  55. * http://www.js-examples.com/page/tutorials__key_codes.html
  56. */
  57. codec.decode = function(dec, node, into)
  58. {
  59. if (into != null)
  60. {
  61. var editor = into.editor;
  62. node = node.firstChild;
  63. while (node != null)
  64. {
  65. if (!this.processInclude(dec, node, into) &&
  66. node.nodeName == 'add')
  67. {
  68. var as = node.getAttribute('as');
  69. var action = node.getAttribute('action');
  70. var control = node.getAttribute('control');
  71. into.bindAction(as, action, control);
  72. }
  73. node = node.nextSibling;
  74. }
  75. }
  76. return into;
  77. };
  78. // Returns the codec into the registry
  79. return codec;
  80. }());
  81. __mxOutput.mxDefaultKeyHandlerCodec = typeof mxDefaultKeyHandlerCodec !== 'undefined' ? mxDefaultKeyHandlerCodec : undefined;