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.

68 lines
2.3 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 textpalette = {};
  7. /* We setup the palette with fonts */
  8. textpalette.TextPalette = function(invoker, primaryText) {
  9. palette.Palette.call(this, invoker, primaryText);
  10. this.template = '<input id="text-input" value="Paint" type="text" style="margin:10px;">' + '<center><table><tbody>' + '{{#rows}}' + '<tr>' + '{{#.}}' + '<td>' + '<button lineHeight="{{lineHeight}}" fontFamily="{{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/>';
  11. var rows = [
  12. [{
  13. icon: 'icons/text/arial.svg',
  14. lineHeight: '0.7',
  15. fontFamily: 'Arial'
  16. }, {
  17. icon: 'icons/text/comic-sans.svg',
  18. lineHeight: '0.8',
  19. fontFamily: 'Comic Sans MS'
  20. }, {
  21. icon: 'icons/text/verdana.svg',
  22. lineHeight: '0.8',
  23. fontFamily: 'Verdana'
  24. }]
  25. ];
  26. var textsElem = document.createElement('div');
  27. textsElem.innerHTML = mustache.render(this.template, {
  28. rows: rows
  29. });
  30. this.setContent([textsElem]);
  31. var buttons = textsElem.querySelectorAll('button');
  32. var that = this;
  33. function popDownOnButtonClick(event) {
  34. for (var i = 0; i < buttons.length; i++) {
  35. buttons[i].style.border = '0px solid #000';
  36. }
  37. event.target.style.border = '1px solid #f00';
  38. PaintApp.modes.Text.fontFamily = event.target.getAttribute('fontFamily');
  39. PaintApp.modes.Text.lineHeight = event.target.getAttribute('lineHeight');
  40. that.popDown();
  41. }
  42. for (var i = 0; i < buttons.length; i++) {
  43. buttons[i].addEventListener('click', popDownOnButtonClick);
  44. }
  45. popDownOnButtonClick({
  46. target: buttons[0]
  47. });
  48. };
  49. var addEventListener = function(type, listener, useCapture) {
  50. return this.getPalette().addEventListener(type, listener, useCapture);
  51. };
  52. textpalette.TextPalette.prototype = Object.create(palette.Palette.prototype, {
  53. addEventListener: {
  54. value: addEventListener,
  55. enumerable: true,
  56. configurable: true,
  57. writable: true
  58. }
  59. });
  60. return textpalette;
  61. });