/** * editor_plugin_src.js * * Copyright 2009, Moxiecode Systems AB * Released under LGPL License. * * License: http://tinymce.moxiecode.com/license * Contributing: http://tinymce.moxiecode.com/contributing */ /* Macgirvin Aug-2010 changed from punbb to dfrn dialect */ (function() { tinymce.create('tinymce.plugins.BBCodePlugin', { init : function(ed, url) { var t = this, dialect = ed.getParam('bbcode_dialect', 'dfrn').toLowerCase(); ed.onBeforeSetContent.add(function(ed, o) { o.content = t['_' + dialect + '_bbcode2html'](o.content); }); ed.onPostProcess.add(function(ed, o) { if (o.set) o.content = t['_' + dialect + '_bbcode2html'](o.content); if (o.get) o.content = t['_' + dialect + '_html2bbcode'](o.content); }); }, getInfo : function() { return { longname : 'BBCode Plugin', author : 'Moxiecode Systems AB', authorurl : 'http://tinymce.moxiecode.com', infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/bbcode', version : tinymce.majorVersion + "." + tinymce.minorVersion }; }, // Private methods // HTML -> BBCode in DFRN dialect _dfrn_html2bbcode : function(s) { s = tinymce.trim(s); function rep(re, str) { //modify code to keep stuff intact within [code][/code] blocks //Waitman Gobble NO WARRANTY var o = new Array(); var x = s.split("[code]"); var i = 0; var si = ""; si = x.shift(); si = si.replace(re,str); o.push(si); for (i = 0; i < x.length; i++) { var no = new Array(); var j = x.shift(); var g = j.split("[/code]"); no.push(g.shift()); si = g.shift(); si = si.replace(re,str); no.push(si); o.push(no.join("[/code]")); } s = o.join("[code]"); }; /* oembed */ function _h2b_cb(match) { function s_h2b(data) { match = data; } $.ajax({ type:"POST", url: 'oembed/h2b', data: {text: match}, async: false, success: s_h2b, dataType: 'html' }); return match; } if (s.indexOf('class="oembed')>=0){ //alert("request oembed html2bbcode"); s = _h2b_cb(s); } /* /oembed */ // example: to [b] rep(/(.*?)<\/a>/gi,"[bookmark=$1]$2[/bookmark]"); rep(/(.*?)<\/a>/gi,"[url=$1]$2[/url]"); rep(/(.*?)<\/span>/gi,"[size=$1]$2[/size]"); rep(/(.*?)<\/span>/gi,"[color=$1]$2[/color]"); rep(/(.*?)<\/font>/gi,"$1"); rep(//gi,"[img=$1x$2]$3[/img]"); rep(//gi,"[img=$2x$1]$3[/img]"); rep(//gi,"[img=$3x$2]$1[/img]"); rep(//gi,"[img=$2x$3]$1[/img]"); rep(//gi,"[img]$1[/img]"); rep(/