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.

94 lines
3.5 KiB

  1. define(["sugar-web/graphics/palette"], function (palette) {
  2. 'use strict';
  3. var listpalette = {};
  4. listpalette.Listpalette = function (invoker, primaryText, menuData) {
  5. palette.Palette.call(this, invoker, primaryText);
  6. this.listEvent = document.createEvent("CustomEvent");
  7. this.listEvent.initCustomEvent('list', 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.setList(this.id);
  27. }
  28. this.buttons.push(newbutton);
  29. div.appendChild(newbutton);
  30. }
  31. this.setContent([div]);
  32. }
  33. this.setList = function(newlist) {
  34. var currentList = this.getList();
  35. var noList = (currentList.length != 0 && currentList == newlist);
  36. var listIndex = -1;
  37. for (var i = 0 ; i < this.categories.length ; i++) {
  38. if (this.categories[i].id == newlist) {
  39. listIndex = i;
  40. break;
  41. }
  42. }
  43. if (listIndex == -1) {
  44. return;
  45. }
  46. for (var i = 0 ; i < this.buttons.length ; i++) {
  47. this.buttons[i].className = 'toolbutton palette-button palette-button-notselected';
  48. }
  49. if (noList) {
  50. this.getPalette().dispatchEvent(this.listEvent);
  51. return;
  52. }
  53. this.buttons[listIndex].className = 'toolbutton palette-button palette-button-selected';
  54. that.getPalette().dispatchEvent(that.listEvent);
  55. }
  56. };
  57. var addEventListener = function (type, listener, useCapture) {
  58. return this.getPalette().addEventListener(type, listener, useCapture);
  59. };
  60. listpalette.Listpalette.prototype =
  61. Object.create(palette.Palette.prototype, {
  62. addEventListener: {
  63. value: addEventListener,
  64. enumerable: true,
  65. configurable: true,
  66. writable: true
  67. }
  68. });
  69. listpalette.Listpalette.prototype.setCategories = function(newcategories) {
  70. this.setCategories(newcategories);
  71. }
  72. listpalette.Listpalette.prototype.setList = function(newlist) {
  73. this.setList(newlist);
  74. }
  75. listpalette.Listpalette.prototype.getList = function() {
  76. for (var i = 0 ; i < this.buttons.length ; i++) {
  77. if (this.buttons[i].className == 'toolbutton palette-button palette-button-selected')
  78. return this.categories[i].id;
  79. }
  80. return "";
  81. }
  82. return listpalette;
  83. });