annotate media/js/tiny_mce/plugins/bbcode/editor_plugin_src.js @ 45:a5b4c5ce0658

Breaking down and controlling all media files, including javascript libraries.
author Brian Neal <bgneal@gmail.com>
date Fri, 19 Jun 2009 03:16:03 +0000
parents
children 149c3567fec1
rev   line source
bgneal@45 1 /**
bgneal@45 2 * $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $
bgneal@45 3 *
bgneal@45 4 * @author Moxiecode
bgneal@45 5 * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
bgneal@45 6 */
bgneal@45 7
bgneal@45 8 (function() {
bgneal@45 9 tinymce.create('tinymce.plugins.BBCodePlugin', {
bgneal@45 10 init : function(ed, url) {
bgneal@45 11 var t = this, dialect = ed.getParam('bbcode_dialect', 'punbb').toLowerCase();
bgneal@45 12
bgneal@45 13 ed.onBeforeSetContent.add(function(ed, o) {
bgneal@45 14 o.content = t['_' + dialect + '_bbcode2html'](o.content);
bgneal@45 15 });
bgneal@45 16
bgneal@45 17 ed.onPostProcess.add(function(ed, o) {
bgneal@45 18 if (o.set)
bgneal@45 19 o.content = t['_' + dialect + '_bbcode2html'](o.content);
bgneal@45 20
bgneal@45 21 if (o.get)
bgneal@45 22 o.content = t['_' + dialect + '_html2bbcode'](o.content);
bgneal@45 23 });
bgneal@45 24 },
bgneal@45 25
bgneal@45 26 getInfo : function() {
bgneal@45 27 return {
bgneal@45 28 longname : 'BBCode Plugin',
bgneal@45 29 author : 'Moxiecode Systems AB',
bgneal@45 30 authorurl : 'http://tinymce.moxiecode.com',
bgneal@45 31 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/bbcode',
bgneal@45 32 version : tinymce.majorVersion + "." + tinymce.minorVersion
bgneal@45 33 };
bgneal@45 34 },
bgneal@45 35
bgneal@45 36 // Private methods
bgneal@45 37
bgneal@45 38 // HTML -> BBCode in PunBB dialect
bgneal@45 39 _punbb_html2bbcode : function(s) {
bgneal@45 40 s = tinymce.trim(s);
bgneal@45 41
bgneal@45 42 function rep(re, str) {
bgneal@45 43 s = s.replace(re, str);
bgneal@45 44 };
bgneal@45 45
bgneal@45 46 // example: <strong> to [b]
bgneal@45 47 rep(/<a.*?href=\"(.*?)\".*?>(.*?)<\/a>/gi,"[url=$1]$2[/url]");
bgneal@45 48 rep(/<font.*?color=\"(.*?)\".*?class=\"codeStyle\".*?>(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]");
bgneal@45 49 rep(/<font.*?color=\"(.*?)\".*?class=\"quoteStyle\".*?>(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]");
bgneal@45 50 rep(/<font.*?class=\"codeStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]");
bgneal@45 51 rep(/<font.*?class=\"quoteStyle\".*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[quote][color=$1]$2[/color][/quote]");
bgneal@45 52 rep(/<span style=\"color: ?(.*?);\">(.*?)<\/span>/gi,"[color=$1]$2[/color]");
bgneal@45 53 rep(/<font.*?color=\"(.*?)\".*?>(.*?)<\/font>/gi,"[color=$1]$2[/color]");
bgneal@45 54 rep(/<span style=\"font-size:(.*?);\">(.*?)<\/span>/gi,"[size=$1]$2[/size]");
bgneal@45 55 rep(/<font>(.*?)<\/font>/gi,"$1");
bgneal@45 56 rep(/<img.*?src=\"(.*?)\".*?\/>/gi,"[img]$1[/img]");
bgneal@45 57 rep(/<span class=\"codeStyle\">(.*?)<\/span>/gi,"[code]$1[/code]");
bgneal@45 58 rep(/<span class=\"quoteStyle\">(.*?)<\/span>/gi,"[quote]$1[/quote]");
bgneal@45 59 rep(/<strong class=\"codeStyle\">(.*?)<\/strong>/gi,"[code][b]$1[/b][/code]");
bgneal@45 60 rep(/<strong class=\"quoteStyle\">(.*?)<\/strong>/gi,"[quote][b]$1[/b][/quote]");
bgneal@45 61 rep(/<em class=\"codeStyle\">(.*?)<\/em>/gi,"[code][i]$1[/i][/code]");
bgneal@45 62 rep(/<em class=\"quoteStyle\">(.*?)<\/em>/gi,"[quote][i]$1[/i][/quote]");
bgneal@45 63 rep(/<u class=\"codeStyle\">(.*?)<\/u>/gi,"[code][u]$1[/u][/code]");
bgneal@45 64 rep(/<u class=\"quoteStyle\">(.*?)<\/u>/gi,"[quote][u]$1[/u][/quote]");
bgneal@45 65 rep(/<\/(strong|b)>/gi,"[/b]");
bgneal@45 66 rep(/<(strong|b)>/gi,"[b]");
bgneal@45 67 rep(/<\/(em|i)>/gi,"[/i]");
bgneal@45 68 rep(/<(em|i)>/gi,"[i]");
bgneal@45 69 rep(/<\/u>/gi,"[/u]");
bgneal@45 70 rep(/<span style=\"text-decoration: ?underline;\">(.*?)<\/span>/gi,"[u]$1[/u]");
bgneal@45 71 rep(/<u>/gi,"[u]");
bgneal@45 72 rep(/<blockquote[^>]*>/gi,"[quote]");
bgneal@45 73 rep(/<\/blockquote>/gi,"[/quote]");
bgneal@45 74 rep(/<br \/>/gi,"\n");
bgneal@45 75 rep(/<br\/>/gi,"\n");
bgneal@45 76 rep(/<br>/gi,"\n");
bgneal@45 77 rep(/<p>/gi,"");
bgneal@45 78 rep(/<\/p>/gi,"\n");
bgneal@45 79 rep(/&nbsp;/gi," ");
bgneal@45 80 rep(/&quot;/gi,"\"");
bgneal@45 81 rep(/&lt;/gi,"<");
bgneal@45 82 rep(/&gt;/gi,">");
bgneal@45 83 rep(/&amp;/gi,"&");
bgneal@45 84
bgneal@45 85 return s;
bgneal@45 86 },
bgneal@45 87
bgneal@45 88 // BBCode -> HTML from PunBB dialect
bgneal@45 89 _punbb_bbcode2html : function(s) {
bgneal@45 90 s = tinymce.trim(s);
bgneal@45 91
bgneal@45 92 function rep(re, str) {
bgneal@45 93 s = s.replace(re, str);
bgneal@45 94 };
bgneal@45 95
bgneal@45 96 // example: [b] to <strong>
bgneal@45 97 rep(/\n/gi,"<br />");
bgneal@45 98 rep(/\[b\]/gi,"<strong>");
bgneal@45 99 rep(/\[\/b\]/gi,"</strong>");
bgneal@45 100 rep(/\[i\]/gi,"<em>");
bgneal@45 101 rep(/\[\/i\]/gi,"</em>");
bgneal@45 102 rep(/\[u\]/gi,"<u>");
bgneal@45 103 rep(/\[\/u\]/gi,"</u>");
bgneal@45 104 rep(/\[url=([^\]]+)\](.*?)\[\/url\]/gi,"<a href=\"$1\">$2</a>");
bgneal@45 105 rep(/\[url\](.*?)\[\/url\]/gi,"<a href=\"$1\">$1</a>");
bgneal@45 106 rep(/\[img\](.*?)\[\/img\]/gi,"<img src=\"$1\" />");
bgneal@45 107 rep(/\[color=(.*?)\](.*?)\[\/color\]/gi,"<font color=\"$1\">$2</font>");
bgneal@45 108 rep(/\[code\](.*?)\[\/code\]/gi,"<span class=\"codeStyle\">$1</span>&nbsp;");
bgneal@45 109 rep(/\[quote.*?\](.*?)\[\/quote\]/gi,"<span class=\"quoteStyle\">$1</span>&nbsp;");
bgneal@45 110
bgneal@45 111 return s;
bgneal@45 112 }
bgneal@45 113 });
bgneal@45 114
bgneal@45 115 // Register plugin
bgneal@45 116 tinymce.PluginManager.add('bbcode', tinymce.plugins.BBCodePlugin);
bgneal@45 117 })();