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.

77 lines
2.4 KiB

  1. define(["sugar-web/graphics/palette"], function (palette) {
  2. 'use strict';
  3. var sizepalette = {};
  4. sizepalette.SizePalette = function (invoker, primaryText) {
  5. palette.Palette.call(this, invoker, primaryText);
  6. this.sharedEvent = document.createEvent("CustomEvent");
  7. this.sharedEvent.initCustomEvent('size', true, true, {});
  8. this.buttons = [];
  9. var div = document.createElement('div');
  10. for (var i = 4; i <= 6; i++) {
  11. var button = document.createElement("div");
  12. button.value = i;
  13. button.onmouseover = function() {
  14. this.style.background = "#ccc";
  15. };
  16. button.onmouseout = function() {
  17. this.style.background = "#000";
  18. };
  19. button.style.borderRadius = "0";
  20. button.style.width = "100%";
  21. if (i != 4) {
  22. button.style.marginTop = "3px";
  23. }
  24. button.innerHTML = "<img style='vertical-align: middle; margin-right:3px;' src='icons/" + i + "x" + i + ".svg'>" + i + " X " + i;
  25. div.appendChild(button);
  26. this.buttons.push(button);
  27. }
  28. this.setContent([div]);
  29. var that = this;
  30. that.getPalette().firstChild.style.backgroundColor = "transparent";
  31. that.getPalette().firstChild.style.backgroundImage = "";
  32. function popDownOnButtonClick(event) {
  33. console.log(event);
  34. that.popDown();
  35. }
  36. for (var i = 0; i < this.buttons.length; i++) {
  37. var t = this;
  38. var button = t.buttons[i];
  39. (function (button) {
  40. button.addEventListener("click", function () {
  41. that.sharedEvent.detail.value = button.value;
  42. that.getPalette().dispatchEvent(that.sharedEvent);
  43. that.popDown();
  44. });
  45. })(button);
  46. button.addEventListener('size', popDownOnButtonClick);
  47. }
  48. };
  49. var addEventListener = function (type, listener, useCapture) {
  50. return this.getPalette().addEventListener(type, listener, useCapture);
  51. };
  52. sizepalette.SizePalette.prototype =
  53. Object.create(palette.Palette.prototype, {
  54. addEventListener: {
  55. value: addEventListener,
  56. enumerable: true,
  57. configurable: true,
  58. writable: true
  59. }
  60. });
  61. return sizepalette;
  62. });