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.

87 lines
2.9 KiB

  1. /* Text palette to enter text and to choose font */
  2. define([
  3. 'sugar-web/graphics/palette',
  4. 'mustache'
  5. ], function(palette, mustache) {
  6. var fontpalette = {};
  7. /* We setup the palette with fonts */
  8. fontpalette.Fontpalette = function(invoker, primaryText) {
  9. palette.Palette.call(this, invoker, primaryText);
  10. this.getPalette().id = "fontpalette";
  11. this.fontChangeEvent = document.createEvent('CustomEvent');
  12. this.fontChangeEvent.initCustomEvent('fontChange', true, true, {
  13. 'family': 'Arial'
  14. });
  15. this.template = '<center style="padding-top:6px ; "><table><tbody>' + '{{#rows}}' + '<tr>' + '{{#.}}' + '<td>' + '<button lineHeight="{{lineHeight}}" title="{{fontFamily}}" style="height:55px; width:55px; background-size:40px !important; background: #fff url({{ icon }}) no-repeat center; "></button>' + '</td>' + '{{/.}}' + '</tr>' + '{{/rows}}' + '</tbody></table></center>' + '<br/>';
  16. var rows = [
  17. [{
  18. icon: 'icons/font-arial.svg',
  19. lineHeight: '0.7',
  20. fontFamily: 'Arial'
  21. }, {
  22. icon: 'icons/font-comic-sans.svg',
  23. lineHeight: '0.8',
  24. fontFamily: 'Comic Sans MS'
  25. }, {
  26. icon: 'icons/font-verdana.svg',
  27. lineHeight: '0.8',
  28. fontFamily: 'Verdana'
  29. }]
  30. ];
  31. var textsElem = document.createElement('div');
  32. textsElem.innerHTML = mustache.render(this.template, {
  33. rows: rows
  34. });
  35. this.setContent([textsElem]);
  36. var buttons = textsElem.querySelectorAll('button');
  37. var that = this;
  38. function popDownOnButtonClick(event) {
  39. that.popDown();
  40. }
  41. for (var i = 0; i < buttons.length; i++) {
  42. buttons[i].addEventListener('click', function(e) {
  43. that.fontChangeEvent.detail.family = e.target.title;
  44. that.getPalette().dispatchEvent(that.fontChangeEvent);
  45. that.popDown();
  46. });
  47. }
  48. popDownOnButtonClick({
  49. target: buttons[0]
  50. });
  51. };
  52. var setFont = function (font) {
  53. var buttons = this.getPalette().querySelectorAll('button');
  54. for (var i = 0; i < buttons.length; i++) {
  55. if (font == buttons[i].title)
  56. buttons[i].style.border = '1px solid #f00';
  57. else
  58. buttons[i].style.border = '0px solid #000';
  59. }
  60. };
  61. var addEventListener = function(type, listener, useCapture) {
  62. return this.getPalette().addEventListener(type, listener, useCapture);
  63. };
  64. fontpalette.Fontpalette.prototype = Object.create(palette.Palette.prototype, {
  65. setFont: {
  66. value: setFont,
  67. enumerable: true,
  68. configurable: true,
  69. writable: true
  70. },
  71. addEventListener: {
  72. value: addEventListener,
  73. enumerable: true,
  74. configurable: true,
  75. writable: true
  76. }
  77. });
  78. return fontpalette;
  79. });