sqUbbEditor UBB 编辑器 v1.0 by shawl.qiu
CREATED BY STABX, AT 2007-5-6.sqUbbEditor UBB 编辑器
---/-------------------------------------------------------------
Version 1.0
老早前就想过写个功能完整点人性点的 Ubb 编辑器, 不过倒是先写了两个 HTML 编辑器...
1. sqEditor HTML 编辑器 v1.3 By shawl.qiu(asp) (新版本 1.4 尚未发布)
http://blog.csdn.net/btbtd/archive/2007/01/16/1484070.aspx
2. sqEditor HTML 编辑器 for .net v1.0 By shawl.qiu (新版本 1.1 尚未发布)
http://blog.csdn.net/btbtd/archive/2007/03/03/1519745.aspx
不过本次在写这个 UBB 编辑器的时候, 倒是收获不小, 随便扯谈一下本人觉得收获得比较不错的两点:
1. 使用 js 取元素相对于屏幕的绝对位置, 适用于各浏览器.
方案:
- function fFindPos(oEle, sReturnBy)
- { // shawl.qiu script
- if(!oEle)
- {
- alert("对象不能为空!");
- return;
- }
- if(sReturnBy!="y")
- {
- return fFindPosX(oEle);
- }
- else
- {
- return fFindPosY(oEle);
- }
- function fFindPosX(oEle)
- { // shawl.qiu script
- var iLeft = 0;
- if(oEle.offsetParent)
- {
- while(true)
- {
- iLeft += oEle.offsetLeft;
- if(!oEle.offsetParent)
- {
- break;
- } // end if 1
- oEle = oEle.offsetParent;
- } // end while
- }
- else if(oEle.x)
- {
- iLeft += oEle.x;
- }
- return iLeft;
- } // end function fFindPosX
- function fFindPosY(oEle)
- { // shawl.qiu script
- var iTop = 0;
- if(oEle.offsetParent)
- {
- while(true)
- {
- iTop += oEle.offsetTop;
- if(!oEle.offsetParent)
- {
- break;
- } // end if 1
- oEle = oEle.offsetParent;
- } // end while
- }
- else if(oEle.y)
- {
- iTop += oEle.y;
- }
- return iTop;
- } // end function fFindPosX
- } // end function fFindPos
2. css 完美定义 pre/定义自动换行.
- pre
- {
- white-space: pre; /* CSS2 */
- white-space: -moz-pre-wrap; /* Mozilla */
- white-space: -hp-pre-wrap; /* HP printers */
- white-space: -o-pre-wrap; /* Opera 7 */
- white-space: -pre-wrap; /* Opera 4-6 */
- white-space: pre-wrap; /* CSS 2.1 */
- white-space: pre-line; /* CSS 3 (and 2.1 as well, actually) */
- word-wrap: break-word; /* IE */
- padding:2px;
- }
还有不少收获, 这个...我并不总是很慷慨, 或者说我不想一次性的慷慨.
话归正题, UBB 编辑器的主要功能概述:
1. 数据入库时不编码, 数据显示时 JS 自动编码. (这样有多方面的好处, 概念问题, 恕不详细)
2. 可以动态设置是否编码 UBB
3. 可以动态设置是否编码 媒体文件
4. 可以动态设置是否 自动识别链接
5. 可以动态设置是否添加 CSS 文件
6. 编辑时可以预览HTML 效果.
7. 编辑时可以预览HTML 源码
8. ... 具体功能自己体会.
调用参考:
--/------------------------------
1. 以列表显示 UBB 域 调用
- <script type='text/javascript' src='/sqUbbEditor/default.js'></script>
- <script type="text/javascript">
- //<![CDATA[
- onload =
- function()
- {
- Ubb.Main.Path = "/sqUbbEditor/";
- Ubb.Encode.ID = 'UbbEncodeMain';
- Ubb.Encode.Bool = true;
- Ubb.Encode.Media.Bool = false;
- Ubb.Encode.AutoAttachLink = true;
- Ubb.Encode.TabLen = 2;
- Ubb.Encode.WidthForIe = "100%";
- Ubb.Encode.AppendCss = true;
- Ubb.Encode.Go();
- } // end onload
- //]]>
- </script>
- <div id="UbbEncodeMain"> <!-- 主ID -->
- <pre>
- ubb 内容
- </pre>
- <pre>
- ubb 内容
- </pre>
- ...
- </div>
2. 主显示页调用
- <script type='text/javascript' src='/sqUbbEditor/default.js'></script>
- <script type="text/javascript">
- //<![CDATA[
- onload =
- function()
- {
- Ubb.Main.Path = "/sqUbbEditor/";
- Ubb.Encode.ID = 'UbbEncodeMain';
- Ubb.Encode.Bool = <%
- Response.Write(
- bool.Parse(
- Datum.GetDataTable(
- "select * from guestbook where gbid="+gbid, Conn).Rows[0]["gbubbdisable"]+"")?"false":"true"
- );
- %>;
- Ubb.Encode.TabLen = 2;
- Ubb.Encode.WidthForIe = "100%";
- Ubb.Encode.AppendCss = true;
- Ubb.Encode.Go();
- } // end onload
- //]]>
- </script>
- <div id="UbbEncodeMain" class="UbbMain">
- <pre>
- 内容
- </pre>
- </div>
详细情况请看 /sqUbbEditor/demo/ 使用演示(asp.net c#)
Author: shawl.qiu
E-Mail: shawl.qiu@gmail.com
Blog: http://blog.csdn.net/btbtd/
CreatedDate: 2007-5-6
© 2007-2010 shawl.qiu. All rights reserved.
下载:
http://files.myopera.com/btbtd/sqUbbEditor/sqUbbEditor_v1.0.7z
目录:
1. sqUbbEditor 核心代码
shawl.qiu
2007-5-6
http://blog.csdn.net/btbtd/
内容:
1. sqUbbEditor 核心代码
- // shawl.qiu JavaScript Document
- /*-----------------------------------------------------------------------------------*/
- * sqUbbEditor UBB 编辑器 v1.0
- /*-----------------------------------------------------------------------------------*/
- //---------------------------------begin class Ubb()-------------------------------//
- function sqUbbEditor()
- { // shawl.qiu code
- //------------------------------------begin public variable
- //---------------begin about
- this.auSubject = 'sqUbbEditor UBB 编辑器';
- this.auVersion = 'v1.0';
- this.au = 'shawl.qiu';
- this.auEmail = 'shawl.qiu@gmail.com';
- this.auBlog = 'http://blog.csdn.net/btbtd';
- this.auCreateDate = '2007-5-3';
- //---------------end about
- this.Main = function(){};
- this.Main.ID = "UbbMain";
- this.Main.Path = "/sqUbbEditor/";
- this.Main.Text = function(){};
- this.Main.Text.ID = "UbbTextMain";
- this.Encode = function(){}
- this.Encode.ID = "UbbEncodeMain";
- this.Encode.Bool = true;
- this.Encode.Media = function(){}
- this.Encode.Media.Bool = true;
- this.Encode.AutoAttachLink = true;
- this.Encode.Go = fEncode;
- this.Encode.TabLen = 2;
- this.Encode.WidthForIe = "100%";
- this.Encode.WidthForIeByPre = "100%";
- this.Encode.AppendCss = true;
- this.Encode.Director = function(){}
- this.Encode.Director.Go = fEncodePre;
- this.Encode.Director.AppendCss =
- function(oDocument)
- {
- fAppendStyle(Tl.Main.Path+"style/css.css", oDocument);
- fAppendStyle(Tl.Main.Path+"style/ubb.css", oDocument);
- }
- this.Reload = "?";
- this.CallBack = null;
- this.Debug = false;
- this.Cmd = fCmd;
- this.Exec = fExec;
- this.Test = function(oParent, sTargetId)
- {
- }
- this.Clear = function(){}
- this.Clear.Html = false;
- this.Width = function()
- {
- return "650px;";
- }
- this.Select = fSelect;
- this.Popup = fWinPopup;
- this.Print = fPrint;
- this.Func = fFunc;
- //------------------------------------end public variable
- //------------------------------------begin private variable
- var Tl = this;
- var pMain = null;
- var pTextMain = null;
- var pUbbHtmlPath = "html/Ubb.htm";
- var pRndStr = "";
- var pFormSubmitFunc = null;
- var pFormSubmitFunc1 = null;
- var pFormResetFunc = null;
- var pForm = null;
- var pEncodeMain = null;
- var pDecodeTempStr = "";
- //------------------------------------end private variable
- //------------------------------------begin public method
- //------------------------------------end public method
- //------------------------------------begin private method
- function fEncode()
- {
- if(!Tl.Encode.Bool) return;
- pEncodeMain = document.getElementById(Tl.Encode.ID);
- if(pEncodeMain==null)
- {
- alert("解码 Ubb 域为 null!");
- return false;
- }
- if(Tl.Encode.AppendCss)
- {
- fAppendStyle(Tl.Main.Path+"style/css.css");
- fAppendStyle(Tl.Main.Path+"style/ubb.css");
- }
- if(fIsIe())
- {
- pEncodeMain.style.width = Tl.Encode.WidthForIe;
- pEncodeMain.style.overflow = "hidden";
- }
- var PreSet = pEncodeMain.getElementsByTagName("pre");
- for(var i=0, j=PreSet.length; i<j; i++)
- {
- fEncodePre(PreSet[i]);
- } // end for
- } // end function fEncode
- function fEncodePre(ElePre, oDocument, EleAdti)
- {
- if(!oDocument) oDocument = document;
- if(typeof(ElePre)=="object")
- {
- var sTemp = ElePre.innerHTML;
- }
- else
- {
- var sTemp = ElePre;
- }
- // tag len, unit by space
- if(Tl.Encode.TabLen!=null&&Tl.Encode.TabLen>0)
- {
- sTemp = sTemp.
- replace(//t/gi, fStrSpace(" ", Tl.Encode.TabLen));
- }
- // [align]
- //alert(ElePre.innerHTML);
- sTemp = sTemp.
- replace(//[align=([^/]]+)/]/gi, "<div align='$1' class='UbbAlign$1'>")
- ;
- sTemp = sTemp.
- replace(//[//align/](/r/n|/r|/n)*/gi, "</div>")
- ;
- // [code]
- sTemp = sTemp.
- replace(//[(code)/](/r/n|/r|/n)*/gi, "[code][ol]")
- ;
- sTemp = sTemp.
- replace(//[//(code)/](/r/n|/r|/n)*/gi, "[/ol][/code]")
- ;
- sTemp = sTemp.
- replace(//[(quote|cite|code)/](/r/n|/r|/n)*/gi, "<div class='Ubb$1'>")
- ;
- sTemp = sTemp.
- replace(//[//(quote|cite|code)/](/r/n|/r|/n)*/gi, "</div><br/>")
- ;
- var s1Dims = "b|i|u|del|sup|sub|pre|quote|cite|h1|h2|h3|h4|h5|h6";
- var Re1Dims = new RegExp("//[("+s1Dims+")//]", "gi");
- var Re1Dims1 = new RegExp("//[///("+s1Dims+")//]", "gi");
- sTemp = sTemp.
- replace(Re1Dims, "<$1 class='Ubb$1'>").
- replace(Re1Dims1,"</$1>")
- ;
- sTemp = sTemp.
- replace(//[(hr|br)///](/r/n|/r|/n)*/gi, "<$1/>")
- ;
- sTemp = sTemp.
- replace
- (/(/[ol/])([/s/S]*?)(/[//ol/])(/r/n|/r|/n)*/gi,
- function($1, $2, $3, $4)
- {
- $2 = "<ol class='Ubbol'>";
- return fReplaceList($1, $2, $3, $4);
- } // end functoin
- ) // end replace
- ;
- sTemp = sTemp.
- replace
- (/(/[ul/])([/s/S]*?)(/[//ul/](/r/n|/r|/n)*)/gi,
- function($1, $2, $3, $4)
- {
- $2 = "<ul class='Ubbul'>";
- return fReplaceList($1, $2, $3, $4);
- } // end functoin
- ) // end replace
- ;
- // [bgcolor] && [fgcolor]
- sTemp = sTemp.
- replace
- (
- //[bgcolor/=([^/]]+)/]/gi,
- "<span style='background-color:$1!important'>"
- )
- ;
- sTemp = sTemp.
- replace
- (
- //[fgcolor/=([^/]]+)/]/gi,
- "<span style='color:$1!important'>"
- )
- ;
- sTemp = sTemp.
- replace
- (
- //[//(bgcolor|fgcolor)/]/gi,
- "</span>"
- )
- ;
- // [email]
- sTemp = sTemp.
- replace
- (
- /(/[email/])([/s/S]+?)/[//email/]/gi,
- function($1, $2, $3)
- {
- if($3.indexOf($2)>-1)
- {
- return $1;
- }
- return "<a href='mailto:"+fStrTrim($3)+"' target='_blank' class='Ubbemail'>"+$3+"</a>";
- }
- )
- ;
- // [url]
- sTemp = sTemp.
- replace
- (
- /(/[url/])([/s/S]+?)/[//url/]/gi,
- function($1, $2, $3)
- {
- if($3.indexOf($2)>-1)
- {
- return $1;
- }
- return "<a href='"+fStrTrim($3)+"' target='_blank' class='Ubburl'>"+$3+"</a>";
- }
- )
- ;
- // [anchor]
- sTemp = sTemp.
- replace
- (
- /(/[anchor/])([/s/S]+?)/[//anchor/]/gi,
- function($1, $2, $3)
- {
- if($3.indexOf($2)>-1)
- {
- return $1;
- }
- return "<a name='"+fStrTrim($3)+"' class='Ubbanchor'>"+$3+"</a>";
- }
- )
- ;
- // [img]
- sTemp = sTemp.
- replace
- (
- /(/[img/])([/s/S]+?)/[//img/]/gi,
- function($1, $2, $3)
- {
- if($3.indexOf($2)>-1)
- {
- return $1;
- }
- return "<img src='"+fStrTrim($3)+"' class='Ubbimg' />";
- }
- )
- ;
- // [icon]
- sTemp = sTemp.
- replace
- (
- //[icon/=([^///[]+)///]/gi,
- "<img src='"+Tl.Main.Path+"emotion/$1' class='Ubbicon' />"
- )
- ;
- if(Tl.Encode.Media.Bool)
- {
- // [swf]
- sTemp = sTemp.
- replace
- (
- //[swf/=(/d+),(/d+)/]([/s/S]+?)/[//swf/]/gi,
- function($1, $2, $3, $4)
- {
- if($4.indexOf("[swf")>-1)
- {
- return $1;
- }
- $4 = fStrTrim($4);
- return fDisplaySwf($2, $3, $4, "Ubbswf");
- }
- )
- ;
- // [rm]
- sTemp = sTemp.
- replace
- (
- //[rm/=(/d+),(/d+)/]([/s/S]+?)/[//rm/]/gi,
- function($1, $2, $3, $4)
- {
- if($4.indexOf("[rm")>-1)
- {
- return $1;
- }
- $4 = fStrTrim($4);
- return fDisplayRm($2, $3, $4, "Ubbrm");
- }
- )
- ;
- sTemp = sTemp.
- replace
- (
- //[rm]([/s/S]+?)/[//rm]/gi,
- function($1, $2)
- {
- if($2.indexOf("[rm")>-1)
- {
- return $1;
- }
- $2 = fStrTrim($2);
- return fDisplayRm(300, 0, $2, "Ubbrm");
- }
- )
- ;
- // [wmp]
- sTemp = sTemp.
- replace
- (
- //[wmp/=(/d+),(/d+)/]([/s/S]+?)/[//wmp/]/gi,
- function($1, $2, $3, $4)
- {
- if($4.indexOf("[wmp")>-1)
- {
- return $1;
- }
- $4 = fStrTrim($4);
- return fDisplayWmp($2, $3, $4, "Ubbwmp");
- }
- )
- ;
- sTemp = sTemp.
- replace
- (
- //[wmp]([/s/S]+?)/[//wmp]/gi,
- function($1, $2)
- {
- if($2.indexOf("[wmp")>-1)
- {
- return $1;
- }
- $2 = fStrTrim($2);
- return fDisplayWmp(300, 68, $2, "Ubbwmp");
- }
- )
- ;
- } // end if
- if(fIsIe())
- {
- sTemp = sTemp.replace(//r/n/g, "HHJFGHJhjgJHGJHG787687JHKJh9889")
- ;
- if(typeof(ElePre)=="object")
- {
- ElePre.innerHTML = sTemp.
- replace(/HHJFGHJhjgJHGJHG787687JHKJh9889/gi, "<br/>");
- ;
- }
- else
- {
- EleAdti.innerHTML = sTemp.
- replace(/HHJFGHJhjgJHGJHG787687JHKJh9889/gi, "<br/>");
- ;
- }
- }
- else
- {
- if(typeof(ElePre)=="object")
- {
- ElePre.innerHTML = sTemp;
- }
- else
- {
- EleAdti.innerHTML = sTemp.
- replace(/HHJFGHJhjgJHGJHG787687JHKJh9889/gi, "<br/>");
- ;
- }
- }
- if(Tl.Encode.AutoAttachLink)
- {
- if(typeof(ElePre)=="object")
- {
- fDomAtcLink(ElePre, oDocument);
- }
- else
- {
- fDomAtcLink(EleAdti, oDocument);
- ;
- }
- }
- } // end function fEncodePre
- function fDomAtcLink(oEle, oDocument, sLinkCssName, sEmailCssName, sTarget)
- {
- if(!oDocument) oDocument = document;
- if(!sTarget) sTarget = "_blank";
- if(!sLinkCssName) sLinkCssName = "Ubburl";
- if(!sEmailCssName) sEmailCssName = "Ubbemail";
- var oNode, sStr='', oSpan;
- for(var i=0, j=oEle.childNodes.length; i<j; i++)
- {
- oNode=oEle.childNodes[i];
- if(oNode.nodeType==3)
- {
- if(oNode.parentNode.nodeName=='A')return false;
- if(oNode.data.indexOf('http')<0&&oNode.data.indexOf('ftp')<0&&
- oNode.data.indexOf('@')<0)continue;
- oSpan=oDocument.createElement('span');
- sStr=oNode.data.replace(//&/g,'&').replace(/</g,'<').replace(/>/g,'>');
- //sStr=sqMethod.encode(oNode.data);
- sStr=sStr.replace(/(ht|f)tp(s|)/:[/-/w.:]+(//[^ /n/r/'/"]+|)/gi,function(match){
- return '<a href="'+match+'" class="sqUrl '+
- sLinkCssName+'" target="'+sTarget+'">'+match+'</a>'; } );
- sStr=sStr.replace(/[/w.]+@[/w/-.]+(//[^ /n/r/'/"]+|)/gi,function(match){
- return '<a href="mailto:'+match+'" class="sqMail '+sEmailCssName+'">'+match+'</a>'; } );
- oSpan.innerHTML=sStr;
- oEle.replaceChild(oSpan, oNode);
- } // end if
- if(oNode.nodeType==1)arguments.callee(oEle.childNodes[i], oDocument);
- } // end for
- oNode=oSpan=null; // shawl.qiu script
- } // end function fDomAtcLink
- function fDisplayWmp(iWidth, iHeight, sPath, sDivCssName)
- {
- if(!sPath)
- {
- alert("wmp 路径 不能为空!");
- return;
- }
- sPath = sPath.replace(/^/s*|/s*$/g, "");
- if(!iWidth) iWidth = 500;
- if(!iHeight) iHeight = 68;
- if(!sDivCssName) sDivCssName = "Ubbwmp";
- return "<div class='"+sDivCssName+"'>"+
- "<object align=middle classid=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"+
- " class=OBJECT id=MediaPlayer width="+iWidth+" height="+iHeight+" >"+
- "<param name=ShowStatusBar value=-1>"+
- "<param name=Filename value="+sPath+">"+
- "<embed type=application/x-oleobject "+
- "codebase=http://activex.microsoft.com/activex/controls/mplayer/en/"+
- "nsmp2inf.cab#Version=5,1,52,701 flename=mp src="+sPath+" width="+iWidth+" height="+iHeight+">"+
- "</embed>"+
- "</object>"+
- "</div>"
- ;
- } // end function fDisplayWmp
- function fDisplayRm(iWidth, iHeight, sPath, sDivCssName)
- {
- if(!sPath)
- {
- alert("rm 路径 不能为空!");
- return;
- }
- sPath = sPath.replace(/^/s*|/s*$/g, "");
- if(!sDivCssName) sDivCssName = "Ubbrm";
- return "<div class='"+sDivCssName+"'>"+
- "<OBJECT classid=clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA"+
- " class=OBJECT id=RAOCX width="+iWidth+" height="+iHeight+">"+
- "<PARAM NAME=SRC VALUE="+sPath+"><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="+iWidth+">"+
- "<PARAM NAME=SRC VALUE="+sPath+"><PARAM NAME=AUTOSTART VALUE=-1>"+
- "<PARAM NAME=CONTROLS VALUE=controlpanel>"+
- "<PARAM NAME=CONSOLE VALUE=Clip1>"+
- "</OBJECT>"+
- "</div>"
- ;
- } // end function fDisplayRm
- function fReplaceList($1, $2, $3, $4)
- {
- if($3.indexOf($2)>-1)
- {
- return $1;
- }
- var sSet = $3.split(//r/n|/r|/n/);
- var sTemp = "";
- for(var i=0, j=sSet.length; i<j; i++)
- {
- sTemp += "<li>"+sSet[i]+"</li>";
- }
- return fGetTagPart($2)+sTemp+fGetTagPart($4);
- }
- function fGetTagPart(ipt)
- {
- return ipt.replace(//[/g, "<").replace(//]/g, ">");
- }
- function fDisplaySwf(iWidth, iHeight, sPath, sDivClassName)
- {
- if(!sPath)
- {
- alert("flash 路径 不能为空!");
- return;
- }
- sPath = sPath.replace(/^/s*|/s*$/g, "");
- if(!iWidth) iWidth = 500;
- if(!iHeight) iHeight = 500;
- if(!sDivClassName) sDivClassName = "Ubbswf";
- return "<div class='"+sDivClassName+
- "'><object classid=/"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000/" "+
- "codebase=/"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version="+
- "5,0,0,0/" width=/""+iWidth+"/" height=/""+iHeight+"/">"+
- "<param name=movie value=/""+sPath+"/">"+
- " <param name=quality value=high>"+
- "<param name=/"wmode/" value=/"transparent/">"+
- "<embed src=/""+sPath+"/" quality=high "+
- "pluginspage=/"http://www.macromedia.com/shockwave/download/"+
- "index.cgi?P1_Prod_Version=ShockwaveFlash/" type=/"application/x-shockwave-flash/""+
- "width=/""+iWidth+"/" height=/""+iHeight+"/" wmode=/"transparent/">"+
- "</embed> "+
- "</object>"+
- "</div>";
- } // end function fDisplaySwf
- function fStrTrim(sStr)
- {
- var o=sStr?sStr:this;
- if(!o||o=='')return '';
- return o.replace(/^/s+|/s+$/g,'');
- } // shawl.qiu code
- function fStrSpace(nStr, nTime){
- var nLen=arguments.length;
- if(nLen===0){
- nStr=' '
- nTime=2;
- }
- if(nLen==1){
- nStr+=' ';
- nTime=2;
- }
- return new Array(nTime+1).join(nStr);
- } // shawl.qiu code
- function fFunc(sCmd, bOpt, vVal)
- {
- pTextMain.focus();
- switch(sCmd)
- {
- case "emptyAll":
- var bDel = confirm('现在清空全部内容吗?');
- if(bDel)
- {
- pTextMain.value = "";
- }
- return false;
- break;
- case "insertHTML":
- fAppendText(pTextMain, vVal);
- return false;
- break;
- case "emotion":
- fEmotion();
- return false;
- break;
- case "eraserAll":
- var bCfm = confirm('现在清除所有格式吗?');
- if(bCfm)
- {
- pTextMain.value = pTextMain.value.
- replace
- (
- //[[^/[]+?/]/g
- ,
- ""
- );
- }
- return false;
- break;
- case "ClearFormat":
- var bCfm = confirm('现在清除选中内容的格式吗?');
- if(bCfm)
- {
- fClearFormat(pTextMain);
- }
- return false;
- break;
- }
- if(fCkBrs()==3) return false;
- document.execCommand(sCmd, bOpt, vVal);
- return false;
- }
- function fEmotion(){
- Tl.Popup('about:blank', 500,500);
- fXh('GET', Tl.Main.Path+'html/popup_emotion.htm'+Tl.Reload, fGetEmo);
- function fGetEmo(sSrc){
- sSrc=sSrc.replace(/src/="/gi,'src="'+Tl.Main.Path);
- if(oPopup){
- oPopup.document.write(sSrc);
- oPopup.document.close();
- } // end if
- } // end function fGetEmo
- } // end function fEmotion
- function fClearFormat(oTextMain)
- { // shawl.qiu script
- var txa = oTextMain;
- txa.focus();
- var re=//[[^/[]+?/]/g;
- if(document.selection&&document.selection.type== "Text")
- {
- // IE, Opera
- var oStr=document.selection.createRange();
- oStr.text=oStr.text.replace(re,"");
- }
- else if(window.getSelection&&txa.selectionStart>-1)
- {
- // Netscape
- var st=txa.selectionStart;
- var ed=txa.selectionEnd;
- txa.value=txa.value.substring(0,st)+
- txa.value.substring(st,ed).replace(re,"")+
- txa.value.slice(ed);
- }
- else
- {
- //txa.value+=markup;
- } // end if
- } // end function fAppendText
- function fAppendText(oTextMain, markup)
- { // shawl.qiu script
- var txa = oTextMain;
- txa.focus();
- if(document.selection&&document.selection.type== "Text")
- {
- // IE, Opera
- var oStr=document.selection.createRange();
- oStr.text=oStr.text+markup;
- }
- else if(window.getSelection&&txa.selectionStart>-1)
- {
- // Netscape
- var st=txa.selectionStart;
- var ed=txa.selectionEnd;
- txa.value=txa.value.substring(0,st)+
- txa.value.substring(st,ed)+markup+
- txa.value.slice(ed);
- }
- else
- {
- txa.value+=markup;
- } // end if
- } // end function fAppendText
- function fPrint()
- {
- return false;
- }
- function fIsIe()
- {
- return navigator.appName=='Microsoft Internet Explorer';
- }
- function fIsOpera(){
- return navigator.appName=='Opera';
- }
- function fCmd(ipt, bNotBoth)
- {
- if(ipt==""||!ipt)
- {
- alert("添加字串不能为空!");
- return false;
- }
- PlusUbbTag(pTextMain, ipt, bNotBoth);
- return false;
- } // end function fCmd
- function PlusUbbTag(oTextMain, markup, bNotBoth)
- { // shawl.qiu script
- var txa = oTextMain;
- txa.focus();
- var strEnd=markup.replace(//[/ig,'[/');
- if (strEnd.indexOf('=')>-1)
- {
- strEnd=strEnd.replace(/(.*?)/=.*?/]/,'$1]');
- } // end if
- switch(strEnd.match(//[/g).length)
- {
- case 2:
- strEnd = strEnd.replace(/(^.*?/])(.*)/, "$2$1");
- break;
- }
- if(document.selection&&document.selection.type== "Text")
- {
- // IE, Opera
- var oStr=document.selection.createRange();
- if(bNotBoth)
- {
- oStr.text = oStr.text + markup.replace(//]/g, "/]");
- return false;
- }
- oStr.text=markup+oStr.text+strEnd;
- }
- else if(window.getSelection&&txa.selectionStart>-1)
- {
- // Netscape
- var st=txa.selectionStart;
- var ed=txa.selectionEnd;
- if(bNotBoth)
- {
- txa.value=
- txa.value.substring(0,st) +
- txa.value.substring(st,ed)+
- markup.replace(//]/g, "/]")+
- txa.value.slice(ed);
- return false;
- }
- txa.value=txa.value.substring(0,st)+markup+
- txa.value.substring(st,ed)+strEnd+
- txa.value.slice(ed);
- }
- else
- {
- if(bNotBoth)
- {
- txa.value = txa.value + markup.replace(//]/g, "/]");
- return false;
- }
- txa.value+=markup+strEnd;
- } // end if
- return false;
- } // end function PlusUbbTag
- function fAddText(ipt)
- {
- return false;
- }
- function fExec()
- {
- pMain = document.getElementById(Tl.Main.ID);
- pTextMain = document.getElementById(Tl.Main.Text.ID);
- if(pMain==null)
- {
- alert("无法获得UBB主域");
- return;
- } // end if
- if(pTextMain == null)
- {
- alert("无法获得UBB 编辑域!");
- return;
- }
- pForm = pTextMain.form;
- try
- {
- pFormSubmitFunc1 = pForm.onsubmit;
- }
- catch(e)
- {
- }
- try
- {
- pFormResetFunc = pForm.onreset;
- }
- catch(e)
- {
- }
- pForm.onreset =
- function()
- {
- var bReset = false;
- try{ bReset = pFormResetFunc(); } catch(e) {}
- if(bReset)
- {
- return true;
- } // end if
- return confirm("现在重置吗?");
- }
- pForm.onsubmit =
- function()
- {
- var bSubmit = true;
- try{ bSubmit = pFormSubmitFunc1(); } catch(e) {}
- if(!bSubmit)
- {
- return false;
- } // end if
- return confirm("现在提交数据吗?");
- }
- if(Tl.Clear.Html)
- {
- try
- {
- pFormSubmitFunc = pForm.onsubmit;
- }
- catch(e)
- {
- } // end try
- pForm.onsubmit =
- function()
- {
- var bSubmit = true;
- try{ bSubmit = pFormSubmitFunc(); } catch(e) {}
- if(!bSubmit)
- {
- return false;
- } // end if
- pTextMain.value = pTextMain.value.replace(//>/g, ">").replace(//</g,"<");
- };
- }
- //pMain.innerHTML = "正在加载 UBB 列表, 请稍候...";
- fHl(pMain, false, true);
- fAppendStyle(Tl.Main.Path+"style/css.css");
- if(Tl.CallBack == null)
- {
- fXh("GET", Tl.Main.Path+pUbbHtmlPath+
- Tl.Reload+fRandomLetter(20)+"="+fRandomLetter(20), fCallBack);
- }
- else
- {
- fXh("GET", Tl.Main.Path+pUbbHtmlPath+
- Tl.Reload+fRandomLetter(20)+"="+fRandomLetter(20), Tl.CallBack);
- } // end if
- } // end function fExec;
- function fRandomBy(nUnder, nOver){
- switch(arguments.length){
- case 1: return parseInt(Math.random()*nUnder+1);
- case 2: return parseInt(Math.random()*(nOver-nUnder+1) + nUnder);
- default: return 0;
- }
- } // shawl.qiu code
- function fRandomLetter(nLen, sCase){
- var ar='';
- var arUp=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S',
- 'T','U','V','W','X','Y','Z'];
- var arLw=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t',
- 'u','v','w','x','y','z'];
- var arDgt=[0,1,2,3,4,5,6,7,8,9];
- switch(sCase){
- case 'upper': ar=arUp; break;
- case 'lower': ar=arLw; break;
- case 'letter': ar=arUp.concat(arLw); break;
- default:ar=arUp.concat(arLw, arDgt);
- }
- if(nLen&&nLen>0){
- if(!isFinite(nLen))return false;
- if(nLen<0)return false;
- var iLetter='';
- nLen=parseInt(nLen);
- for(var i=0; i<nLen; i++){
- iLetter+=ar[fRandomBy(0,ar.length-1)];
- }
- return iLetter;
- }
- return ar[fRandomBy(0,ar.length-1)];
- } // shawl.qiu code
- function fCallBack(ipt)
- {
- ipt = ipt.replace(/(src/=/")(icon)/gi, "$1"+Tl.Main.Path+"$2");
- pMain.innerHTML = ipt;
- }
- function fXh(sMethod, sUrl,oFunc){
- var xh;
- try{
- xh=new XMLHttpRequest();
- } catch(e) {
- try{
- xh=new ActiveXObject('microsoft.xmlhttp');
- } catch(e){
- try{ xh=new ActiveXObject("Msxml2.XMLHTTP"); } catch(e){} // end try 2
- } // end try 1
- } // end try
- xh.open(sMethod, sUrl);
- xh.onreadystatechange=function(){
- if(xh.readyState==4&&xh.status==200){
- if(oFunc) oFunc(xh.responseText);
- else alert(xh.responseText);
- }
- }
- xh.send(null);
- } // end function fXh
- function fHl(oTag, sMsg, bClearExists)
- {
- if(typeof(oTag)=="string")
- {
- oTag = document.getElementById(oTag);
- }
- if(!sMsg)
- {
- sMsg = "正在加载 Ubb 标签列表, 请稍假...";
- }
- if(bClearExists)
- {
- oTag.innerHTML = "";
- }
- oTag.innerHTML += "<div style=/"display:table;width:100%;background-color:yellow!important;"+
- "color:black!important;text-align:center!important;margin:10px 0px;/">"+
- sMsg+
- "</div>";
- } // end function fHl
- function fSelect(oParent, sTargetId, evt)
- {
- var oTemp = document.getElementById(sTargetId);
- var iPWidth = oParent.offsetWidth;
- if(fIsIe())
- {
- oTemp.style.left = oParent.offsetLeft;
- oTemp.style.top = oParent.offsetTop+oParent.offsetHeight;
- }
- else if(fIsOpera())
- {
- oTemp.style.left = oParent.offsetLeft;
- oTemp.style.top = oParent.offsetTop+oParent.offsetHeight;
- }
- else
- {
- oTemp.style.left = fFindPos(oParent)+"px";
- }
- for(var i=0, j=oTemp.childNodes.length; i<j; i++)
- {
- var oTempSub = oTemp.childNodes[i];
- if(oTempSub.nodeType!=1) continue;
- oTempSub.className = "sqEditorCssBorder";
- oTempSub.style.width = iPWidth+"px";
- switch(sTargetId)
- {
- case "sqHeaderSize":
- oTempSub.onclick =
- function()
- {
- var sTagName = this.childNodes[0].tagName.toLowerCase();
- oParent.innerHTML = sTagName;
- Tl.Cmd('['+sTagName+']');
- fHidEle(this.parentNode);
- return false;
- } // end oTempSub.onclick
- break;
- case "sqDdBgColor":
- oTempSub.onclick =
- function()
- {
- var sTagName = this.innerHTML.toLowerCase();
- oParent.innerHTML = sTagName;
- oParent.style.color = this.style.color;
- oParent.style.backgroundColor = this.style.backgroundColor;
- Tl.Cmd('[bgcolor='+sTagName+']');
- fHidEle(this.parentNode);
- return false;
- } // end oTempSub.onclick
- break;
- case "sqDdFgColor":
- oTempSub.onclick =
- function()
- {
- var sTagName = this.innerHTML.toLowerCase();
- oParent.innerHTML = sTagName;
- oParent.style.color = this.style.color;
- oParent.style.backgroundColor = this.style.backgroundColor;
- Tl.Cmd('[fgcolor='+sTagName+']');
- fHidEle(this.parentNode);
- return false;
- } // end oTempSub.onclick
- break;
- } // end switch
- } // end for
- fHidEle(oTemp);
- return false;
- function fHidEle(obj)
- {
- obj.style.display=='none'?obj.style.display='block':obj.style.display='none';
- } // end function fHidEle
- } // end function fSelect
- function fGetEleOffsetPsti(oEle, iPsti)
- {
- if(fCkBrs()!=1) return oEle.offsetLeft;
- var debug = false;
- if(debug)
- {
- alert(
- "oEle.tagName: "+oEle.tagName+
- "/noEle.offsetLeft: "+oEle.offsetLeft
- );
- }
- iPsti = oEle.offsetLeft;
- if(oEle!=null && oEle.tagName!="BODY")
- {
- iPsti+=arguments.callee(oEle.parentNode, iPsti);
- }
- return iPsti;
- function fCkBrs()
- {
- switch (navigator.appName)
- {
- case 'Opera': return 2;
- case 'Netscape': return 3;
- default: return 1;
- }
- } // end function fCkBrs
- } // end function fGetEleOffsetPsti
- function fCkBrs()
- {
- switch (navigator.appName)
- {
- case 'Opera': return 2;
- case 'Netscape': return 3;
- default: return 1;
- }
- } // end function fCkBrs
- function fAppendStyle(sPath, oDocument)
- {
- if(sPath==""||!sPath)
- {
- alert("CSS 路径不能为空!");
- return;
- }
- if(!oDocument)
- {
- oDocument = document;
- }
- var oSty=oDocument.createElement('link');
- oSty.href=sPath;
- oSty.rel='stylesheet';
- oSty.type='text/css';
- oDocument.body.insertBefore(oSty, oDocument.body.firstChild);
- oSty=null;
- } // end function fAppendStyle
- function fListMtd(obj, e){
- if(!e)var e=window.event;
- var sur=e.srcElement||e.target;
- try{w.close();}catch(e){}
- w=open('','newwin','width=500,height=500,left=300,top=100,scrollbars');
- w.document.write('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />');
- w.document.write('<style>body{width:400px;word-w.document.writeap: break-word;}</style>');
- w.focus;
- w.document.ondblclick=function(){w.close();}
- fListMtd(obj, w);
- w.onload=function(){ w.document.title=sur.firstChild.data;};
- w.document.close();
- return true;
- function fListMtd(obj, target){
- var ar=new Array();
- var j=0;
- for(var i in obj){
- try{
- ar[j]=i.bold()+' '+(typeof obj[i]).fontcolor('red')+
- ' '+(obj[i]+'').fontcolor('blue');
- j++;
- }catch(e){
- ar[j]=i.bold()+' '+(typeof obj[i]).fontcolor('red')+
- (' empty').fontcolor('red').bold()
- j++;
- }
- }
- ar=ar.sort();
- for(var i=0; i<ar.length; i++){
- target.document.write(i+1,'. ',ar[i],'<br/>');
- }
- return true;
- }
- } // end function fListMtd
- function fFindPos(oEle, sReturnBy)
- { // shawl.qiu script
- if(!oEle)
- {
- alert("对象不能为空!");
- return;
- }
- if(sReturnBy!="y")
- {
- return fFindPosX(oEle);
- }
- else
- {
- return fFindPosY(oEle);
- }
- function fFindPosX(oEle)
- { // shawl.qiu script
- var iLeft = 0;
- if(oEle.offsetParent)
- {
- while(true)
- {
- iLeft += oEle.offsetLeft;
- if(!oEle.offsetParent)
- {
- break;
- } // end if 1
- oEle = oEle.offsetParent;
- } // end while
- }
- else if(oEle.x)
- {
- iLeft += oEle.x;
- }
- return iLeft;
- } // end function fFindPosX
- function fFindPosY(oEle)
- { // shawl.qiu script
- var iTop = 0;
- if(oEle.offsetParent)
- {
- while(true)
- {
- iTop += oEle.offsetTop;
- if(!oEle.offsetParent)
- {
- break;
- } // end if 1
- oEle = oEle.offsetParent;
- } // end while
- }
- else if(oEle.y)
- {
- iTop += oEle.y;
- }
- return iTop;
- } // end function fFindPosX
- } // end function fFindPos
- function fWinPopup(sUrl, iWidth, iHeight, sAddition){
- try{oPopup.close()}catch(e){}
- if(!sUrl)return false;
- if(!iWidth)iWidth=screen.availWidth-200;
- if(!iHeight)iHeight=screen.availHeight-150;
- if(!sAddition)sAddition='';
- var iMrgHor=(screen.availWidth-iWidth)/2;
- var iMrgVtc=(screen.availHeight-iHeight)/2;
- oPopup=open('about:blank','sqPopup','width='+iWidth+',height='+iHeight+',left='+iMrgHor
- +',top='+iMrgVtc+',scrollbars'+sAddition);
- oPopup.location.href=sUrl;
- oPopup.focus();
- oPopup.document.ondblclick=function(){oPopup.close();}
- oPopup.document.onkeydown=function(){ if(oPopup.event.keyCode==27)oPopup.close(); }
- return false;
- } // shawl.qiu script
- //------------------------------------end private method
- } // shawl.qiu code
- //---------------------------------end class Ubb()---------------------------------//
- var Ubb = new sqUbbEditor();