plugin.min.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. tinymce.PluginManager.add('o2indent2em', function(editor, url) {
  2. var pluginName='首行缩进';
  3. var global$1 = tinymce.util.Tools.resolve('tinymce.util.Tools');
  4. var indent2em_val = editor.getParam('indent2em_val', '2em');
  5. var doAct = function () {
  6. var dom = editor.dom;
  7. var blocks = editor.selection.getSelectedBlocks();
  8. var act = '';
  9. global$1.each(blocks, function (block) {
  10. if(act==''){
  11. act = dom.getStyle(block,'text-indent')==indent2em_val ? 'remove' : 'add';
  12. }
  13. if( act=='add' ){
  14. dom.setStyle(block, 'text-indent', indent2em_val);
  15. }else{
  16. var style=dom.getAttrib(block,'style');
  17. var reg = new RegExp('text-indent:[\\s]*' + indent2em_val + ';', 'ig');
  18. style = style.replace(reg, '');
  19. dom.setAttrib(block,'style',style);
  20. }
  21. });
  22. };
  23. editor.ui.registry.getAll().icons.indent2em || editor.ui.registry.addIcon('indent2em','<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>');
  24. var stateSelectorAdapter = function (editor, selector) {
  25. return function (buttonApi) {
  26. return editor.selection.selectorChangedWithUnbind(selector.join(','), buttonApi.setActive).unbind;
  27. };
  28. };
  29. editor.ui.registry.addToggleButton('o2indent2em', {
  30. icon: 'indent2em',
  31. tooltip: pluginName,
  32. onAction: function () {
  33. doAct();
  34. },
  35. onSetup: stateSelectorAdapter(editor, [
  36. '*[style*="text-indent"]',
  37. '*[data-mce-style*="text-indent"]',
  38. ])
  39. });
  40. editor.ui.registry.addMenuItem('o2indent2em', {
  41. text: pluginName,
  42. onAction: function() {
  43. doAct();
  44. }
  45. });
  46. editor.addCommand('indent2em', doAct );
  47. return {
  48. getMetadata: function () {
  49. return {
  50. name: pluginName,
  51. url: "http://tinymce.ax-z.cn/more-plugins/indent2em.php",
  52. };
  53. }
  54. };
  55. });