/** * $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $ * * @id Moxiecode * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved. */ // URL : http://support.utiliweb.fr/handlers/tiny_mce/plugins/bbcodev2/editor_plugin_src.js (function() { tinymce.create('tinymce.plugins.BBCodev2Plugin', { init : function(ed, url) { var t = this, dialect = ed.getParam('bbcode_dialect', 'punbb').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); }); function replaceContent(component, tag) { var cm = ed.controlManager.get(component); if (ed.selection.getContent() !== '') { ed.selection.setContent('[' + tag + ']' + ed.selection.getContent() + '[/' + tag + ']'); } else if (cm.isActive()) { ed.selection.setContent('[/' + tag + ']'); cm.setActive(false); } else { ed.selection.setContent('[' + tag + ']'); cm.setActive(true); } } ed.addCommand('preCmd', function () { replaceContent('pre', 'code'); }); ed.addCommand('ytCmd', function () { replaceContent('yt', 'yt'); }); ed.addCommand('mapCmd', function () { replaceContent('map', 'map'); }); ed.addCommand('spoilCmd', function () { replaceContent('spoil', 'spoiler'); }); ed.addCommand('linkCmd', function () { var entry = prompt(); if (entry) ed.selection.setContent('' + ed.selection.getContent() + ''); }); ed.addCommand('imageCmd', function () { var entry = prompt(); if (entry) ed.selection.setContent(''); }); ed.onInit.add(function (ed) { var cm = ed.controlManager; if (cm.get('pre')) cm.get('pre').settings.cmd = 'preCmd'; if (cm.get('yt')) cm.get('yt').settings.cmd = 'ytCmd'; if (cm.get('map')) cm.get('map').settings.cmd = 'mapCmd'; if (cm.get('link')) cm.get('link').settings.cmd = 'linkCmd'; if (cm.get('image')) cm.get('image').settings.cmd = 'imageCmd'; if (cm.get('spoil')) cm.get('spoil').settings.cmd = 'spoilCmd'; }); }, getInfo : function() { return { longname : 'BBCodev2 Plugin', id : 'Moxiecode Systems AB', idurl : 'http://tinymce.moxiecode.com', infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/bbcodev2', version : tinymce.majorVersion + "." + tinymce.minorVersion }; }, // Private methods // HTML -> BBCode in PunBB dialect _punbb_html2bbcode : function(s) { s = tinymce.trim(s); function rep(re, str) { s = s.replace(re, str); }; // example: to [b] rep(/

