bgneal@45: /** bgneal@45: * $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $ bgneal@45: * bgneal@45: * @author Moxiecode bgneal@45: * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved. bgneal@45: */ bgneal@45: bgneal@45: (function() { bgneal@45: tinymce.create('tinymce.plugins.BBCodePlugin', { bgneal@45: init : function(ed, url) { bgneal@45: var t = this, dialect = ed.getParam('bbcode_dialect', 'punbb').toLowerCase(); bgneal@45: bgneal@45: ed.onBeforeSetContent.add(function(ed, o) { bgneal@45: o.content = t['_' + dialect + '_bbcode2html'](o.content); bgneal@45: }); bgneal@45: bgneal@45: ed.onPostProcess.add(function(ed, o) { bgneal@45: if (o.set) bgneal@45: o.content = t['_' + dialect + '_bbcode2html'](o.content); bgneal@45: bgneal@45: if (o.get) bgneal@45: o.content = t['_' + dialect + '_html2bbcode'](o.content); bgneal@45: }); bgneal@45: }, bgneal@45: bgneal@45: getInfo : function() { bgneal@45: return { bgneal@45: longname : 'BBCode Plugin', bgneal@45: author : 'Moxiecode Systems AB', bgneal@45: authorurl : 'http://tinymce.moxiecode.com', bgneal@45: infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/bbcode', bgneal@45: version : tinymce.majorVersion + "." + tinymce.minorVersion bgneal@45: }; bgneal@45: }, bgneal@45: bgneal@45: // Private methods bgneal@45: bgneal@45: // HTML -> BBCode in PunBB dialect bgneal@45: _punbb_html2bbcode : function(s) { bgneal@45: s = tinymce.trim(s); bgneal@45: bgneal@45: function rep(re, str) { bgneal@45: s = s.replace(re, str); bgneal@45: }; bgneal@45: bgneal@45: // example: to [b] bgneal@45: rep(/(.*?)<\/a>/gi,"[url=$1]$2[/url]"); bgneal@45: rep(/(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]"); bgneal@45: rep(/(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]"); bgneal@45: rep(/(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]"); bgneal@45: rep(/(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]"); bgneal@45: rep(/(.*?)<\/span>/gi,"[color=$1]$2[/color]"); bgneal@45: rep(/(.*?)<\/font>/gi,"[color=$1]$2[/color]"); bgneal@45: rep(/(.*?)<\/span>/gi,"[size=$1]$2[/size]"); bgneal@45: rep(/(.*?)<\/font>/gi,"$1"); bgneal@45: rep(//gi,"[img]$1[/img]"); bgneal@45: rep(/(.*?)<\/span>/gi,"[code]$1[/code]"); bgneal@45: rep(/(.*?)<\/span>/gi,"[quote]$1[/quote]"); bgneal@45: rep(/(.*?)<\/strong>/gi,"[code][b]$1[/b][/code]"); bgneal@45: rep(/(.*?)<\/strong>/gi,"[quote][b]$1[/b][/quote]"); bgneal@45: rep(/(.*?)<\/em>/gi,"[code][i]$1[/i][/code]"); bgneal@45: rep(/(.*?)<\/em>/gi,"[quote][i]$1[/i][/quote]"); bgneal@45: rep(/(.*?)<\/u>/gi,"[code][u]$1[/u][/code]"); bgneal@45: rep(/(.*?)<\/u>/gi,"[quote][u]$1[/u][/quote]"); bgneal@45: rep(/<\/(strong|b)>/gi,"[/b]"); bgneal@45: rep(/<(strong|b)>/gi,"[b]"); bgneal@45: rep(/<\/(em|i)>/gi,"[/i]"); bgneal@45: rep(/<(em|i)>/gi,"[i]"); bgneal@45: rep(/<\/u>/gi,"[/u]"); bgneal@45: rep(/(.*?)<\/span>/gi,"[u]$1[/u]"); bgneal@45: rep(//gi,"[u]"); bgneal@45: rep(/]*>/gi,"[quote]"); bgneal@45: rep(/<\/blockquote>/gi,"[/quote]"); bgneal@45: rep(/
/gi,"\n"); bgneal@45: rep(//gi,"\n"); bgneal@45: rep(/
/gi,"\n"); bgneal@45: rep(/

/gi,""); bgneal@45: rep(/<\/p>/gi,"\n"); bgneal@45: rep(/ /gi," "); bgneal@45: rep(/"/gi,"\""); bgneal@45: rep(/</gi,"<"); bgneal@45: rep(/>/gi,">"); bgneal@45: rep(/&/gi,"&"); bgneal@45: bgneal@45: return s; bgneal@45: }, bgneal@45: bgneal@45: // BBCode -> HTML from PunBB dialect bgneal@45: _punbb_bbcode2html : function(s) { bgneal@45: s = tinymce.trim(s); bgneal@45: bgneal@45: function rep(re, str) { bgneal@45: s = s.replace(re, str); bgneal@45: }; bgneal@45: bgneal@45: // example: [b] to bgneal@45: rep(/\n/gi,"
"); bgneal@45: rep(/\[b\]/gi,""); bgneal@45: rep(/\[\/b\]/gi,""); bgneal@45: rep(/\[i\]/gi,""); bgneal@45: rep(/\[\/i\]/gi,""); bgneal@45: rep(/\[u\]/gi,""); bgneal@45: rep(/\[\/u\]/gi,""); bgneal@45: rep(/\[url=([^\]]+)\](.*?)\[\/url\]/gi,"$2"); bgneal@45: rep(/\[url\](.*?)\[\/url\]/gi,"$1"); bgneal@45: rep(/\[img\](.*?)\[\/img\]/gi,""); bgneal@45: rep(/\[color=(.*?)\](.*?)\[\/color\]/gi,"$2"); bgneal@45: rep(/\[code\](.*?)\[\/code\]/gi,"$1 "); bgneal@45: rep(/\[quote.*?\](.*?)\[\/quote\]/gi,"$1 "); bgneal@45: bgneal@45: return s; bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // Register plugin bgneal@45: tinymce.PluginManager.add('bbcode', tinymce.plugins.BBCodePlugin); bgneal@45: })();