annotate static/js/tiny_mce/plugins/bbcode/editor_plugin_src.js @ 1057:afb6fbd0dc45

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