META-INF.web.lib.editor.xheditor_plugins.ubb.js Maven / Gradle / Ivy
/*!
* WYSIWYG UBB Editor support for xhEditor
* @requires xhEditor
*
* @author Yanis.Wang
* @site http://xheditor.com/
* @licence LGPL(http://www.opensource.org/licenses/lgpl-license.php)
*
* @Version: 0.9.12 (build 120228)
*/
;function ubb2html(l){var h,j=String(l),n=new Array(),i=0;var m=["10px","13px","16px","18px","24px","32px","48px"];j=j.replace(/[<>&"]/g,function(a){return{"<":"<",">":">","&":"&",'"':"""}[a]});j=j.replace(/\r?\n/g,"
");j=j.replace(/\[code\s*(?:=\s*([^\]]+?))?\]([\s\S]*?)\[\/code\]/ig,function(b,c,a){i++;n[i]=b;return"[\tubbcodeplace_"+i+"\t]"});j=j.replace(/\[(\/?)(b|u|i|s|sup|sub)\]/ig,"<$1$2>");j=j.replace(/\[color\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]/ig,'');j=j.replace(/\[font\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]/ig,'');j=j.replace(/\[\/(color|font)\]/ig,"");j=j.replace(/\[size\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]/ig,function(a,b){if(b.match(/^\d+$/)){b=m[b-1]}return''});j=j.replace(/\[back\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]/ig,'');j=j.replace(/\[\/(size|back)\]/ig,"");for(h=0;h<3;h++){j=j.replace(/\[align\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\](((?!\[align(?:\s+[^\]]+)?\])[\s\S])*?)\[\/align\]/ig,'$2
')}j=j.replace(/\[img\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*?)?\s*\[\/img\]/ig,'');j=j.replace(/\[img\s*=([^,\]]*)(?:\s*,\s*(\d*%?)\s*,\s*(\d*%?)\s*)?(?:,?\s*(\w+))?\s*\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*)?\s*\[\/img\]/ig,function(e,b,g,c,d,p){var a='";return a});j=j.replace(/\[emot\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\/\]/ig,'');j=j.replace(/\[url\]\s*(((?!")[\s\S])*?)(?:"[\s\S]*?)?\s*\[\/url\]/ig,'$1');j=j.replace(/\[url\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]\s*([\s\S]*?)\s*\[\/url\]/ig,'$2');j=j.replace(/\[email\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*?)?\s*\[\/email\]/ig,'$1');j=j.replace(/\[email\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]\s*([\s\S]+?)\s*\[\/email\]/ig,'$2');j=j.replace(/\[quote\]/ig,"");j=j.replace(/\[\/quote\]/ig,"
");j=j.replace(/\[flash\s*(?:=\s*(\d+)\s*,\s*(\d+)\s*)?\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*?)?\s*\[\/flash\]/ig,function(a,d,b,c){if(!d){d=480}if(!b){b=400}return''});j=j.replace(/\[media\s*(?:=\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d+)\s*)?)?\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*?)?\s*\[\/media\]/ig,function(b,e,c,a,d){if(!e){e=480}if(!c){c=400}return''});j=j.replace(/\[table\s*(?:=\s*(\d{1,4}%?)\s*(?:,\s*([^\]"]+)(?:"[^\]]*?)?)?)?\s*\]/ig,function(b,c,d){var a=""});j=j.replace(/\[tr\s*(?:=\s*([^\]"]+?)(?:"[^\]]*?)?)?\s*\]/ig,function(a,b){return""});j=j.replace(/\[td\s*(?:=\s*(\d{1,2})\s*,\s*(\d{1,2})\s*(?:,\s*(\d{1,4}%?))?)?\s*\]/ig,function(b,c,a,d){return"1?' colspan="'+c+'"':"")+(a>1?' rowspan="'+a+'"':"")+(d?' width="'+d+'"':"")+">"});j=j.replace(/\[\/(table|tr|td)\]/ig,"$1>");j=j.replace(/\[\*\]((?:(?!\[\*\]|\[\/list\]|\[list\s*(?:=[^\]]+)?\])[\s\S])+)/ig,"$1 ");j=j.replace(/\[list\s*(?:=\s*([^\]"]+?)(?:"[^\]]*?)?)?\s*\]/ig,function(b,c){var a=""});j=j.replace(/\[\/list\]/ig,"
");j=j.replace(/\[hr\/\]/ig,"
");for(h=1;h<=i;h++){j=j.replace("[\tubbcodeplace_"+h+"\t]",n[h])}j=j.replace(/(^|<\/?\w+(?:\s+[^>]*?)?>)([^<$]+)/ig,function(b,c,a){return c+a.replace(/[\t ]/g,function(d){return{"\t":" "," ":" "}[d]})});function k(a){if(a!=null&&a!=""){return !isNaN(a)}else{return false}}return j}function html2ubb(o){var w=/\s+src\s*=\s*(["']?)\s*(.+?)\s*\1(\s|$)/i,q=/\s+width\s*=\s*(["']?)\s*(\d+(?:\.\d+)?%?)\s*\1(\s|$)/i,x=/\s+height\s*=\s*(["']?)\s*(\d+(?:\.\d+)?%?)\s*\1(\s|$)/i,r=/(?:background|background-color|bgcolor)\s*[:=]\s*(["']?)\s*((rgb\s*\(\s*\d{1,3}%?,\s*\d{1,3}%?\s*,\s*\d{1,3}%?\s*\))|(#[0-9a-f]{3,6})|([a-z]{1,20}))\s*\1/i;var v,t=String(o),p=new Array(),u=0;t=t.replace(/[ \t]*\r?\n[ \t]*/g,"");t=t.replace(/<(script|style)(\s+[^>]*?)?>[\s\S]*?<\/\1>/ig,"");t=t.replace(//ig,"");t=t.replace(/
]*)?\/?>/ig,"\r\n");t=t.replace(/\[code\s*(=\s*([^\]]+?))?\]([\s\S]*?)\[\/code\]/ig,function(c,a,b){u++;p[u]=c;return"[\tubbcodeplace_"+u+"\t]"});t=t.replace(/<(\/?)(b|u|i|s)(\s+[^>]*?)?>/ig,"[$1$2]");t=t.replace(/<(\/?)strong(\s+[^>]*?)?>/ig,"[$1b]");t=t.replace(/<(\/?)em(\s+[^>]*?)?>/ig,"[$1i]");t=t.replace(/<(\/?)(strike|del)(\s+[^>]*?)?>/ig,"[$1s]");t=t.replace(/<(\/?)(sup|sub)(\s+[^>]*?)?>/ig,"[$1$2]");function s(c,a,d,b){if(!d){return b}var e=[],g=[];var f;f=d.match(/ face\s*=\s*"\s*([^"]+)\s*"/i);if(f){e.push("[font="+f[1]+"]");g.push("[/font]")}f=d.match(/ size\s*=\s*"\s*(\d+)\s*"/i);if(f){e.push("[size="+f[1]+"]");g.push("[/size]")}f=d.match(/ color\s*=\s*"\s*([^"]+)\s*"/i);if(f){e.push("[color="+i(f[1])+"]");g.push("[/color]")}return e.join("")+b+g.join("")}t=t.replace(/<(font)(\s+[^>]*?)?>(((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S])*?<\/\1>)*?<\/\1>)*?)<\/\1>/ig,s);t=t.replace(/<(font)(\s+[^>]*?)?>(((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S])*?<\/\1>)*?)<\/\1>/ig,s);t=t.replace(/<(font)(\s+[^>]*?)?>(((?!<\1(\s+[^>]*?)?>)[\s\S])*?)<\/\1>/ig,s);for(v=0;v<3;v++){t=t.replace(/<(span)(?:\s+[^>]*?)?\s+style\s*=\s*"((?:[^"]*?;)*\s*(?:font-family|font-size|color|background|background-color)\s*:[^"]*)"(?: [^>]+)?>(((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S])*?<\/\1>)*?<\/\1>)*?)<\/\1>/ig,function(j,g,f,a){var l=f.match(/(?:^|;)\s*font-family\s*:\s*([^;]+)/i),h=f.match(/(?:^|;)\s*font-size\s*:\s*([^;]+)/i),d=f.match(/(?:^|;)\s*color\s*:\s*([^;]+)/i),c=f.match(/(?:^|;)\s*(?:background|background-color)\s*:\s*([^;]+)/i),k=a;var e=[],b=[];if(l){e.push("[font="+l[1]+"]");b.push("[/font]")}if(h){e.push("[size="+h[1]+"]");b.push("[/size]")}if(d){e.push("[color="+i(d[1])+"]");b.push("[/color]")}if(c){e.push("[back="+i(c[1])+"]");b.push("[/back]")}return e.join("")+k+b.join("")})}function i(b){var a;if(a=b.match(/\s*rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/i)){b=(a[1]*65536+a[2]*256+a[3]*1).toString(16);while(b.length<6){b="0"+b}b="#"+b}b=b.replace(/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i,"#$1$1$2$2$3$3");return b}for(v=0;v<3;v++){t=t.replace(/<(div|p)(?:\s+[^>]*?)?[\s"';]\s*(?:text-)?align\s*[=:]\s*(["']?)\s*(left|center|right)\s*\2[^>]*>(((?!<\1(\s+[^>]*?)?>)[\s\S])+?)<\/\1>/ig,"[align=$3]$4[/align]")}for(v=0;v<3;v++){t=t.replace(/<(center)(?:\s+[^>]*?)?>(((?!<\1(\s+[^>]*?)?>)[\s\S])*?)<\/\1>/ig,"[align=center]$2[/align]")}for(v=0;v<3;v++){t=t.replace(/<(p|div)(?:\s+[^>]*?)?\s+style\s*=\s*"(?:[^;"]*;)*\s*text-align\s*:([^;"]*)[^"]*"(?: [^>]+)?>(((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S])*?<\/\1>)*?<\/\1>)*?)<\/\1>/ig,function(d,a,b,c){return"[align="+b+"]"+c+"[/align]"})}t=t.replace(/]*?)?\s+href=(["'])\s*(.+?)\s*\1[^>]*>\s*([\s\S]*?)\s*<\/a>/ig,function(e,d,f,b){if(!(f&&b)){return""}var a="url",c;if(f.match(/^mailto:/i)){a="email";f=f.replace(/mailto:(.+?)/i,"$1")}c="["+a;if(f!=b){c+="="+f}return c+"]"+b+"[/"+a+"]"});t=t.replace(/]*?)\/?>/ig,function(g,k){var h=k.match(/\s+emot\s*=\s*(["']?)\s*(.+?)\s*\1(\s|$)/i);if(h){return"[emot="+h[2]+"/]"}var e=k.match(w),c=k.match(/\s+alt\s*=\s*(["']?)\s*(.*?)\s*\1(\s|$)/i),f=k.match(q),b=k.match(x),a=k.match(/\s+align\s*=\s*(["']?)\s*(\w+)\s*\1(\s|$)/i),j="[img",d="";if(!e){return""}d+=c[2];if(f||b){d+=","+(f?f[2]:"")+","+(b?b[2]:"")}if(a){d+=","+a[2]}if(d){j+="="+d}j+="]"+e[2]+"[/img]";return j});t=t.replace(/]*?)?>/ig,"[quote]");t=t.replace(/<\/blockquote>/ig,"[/quote]");t=t.replace(/