Skip to content

Instantly share code, notes, and snippets.

@ericpedia
Created February 14, 2012 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericpedia/1831001 to your computer and use it in GitHub Desktop.
Save ericpedia/1831001 to your computer and use it in GitHub Desktop.
Split TinyMCE table above selected row into tbody and thead
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