ubb代码大家都知道,asp vbscript,php javascript都很多。
用java技术实现的ubb编辑器道是很少,其实也不是什么困难的事情,说到底是一个replace的问题。下面看我如何实现:
1,新建一个用于解析ubb代码的类:ubbtest.java(不用多说什么,自己看代码).
- import java.util.regex. * ; // 导入正则表达式包中的类
- /**
- * 使网页支持ubbcode.
- * @author tom.dai
- * @version 1.0
- */
- public final class Ubbcode {
- private static final String ImagePath = "Images/" ; // 定义图片路径
- private static final String emotImagePath = "images/emot/" ;
- /**
- * @description 转换代码,使之支持ubbcode.
- * @param strContent 转换前的代码.
- * @return result 转换后的内容.
- */
- public static String UBBCode(String strContent) { //
- strContent = dvHTMLEncode(strContent);
- strContent = FilterJS(strContent);
- String re;
- // re.IgnoreCase =true
- // re.Global=True
- Pattern pattern = null ; //
- Matcher matcher = null ;
- // 转换IMG
- //re = "//[IMG//](http|https|ftp)://(.[^//[]*)//[///IMG//]" ;
- //re = "//[img//](.[^//[]*)//[///img//]" ;
- re ="//[img//](http|https|ftp)://(.[^//[]*)//[///img//]";
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(strContent);
- strContent = matcher.replaceAll( "<a οnfοcus=this.blur() href=/"$1://$2/" target=_blank><IMG SRC=/"$1://$2/" border=0 alt=按此在新窗口浏览图片 οnlοad=/"javascript:if(this.width> screen.width-333)this.width=screen.width-333/"></a>");
- re ="//[img=*([0-9]*),*([0-9]*)//](http|https|ftp)://(.[^//[]*)//[///img//]";
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(strContent);
- strContent = matcher.replaceAll( "<a οnfοcus=this.blur() href=/"$3://$4/" target=_blank><IMG SRC=/"$3://$4/" border=0 alt=按此在新窗口浏览图片 width =/"$1/" height=/"$2/" ></a>");
- /*
- // 转换UPLOAD
- re = "//[upload=(gif|jpg|jpeg|bmp|png)//](.[^//[]*)(gif|jpg|jpeg|bmp|png)//[///upload] " ;
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(strContent);
- strContent = matcher.replaceAll( "<br><IMG SRC=/"" + ImagePath + " $1.gif /" border=0>此主题相关图片如下:<br><A HREF=/" $2 $1 /" TARGET=_blank> <IMG SRC=/" $2 $1 /" border=0 alt=按此在新窗口浏览图片 οnlοad=/" javascript: if( this.width > screen.width-333) this .width = screen.width - 333 /" ></A>" );
- re = "//[upload=(.[^//[]*)//](.[^//[]*)//[///upload] " ;
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(strContent);
- strContent = matcher.replaceAll( "<br><img SRC=/"" + ImagePath +
- "$1.gif/" border = 0 > < a href = /"$2/" > 点击浏览该文件 </a>");
- */
- // 转换DIR
- re = "//[dir=*([0-9]*),*([0-9]*)//](.[^//[]*)//[///dir]" ;
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(strContent);
- strContent = matcher.replaceAll("<object classid=clsid:166B1BCA-3F9C-11CF-8075-444553540000 codebase=http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=7,0,2,0 width=$1 height=$2><param name=src value=$3><embed src=$3 pluginspage=http://www.macromedia.com/shockwave/download/ width=$1 height=$2></embed></object>");
- // 转换QT
- re = "//[qt=*([0-9]*),*([0-9]*)//](.[^//[]*)//[///qt]" ;
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(strContent);
- strContent = matcher.replaceAll("<embed src=$3 width=$1 height=$2 autoplay=true loop=false controller=true playeveryframe=false cache=false scale=TOFIT bgcolor=#000000 kioskmode=false targetcache=false pluginspage=http://www.apple.com/quicktime/>;");
- // 转换MP
- re = "//[mp=*([0-9]*),*([0-9]*)//](.[^//[]*)//[///mp]" ;
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(strContent);
- strContent = matcher.replaceAll("<object align=middle classid=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95 class=OBJECT id=MediaPlayer width=$1 height=$2 ><param name=ShowStatusBar value=-1><param name=Filename value=$3><embed type=application/x-oleobject codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701 flename=mp src=$3 width=$1 height=$2></embed></object>");
- // 转换RM
- re = "//[rm=*([0-9]*),*([0-9]*)//](.[^//[]*)//[///rm]" ;
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(strContent);
- strContent = matcher.replaceAll( "<OBJECT classid=clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA class=OBJECT id=RAOCX width=$1 height=$2><PARAM NAME=SRC VALUE=$3><PARAM NAME=CONSOLE VALUE=Clip1><PARAM NAME=CONTROLS VALUE=imagewindow><PARAM NAME=AUTOSTART VALUE=true></OBJECT><br><OBJECT classid=CLSID:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA height=32 id=video2 width=$1><PARAM NAME=SRC VALUE=$3><PARAM NAME=AUTOSTART VALUE=-1><PARAM NAME=CONTROLS VALUE=controlpanel><PARAM NAME=CONSOLE VALUE=Clip1></OBJECT>");
- // 转换FLASH
- re = "(//[flash//])(.[^//[]*)(//[///flash])" ;
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(strContent);
- strContent = matcher.replaceAll("<a href=/"$2/" TARGET=_blank><IMG SRC=/""+ImagePath+"bb_flash.gif/" border=0 alt=点击开新窗口欣赏该FLASH动画! height=16 width=16>[全屏欣赏]</a><br><OBJECT codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=500 height=400><PARAM NAME=movie VALUE=/"$2/" ><PARAM NAME=quality VALUE=high><embed src=/"$2/" quality=high pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width=300 height=300>$2</embed></OBJECT>");
- re = "(//[flash=*([0-9]*),*([0-9]*)//])(.[^//[]*)(//[///flash]) " ;
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(strContent);
- strContent = matcher.replaceAll("<a href=/"$4/" TARGET=_blank><IMG SRC=/" "+ImagePath+"bb_flash.gif/" border=0 alt=点击开新窗口欣赏该FLASH动画! height=16 width=16>[全屏欣赏]</a> <br><OBJECT codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=$2 height=$3><PARAM NAME=movie VALUE=/" $4 /" ><PARAM NAME=quality VALUE=high><embed src=/" $4 /" quality=high pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width=$2 height=$3>$4</embed></OBJECT>");
- //转换flv
- re = "(//[flv//])(.[^//[]*)(//[///flv])" ;
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(strContent);
- strContent = matcher.replaceAll("<embed src=/"http://www.blueidea.com/articleimg/2006/08/3995/vcastr.swf?vcastr_file=$2/" showMovieInfo=0 pluginspage=/"http://www.macromedia.com/go/getflashplayer/" type=/"application/x-shockwave-flash/" wmode=/"transparent/" quality=/"high/" width=/"458/" height=/"350/"></embed>");
- // 转换URL
- re = "(//[url//])(.[^//[]*)(//[///url])" ;
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(strContent);
- strContent = matcher.replaceAll( "<A HREF=/" $2 /" TARGET=_blank>$2</A>");
- re = "(//[url=(.[^//[]*)//])(.[^//[]*)(//[///url])";
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(strContent);
- strContent = matcher.replaceAll("<A href=/"$2/" TARGET=_blank>$3</A>" );
- // 转换EMAIL
- re = "(//[email//])(//S+//@.[^//[]*)(//[///email])" ;
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(strContent);
- strContent = matcher.replaceAll("<img align=absmiddle src=/""+ImagePath+"email1.gif/">< A HREF = /"mailto:$2/">$2</A>");
- re = "(//[email=(//S+//@.[^//[]*)//])(.[^//[]*)(//[///email])" ;
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(strContent);
- strContent = matcher.replaceAll( "<img align=absmiddle src=/""+ImagePath+"email1.gif/">< A HREF =/" mailto:$2/" TARGET =_blank >$3</A>" );
- /*
- // 自动识别网址
- re ="^((http|https|ftp|rtsp|mms):(//|)[A-Za-z0-9//./=//?%//-&_~`@':+!]+)" ;
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(strContent);
- strContent = matcher.replaceAll(
- "<img align=absmiddle src=pic/url.gif border=0><a target=_blank href=$1>$1</a>");
- re ="((http|https|ftp|rtsp|mms):(//|)[A-Za-z0-9//./=//?%//-&_~`@':+!]+)$" ;
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(strContent);
- strContent = matcher.replaceAll("<img align=absmiddle src=pic/url.gif border=0><a target=_blank href=$1>$1</a>");
- re = "([^>=/"])((http|https|ftp|rtsp|mms):(//|)[A-Za-z0-9//./=//?%//-&_~`@':+!]+)";
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(strContent);
- strContent = matcher.replaceAll( "$1<img align=absmiddle src=pic/url.gif border=0><a target=_blank href=$2>$2</a>" );
- // 自动识别www等开头的网址
- re = "([^(http://|http:)])((www|cn)[.](//w)+[.]{1,}(net|com|cn|org|cc)(((///[//~]*|//[//~]*)(//w)+)|[.](//w)+)*(((([?](//w)+){1}[=]*))*((//w)+){1}([//&](//w)+[//=](//w)+)*)*)" ;
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(strContent);
- strContent = matcher.replaceAll( "<img align=absmiddle src=pic/url.gif border=0><a target=_blank href=http://$2>$2</a>" );
- // 自动识别Email地址,如打开本功能在浏览内容很多的帖子会引起服务器停顿
- re = "([^(=)])((//w)+[@]{1}((//w)+[.]){1,3}(//w)+)" ;
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(strContent);
- strContent = matcher.replaceAll( "<img align=absmiddle src=pic/url.gif border=0><a target=_blank href=/" mailto:$2 /" >$2</a>" );
- */
- // 转换EM
- re = "//[em(.[^//[]*)//]" ;
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(strContent);
- strContent = matcher.replaceAll( "<img src=/"" + emotImagePath + "em$1.gif/" border = 0 align = middle >");
- // 转换HTML
- re = "//[html//](.[^//[]*)//[///html] " ;
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(strContent);
- strContent = matcher.replaceAll( "<table width='100%' border='0' cellspacing='0' cellpadding='6' class=tableborder1> <td><b>以下内容为程序代码:</b><br>$1</td>< /table>" );
- // 转换CODE
- re = "//[code//](.[^//[]*)//[///code]" ;
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(strContent);
- strContent = matcher.replaceAll( "<table width='100%' border='0' cellspacing='0' cellpadding='6' class=tableborder1> <td><b>以下内容为程序代码:</b><br>$1</td></table>" );
- // 转换COLOR
- re = "//[color=(.[^//[]*)//](.[^//[]*)//[///color]" ;
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(strContent);
- strContent = matcher.replaceAll( "<font color=$1>$2</font>" );
- // 转换font
- re = "//[font=(.[^//[]*)//](.[^//[]*)//[///font]" ;
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(strContent);
- strContent = matcher.replaceAll( "<font face=$1>$2</font>" );
- // 转换ALIGN
- re = "//[align=(center|left|right)//](.*)//[///align]" ;
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(strContent);
- strContent = matcher.replaceAll( "<div align=$1>$2</div>" );
- // 转换QUOTE
- re = "//[quote//](.*)//[///quote]" ;
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(strContent);
- strContent = matcher.replaceAll( " <table style=/" width: 80 % /" cellpadding=5 cellspacing=1 class=tableborder1><TR><TD class=tableborder1>$1</td></tr></table><br> " );
- // 转换FLY
- re = "//[fly//](.*)//[///fly]" ;
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(strContent);
- strContent = matcher.replaceAll(
- "<marquee width=90% behavior=alternate scrollamount=3>$1</marquee>" );
- // 转换MOVE
- re = "//[move//](.*)//[///move]" ;
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(strContent);
- strContent = matcher.replaceAll( " <MARQUEE scrollamount=3>$1</marquee>" );
- // 转换GLOW
- re = "//[glow=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)//](.[^//[]*)//[///glow]" ;
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(strContent);
- strContent = matcher.replaceAll(
- "<table width=$1 style=/" filter:glow(color = $2 , strength = $3 )/" >$4</table>" );
- // 转换SHADOW
- re ="//[shadow=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)//](.[^//[]*)//[///shadow]" ;
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(strContent);
- strContent = matcher.replaceAll("<table width=$1 style=/" filter:shadow(color = $2 , strength = $3 )/" >$4</table>");
- re ="//[i](.[^//[]*)//[///i]" ;
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(strContent);
- strContent = matcher.replaceAll( "<i>$1</i>" );
- re ="//[u](.[^//[]*)//[///u]" ;
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(strContent);
- strContent = matcher.replaceAll( "<u>$1</u>" );
- re = "//[b](.[^//[]*)//[///b]" ;
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(strContent);
- strContent = matcher.replaceAll( "<b>$1</b>" );
- re = "//[size=([1-7])//](.[^//[]*)//[///size]" ;
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(strContent);
- strContent = matcher.replaceAll( "<font size=$1>$2</font>" );
- /* re ="(//s)";
- matcher = pattern.matcher(strContent);
- strContent=matcher.replaceAll("<I>$1</I>"); */
- /* String[] searcharray=new String[]{"[/url]","[/email]","[/color]", "[/size]","[/font]", "[/align]", "[b]", "[/b]","[i]", "[/i]", "[u]", "[/u]", "[list]", "[list=1]","[list=a]","[list=A]", "[*]", "[/list]", "[indent]", "[/indent]","[code]","[/code]","[quote]","[/quote]","[table]","[tr]","[td]","[/tr]","[/td]","[/table]"};
- String[] replacearray=new String[]{"</a>","</a>","</font>", "</font>", "</font>", "</div>", "<b>", "</b>", "<i>","</i>", "<u>", "</u>", "<ul>", "<ol type=1>", "<ol type=a>","<ol type=A>", "<li>", "</ul></ol>", "<blockquote>", "</blockquote>","<div><textarea name=/"codes/" id=/"codes/" rows=/"12/" cols=/"65/">","</textarea><br/><input type=/"button/" value=/"运行代码/" οnclick=/"RunCode()/"> <input type=/"button/" value=/"复制代码/" οnclick=/"CopyCode()/"> <input type=/"button/" value=/"另存代码/" οnclick=/"SaveCode()/"> 提示:您可以先修改部分代码再运行</div>","<div style=/"background:#E2F2FF;width:90%;height:300px;border:1px solid #3CAAEC/">","</div>","<table>","<tr>","<td>","</tr>","</td>","</table>"};
- for(int i=0;i<searcharray.length;i++)
- strContent=replace(strContent,searcharray[i],replacearray[i]);
- */
- re = null ;
- return strContent;
- }
- /**
- * 过滤javascript代码.
- * @param v转换前的代码.
- * @return v转换后的内容.
- */
- public static String FilterJS(String v) {
- try{
- if ( ! v.equals( "null" ) && v != null ) {
- String t, re;
- re = "(javascript)" ;
- t = re.replace(v, "javascript" );
- re = " (jscript:)" ;
- t = re.replace(t, "jscript:" );
- re = " (js:) " ;
- t = re.replace(t, "js:" );
- re = " (value) " ;
- t = re.replace(t, "value" );
- re = " (about:)" ;
- t = re.replace(t, "about:" );
- re = " (file:)" ;
- t = re.replace(t, "file:" );
- re = "(document.cookie)" ;
- t = re.replace(t, "documents.cookie" );
- re = "(vbscript:)" ;
- t = re.replace(t, "vbscript:" );
- re = "(vbs:)" ;
- t = re.replace(t, "vbs:" );
- re = "(on(mouse|exit|error|click|key))" ;
- t = re.replace(t, "on$2" );
- re = "(&#)" ;
- t = re.replace(t, "&#" );
- re = null ;
- }}catch(Exception e)
- {
- e.printStackTrace();
- }
- return v;
- }
- /**
- * 替换一些特殊符号为html语法标记.
- * @param fString转换前的代码.
- * @return fString转换后的内容.
- */
- public static String dvHTMLEncode(String fString) {
- try{
- if ( ! fString.equals( "null" ) && fString != null ) {
- fString = replace(fString, ">" , ">" );
- fString = replace(fString, "<" , "<" );
- fString = replace(fString, "&" , "&" );
- fString = replace(fString, " " , " " );
- fString = replace(fString, "/"" , """);
- fString = replace(fString, "/'" , "'" );
- fString = replace(fString, "/r" , " " );
- fString = replace(fString, "/n" , "<BR>" );
- fString = replace(fString, "" , "//" );
- }}catch(Exception e)
- {
- e.printStackTrace();
- }
- return fString;
- }
- /**
- * html语法标记转换符号本身.
- * @param fString转换前的代码.
- * @return fString转换后的内容.
- */
- public static String dvHTMLCode(String fString) {
- if ( ! fString.equals( "null" ) && fString != null ) {
- fString = replace(fString, ">" , ">" );
- fString = replace(fString, "<" , "<" );
- fString = replace(fString, "&" , "&" );
- fString = replace(fString, " " , " " );
- fString = replace(fString, """ , "/"" );
- fString = replace(fString, "'" , "/'" );
- fString = replace(fString, "//" , " " );
- fString = replace(fString, "<BR>" , "/n" );
- }
- return fString;
- }
- public static String nohtml(String str) {
- String re;
- Pattern pattern = null ;
- Matcher matcher = null ;
- re = "(//<.[^//<]*//>)" ;
- pattern = Pattern.compile(re);
- matcher = pattern.matcher(str);
- str = matcher.replaceAll( " " );
- re = " (//<///[^//<]*//>)" ;
- str = re.replace(str, " " );
- re = null ;
- return str;
- }
- /**
- * 分割函数.
- * @param source原字符串,div将要被分割的字符串.
- * @return returnStr分割后的字符串.
- */
- public static String[] split(String source, String div) {
- int arynum = 0 , intIdx = 0 , intIdex = 0 , div_length = div.length();
- if (source.compareTo("") != 0 ) {
- if (source.indexOf(div) != - 1 ) {
- intIdx = source.indexOf(div);
- for ( int intCount = 1 ; ; intCount ++ ) {
- if (source.indexOf(div, intIdx + div_length) != - 1 ) {
- intIdx = source.indexOf(div, intIdx + div_length);
- arynum = intCount;
- } else {
- arynum += 2 ;
- break ;
- }
- }
- } else {
- arynum = 1 ;
- }
- } else {
- arynum = 0 ;
- }
- intIdx = 0 ;
- intIdex = 0 ;
- String[] returnStr = new String[arynum];
- if (source.compareTo("") != 0 ) {
- if (source.indexOf(div) != - 1 ) {
- intIdx = ( int ) source.indexOf(div);
- returnStr[ 0 ] = (String) source.substring( 0 , intIdx);
- for ( int intCount = 1 ; ; intCount ++ ) {
- if (source.indexOf(div, intIdx + div_length) != - 1 ) {
- intIdex = ( int ) source.indexOf(div, intIdx + div_length);
- returnStr[intCount] = (String) source.substring(intIdx +
- div_length,
- intIdex);
- intIdx = ( int ) source.indexOf(div, intIdx + div_length);
- } else {
- returnStr[intCount] = (String) source.substring(intIdx +
- div_length,
- source.length());
- break ;
- }
- }
- } else {
- returnStr[ 0 ] = (String) source.substring( 0 , source.length());
- return returnStr;
- }
- } else {
- return returnStr;
- }
- return returnStr;
- }
- /**
- * 替换函数.
- * @param str替换前的字符串,substr被替换的字符,restr替换的字符.
- * @return 替换后并且经过除空处理的字符串.
- */
- public static String replace(String str, String substr, String restr) {
- String[] tmp = split(str, substr);
- String returnstr = null ;
- if (tmp.length != 0 ) {
- returnstr = tmp[ 0 ];
- for ( int i = 0 ; i < tmp.length - 1 ; i ++ ) {
- returnstr = dealNull(returnstr) + restr + tmp[i + 1 ];
- }
- }
- return dealNull(returnstr);
- }
- /**
- * 除空处理函数.
- * @param str原字符串.
- * @return 处理后的字符串.
- */
- public static String dealNull(String str) {
- String returnstr = null ;
- if (str == null ) {
- returnstr = "" ;
- } else {
- returnstr = str;
- }
- return returnstr;
- }
- public static String tostring(Character i) {
- Character c = i;
- return c.toString();
- }
- /* public static void main(String args[]) throws Exception
- {
- Ubbcode ubb=new Ubbcode();
- String strContent="[IMG]HTTP://123.jpg[/IMG] ";
- System.out.println("the new string is:"+ubb.UBBCode(strContent));
- }*/
- }
2。新建一个serverlet,ubb.java
- import java.io.IOException;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- /**
- * Servlet implementation class for Servlet: ubb
- *
- */
- public class ubb extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
- static final long serialVersionUID = 1L;
- /* (non-Java-doc)
- * @see javax.servlet.http.HttpServlet#HttpServlet()
- */
- public ubb() {
- super();
- }
- /* (non-Java-doc)
- * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
- */
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- // TODO Auto-generated method stub
- doPost(request,response);
- }
- /* (non-Java-doc)
- * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
- */
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- // System.out.println("begin");
- // System.out.println("The request get paramter mssgcontent is : "+request.getParameter("mssgcontent"));
- Ubbcode ubb=new Ubbcode();
- String strContent=request.getParameter("mssgcontent");
- response.setContentType("text/html;charset=utf-8");
- response.getWriter().write(ubb.UBBCode(strContent));
- }
- }
注:web-info/web.xml中serverlet配置:
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
- <display-name>Ubbtest</display-name>
- <welcome-file-list>
- <welcome-file>index.html</welcome-file>
- <welcome-file>index.htm</welcome-file>
- <welcome-file>index.jsp</welcome-file>
- <welcome-file>default.html</welcome-file>
- <welcome-file>default.htm</welcome-file>
- <welcome-file>default.jsp</welcome-file>
- </welcome-file-list>
- <servlet>
- <description></description>
- <display-name>ubb</display-name>
- <servlet-name>ubb</servlet-name>
- <servlet-class>ubb</servlet-class>
- </servlet>
- <servlet-mapping>
- <servlet-name>ubb</servlet-name>
- <url-pattern>/ubb</url-pattern>
- </servlet-mapping>
- </web-app>
3.新建bbcode.js。用于页面显示(版权归动网论坛)。
-
- /******************************************************************************
- Crossday Discuz! Board - HTML <=> BB Code for Discuz!
- Copyright 2001-2006 Comsenz Inc. (http://www.comsenz.com)
- *******************************************************************************/
- var re;
- var pcodecount = '-1';
- var codecount = 0;
- var codehtml = new Array();
- function addslashes(str) {
- var searcharray = ['', '///'', '', '///(', '///)', '///[', '///]', '///{', '///}', '///^', '///$', '///?', '///.', '///*', '///+', '///|'];
- var replacearray = ['', '///'', '///', '//(', '//)', '//[', '//]', '//{', '//}', '//^', '//$', '//?', '//.', '//*', '//+', '//|'];
- var len = searcharray.length;
- for(var i = 0; i < len; i++) {
- re = new RegExp(searcharray[i], "g");
- str = str.replace(re, replacearray[i]);
- }
- return str;
- }
- function atag(aoptions, text) {
- if(trim(text) == '') {
- return '';
- }
- href = getoptionvalue('href', aoptions);
- if(href.substr(0, 11) == 'javascript:') {
- return trim(recursion('a', text, 'atag'));
- } else if(href.substr(0, 7) == 'mailto:') {
- tag = 'email';
- href = href.substr(7);
- } else {
- tag = 'url';
- }
- return '[' + tag + '=' + href + ']' + trim(recursion('a', text, 'atag')) + '[/' + tag + ']';
- }
- function bbcode2html(str) {
- str = trim(str);
- if(str == '') {
- return '';
- }
- if(!fetchCheckbox('bbcodeoff') && allowbbcode) {
- str= str.replace(//s*/[code/]([/s/S]+?)/[//code/]/s*/ig, function($1, $2) {return parsecode($2);});
- }
- if(!forumallowhtml && !(allowhtml && fetchCheckbox('htmlon'))) {
- str = str.replace(/</ig, '<');
- str = str.replace(/>/ig, '>');
- }
- if(!fetchCheckbox('smileyoff') && allowsmilies) {
- for(id in smilies) {
- re = new RegExp(addslashes(smilies[id]['code']), "g");
- str = str.replace(re, '<img src="./images/smilies/' + smilies[id]['url'] + '" border="0" smilieid="' + id + '" alt="' + smilies[id]['code'] + '" />');
- }
- }
- if(!fetchCheckbox('parseurloff')) {
- str = str.replace(/^((http|https|ftp|rtsp|mms):[A-Za-z0-9/.//=/?%/-&_~`@':+!]+)/ig, '<a href="$1" target="_blank">$1</a>');
- str = str.replace(/((http|https|ftp|rtsp|mms):[A-Za-z0-9/.//=/?%/-&_~`@':+!]+)$/ig, '<a href="$1" target="_blank">$1</a>');
- str = str.replace(/[^>=/]""]((http|https|ftp|rtsp|mms):[A-Za-z0-9/.//=/?%/-&_~`@':+!]+)/ig, '<a href="$1" target="_blank">$1</a>');
- }
- if(!fetchCheckbox('bbcodeoff') && allowbbcode) {
- str= str.replace(//[url/]/s*(www.|https?:|ftp:|gopher:|news:|telnet:|rtsp:|mms:|callto:|ed2k:){1}([^/[/"']+?)/s*/[//url/]/ig, function($1, $2, $3) {return cuturl($2 + $3);});
- str= str.replace(//[url=www.([^/[/"']+?)/](.+?)/[//url/]/ig, '<a href="http://www.$1" target="_blank">$2</a>');
- str= str.replace(//[url=(https?|ftp|gopher|news|telnet|rtsp|mms|callto|ed2k){1}:([^/[/"']+?)/]([/s/S]+?)/[//url/]/ig, '<a href="$1://$2" target="_blank">$3</a>');
- str= str.replace(//[email/](.*?)/[//email/]/ig, '<a href="mailto:$1">$1</a>');
- str= str.replace(//[email=(.[^/[]*)/](.*?)/[//email/]/ig, '<a href="mailto:$1" target="_blank">$2</a>');
- str = str.replace(//[color=([^/[/<]+?)/]/ig, '<font color="$1">');
- str = str.replace(//[size=(/d+?)/]/ig, '<font size="$1">');
- str = str.replace(//[size=(/d+(px|pt|in|cm|mm|pc|em|ex|%)+?)/]/ig, '<font style="font-size: $1">');
- str = str.replace(//[font=([^/[/<]+?)/]/ig, '<font face="$1">');
- str = str.replace(//[align=([^/[/<]+?)/]/ig, '<p align="$1">');
- re = //s*/[table(=(/d{1,3}%?))?/][/n/r]*([/s/S]+?)[/n/r]*/[//table/]/s*/ig;
- str = str.replace(re, function($1, $2, $3, $4) {return parsetable($3, $4);});
- str = str.replace(re, function($1, $2, $3, $4) {return parsetable($3, $4);});
- str = str.replace(re, function($1, $2, $3, $4) {return parsetable($3, $4);});
- str = str.replace(re, function($1, $2, $3, $4) {return parsetable($3, $4);});
- var searcharray = new Array(
- '///[color///]', '///[size///]', '///[font///]', '///[align///]', '///[b///]', '///[b///]',
- '///[i///]', '///[i///]', '///[u///]', '///[u///]', '///[list///]', '///[list=1///]', '///[list=a///]',
- '///[list=A///]', '///[///*///]', '///[list///]', '///[indent///]', '///[indent///]'
- );
- var replacearray = new Array(
- '</font>', '</font>', '</font>', '</p>', '<b>', '</b>', '<i>',
- '</i>', '<u>', '</u>', '<ul>', '<ol type=1>', '<ol type=a>',
- '<ol type=A>', '<li>', '</ul></ol>', '<blockquote>', '</blockquote>'
- );
- var len = searcharray.length;
- for(var i = 0; i < len; i++) {
- re = new RegExp(searcharray[i], "ig");
- str = str.replace(re, replacearray[i]);
- }
- }
- if(!fetchCheckbox('bbcodeoff')) {
- if(allowimgcode) {
- str = str.replace(//[img/]/s*([^/[/</r/n]+?)/s*/[//img/]/ig, '<img src="$1" border="0" οnlοad="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt=/'Click here to open new window//nCTRL+Mouse wheel to zoom in/out/';}" οnmοuseοver="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor=/'hand/'; this.alt=/'Click here to open new window//nCTRL+Mouse wheel to zoom in/out/';}" οnclick="if(!this.resized) {return true;} else {window.open(/'$1/');}" onmousewheel="return imgzoom(this);" alt="" />');
- str = str.replace(//[img=(/d{1,3})[x|/,](/d{1,3})/]/s*([^/[/</r/n]+?)/s*/[//img/]/ig, '<img width="$1" height="$2" src="$3" border="0" alt="" />');
- } else {
- str = str.replace(//[img/]/s*([^/[/</r/n]+?)/s*/[//img/]/ig, '<a href="$1" target="_blank">$1</a>');
- str = str.replace(//[img=(/d{1,3})[x|/,](/d{1,3})/]/s*([^/[/</r/n]+?)/s*/[//img/]/ig, '<a href="$1" target="_blank">$1</a>');
- }
- }
- for(var i = 0; i <= pcodecount; i++) {
- str = str.replace("[/tDISCUZ_CODE_" + i + "/t]", codehtml[i]);
- }
- if(!forumallowhtml && !(allowhtml && fetchCheckbox('htmlon'))) {
- str = str.replace(//t/ig, ' ');
- str = str.replace(/ /ig, ' ');
- str = str.replace(/ /ig, ' ');
- str = str.replace(//r/n/ig, '<br />');
- str = str.replace(/[/r/n]/ig, '<br />');
- }
- return(str);
- }
- function codetag(text) {
- pcodecount++;
- text = text.replace(/<br[^/>]*>/ig, "/n");
- text = text.replace(/^[/n/r]*([/s/S]+?)[/n/r]*$/ig, '$1');
- text = text.replace(/<(//|)[A-Za-z].*?>/ig, '');
- codehtml[pcodecount] = "[code]" + text + "[/code]";
- codecount++;
- return "[/tDISCUZ_CODE_" + pcodecount + "/t]";
- }
- function cuturl(url) {
- var length = 65;
- var urllink = '<a href="' + (url.toLowerCase().substr(0, 4) == 'www.' ? 'http://' + url : url) + '" target="_blank">';
- if(url.length > length) {
- url = url.substr(0, parseInt(length * 0.5)) + ' ... ' + url.substr(url.length - parseInt(length * 0.3));
- }
- urllink += url + '</a>';
- return urllink;
- }
- function dpstag(options, text, tagname) {
- if(trim(text) == '') {
- return '';
- }
- var pend = parsestyle(options, '', '');
- var prepend = pend['prepend'];
- var append = pend['append'];
- if(in_array(tagname, ['div', 'p'])) {
- align = getoptionvalue('align', options);
- if(in_array(align, ['left', 'center', 'right'])) {
- prepend = '[align=' + align + ']' + prepend;
- append += '[/align]';
- } else {
- append += "/n";
- }
- }
- return prepend + recursion(tagname, text, 'dpstag') + append;
- }
- function fetchCheckbox(cbn) {
- return $(cbn) && $(cbn).checked == true ? 1 : 0;
- }
- function fetchoptionvalue(option, text) {
- if((position = strpos(text, option)) !== false) {
- delimiter = position + option.length;
- if(text.charAt(delimiter) == '"') {
- delimchar = '"';
- } else if(text.charAt(delimiter) == '/'') {
- delimchar = '/'';
- } else {
- delimchar = ' ';
- }
- delimloc = strpos(text, delimchar, delimiter + 1);
- if(delimloc === false) {
- delimloc = text.length;
- } else if(delimchar == '"' || delimchar == '/'') {
- delimiter++;
- }
- return trim(text.substr(delimiter, delimloc - delimiter));
- } else {
- return '';
- }
- }
- function fonttag(fontoptions, text) {
- var prepend = '';
- var append = '';
- var tags = new Array();
- tags = {'font' : 'face=', 'size' : 'size=', 'color' : 'color='};
- for(bbcode in tags) {
- optionvalue = fetchoptionvalue(tags[bbcode], fontoptions);
- if(optionvalue) {
- prepend += '[' + bbcode + '=' + optionvalue + ']';
- append = '[/' + bbcode + ']' + append;
- }
- }
- var pend = parsestyle(fontoptions, prepend, append);
- return pend['prepend'] + recursion('font', text, 'fonttag') + pend['append'];
- }
- function getoptionvalue(option, text) {
- re = new RegExp(option + "(/s+?)?/=(/s+?)?[/"']?(.+?)([/"']|$|>)", "ig");
- var matches = re.exec(text);
- if(matches != null && matches.length) {
- return trim(matches[3]);
- }
- return '';
- }
- function html2bbcode(str) {
- str = trim(str);
- if(str == '' || forumallowhtml || (allowhtml && fetchCheckbox('htmlon'))) {
- return str;
- }
- str= str.replace(//s*/[code/]([/s/S]+?)/[//code/]/s*/ig, function($1, $2) {return codetag($2);});
- str = str.replace(/<style.*?>[/s/S]*?<//style>/ig, '');
- str = str.replace(/<script.*?>[/s/S]*?<//script>/ig, '');
- str = str.replace(/<noscript.*?>[/s/S]*?<//noscript>/ig, '');
- str = str.replace(/<select.*?>[/s/S]*?<//select>/ig, '');
- str = str.replace(/<object.*?>[/s/S]*?<//object>/ig, '');
- str = str.replace(/<!--[/s/S]*?-->/ig, '');
- str = str.replace(/on[a-zA-Z]{3,16}/s?=/s?(["'])[/s/S]*?/1/ig, '');
- str = str.replace(/(/r/n|/n|/r)/ig, '');
- str = str.replace(/<table([^>]*width[^>]*)>/ig, function($1, $2) {return tabletag($2);});
- str = str.replace(/<table[^>]*>/ig, '[table]');
- str = str.replace(/<tr[^>]*>/ig, '[tr]');
- str = str.replace(/<td>/ig, '[td]');
- str = str.replace(/<td([^>]+)>/ig, function($1, $2) {return tdtag($2);});
- str = str.replace(/<//td>/ig, '[/td]');
- str = str.replace(/<//tr>/ig, '[/tr]');
- str = str.replace(/<//table>/ig, '[/table]');
- str = str.replace(/<h([0-9]+)[^>]*>(.*)<//h//1>/ig, "[size=$1]$2[/size]/n/n");
- str = str.replace(/<img[^>]+smilieid=(["']?)(/d+)(/1)[^>]*>/ig, function($1, $2, $3) {return smilies[$3]['code'];});
- str = str.replace(/<img([^>]*src[^>]*)>/ig, function($1, $2) {return imgtag($2);});
- str = str.replace(/<a/s+?name=(["']?)(.+?)(/1)[/s/S]*?>([/s/S]*?)<//a>/ig, '$4');
- str = str.replace(/<br[^/>]*>/ig, "/n");
- str = recursion('b', str, 'simpletag', 'b');
- str = recursion('strong', str, 'simpletag', 'b');
- str = recursion('i', str, 'simpletag', 'i');
- str = recursion('em', str, 'simpletag', 'i');
- str = recursion('u', str, 'simpletag', 'u');
- str = recursion('a', str, 'atag');
- str = recursion('font', str, 'fonttag');
- str = recursion('blockquote', str, 'simpletag', 'indent');
- str = recursion('ol', str, 'listtag');
- str = recursion('ul', str, 'listtag');
- str = recursion('div', str, 'dpstag');
- str = recursion('p', str, 'dpstag');
- str = recursion('span', str, 'dpstag');
- str = str.replace(/<[///!]*?[^<>]*?>/ig, '');
- for(var i = 0; i <= pcodecount; i++) {
- str = str.replace("[/tDISCUZ_CODE_" + i + "/t]", codehtml[i]);
- }
- str = str.replace(/&/ig, '&');
- str = str.replace(/ /ig, ' ');
- str = str.replace(/</ig, '<');
- str = str.replace(/>/ig, '>');
- return str
- }
- function htmlspecialchars(str) {
- var f = new Array(
- (is_mac && is_ie ? new RegExp('&', 'g') : new RegExp('&(?!#[0-9]+;)', 'g')),
- new RegExp('<', 'g'),
- new RegExp('>', 'g'),
- new RegExp('"', 'g')
- );
- var r = new Array(
- '&',
- '<',
- '>',
- '"'
- );
- for(var i = 0; i < f.length; i++) {
- str = str.replace(f[i], r[i]);
- }
- return str;
- }
- function imgtag(attributes) {
- var width = '';
- var height = '';
- re = /src=(["']?)([/s/S]*?)(/1)/i;
- var matches = re.exec(attributes);
- if(matches != null) {
- var src = matches[2];
- } else {
- return '';
- }
- re = /width=(["']?)(/d+)(/1)/i;
- var matches = re.exec(attributes);
- if(matches != null) {
- width = matches[2];
- }
- re = /height=(["']?)(/d+)(/1)/i;
- var matches = re.exec(attributes);
- if(matches != null) {
- height = matches[2];
- }
- return width > 0 && height > 0 ?
- '[img=' + width + ',' + height + ']' + src + '[/img]' :
- '[img]' + src + '[/img]';
- }
- function listtag(listoptions, text, tagname) {
- text = text.replace(/<li>(([/s/S](?!<//li))*?)(?=<//?ol|<//?ul|<li|/[list|/[//list)/ig, '<li>$1</li>') + (is_opera ? '</li>' : '');
- text = recursion('li', text, 'litag');
- var opentag = '[list]';
- if(tagname == 'ol') {
- var listtype = fetchoptionvalue('type=', listoptions);
- listtype = listtype != '' ? listtype : '1';
- if(in_array(listtype, ['1', 'a', 'A'])) {
- opentag = '[list=' + listtype + ']';
- }
- }
- return text ? opentag + recursion(tagname, text, 'listtag') + '[/list]' : '';
- }
- function litag(listoptions, text) {
- return '[*]' + text.replace(/(/s+)$/g, '');
- }
- function parsecode(text) {
- pcodecount++;
- text = text.replace(/^[/n/r]*([/s/S]+?)[/n/r]*$/ig, '$1');
- text = htmlspecialchars(text);
- codehtml[pcodecount] = '[code]' + text + '[/code]';
- codecount++;
- return "[/tDISCUZ_CODE_" + pcodecount + "/t]";
- }
- function parsestyle(tagoptions, prepend, append) {
- var searchlist = [
- ['align', true, 'text-align://s*(left|center|right);?', 1],
- ['color', true, '^(?://s|)color://s*([^;]+);?', 1],
- ['font', true, 'font-family://s*([^;]+);?', 1],
- ['size', true, 'font-size://s*(//d+(px|pt|in|cm|mm|pc|em|ex|%|));?', 1],
- ['b', false, 'font-weight://s*(bold);?'],
- ['i', false, 'font-style://s*(italic);?'],
- ['u', false, 'text-decoration://s*(underline);?']
- ];
- var style = getoptionvalue('style', tagoptions);
- re = /^(?:/s|)color:/s*rgb/((/d+),/s*(/d+),/s*(/d+)/)(;?)/ig;
- style = style.replace(re, function($1, $2, $3, $4, $5) {return("color:#" + parseInt($2).toString(16) + parseInt($3).toString(16) + parseInt($4).toString(16) + $5);});
- var len = searchlist.length;
- for(var i = 0; i < len; i++) {
- re = new RegExp(searchlist[i][2], "ig");
- match = re.exec(style);
- if(match != null) {
- opnvalue = match[searchlist[i][3]];
- prepend += '[' + searchlist[i][0] + (searchlist[i][1] == true ? '=' + opnvalue + ']' : ']');
- append = '[/' + searchlist[i][0] + ']' + append;
- }
- }
- return {'prepend' : prepend, 'append' : append};
- }
- function parsetable(width, str) {
- if(typeof width == 'undefined') {
- var width = '';
- } else {
- width = width.substr(width.length - 1, width.length) == '%' ? (width.substr(0, width.length - 1) <= 98 ? width : '98%') : (width <= 560 ? width : '98%');
- }
- var string = '<table '
- + (width == '' ? '' : 'width="' + width + '" ')
- + 'align="center" class="t_table">';
- str = str.replace(//[td=(/d{1,2}),(/d{1,2})(,(/d{1,3}%?))?/]/ig, '<td colspan="$1" rowspan="$2" width="$4">');
- str = str.replace(//[tr/]/ig, '<tr>');
- str = str.replace(//[td/]/ig, '<td>');
- str = str.replace(//[//td/]/ig, '</td>');
- str = str.replace(//[//tr/]/ig, '</tr>');
- string += str;
- string += '</table>';
- return string;
- }
- function recursion(tagname, text, dofunction, extraargs) {
- if(extraargs == null) {
- extraargs = '';
- }
- tagname = tagname.toLowerCase();
- var open_tag = '<' + tagname;
- var open_tag_len = open_tag.length;
- var close_tag = '</' + tagname + '>';
- var close_tag_len = close_tag.length;
- var beginsearchpos = 0;
- do {
- var textlower = text.toLowerCase();
- var tagbegin = textlower.indexOf(open_tag, beginsearchpos);
- if(tagbegin == -1) {
- break;
- }
- var strlen = text.length;
- var inquote = '';
- var found = false;
- var tagnameend = false;
- var optionend = 0;
- var t_char = '';
- for(optionend = tagbegin; optionend <= strlen; optionend++) {
- t_char = text.charAt(optionend);
- if((t_char == '"' || t_char == "'") && inquote == '') {
- inquote = t_char;
- } else if((t_char == '"' || t_char == "'") && inquote == t_char) {
- inquote = '';
- } else if(t_char == '>' && !inquote) {
- found = true;
- break;
- } else if((t_char == '=' || t_char == ' ') && !tagnameend) {
- tagnameend = optionend;
- }
- }
- if(!found) {
- break;
- }
- if(!tagnameend) {
- tagnameend = optionend;
- }
- var offset = optionend - (tagbegin + open_tag_len);
- var tagoptions = text.substr(tagbegin + open_tag_len, offset)
- var acttagname = textlower.substr(tagbegin * 1 + 1, tagnameend - tagbegin - 1);
- if(acttagname != tagname) {
- beginsearchpos = optionend;
- continue;
- }
- var tagend = textlower.indexOf(close_tag, optionend);
- if(tagend == -1) {
- break;
- }
- var nestedopenpos = textlower.indexOf(open_tag, optionend);
- while(nestedopenpos != -1 && tagend != -1) {
- if(nestedopenpos > tagend) {
- break;
- }
- tagend = textlower.indexOf(close_tag, tagend + close_tag_len);
- nestedopenpos = textlower.indexOf(open_tag, nestedopenpos + open_tag_len);
- }
- if(tagend == -1) {
- beginsearchpos = optionend;
- continue;
- }
- var localbegin = optionend + 1;
- var localtext = eval(dofunction)(tagoptions, text.substr(localbegin, tagend - localbegin), tagname, extraargs);
- text = text.substring(0, tagbegin) + localtext + text.substring(tagend + close_tag_len);
- beginsearchpos = tagbegin + localtext.length;
- } while(tagbegin != -1);
- return text;
- }
- function simpletag(options, text, tagname, parseto) {
- if(trim(text) == '') {
- return '';
- }
- text = recursion(tagname, text, 'simpletag', parseto);
- return '[' + parseto + ']' + text + '[/' + parseto + ']';
- }
- function strpos(haystack, needle, offset) {
- if(typeof offset == 'undefined') {
- offset = 0;
- }
- index = haystack.toLowerCase().indexOf(needle.toLowerCase(), offset);
- return index == -1 ? false : index;
- }
- function tabletag(attributes) {
- var width = '';
- re = /width=(["']?)(/d{1,3}%?)(/1)/ig;
- var matches = re.exec(attributes);
- if(matches != null && matches.length) {
- width = matches[2].substr(matches[2].length - 1, matches[2].length) == '%' ?
- (matches[2].substr(0, matches[2].length - 1) <= 98 ? matches[2] : '98%') :
- (matches[2] <= 560 ? matches[2] : '98%');
- } else {
- re = /width/s?:/s?(/d{1,3})([px|%])/ig;
- var matches = re.exec(attributes);
- if(matches != null && matches.length) {
- width = matches[2] == '%' ? (matches[1] <= 98 ? matches[1] : '98%') : (matches[1] <= 560 ? matches[1] : '98%');
- }
- }
- return width == '' ? '[table]' : '[table=' + width + ']';
- }
- function tdtag(attributes) {
- var colspan = 1;
- var rowspan = 1;
- var width = '';
- re = /colspan=(["']?)(/d{1,2})(/1)/ig;
- var matches = re.exec(attributes);
- if(matches != null) {
- colspan = matches[2];
- }
- re = /rowspan=(["']?)(/d{1,2})(/1)/ig;
- var matches = re.exec(attributes);
- if(matches != null) {
- rowspan = matches[2];
- }
- re = /width=(["']?)(/d{1,3}%?)(/1)/ig;
- var matches = re.exec(attributes);
- if(matches != null) {
- width = matches[2];
- }
- return in_array(width, ['', '0', '100%']) ?
- (colspan == 1 && rowspan == 1 ? '[td]' : '[td=' + colspan + ',' + rowspan + ']') :
- '[td=' + colspan + ',' + rowspan + ',' + width + ']';
- }
- function trim(str) {
- return (str.replace(/(/s+)$/g, '')).replace(/^/s+/g, '');
- }
- <%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gbk">
- <title>UBB编辑器</title>
- <link rel="stylesheet" type="text/css" id="css" href="Images/ubb.css">
- </head>
- <body>
- <form id="postform" method="post" >
- <table id="postcontent" cellpadding="0" border="0" class="editor" bordercolor="#000000">
- <tr>
- <th colspan="2" >添加贴子</th>
- </tr>
- <tr>
- <td width="26">标题</td>
- <td width="640" style="text-align:left">
- <input type="text" name="title" size="42">
- </td>
- </tr>
- <tr>
- <td>内容</td>
- <td >
- <div align="center">
- <iframe class="editor" ID="Editor" name="Editor" src="edit.jsp?id=mssgcontent" frameBorder="0" marginHeight="0" marginWidth="0" scrolling="No" style="height:324px;width:100%"></iframe>
- </div>
- </td>
- </tr>
- <tr>
- <td>
- <textarea name="mssgcontent" id="mssgcontent" cols="80" rows="2" style="display:none"></textarea>
- </td>
- </tr>
- <tr>
- <td colspan="2">
- <div align="center">
- <input id="SubButton" name="SubButton" type="button" value="添加内容">
- <input type="reset" value="重新填写">
- </div></td>
- </tr>
- </table>
- <br>
- <br>
- <table cellpadding="0" border="0" class="editor" bordercolor="#000000" style="width:650px; height:250px">
- <tr>
- <th height="22" colspan="2" >转换后内容</th>
- </tr>
- <tr>
- <td width="42">
- 内容:
- </td>
- <td width="630" valign="top" class="editor_text">
- <div align="left">
- <div id="reslut" name="reslut"></div>
- </div>
- </td>
- </tr>
- </table>
- </form>
- </body>
- </html>
comm.js
- /******************************************************************************
- Crossday Discuz! Board - Common Modules for Discuz!
- Copyright 2001-2006 Comsenz Inc. (http://www.comsenz.com)
- *******************************************************************************/
- var sPop = null;
- var postSubmited = false;
- var userAgent = navigator.userAgent.toLowerCase();
- var is_opera = (userAgent.indexOf('opera') != -1);
- var is_saf = ((userAgent.indexOf('applewebkit') != -1) || (navigator.vendor == 'Apple Computer, Inc.'));
- var is_webtv = (userAgent.indexOf('webtv') != -1);
- var is_ie = ((userAgent.indexOf('msie') != -1) && (!is_opera) && (!is_saf) && (!is_webtv));
- var is_ie4 = ((is_ie) && (userAgent.indexOf('msie 4.') != -1));
- var is_moz = ((navigator.product == 'Gecko') && (!is_saf));
- var is_kon = (userAgent.indexOf('konqueror') != -1);
- var is_ns = ((userAgent.indexOf('compatible') == -1) && (userAgent.indexOf('mozilla') != -1) && (!is_opera) && (!is_webtv) && (!is_saf));
- var is_ns4 = ((is_ns) && (parseInt(navigator.appVersion) == 4));
- var is_mac = (userAgent.indexOf('mac') != -1);
- function ctlent(event) {
- }
- function storeCaret(textEl){
- if(textEl.createTextRange){
- textEl.caretPos = document.selection.createRange().duplicate();
- }
- }
- function checkall(form, prefix, checkall) {
- var checkall = checkall ? checkall : 'chkall';
- for(var i = 0; i < form.elements.length; i++) {
- var e = form.elements[i];
- if(e.name != checkall && (!prefix || (prefix && e.name.match(prefix)))) {
- e.checked = form.elements[checkall].checked;
- }
- }
- }
- function arraypop(a) {
- if(typeof a != 'object' || !a.length) {
- return null;
- } else {
- var response = a[a.length - 1];
- a.length--;
- return response;
- }
- }
- function arraypush(a, value) {
- a[a.length] = value;
- return a.length;
- }
- function findtags(parentobj, tag) {
- if(typeof parentobj.getElementsByTagName != 'undefined') {return parentobj.getElementsByTagName(tag);}
- else if(parentobj.all && parentobj.all.tags) {return parentobj.all.tags(tag);}
- else {return null;}
- }
- function copycode(obj) {
- var rng = document.body.createTextRange();
- rng.moveToElementText(obj);
- rng.scrollIntoView();
- rng.select();
- rng.execCommand("Copy");
- rng.collapse(false);
- }
- function toggle_collapse(objname, unfolded) {
- if(typeof unfolded == 'undefined') {
- var unfolded = 1;
- }
- var obj = $(objname);
- var oldstatus = obj.style.display;
- var collapsed = getcookie('discuz_collapse');
- var cookie_start = collapsed ? collapsed.indexOf(objname) : -1;
- var cookie_end = cookie_start + objname.length + 1;
- obj.style.display = oldstatus == 'none' ? '' : 'none';
- collapsed = cookie_start != -1 && ((unfolded && oldstatus == 'none') || (!unfolded && oldstatus == '')) ?
- collapsed.substring(0, cookie_start) + collapsed.substring(cookie_end, collapsed.length) : (
- cookie_start == -1 && ((unfolded && oldstatus == '') || (!unfolded && oldstatus == 'none')) ?
- collapsed + objname + ' ' : collapsed);
- expires = new Date();
- expires.setTime(expires.getTime() + (collapsed ? 86400 * 30 : -(86400 * 30 * 1000)));
- document.cookie = 'discuz_collapse=' + escape(collapsed) + '; expires=' + expires.toGMTString() + '; path=/';
- var img = $(objname + '_img');
- var img_regexp = new RegExp((oldstatus == 'none' ? '_yes' : '_no') + '//.gif$');
- var img_re = oldstatus == 'none' ? '_no.gif' : '_yes.gif'
- if(img) {
- img.src = img.src.replace(img_regexp, img_re);
- }
- }
- function imgzoom(o) {
- if(event.ctrlKey) {
- var zoom = parseInt(o.style.zoom, 10) || 100;
- zoom -= event.wheelDelta / 12;
- if(zoom > 0) {
- o.style.zoom = zoom + '%';
- }
- return false;
- } else {
- return true;
- }
- }
- function getcookie(name) {
- var cookie_start = document.cookie.indexOf(name);
- var cookie_end = document.cookie.indexOf(";", cookie_start);
- return cookie_start == -1 ? '' : unescape(document.cookie.substring(cookie_start + name.length + 1, (cookie_end > cookie_start ? cookie_end : document.cookie.length)));
- }
- function AddText(txt) {
- obj = $('message');
- selection = document.selection;
- checkFocus();
- if(typeof(obj.selectionStart) != 'undefined') {
- var opn = obj.selectionStart + 0;
- obj.value = obj.value.substr(0, obj.selectionStart) + txt + obj.value.substr(obj.selectionEnd);
- } else if(selection && selection.createRange) {
- var sel = selection.createRange();
- sel.text = txt;
- sel.moveStart('character', -mb_strlen(txt));
- } else {
- obj.value += txt;
- }
- }
- function insertAtCaret (textEl, text){
- if(textEl.createTextRange && textEl.caretPos){
- var caretPos = textEl.caretPos;
- caretPos.text += caretPos.text.charAt(caretPos.text.length - 2) == ' ' ? text + ' ' : text;
- } else if(textEl) {
- textEl.value += text;
- } else {
- textEl.value = text;
- }
- }
- function checkFocus() {
- var obj = typeof wysiwyg == 'undefined' || !wysiwyg ? $('posteditor_textarea') : editwin;
- if(!obj.hasfocus) {
- obj.focus();
- }
- }
- function closesmiliewindow(e) {
- if(typeof smiliewindow != 'undefined' && !smiliewindow.closed) {
- smiliewindow.close();
- }
- }
- function opensmiliewindow(width, height, editorid) {
- smiliewindow = window.open('post.php?action=smilies' + (editorid ? '&editorid=' + editorid : ''), 'Popup', 'width=' + width + ',height=' + height + ',resizable=yes,scrollbars=yes');
- window.onunload = closesmiliewindow;
- }
- function mb_strlen(str) {
- return (is_ie && str.indexOf('/n') != -1) ? str.replace(//r?/n/g, '_').length : str.length;
- }
- function insertSmiley(smilieid) {
- checkFocus();
- var src = $('smilie_' + smilieid).src;
- var code = $('smilie_' + smilieid).pop ? $('smilie_' + smilieid).pop : $('smilie_' + smilieid).alt;
- if(typeof wysiwyg != 'undefined' && wysiwyg && allowsmilies && (!$('smileyoff') || $('smileyoff').checked == false)) {
- if(is_moz) {
- applyFormat('InsertImage', false, src);
- var smilies = findtags(editdoc.body, 'img');
- for(var i = 0; i < smilies.length; i++) {
- if(smilies[i].src == src && smilies[i].getAttribute('smilieid') < 1) {
- smilies[i].setAttribute('smilieid', smilieid);
- smilies[i].setAttribute('border', "0");
- }
- }
- } else {
- insertText('<img src="' + src + '" border="0" smilieid="' + smilieid + '" alt="" /> ', false);
- }
- } else {
- code += ' ';
- AddText(code);
- }
- }
- function announcement() {
- $('announcement').innerHTML = '<marquee style="filter:progid:DXImageTransform.Microsoft.Alpha(startX=0, startY=0, finishX=10, finishY=100,style=1,opacity=0,finishOpacity=100); margin: 0px 8px" direction="left" scrollamount="2" scrolldelay="1" onMouseOver="this.stop();" onMouseOut="this.start();">' +
- $('announcement').innerHTML + '</marquee>';
- $('announcement').style.display = 'block';
- }
- function $(id) {
- return document.getElementById(id);
- }
- function in_array(needle, haystack) {
- if(typeof needle == 'string') {
- for(var i in haystack) {
- if(haystack[i] == needle) {
- return true;
- }
- }
- }
- return false;
- }
- document.write("<style type='text/css'id='defaultPopStyle'>");
- document.write(".cPopText { font-family: Tahoma, Verdana; background-color: #FFFFCC; border: 1px #000000 solid; font-size: 12px; padding-right: 4px; padding-left: 4px; line-height: 18px; padding-top: 2px; padding-bottom: 2px; visibility: hidden; filter: Alpha(Opacity=80)}");
- document.write("</style>");
- document.write("<div id='popLayer' style='position:absolute;z-index:1000' class='cPopText'></div>");
- function showPopupText(event) {
- if(event.srcElement) o = event.srcElement; else o = event.target;
- if(!o) {
- return;
- }
- MouseX = event.clientX;
- MouseY = event.clientY;
- if(o.alt != null && o.alt != '') {
- o.pop = o.alt;
- o.alt = '';
- }
- if(o.title != null && o.title != '') {
- o.pop = o.title;
- o.title = '';
- }
- if(o.pop != sPop) {
- sPop = o.pop;
- if(sPop == null || sPop == '') {
- $('popLayer').style.visibility = "hidden";
- } else {
- popStyle = o.dyclass != null ? o.dyclass : 'cPopText';
- $('popLayer').style.visibility = "visible";
- showIt();
- }
- }
- }
- function showIt() {
- $('popLayer').className = popStyle;
- $('popLayer').innerHTML = sPop.replace(/<(.*)>/g,"<$1>").replace(//n/g,"<br>");
- var popWidth = $('popLayer').clientWidth;
- var popHeight = $('popLayer').clientHeight;
- var popLeftAdjust = MouseX + 12 + popWidth > document.body.clientWidth ? -popWidth - 24 : 0;
- var popTopAdjust = MouseY + 12 + popHeight > document.body.clientHeight ? -popHeight - 24 : 0;
- $('popLayer').style.left = (MouseX + 12 + document.body.scrollLeft + popLeftAdjust) + 'px';
- $('popLayer').style.top = (MouseY + 12 + document.body.scrollTop + popTopAdjust) + 'px';
- }
- if(!document.onmouseover) {
- document.onmouseover = function(e) {
- var event = e ? e : window.event;
- showPopupText(event);
- };
- }
editor.js
- /******************************************************************************
- Crossday Discuz! Board - Editor Modules for Discuz!
- Copyright 2001-2006 Comsenz Inc. (http://www.comsenz.com)
- *******************************************************************************/
- var editbox = editwin = editdoc = null;
- var cursor = -1;
- var stack = new Array();
- function newEditor(mode, initialtext) {
- wysiwyg = parseInt(mode);
- if(!(is_ie || is_moz || (is_opera && opera.version() >= 9))) {
- allowswitcheditor = wysiwyg = 0;
- }
- var bbcodemode = $('bbcodemode');
- var wysiwygmode = $('wysiwygmode');
- bbcodemode.className = wysiwyg ? 'editor_switcher' : 'editor_switcher_highlight';
- wysiwygmode.className = wysiwyg ? 'editor_switcher_highlight' : 'editor_switcher';
- if(!allowswitcheditor) {
- $(editorid + '_switcher').style.display = 'none';
- }
- $(editorid + '_cmd_table').style.display = wysiwyg ? '' : 'none';
- if(wysiwyg) {
- if($(editorid + '_iframe')) {
- editbox = $(editorid + '_iframe');
- } else {
- var iframe = document.createElement('iframe');
- editbox = textobj.parentNode.appendChild(iframe);
- editbox.id = editorid + '_iframe';
- }
- editwin = editbox.contentWindow;
- editdoc = editwin.document;
- writeEditorContents(isUndefined(initialtext) ? textobj.value : initialtext);
- } else {
- editbox = textobj;
- editwin = textobj;
- editdoc = textobj;
- if(!isUndefined(initialtext)) {
- writeEditorContents(initialtext);
- }
- addSnapshot(textobj.value);
- }
- setEditorEvents();
- }
- function writeEditorContents(text) {
- if(wysiwyg) {
- if(text == '' && window.is_moz) {
- text = '<br />';
- }
- if(editdoc && editdoc.initialized) {
- editdoc.body.innerHTML = text;
- } else {
- editdoc.designMode = 'on';
- editdoc = editwin.document;
- editdoc.open('text/html', 'replace');
- editdoc.write(text);
- editdoc.close();
- editdoc.body.contentEditable = true;
- editdoc.initialized = true;
- }
- } else {
- textobj.value = text;
- }
- setEditorStyle();
- }
- function getEditorContents() {
- return wysiwyg ? editdoc.body.innerHTML : editdoc.value;
- }
- function setEditorStyle() {
- if(wysiwyg) {
- textobj.style.display = 'none';
- editbox.style.display = '';
- if(window.is_moz || window.is_opera) {
- for(var ss = 0; ss < document.styleSheets.length; ss++) {
- if(document.styleSheets[ss].cssRules.length <= 0) {
- continue;
- }
- for(var i = 0; i < document.styleSheets[ss].cssRules.length; i++) {
- if(document.styleSheets[ss].cssRules[i].selectorText == '.wysiwyg') {
- var newss = editdoc.createElement('style');
- newss.type = 'text/css';
- newss.innerHTML = document.styleSheets[ss].cssRules[i].cssText + ' p { margin: 0px; }';
- editdoc.documentElement.childNodes[0].appendChild(newss);
- editdoc.body.style.fontSize = document.styleSheets[ss].cssRules[i].style.fontSize;
- editdoc.body.style.fontFamily = document.styleSheets[ss].cssRules[i].style.fontFamily;
- }
- }
- }
- editbox.style.border = '0px';
- } else if(window.is_ie) {
- if(document.styleSheets['css']) {
- editdoc.createStyleSheet().cssText = document.styleSheets['css'].cssText + ' p { margin: 0px; }';
- editdoc.body.className = 'wysiwyg';
- }
- editdoc.body.style.border = '0px';
- }
- editbox.style.width = textobj.style.width;
- editbox.style.height = textobj.style.height;
- editdoc.body.style.background = '';
- editdoc.body.style.backgroundColor = '#FFFFFF';
- } else {
- var iframe = textobj.parentNode.getElementsByTagName('iframe')[0];
- if(iframe) {
- textobj.style.display = '';
- textobj.style.width = iframe.style.width;
- textobj.style.height = iframe.style.height;
- iframe.style.display = 'none';
- }
- }
- }
- function setEditorEvents() {
- if(wysiwyg) {
- if(window.is_moz || window.is_opera) {
- editdoc.addEventListener('mouseup', function(e) {setContext(); popupmenu.hide();}, true);
- editdoc.addEventListener('keyup', function(e) {setContext();}, true);
- editwin.addEventListener('focus', function(e) {this.hasfocus = true;}, true);
- editwin.addEventListener('blur', function(e) {this.hasfocus = false;}, true);
- //editwin.addEventListener('keydown', function(e) {ctlent(e);}, true);
- } else {
- editdoc.onmouseup = function(e) {setContext(); popupmenu.hide();};
- editdoc.onkeyup = function(e) {setContext();};
- if(editdoc.attachEvent) {
- //editdoc.body.attachEvent("onkeydown", ctlent);
- }
- }
- }
- editwin.onfocus = function(e) {this.hasfocus = true;};
- editwin.onblur = function(e) {this.hasfocus = false;};
- }
- function wrapTags(tagname, useoption, selection) {
- if(tagname=='code') {
- applyFormat('removeformat');
- }
- if(isUndefined(selection)) {
- var selection = getSel();
- if(selection === false) {
- selection = '';
- } else {
- selection += '';
- }
- }
- if(useoption === true) {
- var option = showPrompt(construct_phrase(lang['enter_tag_option'], ('[' + tagname + ']')), '');
- if(option = verifyPrompt(option)) {
- var opentag = '[' + tagname + '=' + option + ']';
- } else {
- return false;
- }
- } else if(useoption !== false) {
- var opentag = '[' + tagname + '=' + useoption + ']';
- } else {
- var opentag = '[' + tagname + ']';
- }
- var closetag = '[/' + tagname + ']';
- var text = opentag + selection + closetag;
- insertText(text, mb_strlen(opentag), mb_strlen(closetag));
- return false;
- }
- function applyFormat(cmd, dialog, argument) {
- if(wysiwyg) {
- editdoc.execCommand(cmd, (isUndefined(dialog) ? false : dialog), (isUndefined(argument) ? true : argument));
- return false;
- }
- switch(cmd) {
- case 'bold':
- case 'italic':
- case 'underline':
- wrapTags(cmd.substr(0, 1), false);
- break;
- case 'justifyleft':
- case 'justifycenter':
- case 'justifyright':
- wrapTags('align', cmd.substr(7));
- break;
- case 'indent':
- wrapTags(cmd, false);
- break;
- case 'fontname':
- wrapTags('font', argument);
- break;
- case 'fontsize':
- wrapTags('size', argument);
- break;
- case 'forecolor':
- wrapTags('color', argument);
- break;
- case 'createlink':
- var sel = getSel();
- if(sel) {
- wrapTags('url', argument);
- } else {
- wrapTags('url', argument, argument);
- }
- break;
- case 'insertimage':
- wrapTags('img', false, argument);
- break;
- }
- }
- function customTags(tagname, params) {
- applyFormat('removeformat');
- if(custombbcodes[tagname].indexOf(']') == -1) {
- custombbcodes[tagname] = '[' + tagname + '][/' + tagname + ']';
- }
- if(params == 1) {
- var selection = getSel();
- if(selection === false) {
- selection = '';
- } else {
- selection += '';
- }
- var opentag = '[' + tagname + ']';
- var closetag = '[/' + tagname + ']';
- var text = opentag + selection + closetag;
- selection == '' ? insertText(custombbcodes[tagname], mb_strlen('[' + tagname + ']'), mb_strlen('[/' + tagname + ']')) : insertText(text, mb_strlen(opentag), mb_strlen(closetag));
- } else {
- insertText(custombbcodes[tagname], custombbcodes[tagname].indexOf(']') + 1, mb_strlen('[/' + tagname + ']'));
- }
- return false;
- }
- function discuzcode(cmd, arg) {
- if(cmd != 'redo') {
- addSnapshot(getEditorContents());
- }
- checkFocus();
- if(in_array(cmd, ['quote', 'code'])) {
- var ret = wrapTags(cmd, false);
- } else if(cmd.substr(0, 6) == 'custom') {
- var ret = customTags(cmd.substr(8), cmd.substr(6, 1));
- } else if(!wysiwyg && cmd == 'removeformat') {
- var simplestrip = new Array('b', 'i', 'u');
- var complexstrip = new Array('font', 'color', 'size');
- var str = getSel();
- if(str === false) {
- return;
- }
- for(var tag in simplestrip) {
- str = stripSimple(simplestrip[tag], str);
- }
- for(var tag in complexstrip) {
- str = stripComplex(complexstrip[tag], str);
- }
- insertText(str);
- } else if(!wysiwyg && cmd == 'undo') {
- addSnapshot(getEditorContents());
- moveCursor(-1);
- if((str = getSnapshot()) !== false) {
- editdoc.value = str;
- }
- } else if(!wysiwyg && cmd == 'redo') {
- moveCursor(1);
- if((str = getSnapshot()) !== false) {
- editdoc.value = str;
- }
- } else if(!wysiwyg && in_array(cmd, ['insertorderedlist', 'insertunorderedlist'])) {
- var listtype = cmd == 'insertorderedlist' ? '1' : '';
- var opentag = '[list' + (listtype ? ('=' + listtype) : '') + ']/n';
- var closetag = '[/list]';
- if(txt = getSel()) {
- var regex = new RegExp('([/r/n]+|^[/r/n]*)(?!//[//*//]|//[///?list)(?=[^/r/n])', 'gi');
- txt = opentag + trim(txt).replace(regex, '$1[*]') + '/n' + closetag;
- insertText(txt, mb_strlen(txt), 0);
- } else {
- insertText(opentag + closetag, opentag.length, closetag.length);
- while(listvalue = prompt(lang['enter_list_item'], '')) {
- if(window.is_opera && opera.version() > 8) {
- listvalue = '/n' + '[*]' + listvalue;
- insertText(listvalue, mb_strlen(listvalue) + 1, 0);
- } else {
- listvalue = '[*]' + listvalue + '/n';
- insertText(listvalue, mb_strlen(listvalue), 0);
- }
- }
- }
- } else if(!wysiwyg && cmd == 'outdent') {
- var sel = getSel();
- sel = stripSimple('indent', sel, 1);
- insertText(sel);
- } else if(cmd == 'createlink') {
- if(wysiwyg) {
- if(window.is_moz || window.is_opera) {
- var url = showPrompt(lang['enter_link_url'], 'http://');
- if((url = verifyPrompt(url)) !== false) {
- if(getSel()) {
- applyFormat('unlink');
- applyFormat('createlink', window.is_ie, (isUndefined(url) ? true : url));
- } else {
- insertText('<a href="' + url + '">' + url + '</a>');
- }
- }
- } else {
- applyFormat('createlink', window.is_ie, (isUndefined(url) ? true : url));
- }
- } else {
- promptLink('url', lang['enter_link_url'], 'http://');
- }
- } else if(!wysiwyg && cmd == 'unlink') {
- var sel = getSel();
- sel = stripSimple('url', sel);
- sel = stripComplex('url', sel);
- insertText(sel);
- } else if(cmd == 'email') {
- if(wysiwyg) {
- var email = showPrompt(lang['enter_email_link'], '');
- email = verifyPrompt(email);
- if(email === false) {
- applyFormat('unlink');
- } else {
- var selection = getSel();
- insertText('<a href="mailto:' + email + '">' + (selection ? selection : email) + '</a>', (selection ? true : false));
- }
- } else {
- promptLink('email', lang['enter_email_link'], '');
- }
- } else if(cmd == 'insertimage') {
- var img = showPrompt(lang['enter_image_url'], 'http://');
- if(img = verifyPrompt(img)) {
- return applyFormat('insertimage', false, img);
- } else {
- return false;
- }
- } else if(cmd == 'table') {
- if(wysiwyg) {
- if(isUndefined(rows)) {
- var rows = showPrompt(lang['enter_table_rows'], '2');
- }
- if(rows != 'null' && isUndefined(columns)) {
- var columns = showPrompt(lang['enter_table_columns'], '2');
- }
- if(!isUndefined(columns) && columns != 'null') {
- rows = /^[-/+]?/d+$/.test(rows) && rows > 0 && rows <= 30 ? rows : 2;
- columns = /^[-/+]?/d+$/.test(columns) && columns > 0 && columns <= 30 ? columns : 2;
- var html = '<table cellspacing="1" cellpadding="4" width="50%" align="center" style="background: ' + BORDERCOLOR + '">';
- for (var row = 0; row < rows; row++) {
- html += '<tr bgcolor="' + ALTBG2 + '">/n';
- for (col = 0; col < columns; col++) {
- html += '<td> </td>/n';
- }
- html+= '</tr>/n';
- }
- html += '</table>/n';
- insertText(html);
- }
- }
- return false;
- } else {
- var ret = applyFormat(cmd, false, (isUndefined(arg) ? true : arg));
- }
- if(cmd != 'undo') {
- addSnapshot(getEditorContents());
- }
- if(wysiwyg) {
- setContext(cmd);
- if(cmd == 'forecolor') {
- $(editorid + '_color_bar').style.backgroundColor = arg;
- }
- }
- checkFocus();
- return ret;
- }
- function setContext(cmd) {
- var contextcontrols = new Array('bold', 'italic', 'underline', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist', 'insertunorderedlist');
- for(var i in contextcontrols) {
- var obj = $(editorid + '_cmd_' + contextcontrols[i]);
- if(obj != null) {
- try {
- var state = editdoc.queryCommandState(contextcontrols[i]);
- } catch(e) {
- var state = false;
- }
- if(isUndefined(obj.state)) {
- obj.state = false;
- }
- if(obj.state != state) {
- obj.state = state;
- buttonContext(obj, (obj.id.substr(obj.id.indexOf('_cmd_') + 5) == cmd ? 'mouseover' : 'mouseout'));
- }
- }
- }
- var fs = editdoc.queryCommandValue('fontname');
- if(fs == '' && !window.is_ie && getComputedStyle) {
- fs = editdoc.body.style.fontFamily;
- } else if(fs == null) {
- fs = '';
- }
- if(fs != $(editorid + '_font_out').fontstate) {
- thingy = fs.indexOf(',') > 0 ? fs.substr(0, fs.indexOf(',')) : fs;
- $(editorid + '_font_out').innerHTML = thingy;
- $(editorid + '_font_out').fontstate = fs;
- }
- var ss = editdoc.queryCommandValue('fontsize');
- if(ss == null || ss == '') {
- ss = formatFontsize(editdoc.body.style.fontSize);
- }
- if(ss != $(editorid + '_size_out').sizestate) {
- if($(editorid + '_size_out').sizestate == null) {
- $(editorid + '_size_out').sizestate = '';
- }
- $(editorid + '_size_out').innerHTML = ss;
- $(editorid + '_size_out').sizestate = ss;
- }
- var cs = editdoc.queryCommandValue('forecolor');
- $(editorid + '_color_bar').style.backgroundColor = rgbToColor(cs);
- }
- function buttonContext(obj, state) {
- if(state == 'mouseover') {
- var mode = obj.state ? 'down' : 'hover';
- if(obj.mode != mode) {
- obj.mode = mode;
- obj.className = 'editor_button' + mode;
- }
- } else {
- var mode = obj.state ? 'selected' : 'normal';
- if(obj.mode != mode) {
- obj.mode = mode;
- obj.className = mode == 'selected' ? 'editor_buttonselected' : 'editor_button' + 'normal';
- }
- }
- if(window.is_ie && event) {
- event.cancelBubble = true;
- }
- }
- function menuContext(obj, state) {
- obj.style.cursor = window.is_ie ? 'hand' : 'pointer';
- var mode = state == 'mouseover' ? 'hover' : 'normal';
- obj.className = 'editor_button' + mode;
- var tds = findtags(obj, 'td');
- for(var i = 0; i < tds.length; i++) {
- if(tds[i].id == editorid + '_menu') {
- tds[i].className = 'editor_menu' + mode;
- } else if(tds[i].id == editorid + '_colormenu') {
- tds[i].className = 'editor_colormenu' + mode;
- }
- }
- }
- function colorContext(obj, state) {
- obj.style.cursor = window.is_ie ? 'hand' : 'pointer';
- var mode = state == 'mouseover' ? 'hover' : 'normal';
- obj.className = 'editor_color' + mode;
- }
- function getSel() {
- if(wysiwyg) {
- if(window.is_moz || window.is_opera) {
- selection = editwin.getSelection();
- checkFocus();
- range = selection ? selection.getRangeAt(0) : editdoc.createRange();
- return readNodes(range.cloneContents(), false);
- } else {
- var range = editdoc.selection.createRange();
- if(range.htmlText && range.text) {
- return range.htmlText;
- } else {
- var htmltext = '';
- for(var i = 0; i < range.length; i++) {
- htmltext += range.item(i).outerHTML;
- }
- return htmltext;
- }
- }
- } else {
- if(!isUndefined(editdoc.selectionStart)) {
- return editdoc.value.substr(editdoc.selectionStart, editdoc.selectionEnd - editdoc.selectionStart);
- } else if(document.selection && document.selection.createRange) {
- return document.selection.createRange().text;
- } else if(getSelection) {
- return getSelection() + '';
- } else {
- return false;
- }
- }
- }
- function insertText(text, movestart, moveend) {
- if(wysiwyg) {
- if(window.is_moz || window.is_opera) {
- var fragment = editdoc.createDocumentFragment();
- var holder = editdoc.createElement('span');
- holder.innerHTML = text;
- while(holder.firstChild) {
- fragment.appendChild(holder.firstChild);
- }
- insertNodeAtSelection(fragment);
- } else {
- checkFocus();
- if(!isUndefined(editdoc.selection) && editdoc.selection.type != 'Text' && editdoc.selection.type != 'None') {
- movestart = false;
- editdoc.selection.clear();
- }
- var sel = editdoc.selection.createRange();
- sel.pasteHTML(text);
- if(text.indexOf('/n') == -1) {
- if(!isUndefined(movestart)) {
- sel.moveStart('character', -mb_strlen(text) +movestart);
- sel.moveEnd('character', -moveend);
- } else if(movestart != false) {
- sel.moveStart('character', -mb_strlen(text));
- }
- }
- }
- } else {
- checkFocus();
- if(!isUndefined(editdoc.selectionStart)) {
- var opn = editdoc.selectionStart + 0;
- editdoc.value = editdoc.value.substr(0, editdoc.selectionStart) + text + editdoc.value.substr(editdoc.selectionEnd);
- if(!isUndefined(movestart)) {
- editdoc.selectionStart = opn + movestart;
- editdoc.selectionEnd = opn + mb_strlen(text) - moveend;
- } else if(movestart !== false) {
- editdoc.selectionStart = opn;
- editdoc.selectionEnd = opn + mb_strlen(text);
- }
- } else if(document.selection && document.selection.createRange) {
- var sel = document.selection.createRange();
- sel.text = text.replace(//r?/n/g, '/r/n');
- if(!isUndefined(movestart)) {
- sel.moveStart('character', -mb_strlen(text) +movestart);
- sel.moveEnd('character', -moveend);
- } else if(movestart !== false) {
- sel.moveStart('character', -mb_strlen(text));
- }
- sel.select();
- } else {
- editdoc.value += text;
- }
- }
- }
- function isUndefined(variable) {
- return typeof variable == 'undefined' ? true : false;
- }
- function showPrompt(dialogtxt, defaultval) {
- return trim(prompt(dialogtxt, defaultval) + '');
- }
- function verifyPrompt(str) {
- if(in_array(str, ['http://', 'null', 'undefined', 'false', '']) || str == null || str == false) {
- return false;
- } else {
- return str;
- }
- }
- function promptLink(tagname, phrase, iprompt) {
- var value = showPrompt(phrase, iprompt);
- if((value = verifyPrompt(value)) !== false) {
- if(getSel()) {
- applyFormat('unlink');
- wrapTags(tagname, value);
- } else {
- wrapTags(tagname, value, value);
- }
- }
- return true;
- }
- function trim(str) {
- return (str.replace(/(/s+)$/g, '')).replace(/^/s+/g, '');
- }
- function stripSimple(tag, str, iterations) {
- var opentag = '[' + tag + ']';
- var closetag = '[/' + tag + ']';
- if(isUndefined(iterations)) {
- iterations = -1;
- }
- while((startindex = stripos(str, opentag)) !== false && iterations != 0) {
- iterations --;
- if((stopindex = stripos(str, closetag)) !== false) {
- var text = str.substr(startindex + opentag.length, stopindex - startindex - opentag.length);
- str = str.substr(0, startindex) + text + str.substr(stopindex + closetag.length);
- } else {
- break;
- }
- }
- return str;
- }
- function stripComplex(tag, str, iterations) {
- var opentag = '[' + tag + '=';
- var closetag = '[/' + tag + ']';
- if(isUndefined(iterations)) {
- iterations = -1;
- }
- while((startindex = stripos(str, opentag)) !== false && iterations != 0) {
- iterations --;
- if((stopindex = stripos(str, closetag)) !== false) {
- var openend = stripos(str, ']', startindex);
- if(openend !== false && openend > startindex && openend < stopindex) {
- var text = str.substr(openend + 1, stopindex - openend - 1);
- str = str.substr(0, startindex) + text + str.substr(stopindex + closetag.length);
- } else {
- break;
- }
- } else {
- break;
- }
- }
- return str;
- }
- function stripos(haystack, needle, offset) {
- if(isUndefined(offset)) {
- offset = 0;
- }
- var index = haystack.toLowerCase().indexOf(needle.toLowerCase(), offset);
- return (index == -1 ? false : index);
- }
- function switchEditor(mode) {
- mode = parseInt(mode);
- if(mode == wysiwyg || !allowswitcheditor) {
- return;
- }
- if(!mode) {
- var controlbar = $(editorid + '_controls');
- var controls = new Array();
- var buttons = findtags(controlbar, 'div');
- var buttonslength = buttons.length;
- for(var i = 0; i < buttonslength; i++) {
- if(buttons[i].id) {
- controls[controls.length] = buttons[i].id;
- }
- }
- var controlslength = controls.length;
- for(var i = 0; i < controlslength; i++) {
- var control = $(controls[i]);
- if(control.id.indexOf(editorid + '_cmd_') != -1) {
- control.className = 'editor_buttonnormal';
- control.state = false;
- control.mode = 'normal';
- } else if(control.id.indexOf(editorid + '_popup_') != -1) {
- control.state = false;
- }
- }
- }
- cursor = -1;
- stack = new Array();
- $(editorid + '_font_out').innerHTML = lang['fontname'];
- $(editorid + '_size_out').innerHTML = lang['fontsize'];
- $(editorid + '_font_out').fontstate = null;
- $(editorid + '_size_out').sizestate = null;
- $(editorid + '_color_bar').style.backgroundColor = '#000000';
- var parsedtext = getEditorContents();
- parsedtext = mode ? bbcode2html(parsedtext) : html2bbcode(parsedtext);
- wysiwyg = mode;
- $(editorid + '_mode').value = mode;
- newEditor(mode, parsedtext);
- checkFocus();
- }
- function formatFontsize(csssize) {
- switch(csssize) {
- case '7.5pt':
- case '10px': return 1;
- case '10pt': return 2;
- case '12pt': return 3;
- case '14pt': return 4;
- case '18pt': return 5;
- case '24pt': return 6;
- case '36pt': return 7;
- default: return lang['fontsize'];
- }
- }
- function rgbToColor(forecolor) {
- if(!window.is_moz && !window.is_opera) {
- return rgbhexToColor((forecolor & 0xFF).toString(16), ((forecolor >> 8) & 0xFF).toString(16), ((forecolor >> 16) & 0xFF).toString(16));
- }
- if(forecolor == '' || forecolor == null) {
- forecolor = getComputedStyle(editdoc.body, null).getPropertyValue('color');
- }
- if(forecolor.toLowerCase().indexOf('rgb') == 0) {
- var matches = forecolor.match(/^rgb/s*/(([0-9]+),/s*([0-9]+),/s*([0-9]+)/)$/);
- if(matches) {
- return rgbhexToColor((matches[1] & 0xFF).toString(16), (matches[2] & 0xFF).toString(16), (matches[3] & 0xFF).toString(16));
- } else {
- return rgbToColor(null);
- }
- } else {
- return forecolor;
- }
- }
- function rgbhexToColor(r, g, b) {
- var coloroptions = {'#000000' : 'Black', '#a0522d' : 'Sienna', '#556b2f' : 'DarkOliveGreen', '#006400' : 'DarkGreen', '#483d8b' : 'DarkSlateBlue', '#000080' : 'Navy', '#4b0082' : 'Indigo', '#2f4f4f' : 'DarkSlateGray', '#8b0000' : 'DarkRed', '#ff8c00' : 'DarkOrange', '#808000' : 'Olive', '#008000' : 'Green', '#008080' : 'Teal', '#0000ff' : 'Blue', '#708090' : 'SlateGray', '#696969' : 'DimGray', '#ff0000' : 'Red', '#f4a460' : 'SandyBrown', '#9acd32' : 'YellowGreen', '#2e8b57' : 'SeaGreen', '#48d1cc' : 'MediumTurquoise', '#4169e1' : 'RoyalBlue', '#800080' : 'Purple', '#808080' : 'Gray', '#ff00ff' : 'Magenta', '#ffa500' : 'Orange', '#ffff00' : 'Yellow', '#00ff00' : 'Lime', '#00ffff' : 'Cyan', '#00bfff' : 'DeepSkyBlue', '#9932cc' : 'DarkOrchid', '#c0c0c0' : 'Silver', '#ffc0cb' : 'Pink', '#f5deb3' : 'Wheat', '#fffacd' : 'LemonChiffon', '#98fb98' : 'PaleGreen', '#afeeee' : 'PaleTurquoise', '#add8e6' : 'LightBlue', '#dda0dd' : 'Plum', '#ffffff' : 'White'};
- return coloroptions['#' + (str_pad(r, 2, 0) + str_pad(g, 2, 0) + str_pad(b, 2, 0))];
- }
- function str_pad(text, length, padstring) {
- text += '';
- padstring += '';
- if(text.length < length) {
- padtext = padstring;
- while(padtext.length < (length - text.length)) {
- padtext += padstring;
- }
- text = padtext.substr(0, (length - text.length)) + text;
- }
- return text;
- }
- function insertNodeAtSelection(text) {
- checkFocus();
- var sel = editwin.getSelection();
- var range = sel ? sel.getRangeAt(0) : editdoc.createRange();
- sel.removeAllRanges();
- range.deleteContents();
- var node = range.startContainer;
- var pos = range.startOffset;
- switch(node.nodeType) {
- case Node.ELEMENT_NODE:
- if(text.nodeType == Node.DOCUMENT_FRAGMENT_NODE) {
- selNode = text.firstChild;
- } else {
- selNode = text;
- }
- node.insertBefore(text, node.childNodes[pos]);
- add_range(selNode);
- break;
- case Node.TEXT_NODE:
- if(text.nodeType == Node.TEXT_NODE) {
- var text_length = pos + text.length;
- node.insertData(pos, text.data);
- range = editdoc.createRange();
- range.setEnd(node, text_length);
- range.setStart(node, text_length);
- sel.addRange(range);
- } else {
- node = node.splitText(pos);
- var selNode;
- if(text.nodeType == Node.DOCUMENT_FRAGMENT_NODE) {
- selNode = text.firstChild;
- } else {
- selNode = text;
- }
- node.parentNode.insertBefore(text, node);
- add_range(selNode);
- }
- break;
- }
- }
- function add_range(node) {
- checkFocus();
- var sel = editwin.getSelection();
- var range = editdoc.createRange();
- range.selectNodeContents(node);
- sel.removeAllRanges();
- sel.addRange(range);
- }
- function readNodes(root, toptag) {
- var html = "";
- var moz_check = /_moz/i;
- switch(root.nodeType) {
- case Node.ELEMENT_NODE:
- case Node.DOCUMENT_FRAGMENT_NODE:
- var closed;
- if(toptag) {
- closed = !root.hasChildNodes();
- html = '<' + root.tagName.toLowerCase();
- var attr = root.attributes;
- for(var i = 0; i < attr.length; ++i) {
- var a = attr.item(i);
- if(!a.specified || a.name.match(moz_check) || a.value.match(moz_check)) {
- continue;
- }
- html += " " + a.name.toLowerCase() + '="' + a.value + '"';
- }
- html += closed ? " />" : ">";
- }
- for(var i = root.firstChild; i; i = i.nextSibling) {
- html += readNodes(i, true);
- }
- if(toptag && !closed) {
- html += "</" + root.tagName.toLowerCase() + ">";
- }
- break;
- case Node.TEXT_NODE:
- html = htmlspecialchars(root.data);
- break;
- }
- return html;
- }
- function moveCursor(increment) {
- var test = cursor + increment;
- if(test >= 0 && stack[test] != null && !isUndefined(stack[test])) {
- cursor += increment;
- }
- }
- function addSnapshot(str) {
- if(stack[cursor] == str) {
- return;
- } else {
- cursor++;
- stack[cursor] = str;
- if(!isUndefined(stack[cursor + 1])) {
- stack[cursor + 1] = null;
- }
- }
- }
- function getSnapshot() {
- if(!isUndefined(stack[cursor]) && stack[cursor] != null) {
- return stack[cursor];
- } else {
- return false;
- }
- }
menu.js
- /******************************************************************************
- Crossday Discuz! Board - Floating Advertisements for Discuz!
- Copyright 2001-2006 Comsenz Inc. (http://www.comsenz.com)
- *******************************************************************************/
- var menuslidetimer = null;
- function Popup_Handler() {
- this.open_steps = 2;
- this.open_fade = false;
- this.active = false;
- this.menus = new Array();
- this.activemenu = null;
- this.hidden_selects = new Array();
- this.activate = function(active) {
- this.active = active;
- }
- this.register = function(clickactive, controlkey, noimage) {
- this.menus[controlkey] = new Popup_Menu(clickactive, controlkey, noimage);
- return this.menus[controlkey];
- }
- this.hide = function() {
- if(this.activemenu != null) this.menus[this.activemenu].hide();
- }
- }
- function Popup_Events() {
- this.controlobj_show = function(e) {
- doane(e);
- clearTimeout(this.slidetimer);
- if(popupmenu.activemenu == null || popupmenu.menus[popupmenu.activemenu].controlkey != this.id) {popupmenu.menus[this.id].show(this, false, popupmenu.menus[this.id].clickactive);}
- }
- this.controlobj_onclick = function(e) {
- doane(e);
- if(popupmenu.activemenu == null || popupmenu.menus[popupmenu.activemenu].controlkey != this.id) {popupmenu.menus[this.id].show(this, false, popupmenu.menus[this.id].clickactive);}
- else {popupmenu.menus[this.id].hide();}
- }
- this.controlobj_onmouseover = function(e) {
- doane(e);
- popupmenu.menus[this.id].hover(this);
- }
- this.menuoption_onclick_function = function(e) {
- this.ofunc(e);
- popupmenu.menus[this.controlkey].hide();
- }
- this.menuoption_onclick_link = function(e) {
- popupmenu.menus[this.controlkey].choose(e, this);
- }
- this.menuoption_onmouseover = function(e) {
- this.className = 'popupmenu_highlight';
- }
- this.menuoption_onmouseout = function(e) {
- this.className = 'popupmenu_option';
- }
- }
- popupmenu = new Popup_Handler();
- popupevents = new Popup_Events();
- function popupmenu_hide(e) {
- if(e && e.button && e.button != 1 && e.type == 'click') return true;
- else popupmenu.hide();
- }
- function Popup_Menu(clickactive, controlkey, noimage) {
- this.controlkey = controlkey;
- this.clickactive = clickactive;
- this.menuname = this.controlkey.split('.')[0] + '_menu';
- if($(this.menuname)) {this.init_menu(clickactive);}
- this.slide_open = (window.is_opera ? false : true);
- this.open_steps = popupmenu.open_steps;
- this.init_control = function(noimage) {
- this.controlobj = $(this.controlkey);
- this.controlobj.state = false;
- if(this.controlobj.firstChild && (this.controlobj.firstChild.tagName == 'TEXTAREA' || this.controlobj.firstChild.tagName == 'INPUT')) {
- } else {
- if(!this.clickactive && !noimage && !(is_mac && window.is_ie)) {
- var img = document.createElement('img');
- img.src = 'images/common/jsmenu.gif';
- img.border = 0;
- img.title = '';
- img.alt = '';
- this.controlobj.appendChild(img);
- }
- this.controlobj.unselectable = true;
- if(!noimage) {
- this.controlobj.style.cursor = window.is_ie ? 'hand' : 'pointer';
- }
- if(clickactive) {
- this.controlobj.onclick = popupevents.controlobj_onclick;
- this.controlobj.onmouseover = popupevents.controlobj_onmouseover;
- } else {
- this.controlobj.onmouseover = popupevents.controlobj_show;
- }
- }
- }
- this.init_control( noimage);
- this.init_menu = function() {
- this.menuobj = $(this.menuname);
- if(this.menuobj && !this.menuobj.initialized) {
- this.menuobj.initialized = true;
- this.menuobj.onclick = ebygum;
- this.menuobj.style.position = 'absolute';
- if(!this.clickactive) {
- this.menuobj.onmouseover = function() {
- clearTimeout(menuslidetimer);
- }
- this.menuobj.onmouseout = function() {
- menuslidetimer = setTimeout("menuhide()",500);
- }
- }
- this.menuobj.style.zIndex = 50;
- if(window.is_ie && !is_mac) {
- this.menuobj.style.filter += "progid:DXImageTransform.Microsoft.shadow(direction=135,color=#CCCCCC,strength=2)";
- }
- this.init_menu_contents();
- }
- }
- this.init_menu_contents = function() {
- var tds = findtags(this.menuobj, 'td');
- for(var i = 0; i < tds.length; i++) {
- if(tds[i].className == 'popupmenu_option' || tds[i].className == 'editor_colornormal') {
- if(window.is_ie && !is_mac) {
- tds[i].style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity=85,finishOpacity=100,style=0)";
- }
- tds[i].style.opacity = 0.85;
- if(tds[i].title && tds[i].title == 'nohighlight') {
- tds[i].title = '';
- } else {
- tds[i].controlkey = this.controlkey;
- if(tds[i].className != 'editor_colornormal') {
- tds[i].onmouseover = popupevents.menuoption_onmouseover;
- tds[i].onmouseout = popupevents.menuoption_onmouseout;
- }
- if(typeof tds[i].onclick == 'function') {
- tds[i].ofunc = tds[i].onclick;
- tds[i].onclick = popupevents.menuoption_onclick_function;
- } else {
- tds[i].onclick = popupevents.menuoption_onclick_link;
- }
- if(!is_saf && !is_kon) {
- try {
- links = findtags(tds[i], 'a');
- for(var j = 0; j < links.length; j++) {
- if(typeof links[j].onclick == 'undefined') links[j].onclick = ebygum;
- }
- }
- catch(e) {}
- }
- }
- }
- }
- }
- this.show = function(obj, instant) {
- if(!popupmenu.active){return false;}
- else if(!this.menuobj) {this.init_menu();}
- if(!this.menuobj) {return false;}
- if(popupmenu.activemenu != null) {popupmenu.menus[popupmenu.activemenu].hide();}
- popupmenu.activemenu = this.controlkey;
- this.menuobj.style.display = '';
- if(popupmenu.slide_open) {this.menuobj.style.clip = 'rect(auto, auto, auto, auto)';}
- this.pos = this.fetch_offset(obj);
- this.leftpx = this.pos['left'];
- this.toppx = this.pos['top'] + obj.offsetHeight;
- if((this.leftpx + this.menuobj.offsetWidth) >= document.body.clientWidth && (this.leftpx + obj.offsetWidth - this.menuobj.offsetWidth) > 0) {
- this.leftpx = this.leftpx + obj.offsetWidth - this.menuobj.offsetWidth;
- this.direction = 'right';
- } else {this.direction = 'left';}
- this.menuobj.style.left = this.leftpx + 'px';
- this.menuobj.style.top = this.toppx + 'px';
- if(!instant && this.slide_open) {
- this.intervalX = Math.ceil(this.menuobj.offsetWidth / this.open_steps);
- this.intervalY = Math.ceil(this.menuobj.offsetHeight / this.open_steps);
- this.slide((this.direction == 'left' ? 0 : this.menuobj.offsetWidth), 0, 0);
- } else if(this.menuobj.style.clip && popupmenu.slide_open) {
- this.menuobj.style.clip = 'rect(auto, auto, auto, auto)';
- }
- this.handle_overlaps(true);
- if(this.menuobj.scrollHeight > 400) {
- this.menuobj.style.height = '400px';
- if(window.is_ie || window.is_opera) {
- this.menuobj.style.width = this.menuobj.scrollWidth + 18;
- }
- if(window.is_opera) {
- this.menuobj.style.overflow = 'scroll';
- } else {
- this.menuobj.style.overflowY = 'scroll';
- }
- }
- }
- this.hide = function(e) {
- if(e && e.button && e.button != 1) {return true;}
- this.stop_slide();
- this.menuobj.style.display = 'none';
- this.handle_overlaps(false);
- popupmenu.activemenu = null;
- }
- this.slidehide = function() {
- popupmenu.menus[popupmenu.activemenu].hide()
- }
- this.hover = function(obj, clickactive) {
- if(popupmenu.activemenu != null) {
- if(popupmenu.menus[popupmenu.activemenu].controlkey != this.id) {this.show(obj, true, clickactive);}
- }
- }
- this.choose = function(e, obj) {
- var links = findtags(obj, 'a');
- if(links[0]) {
- if(window.is_ie) {
- links[0].click();
- window.event.cancelBubble = true;
- } else {
- if(e.shiftKey) {
- window.open(links[0].href);
- e.stopPropagation();
- e.preventDefault();
- } else {
- window.location = links[0].href;
- e.stopPropagation();
- e.preventDefault();
- }
- }
- this.hide();
- }
- }
- this.slide = function(clipX, clipY, opacity) {
- if(this.direction == 'left' && (clipX < this.menuobj.offsetWidth || clipY < this.menuobj.offsetHeight)) {
- if(popupmenu.open_fade && window.is_ie) {
- opacity += 10;
- this.menuobj.filters.item('DXImageTransform.Microsoft.alpha').opacity = opacity;
- }
- clipX += this.intervalX;
- clipY += this.intervalY;
- this.menuobj.style.clip = "rect(auto, " + clipX + "px, " + clipY + "px, auto)";
- this.slidetimer = setTimeout("popupmenu.menus[popupmenu.activemenu].slide(" + clipX + ", " + clipY + ", " + opacity + ");", 0);
- } else if(this.direction == 'right' && (clipX > 0 || clipY < this.menuobj.offsetHeight)) {
- if(popupmenu.open_fade && window.is_ie) {
- opacity += 10;
- menuobj.filters.item('DXImageTransform.Microsoft.alpha').opacity = opacity;
- }
- clipX -= this.intervalX;
- clipY += this.intervalY;
- this.menuobj.style.clip = "rect(auto, " + this.menuobj.offsetWidth + "px, " + clipY + "px, " + clipX + "px)";
- this.slidetimer = setTimeout("popupmenu.menus[popupmenu.activemenu].slide(" + clipX + ", " + clipY + ", " + opacity + ");", 0);
- } else {this.stop_slide();}
- }
- this.stop_slide = function() {
- clearTimeout(this.slidetimer);
- this.menuobj.style.clip = 'rect(auto, auto, auto, auto)';
- if(popupmenu.open_fade && window.is_ie) {this.menuobj.filters.item('DXImageTransform.Microsoft.alpha').opacity = 100;}
- }
- this.fetch_offset = function(obj) {
- var left_offset = obj.offsetLeft;
- var top_offset = obj.offsetTop;
- while ((obj = obj.offsetParent) != null) {
- left_offset += obj.offsetLeft;
- top_offset += obj.offsetTop;
- }
- return { 'left' : left_offset, 'top' : top_offset };
- }
- this.overlaps = function(obj, m) {
- var s = new Array();
- var pos = this.fetch_offset(obj);
- s['L'] = pos['left'];
- s['T'] = pos['top'];
- s['R'] = s['L'] + obj.offsetWidth;
- s['B'] = s['T'] + obj.offsetHeight;
- if(s['L'] > m['R'] || s['R'] < m['L'] || s['T'] > m['B'] || s['B'] < m['T']) {return false;}
- return true;
- }
- this.handle_overlaps = function(dohide) {
- if(window.is_ie) {
- var selects = findtags(document, 'select');
- if(dohide) {
- var menuarea = new Array(); menuarea = {
- 'L' : this.leftpx,
- 'R' : this.leftpx + this.menuobj.offsetWidth,
- 'T' : this.toppx,
- 'B' : this.toppx + this.menuobj.offsetHeight
- };
- for(var i = 0; i < selects.length; i++) {
- if(this.overlaps(selects[i], menuarea)) {
- var hide = true;
- var s = selects[i];
- while (s = s.parentNode) {
- if(s.className == 'popupmenu_popup') {
- hide = false;
- break;
- }
- }
- if(hide) {
- selects[i].style.visibility = 'hidden';
- arraypush(popupmenu.hidden_selects, i);
- }
- }
- }
- } else {
- while (true) {
- var i = arraypop(popupmenu.hidden_selects);
- if(typeof i == 'undefined' || i == null) break;
- else selects[i].style.visibility = 'visible';
- }
- }
- }
- }
- }
- function doane(eventobj) {
- if(!eventobj || window.is_ie) {
- window.event.returnValue = false;
- window.event.cancelBubble = true;
- return window.event;
- } else {
- eventobj.stopPropagation();
- eventobj.preventDefault();
- return eventobj;
- }
- }
- function ebygum(eventobj) {
- if(!eventobj || window.is_ie) {
- window.event.cancelBubble = true;
- return window.event;
- } else {
- if(eventobj.target.type == 'submit') eventobj.target.form.submit();
- eventobj.stopPropagation();
- return eventobj;
- }
- }
- function menuregister(clickactive, controlid, noimage, datefield) {
- if(typeof popupmenu == 'object') {
- popupmenu.register(clickactive, controlid, noimage);
- }
- }
- function menuhide() {
- if(popupmenu.activemenu != null) {
- popupmenu.menus[popupmenu.activemenu].slidehide();
- }
- }
- if(typeof popupmenu == 'object') {
- if(window.attachEvent && !is_saf) {
- document.attachEvent('onclick', popupmenu_hide);
- window.attachEvent('onresize', popupmenu_hide);
- } else if(document.addEventListener && !window.is_saf) {
- document.addEventListener('click', popupmenu_hide, false);
- window.addEventListener('resize', popupmenu_hide, false);
- } else {
- window.onclick = popupmenu_hide;
- window.onresize = popupmenu_hide;
- }
- popupmenu.activate(true);
- }
4.新建edit.jsp
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
<title>UBB编辑器</title>
<link rel="stylesheet" type="text/css" id="css" href="Images/ubb.css">
<script language ="javascript" type="text/javascript" src="Images/common.js"></script>
<script language ="javascript" type="text/javascript" src="Images/menu.js"></script>
<script language ="javascript" type="text/javascript" src="Images/bbcode.js"></script>
<script language ="javascript" type="text/javascript" src="Images/editor.js"></script>
</head>
<body οnkeydοwn="if(event.keyCode==27) return false;">
<script type="text/javascript">
var postminchars = parseInt('0');
var postmaxchars = parseInt('100000');
var disablepostctrl = parseInt('0');
var typerequired = parseInt('');
var bbinsert = parseInt('0');
function checklength() {
var message = bbinsert && wysiwyg ? html2bbcode(getEditorContents()) : $("posteditor_textarea").value;
var showmessage = postmaxchars != 0 ? '系统限制: ' + postminchars + ' 到 ' + postmaxchars + ' 字节' : '';
alert('/n当前长度: ' + message.length + ' 字节/n/n' + showmessage);
}
</script>
<div class="spaceborder" style="width: 100%" >
<table cellspacing="0" cellpadding="4" width="100%">
<tr class="bottom">
<td align="left" class="altbg2" valign="top">
<div id="posteditor">
<script type="text/javascript">
var editorid = 'posteditor';
var wysiwyg = (window.is_ie || window.is_moz || (window.is_opera && opera.version() >= 9)) && parseInt('1') && bbinsert == 1 ? 1 : 0;
var allowswitcheditor = parseInt('1');
var allowhtml = parseInt('0');
var forumallowhtml = parseInt('0');
var allowsmilies = parseInt('1');
var allowbbcode = parseInt('1');
var allowimgcode = parseInt('1');
var smilies = new Array();
smilies[1]= {'code' : ':)', 'url' : 'em01.gif'};
smilies[2]= {'code' : ':(', 'url' : 'em02.gif'};
smilies[3]= {'code' : ':D', 'url' : 'em03.gif'};
smilies[4]= {'code' : ':/'(', 'url' : 'em04.gif'};
smilies[5]= {'code' : ':@', 'url' : 'em05.gif'};
smilies[6]= {'code' : ':o', 'url' : 'em06.gif'};
smilies[7]= {'code' : ':P', 'url' : 'em07.gif'};
smilies[8]= {'code' : ':$', 'url' : 'em08.gif'};
smilies[9]= {'code' : ';P', 'url' : 'em09.gif'};
smilies[10]= {'code' : ':L', 'url' : 'em10.gif'};
smilies[11]= {'code' : ':Q', 'url' : 'em11.gif'};
smilies[12]= {'code' : ':lol', 'url' : 'em12.gif'};
smilies[13]= {'code' : ':hug:', 'url' : 'em13.gif'};
smilies[14]= {'code' : ':victory:', 'url' : 'em14.gif'};
smilies[15]= {'code' : ':time:', 'url' : 'em15.gif'};
smilies[16]= {'code' : ':kiss:', 'url' : 'em16.gif'};
smilies[17]= {'code' : ':handshake', 'url' : 'em17.gif'};
smilies[18]= {'code' : ':call:', 'url' : 'em18.gif'};
smilies[33]= {'code' : ':calld:', 'url' : 'em24.gif'};
smilies[32]= {'code' : ':callc:', 'url' : 'em23.gif'};
smilies[31]= {'code' : ':callb:', 'url' : 'em22.gif'};
smilies[30]= {'code' : ':calla:', 'url' : 'em21.gif'};
smilies[28]= {'code' : ':loveliness:', 'url' : 'em19.gif'};
smilies[29]= {'code' : ':funk:', 'url' : 'em20.gif'};
smilies[34]= {'code' : ':calle:', 'url' : 'em25.gif'};
var BORDERCOLOR = "#7AC4EA";
var ALTBG2 = "#FFFFFF";
function clearcontent() {
if(wysiwyg && bbinsert) {
editdoc.body.innerHTML = is_moz ? '<br />' : '';
} else {
textobj.value = '';
}
}
function resizeEditor(change) {
var editorbox = bbinsert ? editbox : textobj;
var newheight = parseInt(editorbox.style.height, 10) + change;
var newTopheight=parseInt(top.document.getElementById('Editor').style.height,10)+ change;
if(newheight >= 100) {
editorbox.style.height = newheight + 'px';
top.document.getElementById('Editor').style.height = newTopheight + 'px';
}
}
var oURL = location.href;
var offset = oURL.lastIndexOf("id=");
if (offset == -1)
{
alert("请传入调用参数ID,即隐藏的内容表单项ID!");
} else {
offset = offset + 3
}
var sLinkFieldName = oURL.substring(offset)
var oLinkField = parent.document.getElementsByName(sLinkFieldName)[0];
var oForm = oLinkField.form;
// 设置所属表单的提交或reset事件
function setLinkedField() {
if (! oLinkField) return ;
var oForm = oLinkField.form ;
if (!oForm) return ;
if(oForm.addEventListener){
oForm.addEventListener("onsubmit", AttachSubmit);
oForm.addEventListener("onreset", AttachReset);
}else{
oForm.attachEvent("onsubmit", AttachSubmit);
oForm.attachEvent("onreset", AttachReset);
}
AttachReset();
}
// 提交表单
function AttachSubmit() {
if(wysiwyg==0)oLinkField.value=$("posteditor_textarea").value;
else oLinkField.value=html2bbcode(getEditorContents());
showCustomer("ubb");
}
// 附加Reset事件
function AttachReset() {
if(wysiwyg==0)$("posteditor_textarea").value="";
else editdoc.body.innerHTML="";
if (oLinkField.value!=""){
if(wysiwyg==0)$("posteditor_textarea").value=oLinkField.value;
else editdoc.body.innerHTML=bbcode2html(oLinkField.value);
}
}
function attachObjEvent(object, eventName, functionName)
{
try{
if (window.attachEvent) {
object.attachEvent(eventName, functionName);
} else if(window.addEventListener) {
//remove "on" from eventName
object.addEventListener(eventName.substr(2), functionName, false);
}
} catch (E) {
}
}
window.οnlοad=setLinkedField;
attachObjEvent(parent.document.getElementById('SubButton'),"onclick",AttachSubmit);
//attachObjEvent(document,"onclick",setLinkedField);
</script>
<script language="javascript">
var xmlHttp = null;
function showCustomer(str)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Do no support AJAX");
return;
}
var url=str;
//alert("Begin to get url");
var parm=getFormValue();
xmlHttp.onreadystatechange = updatePage;
xmlHttp.open("post",url,true);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
xmlHttp.send(parm);
}
function updatePage() {
if (xmlHttp.readyState == 4) {
var response = xmlHttp.responseText;
parent.document.getElementById("reslut").innerHTML = response;
//document.getElementById("reslut").value = response;
// alert(response);
}
}
function getFormValue()
{
var objparam = parent.document.forms[0].elements;
var url ="";
var len = objparam.length;
var i=0;
for(;i<len;i++)
url+=objparam[i].name+"="+objparam[i].value+"&";
return url;
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}catch (e) {
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
} catch (e){
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
</script>
<script type="text/javascript">
var lang = new Array();
lang["enter_tag_option"]= "请输入 %1 标签的选项:";
lang["enter_list_item"]= "输入一个列表项目./r/n留空或者点击取消完成此列表.";
lang["enter_link_url"]= "请输入链接的地址:";
lang["enter_image_url"]= "请输入图片链接地址:";
lang["enter_email_link"]= "请输入此链接的邮箱地址:";
lang['enter_table_rows']= "请输入行数,最多 30 行:";
lang['enter_table_columns']= "请输入列数,最多 30 列:";
lang['fontname']= "字体";
lang['fontsize']= "大小";
var custombbcodes = new Array();
custombbcodes["qq"] = "[qq=8]116256607[/qq]";
custombbcodes["flash"] = "Flash Movie";
custombbcodes["rm"] = "[rm]rtsp://your.com/example.rm[/rm]";
custombbcodes["wmv"] = "[wmv]mms://your.com/example.wmv[/wmv]";
custombbcodes["page"] = "[page][/page]";
custombbcodes["flv"] = "[flv][/flv]";
var fontoptions = new Array("仿宋_GB2312", "黑体", "楷体_GB2312", "宋体", "新宋体", "Tahoma", "Arial", "Impact", "Verdana", "Times New Roman");
</script>
<table width="100%" cellpadding="0" cellspacing="0" border="0" class="editor">
<tr>
<td id="posteditor_controls" class="editor_controlbar" colspan="2">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td><div class="editor_buttonnormal" id="posteditor_cmd_removeformat" onClick="discuzcode('removeformat')" onMouseOver="buttonContext(this, 'mouseover')" onMouseOut="buttonContext(this, 'mouseout')"><img src="Images/bb_removeformat.gif" width="21" height="20" title="清除文本格式" alt="清除文本格式" /></div></td>
<td><div class="editor_buttonnormal" id="posteditor_cmd_undo" onClick="discuzcode('undo')" onMouseOver="buttonContext(this, 'mouseover')" onMouseOut="buttonContext(this, 'mouseout')"><img src="Images/bb_undo.gif" width="21" height="20" title="撤销" alt="撤销" /></div></td>
<td><div class="editor_buttonnormal" id="posteditor_cmd_redo" onClick="discuzcode('redo')" onMouseOver="buttonContext(this, 'mouseover')" onMouseOut="buttonContext(this, 'mouseout')"><img src="Images/bb_redo.gif" width="21" height="20" title="重做" alt="重做" /></div></td>
<td><img src="Images/bb_separator.gif" width="6" height="20" alt="" /></td>
<td><div class="editor_buttonnormal" id="posteditor_cmd_bold" onClick="discuzcode('bold')" onMouseOver="buttonContext(this, 'mouseover')" onMouseOut="buttonContext(this, 'mouseout')"><img src="Images/bb_bold.gif" width="21" height="20" title="粗体" alt="粗体" /></div></td>
<td><div class="editor_buttonnormal" id="posteditor_cmd_italic" onClick="discuzcode('italic')" onMouseOver="buttonContext(this, 'mouseover')" onMouseOut="buttonContext(this, 'mouseout')"><img src="Images/bb_italic.gif" width="21" height="20" title="斜体" alt="斜体" /></div></td>
<td><div class="editor_buttonnormal" id="posteditor_cmd_underline" onClick="discuzcode('underline')" onMouseOver="buttonContext(this, 'mouseover')" onMouseOut="buttonContext(this, 'mouseout')"><img src="Images/bb_underline.gif" width="21" height="20" title="下划线" alt="下划线" /></div></td>
<td><img src="Images/bb_separator.gif" width="6" height="20" alt="" /></td>
<td id="posteditor_popup_fontname" title="字体"><div class="editor_buttonnormal" onMouseOver="menuContext(this, 'mouseover')" onMouseOut="menuContext(this, 'mouseout')">
<table cellpadding="0" cellspacing="0" border="0" unselectable="on">
<tr>
<td class="editor_menunormal" unselectable="on" id="posteditor_menu"><div id="posteditor_font_out" style="width:91px" unselectable="on">字体</div></td>
<td unselectable="on"><img src="Images/bb_menupop.gif" width="7" height="4" alt="" /></td>
</tr>
</table>
<script type="text/javascript">menuregister(true, "posteditor_popup_fontname")</script></div></td>
<td id="posteditor_popup_fontsize" title="大小"><div class="editor_buttonnormal" onMouseOver="menuContext(this, 'mouseover')" onMouseOut="menuContext(this, 'mouseout')">
<table cellpadding="0" cellspacing="0" border="0" unselectable="on">
<tr>
<td class="editor_menunormal" unselectable="on" id="posteditor_menu"><div id="posteditor_size_out" style="width:25px" unselectable="on">大小</div></td>
<td unselectable="on"><img src="Images/bb_menupop.gif" width="7" height="4" alt="" /></td>
</tr>
</table>
<script type="text/javascript">menuregister(true, "posteditor_popup_fontsize")</script></div></td>
<td id="posteditor_popup_forecolor" title="颜色"><div class="editor_buttonnormal" onMouseOver="menuContext(this, 'mouseover')" onMouseOut="menuContext(this, 'mouseout')">
<table cellpadding="0" cellspacing="0" border="0" unselectable="on">
<tr>
<td class="editor_colormenunormal" unselectable="on" id="posteditor_colormenu"><img src="Images/bb_color.gif" width="21" height="16" alt="" /><br><img src="Images/bb_clear.gif" id="posteditor_color_bar" alt="" style="background-color:black" width="21" height="4" /></td>
<td unselectable="on"><img src="Images/bb_menupop.gif" width="7" height="4" alt="" /></td>
</tr>
</table>
<script type="text/javascript">menuregister(true, "posteditor_popup_forecolor")</script></div></td>
<td><img src="Images/bb_separator.gif" width="6" height="20" alt="" /></td>
<td><div class="editor_buttonnormal" id="posteditor_cmd_justifyleft" onClick="discuzcode('justifyleft')" onMouseOver="buttonContext(this, 'mouseover')" onMouseOut="buttonContext(this, 'mouseout')"><img src="Images/bb_left.gif" width="21" height="20" title="居左" alt="居左" /></div></td>
<td><div class="editor_buttonnormal" id="posteditor_cmd_justifycenter" onClick="discuzcode('justifycenter')" onMouseOver="buttonContext(this, 'mouseover')" onMouseOut="buttonContext(this, 'mouseout')"><img src="Images/bb_center.gif" width="21" height="20" title="居中" alt="居中" /></div></td>
<td><div class="editor_buttonnormal" id="posteditor_cmd_justifyright" onClick="discuzcode('justifyright')" onMouseOver="buttonContext(this, 'mouseover')" onMouseOut="buttonContext(this, 'mouseout')"><img src="Images/bb_right.gif" width="21" height="20" title="居右" alt="居右" /></div></td>
<td><img src="Images/bb_separator.gif" width="6" height="20" alt="" /></td>
<td><div class="editor_buttonnormal" id="posteditor_cmd_insertorderedlist" onClick="discuzcode('insertorderedlist')" onMouseOver="buttonContext(this, 'mouseover')" onMouseOut="buttonContext(this, 'mouseout')"><img src="Images/bb_orderedlist.gif" width="21" height="20" title="排序的列表" alt="排序的列表" /></div></td>
<td><div class="editor_buttonnormal" id="posteditor_cmd_insertunorderedlist" onClick="discuzcode('insertunorderedlist')" onMouseOver="buttonContext(this, 'mouseover')" onMouseOut="buttonContext(this, 'mouseout')"><img src="Images/bb_unorderedlist.gif" width="21" height="20" title="未排序列表" alt="未排序列表" /></div></td>
<td><div class="editor_buttonnormal" id="posteditor_cmd_outdent" onClick="discuzcode('outdent')" onMouseOver="buttonContext(this, 'mouseover')" onMouseOut="buttonContext(this, 'mouseout')"><img src="Images/bb_outdent.gif" width="21" height="20" title="减少缩进" alt="减少缩进" /></div></td>
<td><div class="editor_buttonnormal" id="posteditor_cmd_indent" onClick="discuzcode('indent')" onMouseOver="buttonContext(this, 'mouseover')" onMouseOut="buttonContext(this, 'mouseout')"><img src="Images/bb_indent.gif" width="21" height="20" title="增加缩进" alt="增加缩进" /></div></td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td><div class="editor_buttonnormal" id="posteditor_cmd_createlink" onClick="discuzcode('createlink')" onMouseOver="buttonContext(this, 'mouseover')" onMouseOut="buttonContext(this, 'mouseout')"><img src="Images/bb_url.gif" width="21" height="20" title="插入链接" alt="插入链接" /></div></td>
<td><div class="editor_buttonnormal" id="posteditor_cmd_unlink" onClick="discuzcode('unlink')" onMouseOver="buttonContext(this, 'mouseover')" onMouseOut="buttonContext(this, 'mouseout')"><img src="Images/bb_unlink.gif" width="21" height="20" title="移除链接" alt="移除链接" /></div></td>
<td><div class="editor_buttonnormal" id="posteditor_cmd_email" onClick="discuzcode('email')" onMouseOver="buttonContext(this, 'mouseover')" onMouseOut="buttonContext(this, 'mouseout')"><img src="Images/bb_email.gif" width="21" height="20" title="插入邮箱链接" alt="插入邮箱链接" /></div></td>
<td><div class="editor_buttonnormal" id="posteditor_cmd_insertimage" onClick="discuzcode('insertimage')" onMouseOver="buttonContext(this, 'mouseover')" onMouseOut="buttonContext(this, 'mouseout')"><img src="Images/bb_image.gif" width="21" height="20" title="插入图片" alt="插入图片" /></div></td>
<td><img src="Images/bb_separator.gif" width="6" height="20" alt="" /></td>
<td><div class="editor_buttonnormal" id="posteditor_cmd_wrap0_quote" onClick="discuzcode('quote')" onMouseOver="buttonContext(this, 'mouseover')" onMouseOut="buttonContext(this, 'mouseout')"><img src="Images/bb_quote.gif" width="21" height="20" title="插入引用" alt="插入引用" /></div></td>
<td><div class="editor_buttonnormal" id="posteditor_cmd_wrap0_code" onClick="discuzcode('code')" onMouseOver="buttonContext(this, 'mouseover')" onMouseOut="buttonContext(this, 'mouseout')"><img src="Images/bb_code.gif" width="21" height="20" title="插入代码" alt="插入代码" /></div></td>
<td><div class="editor_buttonnormal" id="posteditor_cmd_table" onClick="discuzcode('table')" onMouseOver="buttonContext(this, 'mouseover')" onMouseOut="buttonContext(this, 'mouseout')"><img src="Images/bb_table.gif" width="21" height="20" title="插入表格" alt="插入表格" /></div></td>
<td><img src="Images/bb_separator.gif" width="6" height="20" alt="" /></td>
<td><div class="editor_buttonnormal" id="posteditor_cmd_custom1_qq" onMouseOver="buttonContext(this, 'mouseover')" onClick="discuzcode('custom1_qq')" onMouseOut="buttonContext(this, 'mouseout')"><IMG title="插入QQ在线状态按钮" height="20" alt=qq src="Images/bb_qq.gif"
width=21></div></td>
<td><div class="editor_buttonnormal" id="posteditor_cmd_custom1_flash" onClick="discuzcode('custom1_flash')" onMouseOver="buttonContext(this, 'mouseover')" onMouseOut="buttonContext(this, 'mouseout')"><img src="Images/bb_flash.gif" width="21" height="20" title="嵌入 Flash 动画" alt="flash" /></div></td>
<td><div class="editor_buttonnormal" id="posteditor_cmd_custom1_flash" onClick="discuzcode('custom1_flv')" onMouseOver="buttonContext(this, 'mouseover')" onMouseOut="buttonContext(this, 'mouseout')"><img src="Images/bb_flash.gif" width="21" height="20" title="嵌入 Flv 视频" alt="flv" /></div></td>
<td><div class="editor_buttonnormal" id="posteditor_cmd_custom1_rm" onClick="discuzcode('custom1_rm')" onMouseOver="buttonContext(this, 'mouseover')" onMouseOut="buttonContext(this, 'mouseout')"><img src="Images/bb_rm.gif" width="21" height="20" title="嵌入 Real 音频或视频" alt="rm" /></div></td>
<td><div class="editor_buttonnormal" id="posteditor_cmd_custom1_wmv" onClick="discuzcode('custom1_wmv')" onMouseOver="buttonContext(this, 'mouseover')" onMouseOut="buttonContext(this, 'mouseout')"><img src="Images/bb_wmv.gif" width="21" height="20" title="嵌入 Windows media 音频或视频" alt="wmv" /></div></td>
<td><div class="editor_buttonnormal" id="posteditor_cmd_custom1_wmv" onClick="discuzcode('custom1_page')" onMouseOver="buttonContext(this, 'mouseover')" onMouseOut="buttonContext(this, 'mouseout')"><IMG title="嵌入分页标签" height="20" alt="标签" src="Images/bb_look.gif" width="21"></div></td>
<td>
<div></div>
</td>
</tr>
</table>
<br>
<div id="posteditor_switcher">
<input type="button" id="bbcodemode" value="UBB 代码模式" onClick="switchEditor(0)" class="editor_switcher_highlight">
<input type="button" id="wysiwygmode" value="所见即所得模式" onClick="switchEditor(1)" class="editor_switcher">
</div>
<div class="popupmenu_popup" id="posteditor_popup_fontname_menu" style="display: none">
<table cellpadding="4" cellspacing="0" border="0" unselectable="on">
<tr><td class="popupmenu_option" onClick="discuzcode('fontname', '仿宋_GB2312')" unselectable="on"><font face="仿宋_GB2312" unselectable="on">仿宋_GB2312</font></td></tr>
<tr><td class="popupmenu_option" onClick="discuzcode('fontname', '黑体')" unselectable="on"><font face="黑体" unselectable="on">黑体</font></td></tr>
<tr><td class="popupmenu_option" onClick="discuzcode('fontname', '楷体_GB2312')" unselectable="on"><font face="楷体_GB2312" unselectable="on">楷体_GB2312</font></td></tr>
<tr><td class="popupmenu_option" onClick="discuzcode('fontname', '宋体')" unselectable="on"><font face="宋体" unselectable="on">宋体</font></td></tr>
<tr><td class="popupmenu_option" onClick="discuzcode('fontname', '新宋体')" unselectable="on"><font face="新宋体" unselectable="on">新宋体</font></td></tr>
<tr><td class="popupmenu_option" onClick="discuzcode('fontname', 'Tahoma')" unselectable="on"><font face="Tahoma" unselectable="on">Tahoma</font></td></tr>
<tr><td class="popupmenu_option" onClick="discuzcode('fontname', 'Arial')" unselectable="on"><font face="Arial" unselectable="on">Arial</font></td></tr>
<tr><td class="popupmenu_option" onClick="discuzcode('fontname', 'Impact')" unselectable="on"><font face="Impact" unselectable="on">Impact</font></td></tr>
<tr><td class="popupmenu_option" onClick="discuzcode('fontname', 'Verdana')" unselectable="on"><font face="Verdana" unselectable="on">Verdana</font></td></tr>
<tr><td class="popupmenu_option" onClick="discuzcode('fontname', 'Times New Roman')" unselectable="on"><font face="Times New Roman" unselectable="on">Times New Roman</font></td></tr>
</table></div>
<div class="popupmenu_popup" id="posteditor_popup_fontsize_menu" style="display: none">
<table cellpadding="4" cellspacing="0" border="0" unselectable="on">
<tr align="center"><td class="popupmenu_option" onClick="discuzcode('fontsize', 1)" unselectable="on"><font size="1" unselectable="on">1</font></td></tr>
<tr align="center"><td class="popupmenu_option" onClick="discuzcode('fontsize', 2)" unselectable="on"><font size="2" unselectable="on">2</font></td></tr>
<tr align="center"><td class="popupmenu_option" onClick="discuzcode('fontsize', 3)" unselectable="on"><font size="3" unselectable="on">3</font></td></tr>
<tr align="center"><td class="popupmenu_option" onClick="discuzcode('fontsize', 4)" unselectable="on"><font size="4" unselectable="on">4</font></td></tr>
<tr align="center"><td class="popupmenu_option" onClick="discuzcode('fontsize', 5)" unselectable="on"><font size="5" unselectable="on">5</font></td></tr>
<tr align="center"><td class="popupmenu_option" onClick="discuzcode('fontsize', 6)" unselectable="on"><font size="6" unselectable="on">6</font></td></tr>
<tr align="center"><td class="popupmenu_option" onClick="discuzcode('fontsize', 7)" unselectable="on"><font size="7" unselectable="on">7</font></td></tr>
</table></div>
<div class="popupmenu_popup" id="posteditor_popup_forecolor_menu" style="display: none">
<table cellpadding="4" cellspacing="0" border="0" unselectable="on"><tr>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'Black')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: Black" unselectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'Sienna')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: Sienna" unselectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'DarkOliveGreen')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: DarkOliveGreen" unselectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'DarkGreen')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: DarkGreen" unselectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'DarkSlateBlue')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: DarkSlateBlue" unselectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'Navy')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: Navy" unselectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'Indigo')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: Indigo" unselectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'DarkSlateGray')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: DarkSlateGray" unselectable="on"></div></td>
</tr><tr>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'DarkRed')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: DarkRed" unselectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'DarkOrange')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: DarkOrange" unselectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'Olive')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: Olive" unselectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'Green')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: Green" unselectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'Teal')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: Teal" unselectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'Blue')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: Blue" unselectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'SlateGray')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: SlateGray" unselectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'DimGray')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: DimGray" unselectable="on"></div></td>
</tr><tr>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'Red')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: Red" unselectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'SandyBrown')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: SandyBrown" unselectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'YellowGreen')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: YellowGreen" unselectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'SeaGreen')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: SeaGreen" unselectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'MediumTurquoise')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: MediumTurquoise" unselectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'RoyalBlue')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: RoyalBlue" unselectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'Purple')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: Purple" unselectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'Gray')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: Gray" unselectable="on"></div></td>
</tr><tr>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'Magenta')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: Magenta" unselectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'Orange')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: Orange" unselectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'Yellow')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: Yellow" unselectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'Lime')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: Lime" unselectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'Cyan')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: Cyan" unselectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'DeepSkyBlue')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: DeepSkyBlue" unselectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'DarkOrchid')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: DarkOrchid" unselectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'Silver')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: Silver" unselectable="on"></div></td>
</tr><tr>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'Pink')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: Pink" unselectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'Wheat')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: Wheat" unselectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'LemonChiffon')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: LemonChiffon" unselectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'PaleGreen')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: PaleGreen" unselectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'PaleTurquoise')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: PaleTurquoise" unselectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'LightBlue')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: LightBlue" unselectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'Plum')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: Plum" unselectable="on"></div></td>
<td class="editor_colornormal" onClick="discuzcode('forecolor', 'White')" unselectable="on" onMouseOver="colorContext(this, 'mouseover')" onMouseOut="colorContext(this, 'mouseout')"><div style="background-color: White" unselectable="on"></div></td>
</tr><tr>
</tr>
</table>
</div>
</table>
<div class="editor_text">
<textarea name="message" rows="10" cols="60" style="width:100%; height:200px" tabindex="100" id="posteditor_textarea" onSelect="javascript: window.storeCaret(this);" onClick="javascript: window.storeCaret(this);" onKeyUp="javascript:window.storeCaret(this);" value="[flv]http://localhost:8080/Ubbtest/2girls1cup1fuwuqituokualiao.flv[/flv]"></textarea>
</div>
<table width=100%" cellpadding="4" cellspacing="0" class="editor_button">
<tr>
<td>
<div class="editor_textexpand"><img src="Images/bb_contract.gif" width="11" height="21" title="收缩编辑框" alt="收缩编辑框" onClick="resizeEditor(-100)" /><img src="Images/bb_expand.gif" width="12" height="21" title="扩展编辑框" alt="扩展编辑框" onClick="resizeEditor(100)" />
</div>
</td>
<td align="right">
<input type="button" class="lightbutton" value="字数检查" onClick="checklength()">
<input type="button" class="lightbutton" value=" 清空内容 " tabindex="103" onClick="clearcontent()">
</td>
</tr>
</table>
<input type="hidden" name="wysiwyg" id="posteditor_mode" value="1">
<script type="text/javascript">
var textobj = $(editorid + '_textarea');
newEditor(wysiwyg);
</script>
</body>
</html>
5。预览效果