Last active
August 29, 2015 14:02
-
-
Save zerolab/583ed4360e32ad439ab3 to your computer and use it in GitHub Desktop.
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
if (typeof tinyMCE !== 'undefined') { | |
// see http://www.tinymce.com/forum/viewtopic.php?id=25977 | |
var ed = tinyMCE.activeEditor; | |
ed.onNodeChange.add(function(ed, cm, n, co, o) { | |
n = ed.dom.getParent(n, 'span.media-element'); | |
tinymce.each(ed.dom.select('span.media-element', o.node), function(n) { | |
// The criterias for choosing the span tags, that insert a br on pressing | |
// enter when the span.xml_include tag was the last one in a paragraph | |
if(!n.hasChildNodes() || (n.hasChildNodes() && n.firstChild.nodeName.toLowerCase() == "br" )) { | |
//the current workaround for chrome | |
if (tinymce.isWebKit) { | |
ed.selection.select(n); | |
var nParent = n.parentNode; | |
ed.dom.remove(n); //faulty n (span tag) is removed | |
nParent.innerHTML = " "; //nParent is now empty, so i have to do this to make next step possible, otherwise cursor jumps to start of textarea in upper left area | |
ed.selection.select(nParent); //selecting the parent element | |
ed.selection.collapse(); //and setting cursor to start of selection | |
} | |
//all other browsers (even IE) work fine | |
else { | |
ed.dom.remove(n.parentNode); | |
} | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment