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.

85 lines
2.7 KiB

  1. define(["sugar-web/graphics/palette"], function (palette) {
  2. 'use strict';
  3. var presencepalette = {};
  4. presencepalette.PresencePalette = function (invoker, primaryText, menuData) {
  5. palette.Palette.call(this, invoker, primaryText);
  6. this.sharedEvent = document.createEvent("CustomEvent");
  7. this.sharedEvent.initCustomEvent('shared', true, true, {});
  8. var div = document.createElement('div');
  9. var txt = document.createElement('span');
  10. txt.innerHTML = "Private";
  11. txt.className = 'network-text';
  12. var hr = document.createElement('hr');
  13. var privatebutton = document.createElement('button');
  14. privatebutton.className = 'toolbutton';
  15. privatebutton.setAttribute('id','private-button');
  16. privatebutton.onclick = function() {
  17. that.setShared(false);
  18. }
  19. var sharedbutton = document.createElement('button');
  20. sharedbutton.className = 'toolbutton';
  21. sharedbutton.setAttribute('id','shared-button');
  22. sharedbutton.onclick = function() {
  23. that.setShared(true);
  24. }
  25. this.setShared = function(state) {
  26. if (state) {
  27. txt.innerHTML = "My neighborhood";
  28. privatebutton.disabled = true;
  29. sharedbutton.disabled = true;
  30. invoker.style.backgroundImage = 'url(lib/sugar-web/graphics/icons/actions/zoom-neighborhood.svg)';
  31. that.getPalette().childNodes[0].style.backgroundImage = 'url(lib/sugar-web/graphics/icons/actions/zoom-neighborhood.svg)';
  32. that.getPalette().dispatchEvent(that.sharedEvent);
  33. } else {
  34. txt.innerHTML = "Private";
  35. privatebutton.disabled = false;
  36. sharedbutton.disabled = false;
  37. }
  38. }
  39. div.appendChild(txt);
  40. div.appendChild(hr);
  41. div.appendChild(privatebutton);
  42. div.appendChild(sharedbutton);
  43. this.setContent([div]);
  44. // Pop-down the palette when a item in the menu is clicked.
  45. this.buttons = div.querySelectorAll('button');
  46. var that = this;
  47. function popDownOnButtonClick(event) {
  48. that.popDown();
  49. }
  50. for (var i = 0; i < this.buttons.length; i++) {
  51. if (this.buttons[i].id == "shared-button")
  52. this.buttons[i].addEventListener('shared', popDownOnButtonClick);
  53. }
  54. };
  55. var addEventListener = function (type, listener, useCapture) {
  56. return this.getPalette().addEventListener(type, listener, useCapture);
  57. };
  58. presencepalette.PresencePalette.prototype =
  59. Object.create(palette.Palette.prototype, {
  60. addEventListener: {
  61. value: addEventListener,
  62. enumerable: true,
  63. configurable: true,
  64. writable: true
  65. }
  66. });
  67. presencepalette.PresencePalette.prototype.setShared = function(state) {
  68. this.setShared(state);
  69. }
  70. return presencepalette;
  71. });