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.
 
 
 
 

40 rivejä
1.3 KiB

  1. import assign from 'object-assign';
  2. import { store } from './helpers';
  3. export var MENU_SHOW = 'REACT_CONTEXTMENU_SHOW';
  4. export var MENU_HIDE = 'REACT_CONTEXTMENU_HIDE';
  5. export function dispatchGlobalEvent(eventName, opts) {
  6. var target = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : window;
  7. // Compatibale with IE
  8. // @see http://stackoverflow.com/questions/26596123/internet-explorer-9-10-11-event-constructor-doesnt-work
  9. var event = void 0;
  10. if (typeof window.CustomEvent === 'function') {
  11. event = new window.CustomEvent(eventName, { detail: opts });
  12. } else {
  13. event = document.createEvent('CustomEvent');
  14. event.initCustomEvent(eventName, false, true, opts);
  15. }
  16. if (target) {
  17. target.dispatchEvent(event);
  18. assign(store, opts);
  19. }
  20. }
  21. export function showMenu() {
  22. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  23. var target = arguments[1];
  24. dispatchGlobalEvent(MENU_SHOW, assign({}, opts, { type: MENU_SHOW }), target);
  25. }
  26. export function hideMenu() {
  27. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  28. var target = arguments[1];
  29. dispatchGlobalEvent(MENU_HIDE, assign({}, opts, { type: MENU_HIDE }), target);
  30. }