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.

89 lines
3.2 KiB

  1. define(["sugar-web/graphics/palette"], function (palette) {
  2. 'use strict';
  3. var parapalette = {};
  4. parapalette.Parapalette = function (invoker, primaryText, menuData) {
  5. palette.Palette.call(this, invoker, primaryText);
  6. this.paraEvent = document.createEvent("CustomEvent");
  7. this.paraEvent.initCustomEvent('para', true, true, {});
  8. this.remoteEvent = document.createEvent("CustomEvent");
  9. this.remoteEvent.initCustomEvent('remote', true, true, {});
  10. var that = this;
  11. that.categories = [];
  12. that.buttons = [];
  13. this.setCategories = function( newcategories) {
  14. this.categories = newcategories;
  15. this.buttons = [];
  16. var div = document.createElement('div');
  17. for (var i = 0 ; i < newcategories.length ; i++) {
  18. var newbutton = document.createElement('button');
  19. newbutton.className = 'toolbutton palette-button palette-button-notselected';
  20. newbutton.setAttribute('id', newcategories[i].id);
  21. newbutton.setAttribute('title', newcategories[i].title);
  22. var url = "url(icons/"+newcategories[i].cmd+".svg)";
  23. newbutton.style.backgroundImage = url;
  24. var newid = newcategories[i].id;
  25. newbutton.onclick = function() {
  26. that.setPara(this.id);
  27. }
  28. this.buttons.push(newbutton);
  29. div.appendChild(newbutton);
  30. }
  31. this.setContent([div]);
  32. }
  33. this.setPara = function(newpara) {
  34. var paraIndex = -1;
  35. for (var i = 0 ; i < this.categories.length ; i++) {
  36. if (this.categories[i].id == newpara) {
  37. paraIndex = i;
  38. break;
  39. }
  40. }
  41. if (paraIndex == -1) {
  42. return;
  43. }
  44. for (var i = 0 ; i < this.buttons.length ; i++) {
  45. this.buttons[i].className = 'toolbutton palette-button palette-button-notselected';
  46. }
  47. this.buttons[paraIndex].className = 'toolbutton palette-button palette-button-selected';
  48. that.getPalette().dispatchEvent(that.paraEvent);
  49. }
  50. };
  51. var addEventListener = function (type, listener, useCapture) {
  52. return this.getPalette().addEventListener(type, listener, useCapture);
  53. };
  54. parapalette.Parapalette.prototype =
  55. Object.create(palette.Palette.prototype, {
  56. addEventListener: {
  57. value: addEventListener,
  58. enumerable: true,
  59. configurable: true,
  60. writable: true
  61. }
  62. });
  63. parapalette.Parapalette.prototype.setCategories = function(newcategories) {
  64. this.setCategories(newcategories);
  65. }
  66. parapalette.Parapalette.prototype.setPara = function(newpara) {
  67. this.setPara(newpara);
  68. }
  69. parapalette.Parapalette.prototype.getPara = function() {
  70. for (var i = 0 ; i < this.buttons.length ; i++) {
  71. if (this.buttons[i].className == 'toolbutton palette-button palette-button-selected')
  72. return this.categories[i].id;
  73. }
  74. return "";
  75. }
  76. return parapalette;
  77. });