hotbox.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * @fileOverview
  3. *
  4. * 热盒 Runtime
  5. *
  6. * @author: techird
  7. * @copyright: Baidu FEX, 2014
  8. */
  9. define(function(require, exports, module) {
  10. var Hotbox = require('../hotbox');
  11. function HotboxRuntime() {
  12. var fsm = this.fsm;
  13. var minder = this.minder;
  14. var receiver = this.receiver;
  15. var container = this.container;
  16. var hotbox = new Hotbox(container);
  17. hotbox.setParentFSM(fsm);
  18. fsm.when('normal -> hotbox', function(exit, enter, reason) {
  19. var node = minder.getSelectedNode();
  20. var position;
  21. if (node) {
  22. var box = node.getRenderBox();
  23. position = {
  24. x: box.cx,
  25. y: box.cy
  26. };
  27. }
  28. hotbox.active('main', position);
  29. });
  30. fsm.when('normal -> normal', function(exit, enter, reason, e) {
  31. if (reason == 'shortcut-handle') {
  32. var handleResult = hotbox.dispatch(e);
  33. if (handleResult) {
  34. e.preventDefault();
  35. } else {
  36. minder.dispatchKeyEvent(e);
  37. }
  38. }
  39. });
  40. fsm.when('modal -> normal', function(exit, enter, reason, e) {
  41. if (reason == 'import-text-finish') {
  42. receiver.element.focus();
  43. }
  44. });
  45. this.hotbox = hotbox;
  46. }
  47. return module.exports = HotboxRuntime;
  48. });