tinymce onPostProcess problem
Here is html content from db
<p>Some p</p>
<p>some p 1</p>
<p><a href="http://www.google.com/">google</a></p>
<p><a href="http://www.yahoo.com/">yahoo</a></p>
<p>{link class="readmore" cat_id="14" content_id="15" slug="Slug 1" content="Content 1"}</p>
<p>{link class="" cat_id="15" content_id="16" slug="Slug 2" content="Content 2"}</p>
<p>Some p 2 </p>
<p>Some p 3</p>
and then i use onBeforeSetContent function and convert html for tinymce like: No problem here...
<p>Some p</p>
<p>some p 1</p>
<p><a href="http://www.google.com/">google</a></p> <p><a href="http://www.yahoo.com/">yahoo</a></p>
<p><a href="#" rel="SpecialLink" class="readmore" title="link class="readmore" cat_id="14" content_id="15" slug="Slug 1" content="Content 1"">Content 1</a>
</p>
<p><a href="#" rel="SpecialLink" class="" title="link class="" cat_id="15" content_id="16" slug="Slug 2" content="Content 2"">Content 2</a></p>
<p>Some p 2 </p>
<p>Some p 3</p&g开发者_Go百科t;
When the form is submitted i want to convert special urls to {link etc.} statement again with onPostProcess function. But it doesn't work. If i console.log(o.content) within onPostProcess content is same ; not converted and is beging saved to mysql wrong. But if console.log(t._get_link(o.content)) within onBeforeSetContent it works. I could not handle it for hours.
ed.onBeforeSetContent.add(function(ed, o) {
o.content = t._do_link(o.content);
});
ed.onPostProcess.add(function(ed, o) {
if (o.get)
o.content = t._get_link(o.content);
});
below _do_link and _get_link functions;
_do_link : function(co) {
return co.replace(/\{link([^<]+)\}/g, function(a,b){
content = b.match(/content=['"]([^'"]+)/i);
aclass = b.match(/class=['"]([^'"]+)/i);
if(aclass == undefined)
{
aclass = '';
}
else
{
aclass = aclass[1];
}
return '<a href="#" rel="SpecialLink" class="'+aclass+'" title="link'+tinymce.DOM.encode(b)+'">'+content[1]+'</a>';
});
},
_get_link : function(co) {
function getAttr(s, n) {
n = new RegExp(n + '="([^"]+)"', 'g').exec(s);
return n ? tinymce.DOM.decode(n[1]) : '';
};
return co.replace(/(<a href="([^"]+)" ([\S]*=.*(\ )*)*>([^<]+)<\/a>)/g, function(a,im) {
var cls = getAttr(im, 'rel');
if ( cls.indexOf('SpecialLink') != -1 )
{
return '{'+tinymce.trim(getAttr(im, 'title'))+'}';
}
return a;
});
}
精彩评论