Click here to Skip to main content
15,881,089 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how do i set Line space in tiny mce editor ? List box in select Line space and apply on all document in tiny mce editor.
Posted

1 solution

i got a solution from


tinymce.create('tinymce.plugins.LineSpacePlugin', {
     createControl: function (n, cm) {
         switch (n) {
             case 'listbox':
                 var mlb = cm.createListBox('listbox', {
                     title: 'Line Space',
                     onselect: function (v) {
                         mlb.focus();
                         var sel = tinymce.activeEditor.selection;
                         var node = tinymce.activeEditor.selection.getNode();
                         if (node.nodeName == 'BODY') {
                             if (v == "") {
                                 var val = '<p>';
                                 var Content = tinyMCE.activeEditor.selection.getContent({ format: 'html' }).replace(/<p(\s*\w*\s*style(\W*line)).*?>/g, val);
                                 Content = Content.replace(/<ul(\s*\w*\s*style(\W*line)).*?>/g, val);
                                 Content = Content.replace(/<li(\s*\w*\s*style(\W*line)).*?>/g, val);
                                 tinyMCE.execCommand('insertHTML', 0, Content);
                             }
                             else {
                                 var val = '<p style="line-height:' + v + 'pt;">';
                                 var Content = tinyMCE.activeEditor.selection.getContent({ format: 'html' }).replace(/<p>/g, val);
                                 Content = Content.replace(/<p(\s*\w*\s*style(\W*line)).*?>/g, val);
                                 Content = Content.replace(/<ul>/g, val);
                                 Content = Content.replace(/<ul(\s*\w*\s*style(\W*line)).*?>/g, val);
                                 Content = Content.replace(/<li>/g, val);
                                 Content = Content.replace(/<li(\s*\w*\s*style(\W*line)).*?>/g, val);
                                 //tinyMCE.activeEditor.selection.setContent(Content);
                                 //tinyMCE.execCommand('mceInsertContent', false, Content);
                                 tinyMCE.execCommand('insertHTML', false, Content);
                                 //tinyMCE.activeEditor.dom.addClass(tinyMCE.activeEditor.dom.select('p'), 'line-height:' + v + 'pt;');
                             }
                         }
                         else if (node.nodeName == "SPAN") {
                             if (v == "") {
                                 if ($(node).parents('LI'))
                                     $(node).parent().css("line-height", "");
                                 else
                                     $(node).closest('p').css("line-height", "");
                             }
                             else {
                                 if ($(node).parents('LI'))
                                     $(node).parent().css("line-height", "" + v + "pt");
                                 else
                                     $(node).closest('p').css("line-height", "" + v + "pt");
                             }
                         }
                         else if (v == "") {
                             $(node).css("line-height", "");
                         }
                         else {
                             $(node).css("line-height", "" + v + "pt");
                         }
                     }
                 });

                 // Add some values to the list box
                 mlb.add('1 pt', '1');
                 mlb.add('2 pt', '2');
                 mlb.add('3 pt', '3');
                 mlb.add('4 pt', '4');
                 mlb.add('5 pt', '5');
                 mlb.add('6 pt', '6');
                 mlb.add('7 pt', '7');
                 mlb.add('8 pt', '8');
                 mlb.add('9 pt', '9');
                 mlb.add('10 pt', '10');
                 mlb.add('11 pt', '11');
                 mlb.add('12 pt', '12');
                 mlb.add('13 pt', '13');
                 mlb.add('14 pt', '14');
                 mlb.add('15 pt', '15');
                 mlb.add('16 pt', '16');
                 mlb.add('17 pt', '17');
                 mlb.add('18 pt', '18');
                 mlb.add('19 pt', '19');
                 mlb.add('20 pt', '20');
                 mlb.add('21 pt', '21');
                 mlb.add('22 pt', '22');
                 mlb.add('23 pt', '23');
                 mlb.add('24 pt', '24');
                 mlb.add('25 pt', '25');
                 // Return the new listbox instance
                 return mlb;
         }

         return null;
     }
 });

 //    function CallBack(obj, v) {
 //       return obj.match(/<p(\s*\w*\s*).*?>/).replace('<p>', '<p style="line-height:' + v + 'pt;">');
 //    }

 // Register plugin with a short name
 tinymce.PluginManager.add('linespace', tinymce.plugins.LineSpacePlugin);
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900