plugin.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. (function (tinymce) {
  2. tinymce.PluginManager.add('lineheight', function (editor, url, $) {
  3. editor.on('init', function () {
  4. editor.formatter.register({
  5. lineheight: {inline: 'span', styles: {'line-height': '%value'}}
  6. });
  7. });
  8. editor.addButton('lineheightselect', function() {
  9. var items = [], defaultLineHeightFormats = '8pt 10pt 12pt 14pt 18pt 24pt 36pt';
  10. var lineheight_formats = editor.settings.lineheight_formats || defaultLineHeightFormats;
  11. lineheight_formats.split(' ').forEach(function(item) {
  12. var text = item, value = item;
  13. // Allow text=value for line-height formats
  14. var values = item.split('=');
  15. if (values.length > 1) {
  16. text = values[0];
  17. value = values[1];
  18. }
  19. items.push({text: text, value: value});
  20. });
  21. return {
  22. type: 'listbox',
  23. text: '行高',
  24. tooltip: '行高',
  25. values: items,
  26. fixedWidth: true,
  27. onPostRender: function() {
  28. var self = this;
  29. editor.on('nodeChange', function(e) {
  30. var formatName = 'lineheight';
  31. var formatter = editor.formatter;
  32. var value = null;
  33. e.parents.forEach(function(node) {
  34. items.forEach(function(item) {
  35. if (formatName) {
  36. if (formatter.matchNode(node, formatName, {value: item.value})) {
  37. value = item.value;
  38. }
  39. } else {
  40. if (formatter.matchNode(node, item.value)) {
  41. value = item.value;
  42. }
  43. }
  44. if (value) {
  45. return false;
  46. }
  47. });
  48. if (value) {
  49. return false;
  50. }
  51. });
  52. self.value(value);
  53. });
  54. },
  55. onselect: function(e) {
  56. tinymce.activeEditor.formatter.apply('lineheight', {value : this.value()});
  57. }
  58. };
  59. });
  60. });
  61. tinymce.PluginManager.requireLangPack('lineheight', 'de');
  62. })(tinymce);