You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

64 lines
1.2 KiB

  1. define([
  2. 'js/system/events',
  3. 'html!ui/templates/context/template',
  4. 'css!ui/templates/context/styles',
  5. 'html!ui/templates/context/templateItem'
  6. ], function (
  7. events,
  8. template,
  9. styles,
  10. templateItem
  11. ) {
  12. return {
  13. tpl: template,
  14. modal: true,
  15. postRender: function () {
  16. this.onEvent('onContextMenu', this.onContextMenu.bind(this));
  17. this.onEvent('onHideContextMenu', this.onMouseDown.bind(this));
  18. this.onEvent('mouseDown', this.onMouseDown.bind(this));
  19. $('.ui-container').on('mouseup', this.onMouseDown.bind(this));
  20. },
  21. onContextMenu: function (config, e) {
  22. let container = this.el.find('.list')
  23. .empty();
  24. config.forEach(function (c, i) {
  25. let text = c.text ? c.text : c;
  26. let html = templateItem
  27. .replace('$TEXT$', text);
  28. let row = $(html)
  29. .appendTo(container);
  30. if (c.callback)
  31. row.on('click', this.onClick.bind(this, i, c.callback));
  32. else
  33. row.addClass('no-hover');
  34. }, this);
  35. this.el
  36. .css({
  37. left: e.clientX,
  38. top: e.clientY
  39. })
  40. .show();
  41. },
  42. onClick: function (index, callback) {
  43. this.el.hide();
  44. callback();
  45. },
  46. onMouseDown: function (e) {
  47. if ((!this.el.is(':visible')) || (e.cancel) || (e.button == 2))
  48. return;
  49. this.el.hide();
  50. }
  51. };
  52. });