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.

74 lines
2.2 KiB

  1. /* Zoom palette */
  2. define([
  3. 'sugar-web/graphics/palette',
  4. 'mustache'
  5. ], function(palette, mustache) {
  6. var zoompalette = {};
  7. /* We setup the palette with zoom icons */
  8. zoompalette.zoomPalette = function(invoker, primaryText) {
  9. palette.Palette.call(this, invoker, primaryText);
  10. this.getPalette().id = "zoompalette";
  11. this.zoomEvent = document.createEvent('CustomEvent');
  12. this.zoomEvent.initCustomEvent('zoom', true, true, {
  13. 'zoom': 3
  14. });
  15. this.popEvent = document.createEvent('CustomEvent');
  16. this.popEvent.initCustomEvent('pop', true, true, {});
  17. this.template = '{{#rows}}' + '{{#.}}' + '<button class="toolbutton zoombuttons" style="height:55px; width:55px; background-image: url({{ icon }}); "></button>' + '</td>' + '{{/.}}' + '{{/rows}}';
  18. var rows = [
  19. [{
  20. icon: 'icons/zoom-out.svg'
  21. }, {
  22. icon: 'icons/zoom-in.svg'
  23. }, {
  24. icon: 'icons/zoom-to-width.svg'
  25. }, {
  26. icon: 'icons/zoom-original.svg'
  27. }]
  28. ];
  29. var zoomElem = document.createElement('div');
  30. zoomElem.innerHTML = mustache.render(this.template, {
  31. rows: rows
  32. });
  33. this.setContent([zoomElem]);
  34. var buttons = zoomElem.querySelectorAll('button');
  35. var that = this;
  36. invoker.addEventListener('click', function(e) {
  37. that.getPalette().dispatchEvent(that.popEvent);
  38. });
  39. function popDownOnButtonClick(event) {
  40. that.popDown();
  41. }
  42. for (var i = 0; i < buttons.length; i++) {
  43. buttons[i].addEventListener('click', function(e) {
  44. for (var j = 0 ; j < buttons.length ; j++)
  45. if (this == buttons[j]) break;
  46. that.zoomEvent.detail.zoom = j;
  47. that.getPalette().dispatchEvent(that.zoomEvent);
  48. that.popDown();
  49. });
  50. }
  51. popDownOnButtonClick({
  52. target: buttons[0]
  53. });
  54. };
  55. var addEventListener = function(type, listener, useCapture) {
  56. return this.getPalette().addEventListener(type, listener, useCapture);
  57. };
  58. zoompalette.zoomPalette.prototype = Object.create(palette.Palette.prototype, {
  59. addEventListener: {
  60. value: addEventListener,
  61. enumerable: true,
  62. configurable: true,
  63. writable: true
  64. }
  65. });
  66. return zoompalette;
  67. });