JAVA版 ubb编辑器

          ubb代码大家都知道,asp vbscript,php javascript都很多。

           用java技术实现的ubb编辑器道是很少,其实也不是什么困难的事情,说到底是一个replace的问题。下面看我如何实现:

          1,新建一个用于解析ubb代码的类:ubbtest.java(不用多说什么,自己看代码).

  1.  import  java.util.regex. * ; // 导入正则表达式包中的类 
  2. /** 
  3.  *  使网页支持ubbcode.
  4.  *  @author  tom.dai
  5.  *  @version  1.0
  6.   */ 
  7. public   final   class  Ubbcode {
  8.      private   static   final  String ImagePath  =   "Images/" ;  // 定义图片路径 
  9.      private   static   final  String emotImagePath  =   "images/emot/" ;
  10.      /** 
  11.      * @description 转换代码,使之支持ubbcode.
  12.      *  @param  strContent 转换前的代码.
  13.      *  @return  result 转换后的内容.
  14.       */ 
  15.      public   static  String UBBCode(String strContent) {  //
  16.         strContent  =  dvHTMLEncode(strContent);
  17.         strContent  =  FilterJS(strContent);
  18.         String re;
  19.          // re.IgnoreCase =true
  20.          // re.Global=True 
  21.         Pattern pattern  =   null ;  //
  22.         Matcher matcher  =   null ;
  23.          // 转换IMG 
  24.         //re  =   "//[IMG//](http|https|ftp)://(.[^//[]*)//[///IMG//]" ;
  25.         //re  =   "//[img//](.[^//[]*)//[///img//]" ;
  26.         re ="//[img//](http|https|ftp)://(.[^//[]*)//[///img//]";
  27.         pattern  =  Pattern.compile(re);
  28.         matcher  =  pattern.matcher(strContent);
  29.         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>");
  30.         re ="//[img=*([0-9]*),*([0-9]*)//](http|https|ftp)://(.[^//[]*)//[///img//]";
  31.         pattern  =  Pattern.compile(re);
  32.         matcher  =  pattern.matcher(strContent);
  33.         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>");
  34.         
  35.         
  36.         /*
  37.         // 转换UPLOAD 
  38.         re  =   "//[upload=(gif|jpg|jpeg|bmp|png)//](.[^//[]*)(gif|jpg|jpeg|bmp|png)//[///upload] " ;
  39.         pattern  =  Pattern.compile(re);
  40.         matcher  =  pattern.matcher(strContent);
  41.         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>" );
  42.         re  =   "//[upload=(.[^//[]*)//](.[^//[]*)//[///upload] " ;
  43.         pattern  =  Pattern.compile(re);
  44.         matcher  =  pattern.matcher(strContent);
  45.         strContent  =  matcher.replaceAll( "<br><img SRC=/"" + ImagePath + 
  46.                                        "$1.gif/"  border = 0 >   < a href = /"$2/" > 点击浏览该文件 </a>"); 
  47.           */ 
  48.          // 转换DIR 
  49.         re  =   "//[dir=*([0-9]*),*([0-9]*)//](.[^//[]*)//[///dir]" ;
  50.         pattern  =  Pattern.compile(re);
  51.         matcher  =  pattern.matcher(strContent);
  52.         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>");
  53.          // 转换QT 
  54.         re  =   "//[qt=*([0-9]*),*([0-9]*)//](.[^//[]*)//[///qt]" ;
  55.         pattern  =  Pattern.compile(re);
  56.         matcher  =  pattern.matcher(strContent);
  57.         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/>;");
  58.          // 转换MP 
  59.         re  =   "//[mp=*([0-9]*),*([0-9]*)//](.[^//[]*)//[///mp]" ;
  60.         pattern  =  Pattern.compile(re);
  61.         matcher  =  pattern.matcher(strContent);
  62.         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>");
  63.          // 转换RM 
  64.         re  =   "//[rm=*([0-9]*),*([0-9]*)//](.[^//[]*)//[///rm]" ;
  65.         pattern  =  Pattern.compile(re);
  66.         matcher  =  pattern.matcher(strContent);
  67.         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>");
  68.          // 转换FLASH 
  69.         re  =   "(//[flash//])(.[^//[]*)(//[///flash])" ;
  70.         pattern  =  Pattern.compile(re);
  71.         matcher  =  pattern.matcher(strContent);
  72.         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>");
  73.         re  =   "(//[flash=*([0-9]*),*([0-9]*)//])(.[^//[]*)(//[///flash]) " ;
  74.         pattern  =  Pattern.compile(re);
  75.         matcher  =  pattern.matcher(strContent);
  76.         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>");
  77.          //转换flv
  78.         re  =   "(//[flv//])(.[^//[]*)(//[///flv])" ;
  79.         pattern  =  Pattern.compile(re);
  80.         matcher  =  pattern.matcher(strContent);
  81.         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>");
  82.         // 转换URL 
  83.         re  =   "(//[url//])(.[^//[]*)(//[///url])" ;
  84.         pattern  =  Pattern.compile(re);
  85.         matcher  =  pattern.matcher(strContent);
  86.         strContent  =  matcher.replaceAll( "<A HREF=/" $2 /"  TARGET=_blank>$2</A>");
  87.         re  =   "(//[url=(.[^//[]*)//])(.[^//[]*)(//[///url])";
  88.         pattern  =  Pattern.compile(re);
  89.         matcher  =  pattern.matcher(strContent);
  90.         strContent  =  matcher.replaceAll("<A href=/"$2/" TARGET=_blank>$3</A>" );
  91.          // 转换EMAIL 
  92.         re  =   "(//[email//])(//S+//@.[^//[]*)(//[///email])" ;
  93.         pattern  =  Pattern.compile(re);
  94.         matcher  =  pattern.matcher(strContent);
  95.         strContent  =  matcher.replaceAll("<img align=absmiddle src=/""+ImagePath+"email1.gif/">< A HREF = /"mailto:$2/">$2</A>"); 
  96.         re  =   "(//[email=(//S+//@.[^//[]*)//])(.[^//[]*)(//[///email])" ;
  97.         pattern  =  Pattern.compile(re);
  98.         matcher  =  pattern.matcher(strContent);
  99.         strContent  =  matcher.replaceAll( "<img align=absmiddle src=/""+ImagePath+"email1.gif/">< A HREF =/" mailto:$2/"  TARGET =_blank >$3</A>" ); 
  100.        /*
  101.         // 自动识别网址 
  102.         re  ="^((http|https|ftp|rtsp|mms):(//|)[A-Za-z0-9//./=//?%//-&_~`@':+!]+)" ;
  103.         pattern  =  Pattern.compile(re);
  104.         matcher  =  pattern.matcher(strContent);
  105.         strContent  =  matcher.replaceAll(
  106.                  "<img align=absmiddle src=pic/url.gif border=0><a target=_blank href=$1>$1</a>");
  107.         re  ="((http|https|ftp|rtsp|mms):(//|)[A-Za-z0-9//./=//?%//-&_~`@':+!]+)$" ;
  108.         pattern  =  Pattern.compile(re);
  109.         matcher  =  pattern.matcher(strContent);
  110.         strContent  =  matcher.replaceAll("<img align=absmiddle src=pic/url.gif border=0><a target=_blank href=$1>$1</a>");
  111.         re  =   "([^>=/"])((http|https|ftp|rtsp|mms):(//|)[A-Za-z0-9//./=//?%//-&_~`@':+!]+)"; 
  112.         pattern  =  Pattern.compile(re);
  113.         matcher  =  pattern.matcher(strContent);
  114.         strContent  =  matcher.replaceAll( "$1<img align=absmiddle src=pic/url.gif border=0><a target=_blank href=$2>$2</a>" );
  115.          // 自动识别www等开头的网址 
  116.         re  =   "([^(http://|http:)])((www|cn)[.](//w)+[.]{1,}(net|com|cn|org|cc)(((///[//~]*|//[//~]*)(//w)+)|[.](//w)+)*(((([?](//w)+){1}[=]*))*((//w)+){1}([//&](//w)+[//=](//w)+)*)*)" ;
  117.         pattern  =  Pattern.compile(re);
  118.         matcher  =  pattern.matcher(strContent);
  119.         strContent  =  matcher.replaceAll( "<img align=absmiddle src=pic/url.gif border=0><a target=_blank href=http://$2>$2</a>" );
  120.          // 自动识别Email地址,如打开本功能在浏览内容很多的帖子会引起服务器停顿 
  121.         re  =   "([^(=)])((//w)+[@]{1}((//w)+[.]){1,3}(//w)+)" ;
  122.         pattern  =  Pattern.compile(re);
  123.         matcher  =  pattern.matcher(strContent);
  124.         strContent  =  matcher.replaceAll( "<img align=absmiddle src=pic/url.gif border=0><a target=_blank href=/" mailto:$2 /" >$2</a>" );
  125.         */
  126.          // 转换EM 
  127.         re  =   "//[em(.[^//[]*)//]" ;
  128.         pattern  =  Pattern.compile(re);
  129.         matcher  =  pattern.matcher(strContent);
  130.         strContent  =  matcher.replaceAll( "<img src=/""  + emotImagePath + "em$1.gif/"  border = 0  align = middle >"); 
  131.          // 转换HTML 
  132.         re  =   "//[html//](.[^//[]*)//[///html] " ;
  133.         pattern  =  Pattern.compile(re);
  134.         matcher  =  pattern.matcher(strContent);
  135.         strContent  =  matcher.replaceAll( "<table width='100%' border='0' cellspacing='0' cellpadding='6' class=tableborder1> <td><b>以下内容为程序代码:</b><br>$1</td>< /table>" );
  136.          // 转换CODE 
  137.         re  =   "//[code//](.[^//[]*)//[///code]" ;
  138.         pattern  =  Pattern.compile(re);
  139.         matcher  =  pattern.matcher(strContent);
  140.         strContent  =  matcher.replaceAll( "<table width='100%' border='0' cellspacing='0' cellpadding='6' class=tableborder1> <td><b>以下内容为程序代码:</b><br>$1</td></table>" );
  141.          // 转换COLOR 
  142.         re  =   "//[color=(.[^//[]*)//](.[^//[]*)//[///color]" ;
  143.         pattern  =  Pattern.compile(re);
  144.         matcher  =  pattern.matcher(strContent);
  145.         strContent  =  matcher.replaceAll( "<font color=$1>$2</font>" );
  146.          // 转换font 
  147.         re  =   "//[font=(.[^//[]*)//](.[^//[]*)//[///font]" ;
  148.         pattern  =  Pattern.compile(re);
  149.         matcher  =  pattern.matcher(strContent);
  150.         strContent  =  matcher.replaceAll( "<font face=$1>$2</font>" );
  151.          // 转换ALIGN 
  152.         re  =   "//[align=(center|left|right)//](.*)//[///align]" ;
  153.         pattern  =  Pattern.compile(re);
  154.         matcher  =  pattern.matcher(strContent);
  155.         strContent  =  matcher.replaceAll( "<div align=$1>$2</div>" );
  156.          // 转换QUOTE 
  157.         re  =   "//[quote//](.*)//[///quote]" ;
  158.         pattern  =  Pattern.compile(re);
  159.         matcher  =  pattern.matcher(strContent);
  160.         strContent  =  matcher.replaceAll( " <table style=/" width: 80 % /"  cellpadding=5 cellspacing=1 class=tableborder1><TR><TD class=tableborder1>$1</td></tr></table><br> " );
  161.          // 转换FLY 
  162.         re  =   "//[fly//](.*)//[///fly]" ;
  163.         pattern  =  Pattern.compile(re);
  164.         matcher  =  pattern.matcher(strContent);
  165.         strContent  =  matcher.replaceAll(
  166.                  "<marquee width=90% behavior=alternate scrollamount=3>$1</marquee>" );
  167.          // 转换MOVE 
  168.         re  =   "//[move//](.*)//[///move]" ;
  169.         pattern  =  Pattern.compile(re);
  170.         matcher  =  pattern.matcher(strContent);
  171.         strContent  =  matcher.replaceAll( " <MARQUEE scrollamount=3>$1</marquee>" );
  172.          // 转换GLOW 
  173.         re  = "//[glow=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)//](.[^//[]*)//[///glow]" ;
  174.         pattern  =  Pattern.compile(re);
  175.         matcher  =  pattern.matcher(strContent);
  176.         strContent  =  matcher.replaceAll(
  177.                  "<table width=$1 style=/" filter:glow(color = $2 , strength = $3 )/" >$4</table>" );
  178.          // 转换SHADOW 
  179.         re  ="//[shadow=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)//](.[^//[]*)//[///shadow]" ;
  180.         pattern  =  Pattern.compile(re);
  181.         matcher  =  pattern.matcher(strContent);
  182.         strContent  =  matcher.replaceAll("<table width=$1 style=/" filter:shadow(color = $2 , strength = $3 )/" >$4</table>"); 
  183.         re  ="//[i](.[^//[]*)//[///i]" ;
  184.         pattern  =  Pattern.compile(re);
  185.         matcher  =  pattern.matcher(strContent);
  186.         strContent  =  matcher.replaceAll( "<i>$1</i>" );
  187.         re  ="//[u](.[^//[]*)//[///u]" ;
  188.         pattern  =  Pattern.compile(re);
  189.         matcher  =  pattern.matcher(strContent);
  190.         strContent  =  matcher.replaceAll( "<u>$1</u>" );
  191.         re  =   "//[b](.[^//[]*)//[///b]" ;
  192.         pattern  =  Pattern.compile(re);
  193.         matcher  =  pattern.matcher(strContent);
  194.         strContent  =  matcher.replaceAll( "<b>$1</b>" );
  195.         re  =   "//[size=([1-7])//](.[^//[]*)//[///size]" ;
  196.         pattern  =  Pattern.compile(re);
  197.         matcher  =  pattern.matcher(strContent);
  198.         strContent  =  matcher.replaceAll( "<font size=$1>$2</font>" );
  199.          /* re ="(//s)";
  200.                  matcher = pattern.matcher(strContent);  
  201.                  strContent=matcher.replaceAll("<I>$1</I>"); */ 
  202.       /*  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]"};
  203.         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>"};
  204.        for(int i=0;i<searcharray.length;i++)
  205.            strContent=replace(strContent,searcharray[i],replacearray[i]);
  206.            */
  207.         re  =   null ;
  208.          return  strContent;
  209.     }
  210. /** 
  211.  *  过滤javascript代码.
  212.  *  @param  v转换前的代码.
  213.  *  @return  v转换后的内容.
  214.   */ 
  215.      public   static  String FilterJS(String v) {
  216.          try{
  217.          if  ( ! v.equals( "null" )  &&  v  !=   null ) {
  218.             String t, re;
  219.             re  =   "(javascript)" ;
  220.             t  =  re.replace(v,  "javascript" );
  221.             re  =   " (jscript:)" ;
  222.             t  =  re.replace(t,  "jscript:" );
  223.             re  =   " (js:) " ;
  224.             t  =  re.replace(t,  "js:" );
  225.             re  =   " (value) " ;
  226.             t  =  re.replace(t,  "value" );
  227.             re  =   " (about:)" ;
  228.             t  =  re.replace(t,  "about:" );
  229.             re  =   " (file:)" ;
  230.             t  =  re.replace(t,  "file:" );
  231.             re  =   "(document.cookie)" ;
  232.             t  =  re.replace(t,  "documents.cookie" );
  233.             re  =   "(vbscript:)" ;
  234.             t  =  re.replace(t,  "vbscript:" );
  235.             re  =   "(vbs:)" ;
  236.             t  =  re.replace(t,  "vbs:" );
  237.             re  =   "(on(mouse|exit|error|click|key))" ;
  238.             t  =  re.replace(t,  "on$2" );
  239.             re  =   "(&#)" ;
  240.             t  =  re.replace(t,  "&#" );
  241.             re  =   null ;
  242.         }}catch(Exception e)
  243.         {
  244.             e.printStackTrace();
  245.         }
  246.          return  v;
  247.     }
  248. /** 
  249.  *  替换一些特殊符号为html语法标记.
  250.  *  @param  fString转换前的代码.
  251.  *  @return  fString转换后的内容.
  252.   */  
  253. public   static  String dvHTMLEncode(String fString) {
  254.     try{
  255.          if  ( ! fString.equals( "null" )  &&  fString  !=   null ) {
  256.             fString  =  replace(fString,  ">" ,  ">" );
  257.             fString  =  replace(fString,  "<" ,  "<" );
  258.             fString  =  replace(fString,  "&" ,  "&" );
  259.             fString  =  replace(fString,  " " ,  " " );
  260.             fString  =  replace(fString,  "/"" ,   """);
  261.             fString  =  replace(fString,  "/'" ,  "'" );
  262.             fString  =  replace(fString,  "/r" ,  " " );
  263.             fString  =  replace(fString,  "/n" ,  "<BR>" );
  264.             fString  =  replace(fString,  "" ,  "//" );
  265.         }}catch(Exception e)
  266.         {
  267.             e.printStackTrace();
  268.         }
  269.          return  fString;
  270.     }
  271. /** 
  272.  *  html语法标记转换符号本身.
  273.  *  @param  fString转换前的代码.
  274.  *  @return  fString转换后的内容.
  275.   */   
  276.    public   static  String dvHTMLCode(String fString) {
  277.          if  ( ! fString.equals( "null" )  &&  fString  !=   null ) {
  278.             fString  =  replace(fString,  ">" ,  ">" );
  279.             fString  =  replace(fString,  "<" ,  "<" );
  280.             fString  =  replace(fString,  "&" ,  "&" );
  281.             fString  =  replace(fString,  "  " ,  "  " );
  282.             fString  =  replace(fString,  """ , "/"" );
  283.             fString  =  replace(fString,  "'" ,  "/'" );
  284.             fString  =  replace(fString,  "//" ,  " " );
  285.             fString  =  replace(fString,  "<BR>" ,  "/n" );
  286.         }
  287.          return  fString;
  288.     }
  289.      public   static  String nohtml(String str) {
  290.         String re;
  291.         Pattern pattern  =   null ;
  292.         Matcher matcher  =   null ;
  293.         re  =   "(//<.[^//<]*//>)" ;
  294.         pattern  =  Pattern.compile(re);
  295.         matcher  =  pattern.matcher(str);
  296.         str  =  matcher.replaceAll( "  " );
  297.         re  =   " (//<///[^//<]*//>)" ;
  298.         str  =  re.replace(str,  "  " );
  299.         re  =   null ;
  300.          return  str;
  301.     }
  302. /** 
  303.  *  分割函数.
  304.  *  @param  source原字符串,div将要被分割的字符串.
  305.  *  @return  returnStr分割后的字符串.
  306.   */   
  307.     public   static  String[] split(String source, String div) {
  308.          int  arynum  =   0 , intIdx  =   0 , intIdex  =   0 , div_length  =  div.length();
  309.          if  (source.compareTo("")  !=   0 ) {
  310.              if  (source.indexOf(div)  !=   - 1 ) {
  311.                 intIdx  =  source.indexOf(div);
  312.                  for  ( int  intCount  =   1 ; ; intCount ++ ) {
  313.                      if  (source.indexOf(div, intIdx  +  div_length)  !=   - 1 ) {
  314.                         intIdx  =  source.indexOf(div, intIdx  +  div_length);
  315.                         arynum  =  intCount;
  316.                     }  else  {
  317.                         arynum  +=   2 ;
  318.                          break ;
  319.                     }
  320.                 }
  321.             }  else  {
  322.                 arynum  =   1 ;
  323.             }
  324.         }  else  {
  325.             arynum  =   0 ;
  326.         }
  327.         intIdx  =   0 ;
  328.         intIdex  =   0 ;
  329.         String[] returnStr  =   new  String[arynum];
  330. if  (source.compareTo("")  !=   0 ) {
  331.              if  (source.indexOf(div)  !=   - 1 ) {
  332.                 intIdx  =  ( int ) source.indexOf(div);
  333.                 returnStr[ 0 ]  =  (String) source.substring( 0 , intIdx);
  334.                  for  ( int  intCount  =   1 ; ; intCount ++ ) {
  335.                      if  (source.indexOf(div, intIdx  +  div_length)  !=   - 1 ) {
  336.                         intIdex  =  ( int ) source.indexOf(div, intIdx  +  div_length);
  337.                         returnStr[intCount]  =  (String) source.substring(intIdx  + 
  338.                                 div_length,
  339.                                 intIdex);
  340.                         intIdx  =  ( int ) source.indexOf(div, intIdx  +  div_length);
  341.                     }  else  {
  342.                         returnStr[intCount]  =  (String) source.substring(intIdx  + 
  343.                                 div_length,
  344.                                 source.length());
  345.                          break ;
  346.                     }
  347.                 }
  348.             }  else  {
  349.                 returnStr[ 0 ]  =  (String) source.substring( 0 , source.length());
  350.                  return  returnStr;
  351.             }
  352.         }  else  {
  353.              return  returnStr;
  354.         }
  355.          return  returnStr;
  356.     }
  357. /** 
  358.  *  替换函数.
  359.  *  @param  str替换前的字符串,substr被替换的字符,restr替换的字符.
  360.  *  @return  替换后并且经过除空处理的字符串.
  361.   */   
  362.      public   static  String replace(String str, String substr, String restr) {
  363.         String[] tmp  =  split(str, substr);
  364.         String returnstr  =   null ;
  365.          if  (tmp.length  !=   0 ) {
  366.             returnstr  =  tmp[ 0 ];
  367.              for  ( int  i  =   0 ; i  <  tmp.length  -   1 ; i ++ ) {
  368.                 returnstr  =  dealNull(returnstr)  +  restr  +  tmp[i  +   1 ];
  369.             }
  370.         }
  371.          return  dealNull(returnstr);
  372.     }
  373. /** 
  374.  *  除空处理函数.
  375.  *  @param  str原字符串.
  376.  *  @return  处理后的字符串.
  377.   */   
  378.      public   static  String dealNull(String str) {
  379.         String returnstr  =   null ;
  380.          if  (str  ==   null ) {
  381.             returnstr  = "" ;
  382.         }  else  {
  383.             returnstr  =  str;
  384.         }
  385.          return  returnstr;
  386.     }
  387.      public   static  String tostring(Character i) {
  388.         Character c  =  i;
  389.          return  c.toString();
  390.     }
  391.     /* public static void main(String args[]) throws Exception
  392.      {
  393.          Ubbcode ubb=new Ubbcode();
  394.          String strContent="[IMG]HTTP://123.jpg[/IMG] ";
  395.          System.out.println("the new string is:"+ubb.UBBCode(strContent));   
  396.      }*/
  397. }

2。新建一个serverlet,ubb.java

  1. import java.io.IOException;
  2. import javax.servlet.ServletException;
  3. import javax.servlet.http.HttpServletRequest;
  4. import javax.servlet.http.HttpServletResponse;
  5. /**
  6.  * Servlet implementation class for Servlet: ubb
  7.  *
  8.  */
  9.  public class ubb extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
  10.    static final long serialVersionUID = 1L;
  11.    
  12.     /* (non-Java-doc)
  13.      * @see javax.servlet.http.HttpServlet#HttpServlet()
  14.      */
  15.     public ubb() {
  16.         super();
  17.     }       
  18.     
  19.     /* (non-Java-doc)
  20.      * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  21.      */
  22.     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  23.         // TODO Auto-generated method stub
  24.         doPost(request,response); 
  25.     }   
  26.     
  27.     /* (non-Java-doc)
  28.      * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  29.      */
  30.     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  31.     //  System.out.println("begin");
  32.     //  System.out.println("The request get paramter mssgcontent is : "+request.getParameter("mssgcontent"));
  33.          Ubbcode ubb=new Ubbcode();
  34.          String strContent=request.getParameter("mssgcontent");
  35.         response.setContentType("text/html;charset=utf-8");
  36.         response.getWriter().write(ubb.UBBCode(strContent));
  37.         
  38.     }               
  39. }

注:web-info/web.xml中serverlet配置:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <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">
  3.   <display-name>Ubbtest</display-name>
  4.   <welcome-file-list>
  5.     <welcome-file>index.html</welcome-file>
  6.     <welcome-file>index.htm</welcome-file>
  7.     <welcome-file>index.jsp</welcome-file>
  8.     <welcome-file>default.html</welcome-file>
  9.     <welcome-file>default.htm</welcome-file>
  10.     <welcome-file>default.jsp</welcome-file>
  11.   </welcome-file-list>
  12.   <servlet>
  13.     <description></description>
  14.     <display-name>ubb</display-name>
  15.     <servlet-name>ubb</servlet-name>
  16.     <servlet-class>ubb</servlet-class>
  17.   </servlet>
  18.   <servlet-mapping>
  19.     <servlet-name>ubb</servlet-name>
  20.     <url-pattern>/ubb</url-pattern>
  21.   </servlet-mapping>
  22. </web-app>

3.新建bbcode.js。用于页面显示(版权归动网论坛)。

    1. /******************************************************************************
    2.   Crossday Discuz! Board - HTML <=> BB Code for Discuz!
    3.   Copyright 2001-2006 Comsenz Inc. (http://www.comsenz.com)
    4. *******************************************************************************/
    5. var re;
    6. var pcodecount = '-1';
    7. var codecount = 0;
    8. var codehtml = new Array();
    9. function addslashes(str) {
    10.     var searcharray = ['', '///'''''///(''///)''///[''///]''///{''///}''///^''///$''///?''///.''///*''///+''///|'];
    11.     var replacearray = ['', '///'''///''//(''//)''//[''//]''//{''//}''//^''//$''//?''//.''//*''//+''//|'];
    12.     var len = searcharray.length;
    13.     for(var i = 0; i < len; i++) {
    14.         re = new RegExp(searcharray[i], "g");
    15.         str = str.replace(re, replacearray[i]);
    16.     }
    17.     return str;
    18. }
    19. function atag(aoptions, text) {
    20.     if(trim(text) == '') {
    21.         return '';
    22.     }
    23.     href = getoptionvalue('href', aoptions);
    24.     if(href.substr(0, 11) == 'javascript:') {
    25.         return trim(recursion('a', text, 'atag'));
    26.     } else if(href.substr(0, 7) == 'mailto:') {
    27.         tag = 'email';
    28.         href = href.substr(7);
    29.     } else {
    30.         tag = 'url';
    31.     }
    32.     return '[' + tag + '=' + href + ']' + trim(recursion('a', text, 'atag')) + '[/' + tag + ']';
    33. }
    34. function bbcode2html(str) {
    35.     str = trim(str);
    36.     if(str == '') {
    37.         return '';
    38.     }
    39.     if(!fetchCheckbox('bbcodeoff') && allowbbcode) {
    40.         str= str.replace(//s*/[code/]([/s/S]+?)/[//code/]/s*/ig, function($1, $2) {return parsecode($2);});
    41.     }
    42.     if(!forumallowhtml && !(allowhtml && fetchCheckbox('htmlon'))) {
    43.         str = str.replace(/</ig, '<');
    44.         str = str.replace(/>/ig, '>');
    45.     }
    46.     if(!fetchCheckbox('smileyoff') && allowsmilies) {
    47.         for(id in smilies) {
    48.             re = new RegExp(addslashes(smilies[id]['code']), "g");
    49.             str = str.replace(re, '<img src="./images/smilies/' + smilies[id]['url'] + '" border="0" smilieid="' + id + '" alt="' + smilies[id]['code'] + '" />');
    50.         }
    51.     }
    52.     if(!fetchCheckbox('parseurloff')) {
    53.         str = str.replace(/^((http|https|ftp|rtsp|mms):[A-Za-z0-9/.//=/?%/-&_~`@':+!]+)/ig, '<a href="$1" target="_blank">$1</a>');
    54.         str = str.replace(/((http|https|ftp|rtsp|mms):[A-Za-z0-9/.//=/?%/-&_~`@':+!]+)$/ig, '<a href="$1" target="_blank">$1</a>');
    55.         str = str.replace(/[^>=/]""]((http|https|ftp|rtsp|mms):[A-Za-z0-9/.//=/?%/-&_~`@':+!]+)/ig, '<a href="$1" target="_blank">$1</a>');
    56.     }
    57.     if(!fetchCheckbox('bbcodeoff') && allowbbcode) {
    58.         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);});
    59.         str= str.replace(//[url=www.([^/[/"']+?)/](.+?)/[//url/]/ig, '<a href="http://www.$1" target="_blank">$2</a>');
    60.         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>');
    61.         str= str.replace(//[email/](.*?)/[//email/]/ig, '<a href="mailto:$1">$1</a>');
    62.         str= str.replace(//[email=(.[^/[]*)/](.*?)/[//email/]/ig, '<a href="mailto:$1" target="_blank">$2</a>');
    63.         str = str.replace(//[color=([^/[/<]+?)/]/ig, '<font color="$1">');
    64.         str = str.replace(//[size=(/d+?)/]/ig, '<font size="$1">');
    65.         str = str.replace(//[size=(/d+(px|pt|in|cm|mm|pc|em|ex|%)+?)/]/ig, '<font style="font-size: $1">');
    66.         str = str.replace(//[font=([^/[/<]+?)/]/ig, '<font face="$1">');
    67.         str = str.replace(//[align=([^/[/<]+?)/]/ig, '<p align="$1">');
    68.         re = //s*/[table(=(/d{1,3}%?))?/][/n/r]*([/s/S]+?)[/n/r]*/[//table/]/s*/ig;
    69.         str = str.replace(re, function($1, $2, $3, $4) {return parsetable($3, $4);});
    70.         str = str.replace(re, function($1, $2, $3, $4) {return parsetable($3, $4);});
    71.         str = str.replace(re, function($1, $2, $3, $4) {return parsetable($3, $4);});
    72.         str = str.replace(re, function($1, $2, $3, $4) {return parsetable($3, $4);});
    73.         var searcharray = new Array(
    74.             '///[color///]''///[size///]''///[font///]''///[align///]''///[b///]''///[b///]',
    75.             '///[i///]''///[i///]''///[u///]''///[u///]''///[list///]''///[list=1///]''///[list=a///]',
    76.             '///[list=A///]''///[///*///]''///[list///]''///[indent///]''///[indent///]'
    77.         );
    78.         var replacearray = new Array(
    79.             '</font>''</font>''</font>''</p>''<b>''</b>''<i>',
    80.             '</i>''<u>''</u>''<ul>''<ol type=1>''<ol type=a>',
    81.             '<ol type=A>''<li>''</ul></ol>''<blockquote>''</blockquote>'
    82.         );
    83.         var len = searcharray.length;
    84.         for(var i = 0; i < len; i++) {
    85.             re = new RegExp(searcharray[i], "ig");
    86.             str = str.replace(re, replacearray[i]);
    87.         }
    88.     }
    89.     if(!fetchCheckbox('bbcodeoff')) {
    90.         if(allowimgcode) {
    91.             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="" />');
    92.             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="" />');
    93.         } else {
    94.             str = str.replace(//[img/]/s*([^/[/</r/n]+?)/s*/[//img/]/ig, '<a href="$1" target="_blank">$1</a>');
    95.             str = str.replace(//[img=(/d{1,3})[x|/,](/d{1,3})/]/s*([^/[/</r/n]+?)/s*/[//img/]/ig, '<a href="$1" target="_blank">$1</a>');
    96.         }
    97.     }
    98.     for(var i = 0; i <= pcodecount; i++) {
    99.         str = str.replace("[/tDISCUZ_CODE_" + i + "/t]", codehtml[i]);
    100.     }
    101.     if(!forumallowhtml && !(allowhtml && fetchCheckbox('htmlon'))) {
    102.         str = str.replace(//t/ig, '        ');
    103.         str = str.replace(/   /ig, '   ');
    104.         str = str.replace(/  /ig, '  ');
    105.         str = str.replace(//r/n/ig, '<br />');
    106.         str = str.replace(/[/r/n]/ig, '<br />');
    107.     }
    108.     return(str);
    109. }
    110. function codetag(text) {
    111.     pcodecount++;
    112.     text = text.replace(/<br[^/>]*>/ig, "/n");
    113.     text = text.replace(/^[/n/r]*([/s/S]+?)[/n/r]*$/ig, '$1');
    114.     text = text.replace(/<(//|)[A-Za-z].*?>/ig, '');
    115.     codehtml[pcodecount] = "[code]" + text + "[/code]";
    116.     codecount++;
    117.     return "[/tDISCUZ_CODE_" + pcodecount + "/t]";
    118. }
    119. function cuturl(url) {
    120.     var length = 65;
    121.     var urllink = '<a href="' + (url.toLowerCase().substr(0, 4) == 'www.' ? 'http://' + url : url) + '" target="_blank">';
    122.     if(url.length > length) {
    123.         url = url.substr(0, parseInt(length * 0.5)) + ' ... ' + url.substr(url.length - parseInt(length * 0.3));
    124.     }
    125.     urllink += url + '</a>';
    126.     return urllink;
    127. }
    128. function dpstag(options, text, tagname) {
    129.     if(trim(text) == '') {
    130.         return '';
    131.     }
    132.     var pend = parsestyle(options, '''');
    133.     var prepend = pend['prepend'];
    134.     var append = pend['append'];
    135.     if(in_array(tagname, ['div''p'])) {
    136.         align = getoptionvalue('align', options);
    137.         if(in_array(align, ['left''center''right'])) {
    138.             prepend = '[align=' + align + ']' + prepend;
    139.             append += '[/align]';
    140.         } else {
    141.             append += "/n";
    142.         }
    143.     }
    144.     return prepend + recursion(tagname, text, 'dpstag') + append;
    145. }
    146. function fetchCheckbox(cbn) {
    147.     return $(cbn) && $(cbn).checked == true ? 1 : 0;
    148. }
    149. function fetchoptionvalue(option, text) {
    150.     if((position = strpos(text, option)) !== false) {
    151.         delimiter = position + option.length;
    152.         if(text.charAt(delimiter) == '"') {
    153.             delimchar = '"';
    154.         } else if(text.charAt(delimiter) == '/'') {
    155.             delimchar = '/'';
    156.         } else {
    157.             delimchar = ' ';
    158.         }
    159.         delimloc = strpos(text, delimchar, delimiter + 1);
    160.         if(delimloc === false) {
    161.             delimloc = text.length;
    162.         } else if(delimchar == '"' || delimchar == '/'') {
    163.             delimiter++;
    164.         }
    165.         return trim(text.substr(delimiter, delimloc - delimiter));
    166.     } else {
    167.         return '';
    168.     }
    169. }
    170. function fonttag(fontoptions, text) {
    171.     var prepend = '';
    172.     var append = '';
    173.     var tags = new Array();
    174.     tags = {'font' : 'face=''size' : 'size=''color' : 'color='};
    175.     for(bbcode in tags) {
    176.         optionvalue = fetchoptionvalue(tags[bbcode], fontoptions);
    177.         if(optionvalue) {
    178.             prepend += '[' + bbcode + '=' + optionvalue + ']';
    179.             append = '[/' + bbcode + ']' + append;
    180.         }
    181.     }
    182.     var pend = parsestyle(fontoptions, prepend, append);
    183.     return pend['prepend'] + recursion('font', text, 'fonttag') + pend['append'];
    184. }
    185. function getoptionvalue(option, text) {
    186.     re = new RegExp(option + "(/s+?)?/=(/s+?)?[/"']?(.+?)([/"']|$|>)""ig");
    187.     var matches = re.exec(text);
    188.     if(matches != null && matches.length) {
    189.         return trim(matches[3]);
    190.     }
    191.     return '';
    192. }
    193. function html2bbcode(str) {
    194.     str = trim(str);
    195.     if(str == '' || forumallowhtml || (allowhtml && fetchCheckbox('htmlon'))) {
    196.         return str;
    197.     }
    198.     str= str.replace(//s*/[code/]([/s/S]+?)/[//code/]/s*/ig, function($1, $2) {return codetag($2);});
    199.     str = str.replace(/<style.*?>[/s/S]*?<//style>/ig, '');
    200.     str = str.replace(/<script.*?>[/s/S]*?<//script>/ig, '');
    201.     str = str.replace(/<noscript.*?>[/s/S]*?<//noscript>/ig, '');
    202.     str = str.replace(/<select.*?>[/s/S]*?<//select>/ig, '');
    203.     str = str.replace(/<object.*?>[/s/S]*?<//object>/ig, '');
    204.     str = str.replace(/<!--[/s/S]*?-->/ig, '');
    205.     str = str.replace(/on[a-zA-Z]{3,16}/s?=/s?(["'])[/s/S]*?/1/ig, '');
    206.     str = str.replace(/(/r/n|/n|/r)/ig, '');
    207.     str = str.replace(/<table([^>]*width[^>]*)>/ig, function($1, $2) {return tabletag($2);});
    208.     str = str.replace(/<table[^>]*>/ig, '[table]');
    209.     str = str.replace(/<tr[^>]*>/ig, '[tr]');
    210.     str = str.replace(/<td>/ig, '[td]');
    211.     str = str.replace(/<td([^>]+)>/ig, function($1, $2) {return tdtag($2);});
    212.     str = str.replace(/<//td>/ig, '[/td]');
    213.     str = str.replace(/<//tr>/ig, '[/tr]');
    214.     str = str.replace(/<//table>/ig, '[/table]');
    215.     str = str.replace(/<h([0-9]+)[^>]*>(.*)<//h//1>/ig, "[size=$1]$2[/size]/n/n");
    216.     str = str.replace(/<img[^>]+smilieid=(["']?)(/d+)(/1)[^>]*>/ig, function($1, $2, $3) {return smilies[$3]['code'];});
    217.     str = str.replace(/<img([^>]*src[^>]*)>/ig, function($1, $2) {return imgtag($2);});
    218.     str = str.replace(/<a/s+?name=(["']?)(.+?)(/1)[/s/S]*?>([/s/S]*?)<//a>/ig, '$4');
    219.     str = str.replace(/<br[^/>]*>/ig, "/n");
    220.     str = recursion('b', str, 'simpletag''b');
    221.     str = recursion('strong', str, 'simpletag''b');
    222.     str = recursion('i', str, 'simpletag''i');
    223.     str = recursion('em', str, 'simpletag''i');
    224.     str = recursion('u', str, 'simpletag''u');
    225.     str = recursion('a', str, 'atag');
    226.     str = recursion('font', str, 'fonttag');
    227.     str = recursion('blockquote', str, 'simpletag''indent');
    228.     str = recursion('ol', str, 'listtag');
    229.     str = recursion('ul', str, 'listtag');
    230.     str = recursion('div', str, 'dpstag');
    231.     str = recursion('p', str, 'dpstag');
    232.     str = recursion('span', str, 'dpstag');
    233.     str = str.replace(/<[///!]*?[^<>]*?>/ig, '');
    234.     for(var i = 0; i <= pcodecount; i++) {
    235.         str = str.replace("[/tDISCUZ_CODE_" + i + "/t]", codehtml[i]);
    236.     }
    237.     str = str.replace(/&/ig, '&');
    238.     str = str.replace(/ /ig, ' ');
    239.     str = str.replace(/</ig, '<');
    240.     str = str.replace(/>/ig, '>');
    241.     return str
    242. }
    243. function htmlspecialchars(str) {
    244.     var f = new Array(
    245.         (is_mac && is_ie ? new RegExp('&''g') : new RegExp('&(?!#[0-9]+;)''g')),
    246.         new RegExp('<''g'),
    247.         new RegExp('>''g'),
    248.         new RegExp('"''g')
    249.     );
    250.     var r = new Array(
    251.         '&',
    252.         '<',
    253.         '>',
    254.         '"'
    255.     );
    256.     for(var i = 0; i < f.length; i++) {
    257.         str = str.replace(f[i], r[i]);
    258.     }
    259.     return str;
    260. }
    261. function imgtag(attributes) {
    262.     var width = '';
    263.     var height = '';
    264.     re = /src=(["']?)([/s/S]*?)(/1)/i;
    265.     var matches = re.exec(attributes);
    266.     if(matches != null) {
    267.         var src = matches[2];
    268.     } else {
    269.         return '';
    270.     }
    271.     re = /width=(["']?)(/d+)(/1)/i;
    272.     var matches = re.exec(attributes);
    273.     if(matches != null) {
    274.         width = matches[2];
    275.     }
    276.     re = /height=(["']?)(/d+)(/1)/i;
    277.     var matches = re.exec(attributes);
    278.     if(matches != null) {
    279.         height = matches[2];
    280.     }
    281.     return width > 0 && height > 0 ?
    282.         '[img=' + width + ',' + height + ']' + src + '[/img]' :
    283.         '[img]' + src + '[/img]';
    284. }
    285. function listtag(listoptions, text, tagname) {
    286.     text = text.replace(/<li>(([/s/S](?!<//li))*?)(?=<//?ol|<//?ul|<li|/[list|/[//list)/ig, '<li>$1</li>') + (is_opera ? '</li>' : '');
    287.     text = recursion('li', text, 'litag');
    288.     var opentag = '[list]';
    289.     if(tagname == 'ol') {
    290.         var listtype = fetchoptionvalue('type=', listoptions);
    291.         listtype = listtype != '' ? listtype : '1';
    292.         if(in_array(listtype, ['1''a''A'])) {
    293.             opentag = '[list=' + listtype + ']';
    294.         }
    295.     }
    296.     return text ? opentag + recursion(tagname, text, 'listtag') + '[/list]' : '';
    297. }
    298. function litag(listoptions, text) {
    299.     return '[*]' + text.replace(/(/s+)$/g, '');
    300. }
    301. function parsecode(text) {
    302.     pcodecount++;
    303.     text = text.replace(/^[/n/r]*([/s/S]+?)[/n/r]*$/ig, '$1');
    304.     text = htmlspecialchars(text);
    305.     codehtml[pcodecount] = '[code]' + text + '[/code]';
    306.     codecount++;
    307.     return "[/tDISCUZ_CODE_" + pcodecount + "/t]";
    308. }
    309. function parsestyle(tagoptions, prepend, append) {
    310.     var searchlist = [
    311.         ['align'true'text-align://s*(left|center|right);?', 1],
    312.         ['color'true'^(?://s|)color://s*([^;]+);?', 1],
    313.         ['font'true'font-family://s*([^;]+);?', 1],
    314.         ['size'true'font-size://s*(//d+(px|pt|in|cm|mm|pc|em|ex|%|));?', 1],
    315.         ['b'false'font-weight://s*(bold);?'],
    316.         ['i'false'font-style://s*(italic);?'],
    317.         ['u'false'text-decoration://s*(underline);?']
    318.     ];
    319.     var style = getoptionvalue('style', tagoptions);
    320.     re = /^(?:/s|)color:/s*rgb/((/d+),/s*(/d+),/s*(/d+)/)(;?)/ig;
    321.     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);});
    322.     var len = searchlist.length;
    323.     for(var i = 0; i < len; i++) {
    324.         re = new RegExp(searchlist[i][2], "ig");
    325.         match = re.exec(style);
    326.         if(match != null) {
    327.             opnvalue = match[searchlist[i][3]];
    328.             prepend += '[' + searchlist[i][0] + (searchlist[i][1] == true ? '=' + opnvalue + ']' : ']');
    329.             append = '[/' + searchlist[i][0] + ']' + append;
    330.         }
    331.     }
    332.     return {'prepend' : prepend, 'append' : append};
    333. }
    334. function parsetable(width, str) {
    335.     if(typeof width == 'undefined') {
    336.         var width = '';
    337.     } else {
    338.         width = width.substr(width.length - 1, width.length) == '%' ? (width.substr(0, width.length - 1) <= 98 ? width : '98%') : (width <= 560 ? width : '98%');
    339.     }
    340.     var string = '<table '
    341.         + (width == '' ? '' : 'width="' + width + '" ')
    342.         + 'align="center" class="t_table">';
    343.     str = str.replace(//[td=(/d{1,2}),(/d{1,2})(,(/d{1,3}%?))?/]/ig, '<td colspan="$1" rowspan="$2" width="$4">');
    344.     str = str.replace(//[tr/]/ig, '<tr>');
    345.     str = str.replace(//[td/]/ig, '<td>');
    346.     str = str.replace(//[//td/]/ig, '</td>');
    347.     str = str.replace(//[//tr/]/ig, '</tr>');
    348.     string += str;
    349.     string += '</table>';
    350.     return string;
    351. }
    352. function recursion(tagname, text, dofunction, extraargs) {
    353.     if(extraargs == null) {
    354.         extraargs = '';
    355.     }
    356.     tagname = tagname.toLowerCase();
    357.     var open_tag = '<' + tagname;
    358.     var open_tag_len = open_tag.length;
    359.     var close_tag = '</' + tagname + '>';
    360.     var close_tag_len = close_tag.length;
    361.     var beginsearchpos = 0;
    362.     do {
    363.         var textlower = text.toLowerCase();
    364.         var tagbegin = textlower.indexOf(open_tag, beginsearchpos);
    365.         if(tagbegin == -1) {
    366.             break;
    367.         }
    368.         var strlen = text.length;
    369.         var inquote = '';
    370.         var found = false;
    371.         var tagnameend = false;
    372.         var optionend = 0;
    373.         var t_char = '';
    374.         for(optionend = tagbegin; optionend <= strlen; optionend++) {
    375.             t_char = text.charAt(optionend);
    376.             if((t_char == '"' || t_char == "'") && inquote == '') {
    377.                 inquote = t_char;
    378.             } else if((t_char == '"' || t_char == "'") && inquote == t_char) {
    379.                 inquote = '';
    380.             } else if(t_char == '>' && !inquote) {
    381.                 found = true;
    382.                 break;
    383.             } else if((t_char == '=' || t_char == ' ') && !tagnameend) {
    384.                 tagnameend = optionend;
    385.             }
    386.         }
    387.         if(!found) {
    388.             break;
    389.         }
    390.         if(!tagnameend) {
    391.             tagnameend = optionend;
    392.         }
    393.         var offset = optionend - (tagbegin + open_tag_len);
    394.         var tagoptions = text.substr(tagbegin + open_tag_len, offset)
    395.         var acttagname = textlower.substr(tagbegin * 1 + 1, tagnameend - tagbegin - 1);
    396.         if(acttagname != tagname) {
    397.             beginsearchpos = optionend;
    398.             continue;
    399.         }
    400.         var tagend = textlower.indexOf(close_tag, optionend);
    401.         if(tagend == -1) {
    402.             break;
    403.         }
    404.         var nestedopenpos = textlower.indexOf(open_tag, optionend);
    405.         while(nestedopenpos != -1 && tagend != -1) {
    406.             if(nestedopenpos > tagend) {
    407.                 break;
    408.             }
    409.             tagend = textlower.indexOf(close_tag, tagend + close_tag_len);
    410.             nestedopenpos = textlower.indexOf(open_tag, nestedopenpos + open_tag_len);
    411.         }
    412.         if(tagend == -1) {
    413.             beginsearchpos = optionend;
    414.             continue;
    415.         }
    416.         var localbegin = optionend + 1;
    417.         var localtext = eval(dofunction)(tagoptions, text.substr(localbegin, tagend - localbegin), tagname, extraargs);
    418.         text = text.substring(0, tagbegin) + localtext + text.substring(tagend + close_tag_len);
    419.         beginsearchpos = tagbegin + localtext.length;
    420.     } while(tagbegin != -1);
    421.     return text;
    422. }
    423. function simpletag(options, text, tagname, parseto) {
    424.     if(trim(text) == '') {
    425.         return '';
    426.     }
    427.     text = recursion(tagname, text, 'simpletag', parseto);
    428.     return '[' + parseto + ']' + text + '[/' + parseto + ']';
    429. }
    430. function strpos(haystack, needle, offset) {
    431.     if(typeof offset == 'undefined') {
    432.         offset = 0;
    433.     }
    434.     index = haystack.toLowerCase().indexOf(needle.toLowerCase(), offset);
    435.     return index == -1 ? false : index;
    436. }
    437. function tabletag(attributes) {
    438.     var width = '';
    439.     re = /width=(["']?)(/d{1,3}%?)(/1)/ig;
    440.     var matches = re.exec(attributes);
    441.     if(matches != null && matches.length) {
    442.         width = matches[2].substr(matches[2].length - 1, matches[2].length) == '%' ?
    443.             (matches[2].substr(0, matches[2].length - 1) <= 98 ? matches[2] : '98%') :
    444.             (matches[2] <= 560 ? matches[2] : '98%');
    445.     } else {
    446.         re = /width/s?:/s?(/d{1,3})([px|%])/ig;
    447.         var matches = re.exec(attributes);
    448.         if(matches != null && matches.length) {
    449.             width = matches[2] == '%' ? (matches[1] <= 98 ? matches[1] : '98%') : (matches[1] <= 560 ? matches[1] : '98%');
    450.         }
    451.     }
    452.     return width == '' ? '[table]' : '[table=' + width + ']';
    453. }
    454. function tdtag(attributes) {
    455.     var colspan = 1;
    456.     var rowspan = 1;
    457.     var width = '';
    458.     re = /colspan=(["']?)(/d{1,2})(/1)/ig;
    459.     var matches = re.exec(attributes);
    460.     if(matches != null) {
    461.         colspan = matches[2];
    462.     }
    463.     re = /rowspan=(["']?)(/d{1,2})(/1)/ig;
    464.     var matches = re.exec(attributes);
    465.     if(matches != null) {
    466.         rowspan = matches[2];
    467.     }
    468.     re = /width=(["']?)(/d{1,3}%?)(/1)/ig;
    469.     var matches = re.exec(attributes);
    470.     if(matches != null) {
    471.         width = matches[2];
    472.     }
    473.     return in_array(width, ['''0''100%']) ?
    474.         (colspan == 1 && rowspan == 1 ? '[td]' : '[td=' + colspan + ',' + rowspan + ']') :
    475.         '[td=' + colspan + ',' + rowspan + ',' + width + ']';
    476. }
    477. function trim(str) {
    478.     return (str.replace(/(/s+)$/g, '')).replace(/^/s+/g, '');
    479. }
       4。新建ubb default.jsp
  1. <%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=gbk">
  5. <title>UBB编辑器</title>
  6. <link rel="stylesheet" type="text/css" id="css" href="Images/ubb.css">
  7. </head>
  8. <body>
  9. <form id="postform" method="post" >
  10. <table  id="postcontent" cellpadding="0" border="0" class="editor"  bordercolor="#000000">
  11. <tr>
  12. <th colspan="2" >添加贴子</th>
  13. </tr>
  14. <tr>
  15. <td width="26">标题</td>
  16. <td width="640" style="text-align:left">
  17. <input type="text" name="title"  size="42">
  18. </td>
  19. </tr>
  20. <tr> 
  21. <td>内容</td>
  22. <td >
  23. <div align="center">
  24. <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>
  25. </div>
  26. </td>
  27. </tr>
  28. <tr>
  29. <td>
  30. <textarea name="mssgcontent" id="mssgcontent" cols="80" rows="2" style="display:none"></textarea>
  31. </td>
  32. </tr>
  33. <tr>
  34. <td colspan="2">
  35.     <div align="center">
  36.       <input id="SubButton" name="SubButton" type="button" value="添加内容"> 
  37.        
  38.       <input type="reset" value="重新填写">
  39.     </div></td>
  40. </tr>
  41. </table>
  42. <br>
  43. <br>
  44. <table cellpadding="0" border="0" class="editor"  bordercolor="#000000" style="width:650px; height:250px">
  45. <tr>
  46. <th height="22" colspan="2" >转换后内容</th>
  47. </tr>
  48. <tr>
  49. <td  width="42">
  50. 内容:
  51. </td>
  52. <td width="630" valign="top" class="editor_text">
  53. <div align="left">
  54. <div id="reslut" name="reslut"></div>
  55. </div>
  56. </td>
  57. </tr>
  58. </table>
  59. </form>
  60. </body>
  61. </html>

comm.js

 

 

  1. /******************************************************************************
  2.   Crossday Discuz! Board - Common Modules for Discuz!
  3.   Copyright 2001-2006 Comsenz Inc. (http://www.comsenz.com)
  4. *******************************************************************************/
  5. var sPop = null;
  6. var postSubmited = false;
  7. var userAgent = navigator.userAgent.toLowerCase();
  8. var is_opera = (userAgent.indexOf('opera') != -1);
  9. var is_saf = ((userAgent.indexOf('applewebkit') != -1) || (navigator.vendor == 'Apple Computer, Inc.'));
  10. var is_webtv = (userAgent.indexOf('webtv') != -1);
  11. var is_ie = ((userAgent.indexOf('msie') != -1) && (!is_opera) && (!is_saf) && (!is_webtv));
  12. var is_ie4 = ((is_ie) && (userAgent.indexOf('msie 4.') != -1));
  13. var is_moz = ((navigator.product == 'Gecko') && (!is_saf));
  14. var is_kon = (userAgent.indexOf('konqueror') != -1);
  15. var is_ns = ((userAgent.indexOf('compatible') == -1) && (userAgent.indexOf('mozilla') != -1) && (!is_opera) && (!is_webtv) && (!is_saf));
  16. var is_ns4 = ((is_ns) && (parseInt(navigator.appVersion) == 4));
  17. var is_mac = (userAgent.indexOf('mac') != -1);
  18. function ctlent(event) {
  19.     
  20. }
  21. function storeCaret(textEl){
  22.     if(textEl.createTextRange){
  23.         textEl.caretPos = document.selection.createRange().duplicate();
  24.     }
  25. }
  26. function checkall(form, prefix, checkall) {
  27.     var checkall = checkall ? checkall : 'chkall';
  28.     for(var i = 0; i < form.elements.length; i++) {
  29.         var e = form.elements[i];
  30.         if(e.name != checkall && (!prefix || (prefix && e.name.match(prefix)))) {
  31.             e.checked = form.elements[checkall].checked;
  32.         }
  33.     }
  34. }
  35. function arraypop(a) {
  36.     if(typeof a != 'object' || !a.length) {
  37.         return null;
  38.     } else {
  39.         var response = a[a.length - 1];
  40.         a.length--;
  41.         return response;
  42.     }
  43. }
  44. function arraypush(a, value) {
  45.     a[a.length] = value;
  46.     return a.length;
  47. }
  48. function findtags(parentobj, tag) {
  49.     if(typeof parentobj.getElementsByTagName != 'undefined') {return parentobj.getElementsByTagName(tag);}
  50.     else if(parentobj.all && parentobj.all.tags) {return parentobj.all.tags(tag);}
  51.     else {return null;}
  52. }
  53. function copycode(obj) {
  54.     var rng = document.body.createTextRange();
  55.     rng.moveToElementText(obj);
  56.     rng.scrollIntoView();
  57.     rng.select();
  58.     rng.execCommand("Copy");
  59.     rng.collapse(false);
  60. }
  61. function toggle_collapse(objname, unfolded) {
  62.     if(typeof unfolded == 'undefined') {
  63.         var unfolded = 1;
  64.     }
  65.     var obj = $(objname);
  66.     var oldstatus = obj.style.display;
  67.     var collapsed = getcookie('discuz_collapse');
  68.     var cookie_start = collapsed ? collapsed.indexOf(objname) : -1;
  69.     var cookie_end = cookie_start + objname.length + 1;
  70.     obj.style.display = oldstatus == 'none' ? '' : 'none';
  71.     collapsed = cookie_start != -1 && ((unfolded && oldstatus == 'none') || (!unfolded && oldstatus == '')) ?
  72.             collapsed.substring(0, cookie_start) + collapsed.substring(cookie_end, collapsed.length) : (
  73.             cookie_start == -1 && ((unfolded && oldstatus == '') || (!unfolded && oldstatus == 'none')) ?
  74.             collapsed + objname + ' ' : collapsed);
  75.     expires = new Date();
  76.     expires.setTime(expires.getTime() + (collapsed ? 86400 * 30 : -(86400 * 30 * 1000)));
  77.     document.cookie = 'discuz_collapse=' + escape(collapsed) + '; expires=' + expires.toGMTString() + '; path=/';
  78.     var img = $(objname + '_img');
  79.     var img_regexp = new RegExp((oldstatus == 'none' ? '_yes' : '_no') + '//.gif$');
  80.     var img_re = oldstatus == 'none' ? '_no.gif' : '_yes.gif'
  81.     if(img) {
  82.         img.src = img.src.replace(img_regexp, img_re);
  83.     }
  84. }
  85. function imgzoom(o) {
  86.     if(event.ctrlKey) {
  87.         var zoom = parseInt(o.style.zoom, 10) || 100;
  88.         zoom -= event.wheelDelta / 12;
  89.         if(zoom > 0) {
  90.             o.style.zoom = zoom + '%';
  91.         }
  92.         return false;
  93.     } else {
  94.         return true;
  95.     }
  96. }
  97. function getcookie(name) {
  98.     var cookie_start = document.cookie.indexOf(name);
  99.     var cookie_end = document.cookie.indexOf(";", cookie_start);
  100.     return cookie_start == -1 ? '' : unescape(document.cookie.substring(cookie_start + name.length + 1, (cookie_end > cookie_start ? cookie_end : document.cookie.length)));
  101. }
  102. function AddText(txt) {
  103.     obj = $('message');
  104.     selection = document.selection;
  105.     checkFocus();
  106.     if(typeof(obj.selectionStart) != 'undefined') {
  107.         var opn = obj.selectionStart + 0;
  108.         obj.value = obj.value.substr(0, obj.selectionStart) + txt + obj.value.substr(obj.selectionEnd);
  109.     } else if(selection && selection.createRange) {
  110.         var sel = selection.createRange();
  111.         sel.text = txt;
  112.         sel.moveStart('character', -mb_strlen(txt));
  113.     } else {
  114.         obj.value += txt;
  115.     }
  116. }
  117. function insertAtCaret (textEl, text){
  118.     if(textEl.createTextRange && textEl.caretPos){
  119.         var caretPos = textEl.caretPos;
  120.         caretPos.text += caretPos.text.charAt(caretPos.text.length - 2) == ' ' ? text + ' ' : text;
  121.     } else if(textEl) {
  122.         textEl.value += text;
  123.     } else {
  124.         textEl.value = text;
  125.     }
  126. }
  127. function checkFocus() {
  128.     var obj = typeof wysiwyg == 'undefined' || !wysiwyg ? $('posteditor_textarea') : editwin;
  129.     if(!obj.hasfocus) {
  130.         obj.focus();
  131.     }
  132. }
  133. function closesmiliewindow(e) {
  134.     if(typeof smiliewindow != 'undefined' && !smiliewindow.closed) {
  135.         smiliewindow.close();
  136.     }
  137. }
  138. function opensmiliewindow(width, height, editorid) {
  139.     smiliewindow = window.open('post.php?action=smilies' + (editorid ? '&editorid=' + editorid : ''), 'Popup''width=' + width + ',height=' + height + ',resizable=yes,scrollbars=yes');
  140.     window.onunload = closesmiliewindow;
  141. }
  142. function mb_strlen(str) {
  143.     return (is_ie && str.indexOf('/n') != -1) ? str.replace(//r?/n/g, '_').length : str.length;
  144. }
  145. function insertSmiley(smilieid) {
  146.     checkFocus();
  147.     var src = $('smilie_' + smilieid).src;
  148.     var code = $('smilie_' + smilieid).pop ? $('smilie_' + smilieid).pop : $('smilie_' + smilieid).alt;
  149.     if(typeof wysiwyg != 'undefined' && wysiwyg && allowsmilies && (!$('smileyoff') || $('smileyoff').checked == false)) {
  150.         if(is_moz) {
  151.             applyFormat('InsertImage'false, src);
  152.             var smilies = findtags(editdoc.body, 'img');
  153.             for(var i = 0; i < smilies.length; i++) {
  154.                 if(smilies[i].src == src && smilies[i].getAttribute('smilieid') < 1) {
  155.                     smilies[i].setAttribute('smilieid', smilieid);
  156.                     smilies[i].setAttribute('border'"0");
  157.                 }
  158.             }
  159.         } else {
  160.             insertText('<img src="' + src + '" border="0" smilieid="' + smilieid + '" alt="" /> 'false);
  161.         }
  162.     } else {
  163.         code += ' ';
  164.         AddText(code);
  165.     }
  166. }
  167. function announcement() {
  168.     $('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();">' +
  169.         $('announcement').innerHTML + '</marquee>';
  170.     $('announcement').style.display = 'block';
  171. }
  172. function $(id) {
  173.     return document.getElementById(id);
  174. }
  175. function in_array(needle, haystack) {
  176.     if(typeof needle == 'string') {
  177.         for(var i in haystack) {
  178.             if(haystack[i] == needle) {
  179.                     return true;
  180.             }
  181.         }
  182.     }
  183.     return false;
  184. }
  185. document.write("<style type='text/css'id='defaultPopStyle'>");
  186. 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)}");
  187. document.write("</style>");
  188. document.write("<div id='popLayer' style='position:absolute;z-index:1000' class='cPopText'></div>");
  189. function showPopupText(event) {
  190.     if(event.srcElement) o = event.srcElement; else o = event.target;
  191.     if(!o) {
  192.         return;
  193.     }
  194.     MouseX = event.clientX;
  195.     MouseY = event.clientY;
  196.     if(o.alt != null && o.alt != '') {
  197.         o.pop = o.alt;
  198.         o.alt = '';
  199.     }
  200.     if(o.title != null && o.title != '') {
  201.         o.pop = o.title;
  202.         o.title = '';
  203.     }
  204.     if(o.pop != sPop) {
  205.         sPop = o.pop;
  206.         if(sPop == null || sPop == '') {
  207.             $('popLayer').style.visibility = "hidden";
  208.         } else {
  209.             popStyle = o.dyclass != null ? o.dyclass : 'cPopText';
  210.             $('popLayer').style.visibility = "visible";
  211.             showIt();
  212.         }
  213.     }
  214. }
  215. function showIt() {
  216.     $('popLayer').className = popStyle;
  217.     $('popLayer').innerHTML = sPop.replace(/<(.*)>/g,"<$1>").replace(//n/g,"<br>");
  218.     var popWidth = $('popLayer').clientWidth;
  219.     var popHeight = $('popLayer').clientHeight;
  220.     var popLeftAdjust = MouseX + 12 + popWidth > document.body.clientWidth ? -popWidth - 24 : 0;
  221.     var popTopAdjust = MouseY + 12 + popHeight > document.body.clientHeight ? -popHeight - 24 : 0;
  222.     $('popLayer').style.left = (MouseX + 12 + document.body.scrollLeft + popLeftAdjust) + 'px';
  223.     $('popLayer').style.top = (MouseY + 12 + document.body.scrollTop + popTopAdjust) + 'px';
  224. }
  225. if(!document.onmouseover) {
  226.     document.onmouseover = function(e) {
  227.         var event = e ? e : window.event;
  228.         showPopupText(event);
  229.     };
  230. }

editor.js

 

  1. /******************************************************************************
  2.   Crossday Discuz! Board - Editor Modules for Discuz!
  3.   Copyright 2001-2006 Comsenz Inc. (http://www.comsenz.com)
  4. *******************************************************************************/
  5. var editbox = editwin = editdoc = null;
  6. var cursor = -1;
  7. var stack = new Array();
  8. function newEditor(mode, initialtext) {
  9.     wysiwyg = parseInt(mode);
  10.     if(!(is_ie || is_moz || (is_opera && opera.version() >= 9))) {
  11.         allowswitcheditor = wysiwyg = 0;
  12.     }
  13.     var bbcodemode = $('bbcodemode');
  14.     var wysiwygmode = $('wysiwygmode');
  15.     bbcodemode.className = wysiwyg ? 'editor_switcher' : 'editor_switcher_highlight';
  16.     wysiwygmode.className = wysiwyg ? 'editor_switcher_highlight' : 'editor_switcher';
  17.     if(!allowswitcheditor) {
  18.         $(editorid + '_switcher').style.display = 'none';
  19.     }
  20.     $(editorid + '_cmd_table').style.display = wysiwyg ? '' : 'none';
  21.     if(wysiwyg) {
  22.         if($(editorid + '_iframe')) {
  23.             editbox = $(editorid + '_iframe');
  24.         } else {
  25.             var iframe = document.createElement('iframe');
  26.             editbox = textobj.parentNode.appendChild(iframe);
  27.             editbox.id = editorid + '_iframe';
  28.         }
  29.         editwin = editbox.contentWindow;
  30.         editdoc = editwin.document;
  31.         writeEditorContents(isUndefined(initialtext) ?  textobj.value : initialtext);
  32.     } else {
  33.         editbox = textobj;
  34.         editwin = textobj;
  35.         editdoc = textobj;
  36.         if(!isUndefined(initialtext)) {
  37.             writeEditorContents(initialtext);
  38.         }
  39.         addSnapshot(textobj.value);
  40.     }
  41.     setEditorEvents();
  42. }
  43. function writeEditorContents(text) {
  44.     if(wysiwyg) {
  45.         if(text == '' && window.is_moz) {
  46.             text = '<br />';
  47.         }
  48.         if(editdoc && editdoc.initialized) {
  49.             editdoc.body.innerHTML = text;
  50.         } else {
  51.             editdoc.designMode = 'on';
  52.             editdoc = editwin.document;
  53.             editdoc.open('text/html''replace');
  54.             editdoc.write(text);
  55.             editdoc.close();
  56.             editdoc.body.contentEditable = true;
  57.             editdoc.initialized = true;
  58.         }
  59.     } else {
  60.         textobj.value = text;
  61.     }
  62.     setEditorStyle();
  63. }
  64. function getEditorContents() {
  65.     return wysiwyg ? editdoc.body.innerHTML : editdoc.value;
  66. }
  67. function setEditorStyle() {
  68.     if(wysiwyg) {
  69.         textobj.style.display = 'none';
  70.         editbox.style.display = '';
  71.         if(window.is_moz || window.is_opera) {
  72.             for(var ss = 0; ss < document.styleSheets.length; ss++) {
  73.                 if(document.styleSheets[ss].cssRules.length <= 0) {
  74.                     continue;
  75.                 }
  76.                 for(var i = 0; i < document.styleSheets[ss].cssRules.length; i++) {
  77.                     if(document.styleSheets[ss].cssRules[i].selectorText == '.wysiwyg') {
  78.                         var newss = editdoc.createElement('style');
  79.                         newss.type = 'text/css';
  80.                         newss.innerHTML = document.styleSheets[ss].cssRules[i].cssText + ' p { margin: 0px; }';
  81.                         editdoc.documentElement.childNodes[0].appendChild(newss);
  82.                         editdoc.body.style.fontSize = document.styleSheets[ss].cssRules[i].style.fontSize;
  83.                         editdoc.body.style.fontFamily = document.styleSheets[ss].cssRules[i].style.fontFamily;
  84.                     }
  85.                 }
  86.             }
  87.             editbox.style.border = '0px';
  88.         } else if(window.is_ie) {
  89.             if(document.styleSheets['css']) {
  90.                 editdoc.createStyleSheet().cssText = document.styleSheets['css'].cssText + ' p { margin: 0px; }';
  91.                 editdoc.body.className = 'wysiwyg';
  92.             }
  93.             editdoc.body.style.border = '0px';
  94.         }
  95.         editbox.style.width = textobj.style.width;
  96.         editbox.style.height = textobj.style.height;
  97.         editdoc.body.style.background = '';
  98.         editdoc.body.style.backgroundColor = '#FFFFFF';
  99.     } else {
  100.         var iframe = textobj.parentNode.getElementsByTagName('iframe')[0];
  101.         if(iframe) {
  102.             textobj.style.display = '';
  103.             textobj.style.width = iframe.style.width;
  104.             textobj.style.height = iframe.style.height;
  105.             iframe.style.display = 'none';
  106.         }
  107.     }
  108. }
  109. function setEditorEvents() {
  110.     if(wysiwyg) {
  111.         if(window.is_moz || window.is_opera) {
  112.             editdoc.addEventListener('mouseup'function(e) {setContext(); popupmenu.hide();}, true);
  113.             editdoc.addEventListener('keyup'function(e) {setContext();}, true);
  114.             editwin.addEventListener('focus'function(e) {this.hasfocus = true;}, true);
  115.             editwin.addEventListener('blur'function(e) {this.hasfocus = false;}, true);
  116.             //editwin.addEventListener('keydown', function(e) {ctlent(e);}, true);
  117.         } else {
  118.             editdoc.onmouseup = function(e) {setContext(); popupmenu.hide();};
  119.             editdoc.onkeyup = function(e) {setContext();};
  120.             if(editdoc.attachEvent) {
  121.                 //editdoc.body.attachEvent("onkeydown", ctlent);
  122.             }
  123.         }
  124.     }
  125.     editwin.onfocus = function(e) {this.hasfocus = true;};
  126.     editwin.onblur = function(e) {this.hasfocus = false;};
  127. }
  128. function wrapTags(tagname, useoption, selection) {
  129.     if(tagname=='code') {
  130.         applyFormat('removeformat');
  131.     }
  132.     if(isUndefined(selection)) {
  133.         var selection = getSel();
  134.         if(selection === false) {
  135.             selection = '';
  136.         } else {
  137.             selection += '';
  138.         }
  139.     }
  140.     if(useoption === true) {
  141.         var option = showPrompt(construct_phrase(lang['enter_tag_option'], ('[' + tagname + ']')), '');
  142.         if(option = verifyPrompt(option)) {
  143.             var opentag = '[' + tagname + '=' + option + ']';
  144.         } else {
  145.             return false;
  146.         }
  147.     } else if(useoption !== false) {
  148.         var opentag = '[' + tagname + '=' + useoption + ']';
  149.     } else {
  150.         var opentag = '[' + tagname + ']';
  151.     }
  152.     var closetag = '[/' + tagname + ']';
  153.     var text = opentag + selection + closetag;
  154.     insertText(text, mb_strlen(opentag), mb_strlen(closetag));
  155.     return false;
  156. }
  157. function applyFormat(cmd, dialog, argument) {
  158.     if(wysiwyg) {
  159.         editdoc.execCommand(cmd, (isUndefined(dialog) ? false : dialog), (isUndefined(argument) ? true : argument));
  160.         return false;
  161.     }
  162.     switch(cmd) {
  163.         case 'bold':
  164.         case 'italic':
  165.         case 'underline':
  166.             wrapTags(cmd.substr(0, 1), false);
  167.             break;
  168.         case 'justifyleft':
  169.         case 'justifycenter':
  170.         case 'justifyright':
  171.             wrapTags('align', cmd.substr(7));
  172.             break;
  173.         case 'indent':
  174.             wrapTags(cmd, false);
  175.             break;
  176.         case 'fontname':
  177.             wrapTags('font', argument);
  178.             break;
  179.         case 'fontsize':
  180.             wrapTags('size', argument);
  181.             break;
  182.         case 'forecolor':
  183.             wrapTags('color', argument);
  184.             break;
  185.         case 'createlink':
  186.             var sel = getSel();
  187.             if(sel) {
  188.                 wrapTags('url', argument);
  189.             } else {
  190.                 wrapTags('url', argument, argument);
  191.             }
  192.             break;
  193.         case 'insertimage':
  194.             wrapTags('img'false, argument);
  195.             break;
  196.     }
  197. }
  198. function customTags(tagname, params) {
  199.     applyFormat('removeformat');
  200.     if(custombbcodes[tagname].indexOf(']') == -1) {
  201.         custombbcodes[tagname] = '[' + tagname + '][/' + tagname + ']';
  202.     }
  203.     if(params == 1) {
  204.         var selection = getSel();
  205.         if(selection === false) {
  206.             selection = '';
  207.         } else {
  208.             selection += '';
  209.         }
  210.         var opentag = '[' + tagname + ']';
  211.         var closetag = '[/' + tagname + ']';
  212.         var text = opentag + selection + closetag;
  213.         selection == '' ? insertText(custombbcodes[tagname], mb_strlen('[' + tagname + ']'), mb_strlen('[/' + tagname + ']')) : insertText(text, mb_strlen(opentag), mb_strlen(closetag));
  214.     } else {
  215.         insertText(custombbcodes[tagname], custombbcodes[tagname].indexOf(']') + 1, mb_strlen('[/' + tagname + ']'));
  216.     }
  217.     return false;
  218. }
  219. function discuzcode(cmd, arg) {
  220.     if(cmd != 'redo') {
  221.         addSnapshot(getEditorContents());
  222.     }
  223.     checkFocus();
  224.     if(in_array(cmd, ['quote''code'])) {
  225.         var ret = wrapTags(cmd, false);
  226.     } else if(cmd.substr(0, 6) == 'custom') {
  227.         var ret = customTags(cmd.substr(8), cmd.substr(6, 1));
  228.     } else if(!wysiwyg && cmd == 'removeformat') {
  229.         var simplestrip = new Array('b''i''u');
  230.         var complexstrip = new Array('font''color''size');
  231.         var str = getSel();
  232.         if(str === false) {
  233.             return;
  234.         }
  235.         for(var tag in simplestrip) {
  236.             str = stripSimple(simplestrip[tag], str);
  237.         }
  238.         for(var tag in complexstrip) {
  239.             str = stripComplex(complexstrip[tag], str);
  240.         }
  241.         insertText(str);
  242.     } else if(!wysiwyg && cmd == 'undo') {
  243.         addSnapshot(getEditorContents());
  244.         moveCursor(-1);
  245.         if((str = getSnapshot()) !== false) {
  246.             editdoc.value = str;
  247.         }
  248.     } else if(!wysiwyg && cmd == 'redo') {
  249.         moveCursor(1);
  250.         if((str = getSnapshot()) !== false) {
  251.             editdoc.value = str;
  252.         }
  253.     } else if(!wysiwyg && in_array(cmd, ['insertorderedlist''insertunorderedlist'])) {
  254.         var listtype = cmd == 'insertorderedlist' ? '1' : '';
  255.         var opentag = '[list' + (listtype ? ('=' + listtype) : '') + ']/n';
  256.         var closetag = '[/list]';
  257.         if(txt = getSel()) {
  258.             var regex = new RegExp('([/r/n]+|^[/r/n]*)(?!//[//*//]|//[///?list)(?=[^/r/n])''gi');
  259.             txt = opentag + trim(txt).replace(regex, '$1[*]') + '/n' + closetag;
  260.             insertText(txt, mb_strlen(txt), 0);
  261.         } else {
  262.             insertText(opentag + closetag, opentag.length, closetag.length);
  263.             while(listvalue = prompt(lang['enter_list_item'], '')) {
  264.                 if(window.is_opera && opera.version() > 8) {
  265.                     listvalue = '/n' + '[*]' + listvalue;
  266.                     insertText(listvalue, mb_strlen(listvalue) + 1, 0);
  267.                 } else {
  268.                     listvalue = '[*]' + listvalue + '/n';
  269.                     insertText(listvalue, mb_strlen(listvalue), 0);
  270.                 }
  271.             }
  272.         }
  273.     } else if(!wysiwyg && cmd == 'outdent') {
  274.         var sel = getSel();
  275.         sel = stripSimple('indent', sel, 1);
  276.         insertText(sel);
  277.     } else if(cmd == 'createlink') {
  278.         if(wysiwyg) {
  279.             if(window.is_moz || window.is_opera) {
  280.                 var url = showPrompt(lang['enter_link_url'], 'http://');
  281.                 if((url = verifyPrompt(url)) !== false) {
  282.                     if(getSel()) {
  283.                         applyFormat('unlink');
  284.                         applyFormat('createlink', window.is_ie, (isUndefined(url) ? true : url));
  285.                     } else {
  286.                         insertText('<a href="' + url + '">' + url + '</a>');
  287.                     }
  288.                 }
  289.             } else {
  290.                 applyFormat('createlink', window.is_ie, (isUndefined(url) ? true : url));
  291.             }
  292.         } else {
  293.             promptLink('url', lang['enter_link_url'], 'http://');
  294.         }
  295.     } else if(!wysiwyg && cmd == 'unlink') {
  296.         var sel = getSel();
  297.         sel = stripSimple('url', sel);
  298.         sel = stripComplex('url', sel);
  299.         insertText(sel);
  300.     } else if(cmd == 'email') {
  301.         if(wysiwyg) {
  302.             var email = showPrompt(lang['enter_email_link'], '');
  303.             email = verifyPrompt(email);
  304.             if(email === false) {
  305.                 applyFormat('unlink');
  306.             } else {
  307.                 var selection = getSel();
  308.                 insertText('<a href="mailto:' + email + '">' + (selection ? selection : email) + '</a>', (selection ? true : false));
  309.             }
  310.         } else {
  311.             promptLink('email', lang['enter_email_link'], '');
  312.         }
  313.     } else if(cmd == 'insertimage') {
  314.         var img = showPrompt(lang['enter_image_url'], 'http://');
  315.         if(img = verifyPrompt(img)) {
  316.             return applyFormat('insertimage'false, img);
  317.         } else {
  318.             return false;
  319.         }
  320.     } else if(cmd == 'table') {
  321.         if(wysiwyg) {
  322.             if(isUndefined(rows)) {
  323.                 var rows = showPrompt(lang['enter_table_rows'], '2');
  324.             }
  325.             if(rows != 'null' && isUndefined(columns)) {
  326.                 var columns = showPrompt(lang['enter_table_columns'], '2');
  327.             }
  328.             if(!isUndefined(columns) && columns != 'null') {
  329.                 rows = /^[-/+]?/d+$/.test(rows) && rows > 0 && rows <= 30 ? rows : 2;
  330.                 columns = /^[-/+]?/d+$/.test(columns) && columns > 0 && columns <= 30 ? columns : 2;
  331.                 var html = '<table cellspacing="1" cellpadding="4" width="50%" align="center" style="background: ' + BORDERCOLOR + '">';
  332.                 for (var row = 0; row < rows; row++) {
  333.                     html += '<tr bgcolor="' + ALTBG2 + '">/n';
  334.                     for (col = 0; col < columns; col++) {
  335.                         html += '<td> </td>/n';
  336.                     }
  337.                     html+= '</tr>/n';
  338.                 }
  339.                 html += '</table>/n';
  340.                 insertText(html);
  341.             }
  342.         }
  343.         return false;
  344.     } else {
  345.         var ret = applyFormat(cmd, false, (isUndefined(arg) ? true : arg));
  346.     }
  347.     if(cmd != 'undo') {
  348.         addSnapshot(getEditorContents());
  349.     }
  350.     if(wysiwyg) {
  351.         setContext(cmd);
  352.         if(cmd == 'forecolor') {
  353.             $(editorid + '_color_bar').style.backgroundColor = arg;
  354.         }
  355.     }
  356.     checkFocus();
  357.     return ret;
  358. }
  359. function setContext(cmd) {
  360.     var contextcontrols = new Array('bold''italic''underline''justifyleft''justifycenter''justifyright''insertorderedlist''insertunorderedlist');
  361.     for(var i in contextcontrols) {
  362.         var obj = $(editorid + '_cmd_' + contextcontrols[i]);
  363.         if(obj != null) {
  364.             try {
  365.                 var state = editdoc.queryCommandState(contextcontrols[i]);
  366.             } catch(e) {
  367.                 var state = false;
  368.             }
  369.             if(isUndefined(obj.state)) {
  370.                 obj.state = false;
  371.             }
  372.             if(obj.state != state) {
  373.                 obj.state = state;
  374.                 buttonContext(obj, (obj.id.substr(obj.id.indexOf('_cmd_') + 5) == cmd ? 'mouseover' : 'mouseout'));
  375.             }
  376.         }
  377.     }
  378.     var fs = editdoc.queryCommandValue('fontname');
  379.     if(fs == '' && !window.is_ie && getComputedStyle) {
  380.         fs = editdoc.body.style.fontFamily;
  381.     } else if(fs == null) {
  382.         fs = '';
  383.     }
  384.     if(fs != $(editorid + '_font_out').fontstate) {
  385.         thingy = fs.indexOf(',') > 0 ? fs.substr(0, fs.indexOf(',')) : fs;
  386.         $(editorid + '_font_out').innerHTML = thingy;
  387.         $(editorid + '_font_out').fontstate = fs;
  388.     }
  389.     var ss = editdoc.queryCommandValue('fontsize');
  390.     if(ss == null || ss == '') {
  391.         ss = formatFontsize(editdoc.body.style.fontSize);
  392.     }
  393.     if(ss != $(editorid + '_size_out').sizestate) {
  394.         if($(editorid + '_size_out').sizestate == null) {
  395.             $(editorid + '_size_out').sizestate = '';
  396.         }
  397.         $(editorid + '_size_out').innerHTML = ss;
  398.         $(editorid + '_size_out').sizestate = ss;
  399.     }
  400.     var cs = editdoc.queryCommandValue('forecolor');
  401.     $(editorid + '_color_bar').style.backgroundColor = rgbToColor(cs);
  402. }
  403. function buttonContext(obj, state) {
  404.     if(state == 'mouseover') {
  405.         var mode = obj.state ? 'down' : 'hover';
  406.         if(obj.mode != mode) {
  407.             obj.mode = mode;
  408.             obj.className = 'editor_button' + mode;
  409.         }
  410.     } else {
  411.         var mode = obj.state ? 'selected' : 'normal';
  412.         if(obj.mode != mode) {
  413.             obj.mode = mode;
  414.             obj.className = mode == 'selected' ? 'editor_buttonselected' : 'editor_button' + 'normal';
  415.         }
  416.     }
  417.     if(window.is_ie && event) {
  418.         event.cancelBubble = true;
  419.     }
  420. }
  421. function menuContext(obj, state) {
  422.     obj.style.cursor = window.is_ie ? 'hand' : 'pointer';
  423.     var mode = state == 'mouseover' ? 'hover' : 'normal';
  424.     obj.className = 'editor_button' + mode;
  425.     var tds = findtags(obj, 'td');
  426.     for(var i = 0; i < tds.length; i++) {
  427.         if(tds[i].id == editorid + '_menu') {
  428.             tds[i].className = 'editor_menu' + mode;
  429.         } else if(tds[i].id == editorid + '_colormenu') {
  430.             tds[i].className = 'editor_colormenu' + mode;
  431.         }
  432.     }
  433. }
  434. function colorContext(obj, state) {
  435.     obj.style.cursor = window.is_ie ? 'hand' : 'pointer';
  436.     var mode = state == 'mouseover' ? 'hover' : 'normal';
  437.     obj.className = 'editor_color' + mode;
  438. }
  439. function getSel() {
  440.     if(wysiwyg) {
  441.         if(window.is_moz || window.is_opera) {
  442.             selection = editwin.getSelection();
  443.             checkFocus();
  444.             range = selection ? selection.getRangeAt(0) : editdoc.createRange();
  445.             return readNodes(range.cloneContents(), false);
  446.         } else {
  447.             var range = editdoc.selection.createRange();
  448.             if(range.htmlText && range.text) {
  449.                 return range.htmlText;
  450.             } else {
  451.                 var htmltext = '';
  452.                 for(var i = 0; i < range.length; i++) {
  453.                     htmltext += range.item(i).outerHTML;
  454.                 }
  455.                 return htmltext;
  456.             }
  457.         }
  458.     } else {
  459.         if(!isUndefined(editdoc.selectionStart)) {
  460.             return editdoc.value.substr(editdoc.selectionStart, editdoc.selectionEnd - editdoc.selectionStart);
  461.         } else if(document.selection && document.selection.createRange) {
  462.             return document.selection.createRange().text;
  463.         } else if(getSelection) {
  464.             return getSelection() + '';
  465.         } else {
  466.             return false;
  467.         }
  468.     }
  469. }
  470. function insertText(text, movestart, moveend) {
  471.     if(wysiwyg) {
  472.         if(window.is_moz || window.is_opera) {
  473.             var fragment = editdoc.createDocumentFragment();
  474.             var holder = editdoc.createElement('span');
  475.             holder.innerHTML = text;
  476.             while(holder.firstChild) {
  477.                 fragment.appendChild(holder.firstChild);
  478.             }
  479.             insertNodeAtSelection(fragment);
  480.         } else {
  481.             checkFocus();
  482.             if(!isUndefined(editdoc.selection) && editdoc.selection.type != 'Text' && editdoc.selection.type != 'None') {
  483.                 movestart = false;
  484.                 editdoc.selection.clear();
  485.             }
  486.             var sel = editdoc.selection.createRange();
  487.             sel.pasteHTML(text);
  488.             if(text.indexOf('/n') == -1) {
  489.                 if(!isUndefined(movestart)) {
  490.                     sel.moveStart('character', -mb_strlen(text) +movestart);
  491.                     sel.moveEnd('character', -moveend);
  492.                 } else if(movestart != false) {
  493.                     sel.moveStart('character', -mb_strlen(text));
  494.                 }
  495.             }
  496.         }
  497.     } else {
  498.         checkFocus();
  499.         if(!isUndefined(editdoc.selectionStart)) {
  500.             var opn = editdoc.selectionStart + 0;
  501.             editdoc.value = editdoc.value.substr(0, editdoc.selectionStart) + text + editdoc.value.substr(editdoc.selectionEnd);
  502.             if(!isUndefined(movestart)) {
  503.                 editdoc.selectionStart = opn + movestart;
  504.                 editdoc.selectionEnd = opn + mb_strlen(text) - moveend;
  505.             } else if(movestart !== false) {
  506.                 editdoc.selectionStart = opn;
  507.                 editdoc.selectionEnd = opn + mb_strlen(text);
  508.             }
  509.         } else if(document.selection && document.selection.createRange) {
  510.             var sel = document.selection.createRange();
  511.             sel.text = text.replace(//r?/n/g, '/r/n');
  512.             if(!isUndefined(movestart)) {
  513.                 sel.moveStart('character', -mb_strlen(text) +movestart);
  514.                 sel.moveEnd('character', -moveend);
  515.             } else if(movestart !== false) {
  516.                 sel.moveStart('character', -mb_strlen(text));
  517.             }
  518.             sel.select();
  519.         } else {
  520.             editdoc.value += text;
  521.         }
  522.     }
  523. }
  524. function isUndefined(variable) {
  525.     return typeof variable == 'undefined' ? true : false;
  526. }
  527. function showPrompt(dialogtxt, defaultval) {
  528.     return trim(prompt(dialogtxt, defaultval) + '');
  529. }
  530. function verifyPrompt(str) {
  531.     if(in_array(str, ['http://''null''undefined''false''']) || str == null || str == false) {
  532.         return false;
  533.     } else {
  534.         return str;
  535.     }
  536. }
  537. function promptLink(tagname, phrase, iprompt) {
  538.     var value = showPrompt(phrase, iprompt);
  539.     if((value = verifyPrompt(value)) !== false) {
  540.         if(getSel()) {
  541.             applyFormat('unlink');
  542.             wrapTags(tagname, value);
  543.         } else {
  544.             wrapTags(tagname, value, value);
  545.         }
  546.     }
  547.     return true;
  548. }
  549. function trim(str) {
  550.     return (str.replace(/(/s+)$/g, '')).replace(/^/s+/g, '');
  551. }
  552. function stripSimple(tag, str, iterations) {
  553.     var opentag = '[' + tag + ']';
  554.     var closetag = '[/' + tag + ']';
  555.     if(isUndefined(iterations)) {
  556.         iterations = -1;
  557.     }
  558.     while((startindex = stripos(str, opentag)) !== false && iterations != 0) {
  559.         iterations --;
  560.         if((stopindex = stripos(str, closetag)) !== false) {
  561.             var text = str.substr(startindex + opentag.length, stopindex - startindex - opentag.length);
  562.             str = str.substr(0, startindex) + text + str.substr(stopindex + closetag.length);
  563.         } else {
  564.             break;
  565.         }
  566.     }
  567.     return str;
  568. }
  569. function stripComplex(tag, str, iterations) {
  570.     var opentag = '[' + tag + '=';
  571.     var closetag = '[/' + tag + ']';
  572.     if(isUndefined(iterations)) {
  573.         iterations = -1;
  574.     }
  575.     while((startindex = stripos(str, opentag)) !== false && iterations != 0) {
  576.         iterations --;
  577.         if((stopindex = stripos(str, closetag)) !== false) {
  578.             var openend = stripos(str, ']', startindex);
  579.             if(openend !== false && openend > startindex && openend < stopindex) {
  580.                 var text = str.substr(openend + 1, stopindex - openend - 1);
  581.                 str = str.substr(0, startindex) + text + str.substr(stopindex + closetag.length);
  582.             } else {
  583.                 break;
  584.             }
  585.         } else {
  586.             break;
  587.         }
  588.     }
  589.     return str;
  590. }
  591. function stripos(haystack, needle, offset) {
  592.     if(isUndefined(offset)) {
  593.         offset = 0;
  594.     }
  595.     var index = haystack.toLowerCase().indexOf(needle.toLowerCase(), offset);
  596.     return (index == -1 ? false : index);
  597. }
  598. function switchEditor(mode) {
  599.     mode = parseInt(mode);
  600.     if(mode == wysiwyg || !allowswitcheditor)  {
  601.         return;
  602.     }
  603.     if(!mode) {
  604.         var controlbar = $(editorid + '_controls');
  605.         var controls = new Array();
  606.         var buttons = findtags(controlbar, 'div');
  607.         var buttonslength = buttons.length;
  608.         for(var i = 0; i < buttonslength; i++) {
  609.             if(buttons[i].id) {
  610.                 controls[controls.length] = buttons[i].id;
  611.             }
  612.         }
  613.         var controlslength = controls.length;
  614.         for(var i = 0; i < controlslength; i++) {
  615.             var control = $(controls[i]);
  616.             if(control.id.indexOf(editorid + '_cmd_') != -1) {
  617.                 control.className = 'editor_buttonnormal';
  618.                 control.state = false;
  619.                 control.mode = 'normal';
  620.             } else if(control.id.indexOf(editorid + '_popup_') != -1) {
  621.                 control.state = false;
  622.             }
  623.         }
  624.     }
  625.     cursor = -1;
  626.     stack = new Array();
  627.     $(editorid + '_font_out').innerHTML = lang['fontname'];
  628.     $(editorid + '_size_out').innerHTML = lang['fontsize'];
  629.     $(editorid + '_font_out').fontstate = null;
  630.     $(editorid + '_size_out').sizestate = null;
  631.     $(editorid + '_color_bar').style.backgroundColor = '#000000';
  632.     var parsedtext = getEditorContents();
  633.     parsedtext = mode ? bbcode2html(parsedtext) : html2bbcode(parsedtext);
  634.     wysiwyg = mode;
  635.     $(editorid + '_mode').value = mode;
  636.     newEditor(mode, parsedtext);
  637.     checkFocus();
  638. }
  639. function formatFontsize(csssize) {
  640.     switch(csssize) {
  641.         case '7.5pt':
  642.         case '10px'return 1;
  643.         case '10pt'return 2;
  644.         case '12pt'return 3;
  645.         case '14pt'return 4;
  646.         case '18pt'return 5;
  647.         case '24pt'return 6;
  648.         case '36pt'return 7;
  649.         default:     return lang['fontsize'];
  650.     }
  651. }
  652. function rgbToColor(forecolor) {
  653.     if(!window.is_moz && !window.is_opera) {
  654.         return rgbhexToColor((forecolor & 0xFF).toString(16), ((forecolor >> 8) & 0xFF).toString(16), ((forecolor >> 16) & 0xFF).toString(16));
  655.     }
  656.     if(forecolor == '' || forecolor == null) {
  657.         forecolor = getComputedStyle(editdoc.body, null).getPropertyValue('color');
  658.     }
  659.     if(forecolor.toLowerCase().indexOf('rgb') == 0) {
  660.         var matches = forecolor.match(/^rgb/s*/(([0-9]+),/s*([0-9]+),/s*([0-9]+)/)$/);
  661.         if(matches) {
  662.             return rgbhexToColor((matches[1] & 0xFF).toString(16), (matches[2] & 0xFF).toString(16), (matches[3] & 0xFF).toString(16));
  663.         } else {
  664.             return rgbToColor(null);
  665.         }
  666.     } else {
  667.         return forecolor;
  668.     }
  669. }
  670. function rgbhexToColor(r, g, b) {
  671.     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'};
  672.     return coloroptions['#' + (str_pad(r, 2, 0) + str_pad(g, 2, 0) + str_pad(b, 2, 0))];
  673. }
  674. function str_pad(text, length, padstring) {
  675.     text += '';
  676.     padstring += '';
  677.     if(text.length < length) {
  678.         padtext = padstring;
  679.         while(padtext.length < (length - text.length)) {
  680.             padtext += padstring;
  681.         }
  682.         text = padtext.substr(0, (length - text.length)) + text;
  683.     }
  684.     return text;
  685. }
  686. function insertNodeAtSelection(text) {
  687.     checkFocus();
  688.     var sel = editwin.getSelection();
  689.     var range = sel ? sel.getRangeAt(0) : editdoc.createRange();
  690.     sel.removeAllRanges();
  691.     range.deleteContents();
  692.     var node = range.startContainer;
  693.     var pos = range.startOffset;
  694.     switch(node.nodeType) {
  695.         case Node.ELEMENT_NODE:
  696.             if(text.nodeType == Node.DOCUMENT_FRAGMENT_NODE) {
  697.                 selNode = text.firstChild;
  698.             } else {
  699.                 selNode = text;
  700.             }
  701.             node.insertBefore(text, node.childNodes[pos]);
  702.             add_range(selNode);
  703.             break;
  704.         case Node.TEXT_NODE:
  705.             if(text.nodeType == Node.TEXT_NODE) {
  706.                 var text_length = pos + text.length;
  707.                 node.insertData(pos, text.data);
  708.                 range = editdoc.createRange();
  709.                 range.setEnd(node, text_length);
  710.                 range.setStart(node, text_length);
  711.                 sel.addRange(range);
  712.             } else {
  713.                 node = node.splitText(pos);
  714.                 var selNode;
  715.                 if(text.nodeType == Node.DOCUMENT_FRAGMENT_NODE) {
  716.                     selNode = text.firstChild;
  717.                 } else {
  718.                     selNode = text;
  719.                 }
  720.                 node.parentNode.insertBefore(text, node);
  721.                 add_range(selNode);
  722.             }
  723.             break;
  724.     }
  725. }
  726. function add_range(node) {
  727.     checkFocus();
  728.     var sel = editwin.getSelection();
  729.     var range = editdoc.createRange();
  730.     range.selectNodeContents(node);
  731.     sel.removeAllRanges();
  732.     sel.addRange(range);
  733. }
  734. function readNodes(root, toptag) {
  735.     var html = "";
  736.     var moz_check = /_moz/i;
  737.     switch(root.nodeType) {
  738.         case Node.ELEMENT_NODE:
  739.         case Node.DOCUMENT_FRAGMENT_NODE:
  740.             var closed;
  741.             if(toptag) {
  742.                 closed = !root.hasChildNodes();
  743.                 html = '<' + root.tagName.toLowerCase();
  744.                 var attr = root.attributes;
  745.                 for(var i = 0; i < attr.length; ++i) {
  746.                     var a = attr.item(i);
  747.                     if(!a.specified || a.name.match(moz_check) || a.value.match(moz_check)) {
  748.                         continue;
  749.                     }
  750.                     html += " " + a.name.toLowerCase() + '="' + a.value + '"';
  751.                 }
  752.                 html += closed ? " />" : ">";
  753.             }
  754.             for(var i = root.firstChild; i; i = i.nextSibling) {
  755.                 html += readNodes(i, true);
  756.             }
  757.             if(toptag && !closed) {
  758.                 html += "</" + root.tagName.toLowerCase() + ">";
  759.             }
  760.             break;
  761.         case Node.TEXT_NODE:
  762.             html = htmlspecialchars(root.data);
  763.             break;
  764.     }
  765.     return html;
  766. }
  767. function moveCursor(increment) {
  768.     var test = cursor + increment;
  769.     if(test >= 0 && stack[test] != null && !isUndefined(stack[test])) {
  770.         cursor += increment;
  771.     }
  772. }
  773. function addSnapshot(str) {
  774.     if(stack[cursor] == str) {
  775.         return;
  776.     } else {
  777.         cursor++;
  778.         stack[cursor] = str;
  779.         if(!isUndefined(stack[cursor + 1])) {
  780.             stack[cursor + 1] = null;
  781.         }
  782.     }
  783. }
  784. function getSnapshot() {
  785.     if(!isUndefined(stack[cursor]) && stack[cursor] != null) {
  786.         return stack[cursor];
  787.     } else {
  788.         return false;
  789.     }
  790. }

menu.js

 

  1. /******************************************************************************
  2.   Crossday Discuz! Board - Floating Advertisements for Discuz!
  3.   Copyright 2001-2006 Comsenz Inc. (http://www.comsenz.com)
  4. *******************************************************************************/
  5. var menuslidetimer = null;
  6. function Popup_Handler() {
  7.     this.open_steps = 2;
  8.     this.open_fade = false;
  9.     this.active = false;
  10.     this.menus = new Array();
  11.     this.activemenu = null;
  12.     this.hidden_selects = new Array();
  13.     this.activate = function(active) {
  14.         this.active = active;
  15.     }
  16.     this.register = function(clickactive, controlkey, noimage) {
  17.         this.menus[controlkey] = new Popup_Menu(clickactive, controlkey, noimage);
  18.         return this.menus[controlkey];
  19.     }
  20.     this.hide = function() {
  21.         if(this.activemenu != nullthis.menus[this.activemenu].hide();
  22.     }
  23. }
  24. function Popup_Events() {
  25.     this.controlobj_show = function(e) {
  26.         doane(e);
  27.         clearTimeout(this.slidetimer);
  28.         if(popupmenu.activemenu == null || popupmenu.menus[popupmenu.activemenu].controlkey != this.id) {popupmenu.menus[this.id].show(thisfalse, popupmenu.menus[this.id].clickactive);}
  29.     }
  30.     this.controlobj_onclick = function(e) {
  31.         doane(e);
  32.         if(popupmenu.activemenu == null || popupmenu.menus[popupmenu.activemenu].controlkey != this.id) {popupmenu.menus[this.id].show(thisfalse, popupmenu.menus[this.id].clickactive);}
  33.         else {popupmenu.menus[this.id].hide();}
  34.     }
  35.     this.controlobj_onmouseover = function(e) {
  36.         doane(e);
  37.         popupmenu.menus[this.id].hover(this);
  38.     }
  39.     this.menuoption_onclick_function = function(e) {
  40.         this.ofunc(e);
  41.         popupmenu.menus[this.controlkey].hide();
  42.     }
  43.     this.menuoption_onclick_link = function(e) {
  44.         popupmenu.menus[this.controlkey].choose(e, this);
  45.     }
  46.     this.menuoption_onmouseover = function(e) {
  47.         this.className = 'popupmenu_highlight';
  48.     }
  49.     this.menuoption_onmouseout = function(e) {
  50.         this.className = 'popupmenu_option';
  51.     }
  52. }
  53. popupmenu = new Popup_Handler();
  54. popupevents = new Popup_Events();
  55. function popupmenu_hide(e) {
  56.     if(e && e.button && e.button != 1 && e.type == 'click')  return true;
  57.     else popupmenu.hide();
  58. }
  59. function Popup_Menu(clickactive, controlkey, noimage) {
  60.     this.controlkey = controlkey;
  61.     this.clickactive = clickactive;
  62.     this.menuname = this.controlkey.split('.')[0] + '_menu';
  63.     if($(this.menuname)) {this.init_menu(clickactive);}
  64.     this.slide_open = (window.is_opera ? false : true);
  65.     this.open_steps = popupmenu.open_steps;
  66.     this.init_control = function(noimage) {
  67.         this.controlobj = $(this.controlkey);
  68.         this.controlobj.state = false;
  69.         if(this.controlobj.firstChild && (this.controlobj.firstChild.tagName == 'TEXTAREA' || this.controlobj.firstChild.tagName == 'INPUT')) {
  70.         } else {
  71.             if(!this.clickactive && !noimage && !(is_mac && window.is_ie)) {
  72.                 var img = document.createElement('img');
  73.                 img.src = 'images/common/jsmenu.gif';
  74.                 img.border = 0;
  75.                 img.title = '';
  76.                 img.alt = '';
  77.                 this.controlobj.appendChild(img);
  78.             }
  79.             this.controlobj.unselectable = true;
  80.             if(!noimage) {
  81.                 this.controlobj.style.cursor = window.is_ie ? 'hand' : 'pointer';
  82.             }
  83.             if(clickactive) {
  84.                 this.controlobj.onclick = popupevents.controlobj_onclick;
  85.                 this.controlobj.onmouseover = popupevents.controlobj_onmouseover;
  86.             } else {
  87.                 this.controlobj.onmouseover = popupevents.controlobj_show;
  88.             }
  89.         }
  90.     }
  91.     this.init_control( noimage);
  92.     this.init_menu = function() {
  93.         this.menuobj = $(this.menuname);
  94.         if(this.menuobj && !this.menuobj.initialized) {
  95.             this.menuobj.initialized = true;
  96.             this.menuobj.onclick = ebygum;
  97.             this.menuobj.style.position = 'absolute';
  98.             if(!this.clickactive) {
  99.                 this.menuobj.onmouseover = function() {
  100.                     clearTimeout(menuslidetimer);
  101.                 }
  102.                 this.menuobj.onmouseout = function() {
  103.                     menuslidetimer = setTimeout("menuhide()",500);
  104.                 }
  105.             }
  106.             this.menuobj.style.zIndex = 50;
  107.             if(window.is_ie && !is_mac) {
  108.                 this.menuobj.style.filter += "progid:DXImageTransform.Microsoft.shadow(direction=135,color=#CCCCCC,strength=2)";
  109.             }
  110.             this.init_menu_contents();
  111.         }
  112.     }
  113.     this.init_menu_contents = function() {
  114.         var tds = findtags(this.menuobj, 'td');
  115.         for(var i = 0; i < tds.length; i++) {
  116.             if(tds[i].className == 'popupmenu_option' || tds[i].className == 'editor_colornormal') {
  117.                 if(window.is_ie && !is_mac) {
  118.                     tds[i].style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity=85,finishOpacity=100,style=0)";
  119.                 }
  120.                 tds[i].style.opacity = 0.85;
  121.                 if(tds[i].title && tds[i].title == 'nohighlight') {
  122.                     tds[i].title = '';
  123.                 } else {
  124.                     tds[i].controlkey = this.controlkey;
  125.                     if(tds[i].className != 'editor_colornormal') {
  126.                         tds[i].onmouseover = popupevents.menuoption_onmouseover;
  127.                         tds[i].onmouseout = popupevents.menuoption_onmouseout;
  128.                     }
  129.                     if(typeof tds[i].onclick == 'function') {
  130.                         tds[i].ofunc = tds[i].onclick;
  131.                         tds[i].onclick = popupevents.menuoption_onclick_function;
  132.                     } else {
  133.                         tds[i].onclick = popupevents.menuoption_onclick_link;
  134.                     }
  135.                     if(!is_saf && !is_kon)  {
  136.                         try {
  137.                             links = findtags(tds[i], 'a');
  138.                             for(var j = 0; j < links.length; j++) {
  139.                                 if(typeof links[j].onclick  == 'undefined') links[j].onclick = ebygum;
  140.                             }
  141.                         }
  142.                         catch(e) {}
  143.                     }
  144.                 }
  145.             }
  146.         }
  147.     }
  148.     this.show = function(obj, instant) {
  149.         if(!popupmenu.active){return false;}
  150.         else if(!this.menuobj)  {this.init_menu();}
  151.         if(!this.menuobj) {return false;}
  152.         if(popupmenu.activemenu != null) {popupmenu.menus[popupmenu.activemenu].hide();}
  153.         popupmenu.activemenu = this.controlkey;
  154.         this.menuobj.style.display = '';
  155.         if(popupmenu.slide_open) {this.menuobj.style.clip = 'rect(auto, auto, auto, auto)';}
  156.         this.pos = this.fetch_offset(obj);
  157.         this.leftpx = this.pos['left'];
  158.         this.toppx = this.pos['top'] + obj.offsetHeight;
  159.         if((this.leftpx + this.menuobj.offsetWidth) >= document.body.clientWidth && (this.leftpx + obj.offsetWidth - this.menuobj.offsetWidth) > 0) {
  160.             this.leftpx = this.leftpx + obj.offsetWidth - this.menuobj.offsetWidth;
  161.             this.direction = 'right';
  162.         } else {this.direction = 'left';}
  163.         this.menuobj.style.left = this.leftpx + 'px';
  164.         this.menuobj.style.top  = this.toppx + 'px';
  165.         if(!instant && this.slide_open) {
  166.             this.intervalX = Math.ceil(this.menuobj.offsetWidth / this.open_steps);
  167.             this.intervalY = Math.ceil(this.menuobj.offsetHeight / this.open_steps);
  168.             this.slide((this.direction == 'left' ? 0 : this.menuobj.offsetWidth), 0, 0);
  169.         } else if(this.menuobj.style.clip && popupmenu.slide_open) {
  170.             this.menuobj.style.clip = 'rect(auto, auto, auto, auto)';
  171.         }
  172.         this.handle_overlaps(true);
  173.         if(this.menuobj.scrollHeight > 400) {
  174.             this.menuobj.style.height = '400px';
  175.             if(window.is_ie || window.is_opera) {
  176.                 this.menuobj.style.width = this.menuobj.scrollWidth + 18;
  177.             }
  178.             if(window.is_opera) {
  179.                 this.menuobj.style.overflow = 'scroll';
  180.             } else {
  181.                 this.menuobj.style.overflowY = 'scroll';
  182.             }
  183.         }
  184.     }
  185.     this.hide = function(e) {
  186.         if(e && e.button && e.button != 1) {return true;}
  187.         this.stop_slide();
  188.         this.menuobj.style.display = 'none';
  189.         this.handle_overlaps(false);
  190.         popupmenu.activemenu = null;
  191.     }
  192.     this.slidehide = function() {
  193.         popupmenu.menus[popupmenu.activemenu].hide()
  194.     }
  195.     this.hover = function(obj, clickactive) {
  196.         if(popupmenu.activemenu != null) {
  197.             if(popupmenu.menus[popupmenu.activemenu].controlkey != this.id) {this.show(obj, true, clickactive);}
  198.         }
  199.     }
  200.     this.choose = function(e, obj) {
  201.         var links = findtags(obj, 'a');
  202.         if(links[0]) {
  203.             if(window.is_ie) {
  204.                 links[0].click();
  205.                 window.event.cancelBubble = true;
  206.             } else {
  207.                 if(e.shiftKey) {
  208.                     window.open(links[0].href);
  209.                     e.stopPropagation();
  210.                     e.preventDefault();
  211.                 } else {
  212.                     window.location = links[0].href;
  213.                     e.stopPropagation();
  214.                     e.preventDefault();
  215.                 }
  216.             }
  217.             this.hide();
  218.         }
  219.     }
  220.     this.slide = function(clipX, clipY, opacity) {
  221.         if(this.direction == 'left' && (clipX < this.menuobj.offsetWidth || clipY < this.menuobj.offsetHeight)) {
  222.             if(popupmenu.open_fade && window.is_ie) {
  223.                 opacity += 10;
  224.                 this.menuobj.filters.item('DXImageTransform.Microsoft.alpha').opacity = opacity;
  225.             }
  226.             clipX += this.intervalX;
  227.             clipY += this.intervalY;
  228.             this.menuobj.style.clip = "rect(auto, " + clipX + "px, " + clipY + "px, auto)";
  229.             this.slidetimer = setTimeout("popupmenu.menus[popupmenu.activemenu].slide(" + clipX + ", " + clipY + ", " + opacity + ");", 0);
  230.         } else if(this.direction == 'right' && (clipX > 0 || clipY < this.menuobj.offsetHeight)) {
  231.             if(popupmenu.open_fade && window.is_ie) {
  232.                 opacity += 10;
  233.                 menuobj.filters.item('DXImageTransform.Microsoft.alpha').opacity = opacity;
  234.             }
  235.             clipX -= this.intervalX;
  236.             clipY += this.intervalY;
  237.             this.menuobj.style.clip = "rect(auto, " + this.menuobj.offsetWidth + "px, " + clipY + "px, " + clipX + "px)";
  238.             this.slidetimer = setTimeout("popupmenu.menus[popupmenu.activemenu].slide(" + clipX + ", " + clipY + ", " + opacity + ");", 0);
  239.         } else {this.stop_slide();}
  240.     }
  241.     this.stop_slide = function() {
  242.         clearTimeout(this.slidetimer);
  243.         this.menuobj.style.clip = 'rect(auto, auto, auto, auto)';
  244.         if(popupmenu.open_fade && window.is_ie) {this.menuobj.filters.item('DXImageTransform.Microsoft.alpha').opacity = 100;}
  245.     }
  246.     this.fetch_offset = function(obj) {
  247.         var left_offset = obj.offsetLeft;
  248.         var top_offset = obj.offsetTop;
  249.         while ((obj = obj.offsetParent) != null) {
  250.             left_offset += obj.offsetLeft;
  251.             top_offset += obj.offsetTop;
  252.         }
  253.         return { 'left' : left_offset, 'top' : top_offset };
  254.     }
  255.     this.overlaps = function(obj, m) {
  256.         var s = new Array();
  257.         var pos = this.fetch_offset(obj);
  258.         s['L'] = pos['left'];
  259.         s['T'] = pos['top'];
  260.         s['R'] = s['L'] + obj.offsetWidth;
  261.         s['B'] = s['T'] + obj.offsetHeight;
  262.         if(s['L'] > m['R'] || s['R'] < m['L'] || s['T'] > m['B'] || s['B'] < m['T']) {return false;}
  263.         return true;
  264.     }
  265.     this.handle_overlaps = function(dohide) {
  266.         if(window.is_ie) {
  267.             var selects = findtags(document, 'select');
  268.             if(dohide) {
  269.                 var menuarea = new Array(); menuarea = {
  270.                     'L' : this.leftpx,
  271.                     'R' : this.leftpx + this.menuobj.offsetWidth,
  272.                     'T' : this.toppx,
  273.                     'B' : this.toppx + this.menuobj.offsetHeight
  274.                 };
  275.                 for(var i = 0; i < selects.length; i++) {
  276.                     if(this.overlaps(selects[i], menuarea)) {
  277.                         var hide = true;
  278.                         var s = selects[i];
  279.                         while (s = s.parentNode) {
  280.                             if(s.className == 'popupmenu_popup') {
  281.                                 hide = false;
  282.                                 break;
  283.                             }
  284.                         }
  285.                         if(hide) {
  286.                             selects[i].style.visibility = 'hidden';
  287.                             arraypush(popupmenu.hidden_selects, i);
  288.                         }
  289.                     }
  290.                 }
  291.             } else {
  292.                 while (true) {
  293.                     var i = arraypop(popupmenu.hidden_selects);
  294.                     if(typeof i == 'undefined' || i == nullbreak;
  295.                     else selects[i].style.visibility = 'visible';
  296.                 }
  297.             }
  298.         }
  299.     }
  300. }
  301. function doane(eventobj) {
  302.     if(!eventobj || window.is_ie)   {
  303.         window.event.returnValue = false;
  304.         window.event.cancelBubble = true;
  305.         return window.event;
  306.     } else {
  307.         eventobj.stopPropagation();
  308.         eventobj.preventDefault();
  309.         return eventobj;
  310.     }
  311. }
  312. function ebygum(eventobj) {
  313.     if(!eventobj || window.is_ie) {
  314.         window.event.cancelBubble = true;
  315.         return window.event;
  316.     } else {
  317.         if(eventobj.target.type == 'submit')  eventobj.target.form.submit();
  318.         eventobj.stopPropagation();
  319.         return eventobj;
  320.     }
  321. }
  322. function menuregister(clickactive, controlid, noimage, datefield) {
  323.     if(typeof popupmenu == 'object') {
  324.         popupmenu.register(clickactive, controlid, noimage);
  325.     }
  326. }
  327. function menuhide() {
  328.     if(popupmenu.activemenu != null) {
  329.         popupmenu.menus[popupmenu.activemenu].slidehide();
  330.     }
  331. }
  332. if(typeof popupmenu == 'object') {
  333.     if(window.attachEvent && !is_saf) {
  334.         document.attachEvent('onclick', popupmenu_hide);
  335.         window.attachEvent('onresize', popupmenu_hide);
  336.     } else if(document.addEventListener && !window.is_saf) {
  337.         document.addEventListener('click', popupmenu_hide, false);
  338.         window.addEventListener('resize', popupmenu_hide, false);
  339.     } else {
  340.         window.onclick = popupmenu_hide;
  341.         window.onresize = popupmenu_hide;
  342.     }
  343.     popupmenu.activate(true);
  344. }

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。预览效果

预览效果

评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值