not really known
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.

53 lines
1.6 KiB

  1. define(["sugar-web/graphics/palette",
  2. "text!sugar-web/graphics/menupalette.html", "mustache"], function (palette, template, mustache) {
  3. 'use strict';
  4. var menupalette = {};
  5. menupalette.MenuPalette = function (invoker, primaryText, menuData) {
  6. palette.Palette.call(this, invoker, primaryText);
  7. this.selectItemEvent = document.createEvent("CustomEvent");
  8. this.selectItemEvent.initCustomEvent('selectItem', true, true, {
  9. 'item': undefined
  10. });
  11. var menuElem = document.createElement('ul');
  12. menuElem.className = "menu";
  13. menuElem.innerHTML = mustache.render(template, menuData);
  14. this.setContent([menuElem]);
  15. // Pop-down the palette when a item in the menu is clicked.
  16. this.buttons = menuElem.querySelectorAll('button');
  17. var that = this;
  18. function popDownOnButtonClick(event) {
  19. that.selectItemEvent.detail.target = event.target;
  20. that.getPalette().dispatchEvent(that.selectItemEvent);
  21. that.popDown();
  22. }
  23. for (var i = 0; i < this.buttons.length; i++) {
  24. this.buttons[i].addEventListener('click', popDownOnButtonClick);
  25. }
  26. };
  27. var addEventListener = function (type, listener, useCapture) {
  28. return this.getPalette().addEventListener(type, listener, useCapture);
  29. };
  30. menupalette.MenuPalette.prototype =
  31. Object.create(palette.Palette.prototype, {
  32. addEventListener: {
  33. value: addEventListener,
  34. enumerable: true,
  35. configurable: true,
  36. writable: true
  37. }
  38. });
  39. return menupalette;
  40. });