plugin.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import tinymce from "tinymce/tinymce";
  2. tinymce.PluginManager.add('indent2em', function(editor) {
  3. var pluginName='首行缩进';
  4. var global$1 = tinymce.util.Tools.resolve('tinymce.util.Tools');
  5. var indent2em_val = editor.getParam('indent2em_val', '2em');
  6. var doAct = function () {
  7. var dom = editor.dom;
  8. var blocks = editor.selection.getSelectedBlocks();
  9. var act = '';
  10. global$1.each(blocks, function (block) {
  11. if(act==''){
  12. act = dom.getStyle(block,'text-indent')==indent2em_val ? 'remove' : 'add';
  13. }
  14. if( act=='add' ){
  15. dom.setStyle(block, 'text-indent', indent2em_val);
  16. }else{
  17. var style=dom.getAttrib(block,'style');
  18. style = style.replace(/text-indent:[\s]*2em;/ig,'');
  19. dom.setAttrib(block,'style',style);
  20. }
  21. });
  22. };
  23. editor.ui.registry.addButton('indent2em', {
  24. text: '<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="24" height="24"><path d="M170.666667 563.2v-102.4H887.466667v102.4zM170.666667 836.266667v-102.4H887.466667v102.4zM512 290.133333v-102.4H887.466667v102.4zM238.933333 341.333333V136.533333l204.8 102.4z" fill="#2c2c2c" p-id="5210"></path></svg>',
  25. tooltip: pluginName,
  26. onAction: function () {
  27. doAct();
  28. }
  29. });
  30. editor.ui.registry.addMenuItem('indent2em', {
  31. text: pluginName,
  32. onAction: function() {
  33. doAct();
  34. }
  35. });
  36. return {
  37. getMetadata: function () {
  38. return {
  39. name: pluginName,
  40. url: "http://tinymce.ax-z.cn/more-plugins/indent2em.php",
  41. };
  42. }
  43. };
  44. });