(.*?)<\/p>/gi,"[code]$1[/code]"); rep(/(.*?)<\/strong>/gi,"[code]$1[/code]"); rep(/(.*?)<\/em>/gi,"[code]$1[/code]"); rep(/(.*?)<\/a>/gi,"[link=$1]$2[/link]"); rep(/(.*?)<\/a>/gi,"[url=$1]$2[/url]"); rep(/(.*?)<\/a>/gi,"[url=$1]$2[/url]"); rep(/(.*?)<\/a>/gi,"[link=$1]$2[/link]"); rep(/(.*?)<\/a>/gi,"[url=$1]$2[/url]"); rep(/(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]"); rep(/(.*?)<\/font>/gi,"[blockquote][color=$1]$2[/color][/blockquote]"); rep(/(.*?)<\/font>/gi,"[code][color=$1]$2[/color][/code]"); rep(/(.*?)<\/font>/gi,"[blockquote][color=$1]$2[/color][/blockquote]"); rep(/(.*?)<\/span>/gi,"[color=$1]$2[/color]"); rep(/(.*?)<\/font>/gi,"[color=$1]$2[/color]"); rep(/(.*?)<\/span>/gi,"[size=$1]$2[/size]"); rep(/(.*?)<\/font>/gi,"$1"); rep(//gi,"[img]$1[/img]"); rep(//gi,"[img=miniature]$1[/img]"); rep(//gi,"[img]$1[/img]"); rep(/(.*?)<\/span>/gi,"[code]$1[/code]"); rep(/(.*?)<\/span>/gi,"[blockquote]$1[/blockquote]"); rep(/(.*?)<\/span>/gi,"[quote=$1]$2[/quote]"); rep(/(.*?)<\/span>/gi,"[quote=$1]$2[/quote]"); rep(/(.*?)<\/span>/gi,"[hide]$1[/hide]"); rep(/

(.*?)<\/p>/gi,"[blockquote]$1[/blockquote]"); rep(/

(.*?)<\/p>/gi,"[hide]$1[/hide]"); rep(/

(.*?)<\/p>/gi,"[quote=$1]$2[/quote]"); rep(/(.*?)<\/span>/gi,"[blockquote]$1[/blockquote]"); rep(/(.*?)<\/strong>/gi,"[quote][b]$1[/b][/quote]"); rep(/(.*?)<\/em>/gi,"[quote][i]$1[/i][/quote]"); rep(/(.*?)<\/u>/gi,"[code][u]$1[/u][/code]"); rep(/(.*?)<\/code>/gi,"[code]$1[/code]"); rep(/(.*?)<\/u>/gi,"[quote][u]$1[/u][/quote]"); rep(/<\/(strong|b)>/gi,"[/b]"); rep(/<(strong|b)>/gi,"[b]"); rep(/<\/(em|i)>/gi,"[/i]"); rep(/<(em|i)>/gi,"[i]"); rep(/<\/u>/gi,"[/u]"); rep(/

.*?<\/div>/gi,"[video=youtube]$1[/video]"); rep(/
.*?<\/div>/gi,"[video=dailymotion]$1[/video]"); rep(/
.*?<\/div>/gi,"[video=veoh]$1[/video]"); rep(/
.*?<\/div>/gi,"[video=vimeo]$1[/video]"); rep(/
.*?<\/div>/gi,"[video=jiwa]$1[/video]"); rep(/
.*?<\/div>/gi,"[deezer]$1[/deezer]"); rep(/
.*?<\/div>/gi,"[picasa]$1[/picasa]"); rep(/(.*?)<\/span>/gi,"[no]$1[/no]"); rep(/(.*?)<\/span>/gi,"[u]$1[/u]"); rep(/

<\/p>/gi,"\n"); rep(/

<\/p>/gi,"\n"); rep(/

<\/p>/gi,"\n"); rep(/

<\/p>/gi,"\n"); rep(/

(.*?)<\/p>/gi,"[$1]$2[/$1]"); rep(//gi,"[u]"); rep(/]*>/gi,"[quote]"); rep(/<\/blockquote>/gi,"[/quote]"); //listes rep(/]*>(.*?)<\/ul>/gi,"[list]$1[/list]"); rep(/

    (.*?)<\/ol>/gi,"[list=lower-alpha]$1[/list]"); rep(/]*>(.*?)<\/ol>/gi,"[list=decimal]$1[/list]"); rep(/
  1. (.*?)<\/li>/gi,"[*]$1\n"); //tableaux rep(/(.*?)<\/tbody><\/table>/gi,"[tableau]$1[/tableau]"); rep(/(.*?)<\/table>/gi,"[tableau]$1[/tableau]"); rep(//gi,"[ligne]"); rep(/<\/td><\/tr>/gi,"[/ligne]"); rep(/<\/td>/gi,"[|]"); rep(/

    /gi,""); rep(//gi,""); rep(/<\/p>/gi,"
    "); rep(/
    /gi,"\n"); rep(//gi,"\n"); rep(/(.*?)<\/span>/gi,"[color=$1]$2[/color]"); rep(/(.*?)<\/span>/gi,"[color=$1]$2[/color]"); rep(/(.*?)<\/span>/gi,"[color=$1]$2[/color]"); rep(/(.*?)<\/font>/gi,"[color=$1]$2[/color]"); rep(/(.*?)<\/font>/gi,"[color=$1]$2[/color]"); rep(/(.*?)<\/font>/gi,"[color=$1]$2[/color]"); rep(/(.*?)<\/span>/gi,"[size=$1]$2[\/size]"); rep(/(.*?)<\/span>/gi,"[size=$1]$2[\/size]"); rep(/(.*?)<\/span>/gi,"[size=$1]$2[\/size]"); rep(/<\!--.*?-->/gi,""); rep(/<\/span>/gi,""); rep(//gi,""); rep(//gi,""); rep(/<\/div>/gi,""); rep(//gi,""); rep(/<\/tr>/gi,""); rep(/<\/table>/gi,""); rep(//gi,""); rep(/<\/tbody>/gi,""); rep(//gi,""); rep(//gi,""); rep(/<\/td>/gi,""); rep(/ /gi," "); rep(/"/gi,"\""); rep(/</gi,"<"); rep(/>/gi,">"); rep(/&/gi,"&"); return s; }, // BBCode -> HTML from PunBB dialect _punbb_bbcode2html : function(s) { s = tinymce.trim(s); function rep(re, str) { s = s.replace(re, str); }; // example: [b] to rep(/\[code\](.*?)\[\/code\]/gi,"

    $1

    "); rep(/\n\n/g, "

    <\/p>"); rep(/\n/g, "
    "); rep(/\[b\]/gi,""); rep(/\[\/b\]/gi,""); rep(/\[i\]/gi,""); rep(/\[\/i\]/gi,""); rep(/\[u\]/gi,""); rep(/\[\/u\]/gi,""); rep(/\[url=([^\]]+)\](.*?)\[\/url\]/gi,"$2"); rep(/\[url\](.*?)\[\/url\]/gi,"
    $1"); rep(/\[link=([^\]]+)\](.*?)\[\/link\]/gi,"$2"); rep(/\[link\](.*?)\[\/link\]/gi,"$1"); rep(/\[img\](.*?)\[\/img\]/gi,""); rep(/\[img=miniature\](.*?)\[\/img\]/gi,""); rep(/\[color=(.*?)\]/gi,""); rep(/\[\/color\]/gi,""); rep(/\[hide\](.*?)\[\/hide\]/gi,"

    $1

    "); rep(/\[blockquote.*?\](.*?)\[\/blockquote\]/gi,"

    $1

    "); rep(/\[quote=(.*?)\](.*?)\[\/quote\]/gi,"

    $2

    "); rep(/\[quote.*?=(.*?)\](.*?)\[\/quote.*?\]/gi,"

    $2

    "); rep(/\[size=(.*?)\]/gi,""); rep(/\[\/size\]/gi,""); rep(/\[no](.*?)\[\/no\]/gi,"$1"); rep(/\[center](.*?)\[\/center\]/gi,"

    $1

    "); rep(/\[left](.*?)\[\/left\]/gi,"

    $1

    "); rep(/\[right](.*?)\[\/right\]/gi,"

    $1

    "); rep(/\[justify](.*?)\[\/justify\]/gi,"

    $1

    "); rep(/\[video=youtube\](.*?)\[\/video\]/gi,"


    $1<\/div>"); rep(/\[video=dailymotion\](.*?)\[\/video\]/gi,"


    $1<\/div>"); rep(/\[video=veoh\](.*?)\[\/video\]/gi,"


    $1<\/div>"); rep(/\[video=vimeo\](.*?)\[\/video\]/gi,"


    $1<\/div>"); rep(/\[video=jiwa\](.*?)\[\/video\]/gi,"


    $1<\/div>"); rep(/\[deezer\](.*?)\[\/deezer\]/gi,"


    $1<\/div>"); rep(/\[picasa\](.*?)\[\/picasa\]/gi,"


    <\/div>"); //tableaux rep(/\[\|\]/gi,""); rep(/\[ligne](.*?)\[\/ligne\]/gi,"$1"); rep(/\[tableau](.*?)\[\/tableau\]/gi,"$1
    "); // lists rep(/\[list\]\[\*\](.*?)\[\/list\]/gi, "
    • $1
    "); rep(/\[list=decimal\]\[\*\](.*?)\[\/list\]/gi, "
    1. $1
    "); rep(/\[list=lower-alpha\]\[\*\](.*?)\[\/list\]/gi, "
    1. $1
    "); rep(/\[list\](.*?)\[\/list\]/gi, "
    • $1
    "); rep(/\[list=decimal\](.*?)\[\/list\]/gi, "
    1. $1
    "); rep(/\[list=lower-alpha\](.*?)\[\/list\]/gi, "
    1. $1
    "); rep(/\[\*\]/gi, "
  2. "); // fix empty li's rep(/

  3. <\/li>/g, ""); rep(//g, ""); return s; } }); // Register plugin tinymce.PluginManager.add('bbcodev2', tinymce.plugins.BBCodev2Plugin); })();