plugin.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. tinymce.PluginManager.add('lineheight', function(editor, url) {
  2. var pluginName='设置行高';
  3. var global$1 = tinymce.util.Tools.resolve('tinymce.util.Tools');
  4. var lineheight_val = editor.getParam('lineheight_val', '1 1.5 1.6 1.75 1.8 2 3 4 5');
  5. editor.on('init', function() {
  6. editor.formatter.register({
  7. lineheight: {
  8. selector: 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table',
  9. styles: { 'line-height': '%value' }
  10. }
  11. });
  12. });
  13. var doAct = function (value) {
  14. editor.formatter.apply('lineheight', { value: value });
  15. editor.fire('change', {});
  16. };
  17. editor.ui.registry.getAll().icons.lineheight || editor.ui.registry.addIcon('lineheight','<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M9.984 12.984v-1.969h12v1.969h-12zM9.984 18.984v-1.969h12v1.969h-12zM9.984 5.016h12v1.969h-12v-1.969zM6 6.984v10.031h2.484l-3.469 3.469-3.516-3.469h2.484v-10.031h-2.484l3.516-3.469 3.469 3.469h-2.484z"></path></svg>');
  18. editor.ui.registry.addMenuButton('lineheight', {
  19. icon: 'lineheight',
  20. tooltip: pluginName,
  21. fetch: function(callback) {
  22. var dom = editor.dom;
  23. var blocks = editor.selection.getSelectedBlocks();
  24. var lhv = 0;
  25. global$1.each(blocks, function(block) {
  26. if(lhv==0){
  27. lhv = dom.getStyle(block,'line-height') ? dom.getStyle(block,'line-height') : 0;
  28. }
  29. });
  30. var items = lineheight_val.split(' ').map(function(item){
  31. var text = item;
  32. var value = item;
  33. return {
  34. type: 'togglemenuitem',
  35. text: text,
  36. active : lhv==value ? true :false,
  37. onAction: function() {
  38. doAct(value);
  39. }
  40. };
  41. });
  42. callback(items);
  43. }
  44. });
  45. return {
  46. getMetadata: function () {
  47. return {
  48. name: pluginName,
  49. url: "http://tinymce.ax-z.cn/more-plugins/lineheight.php",
  50. };
  51. }
  52. };
  53. });