[wp-hackers] Problem with custom TinyMCE button
admin at laptoptips.ca
Fri Feb 6 12:11:35 GMT 2009
Looking at the function there are couple of things:
1. It seems you're mixing DOM nodes and strings. It would be better to
stick to one of them:
var e = the link node;
var h = the href from e;
var txt = the inner text from e;
Then you have enough to make the <video> tag string.
2. You got the link node but it's still in the document so when you do
"insertContent" it puts it at the cursor position inside the existing
<a> tag, making it totally invalid. It's inserted as string, not DOM
node so you'll have to either select the <a> tag and replace it or you
can create new <p> node, set it's content and attribs and replace the
<a> node (TinyMCE makes this pretty easy, all in one step).
Another problem is that you're replacing an inline element <a> with a
block element <p> and the <a> element is most likely inside a <p>. This
probably would be fixed by the internal cleanup in TinyMCE, but may have
some problems in some browsers. All browsers have to render the content
entered in a "contentEditable" area and they are usually quite more
restrictive about malformed HTML there compared to a "normal" page.
More information about the wp-hackers