Created
February 14, 2012 22:16
-
-
Save ericpedia/1831001 to your computer and use it in GitHub Desktop.
Split TinyMCE table above selected row into tbody and thead
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
splitTbodyThead: function() { | |
var ed = tinyMCE.activeEditor; | |
var selection = ed.selection.getContent(); | |
var element = ed.dom.getParent(ed.selection.getNode(), 'tr'); | |
// Give the selected row a class so we can find it later | |
ed.dom.setAttrib( element, 'data-tinymce', 'split'); | |
// Get the whole table | |
var element = ed.dom.getParent(ed.selection.getNode(), 'table'); | |
var html = ed.dom.getOuterHTML( element ); | |
var $html = $(html).wrap('<div></div>').parent(); | |
// Get the index of the row where we want to split | |
// var index = $html.find('tr').index('[data-tinymce=split]'); | |
// alert(index); | |
$html.find('colgroup').remove(); | |
$html.find('table').prepend('<thead></thead>'); | |
$html.find('tr[data-tinymce=split]').prevAll('tr').appendTo('thead'); | |
$html.find('[data-tinymce]').removeAttr('data-tinymce'); | |
// return the new HTML | |
var newHTML = $html.html(); | |
alert($html.html()); | |
// send the new HTML back to the editor | |
// ed.dom.setOuterHTML( element, newHTML); | |
ed.dom.setHTML( element, newHTML); | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment