UBB 编辑器演示 (兼容 IE, Opera, Firefox) By shawl.qiu
说明:
这个很简单, 没啥好说明的.
哦, 还是有点需要说明, 这个UBB编辑器对应的解码与编码是服务端代码, 这个是秘密.
最近狂了解浏览器兼容技术, 已经有点小心点了.
等着我的 HTML 编辑器吧, 照样兼容 IE, Opera, Firefox, 主要技术已经解决了.
shawl.qiu
2006-11-23
UBB 编辑器演示 源代码:
linenum
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
/*-------------------------------------------------------*\
* UBB 编辑器演示 (兼容 IE, Opera, Firefox) By shawl.qiu
* 参数说明:
* target: 字符串, UBB 主编辑域 ID
* markup: 字符串, UBB 标签
\*-------------------------------------------------------*/
function ubbTag(target, markup){
var txa=document.getElementsByName(target)[0];
txa.focus();
var strEnd=markup.replace(/\[/ig,'[/');
if (strEnd.indexOf('=')>-1){
strEnd=strEnd.replace(/(.*?)\=.*?\]/,'$1]');
}
if(document.selection&&document.selection.type== "Text"){
// IE, Opera
var oStr=document.selection.createRange();
oStr.text=markup+oStr.text+strEnd;
} else if(window.getSelection&&txa.selectionStart>-1) {
// Netscape
var st=txa.selectionStart;
var ed=txa.selectionEnd;
txa.value=txa.value.substring(0,st)+markup+
txa.value.substring(st,ed)+strEnd+
txa.value.slice(ed);
} else {
txa.value+=markup+strEnd;
}
} // shawl.qiu script
//]]>
</script>
<form action="" method="post" name="ubbForm" id="ubbForm">
<select onchange="ubbTag('content', '['+this.value+']')">
<option value="h6">h6</option>
<option value="h5">h5</option>
<option value="h4">h4</option>
<option value="h3">h3</option>
<option value="h2">h2</option>
<option value="h1">h1</option>
<option value="h1" selected="selected">font size</option>
</select>
<select onchange="ubbTag('content', '[color='+this.value+']')">
<option value="black">color</option>
<option value="black" style="background-color:black; color:#FFFFFF;">black</option>
<option value="blue" style="background-color:blue; color:#FFFFFF;">blue</option>
<option value="fuchsia" style="background-color:fuchsia; color:#FFFFFF;">fuchsia</option>
<option value="gray" style="background-color:gray; color:#FFFFFF;">gray</option>
<option value="green" style="background-color:green; color:#FFFFFF;">green</option>
<option value="lime" style="background-color:lime;">lime</option>
<option value="maroon" style="background-color:maroon; color:#FFFFFF;"> maroon </option>
<option value="navy" style="background-color:navy; color:#FFFFFF;">navy</option>
<option value="olive" style="background-color:olive; color:#FFFFFF;">olive</option>
<option value="orange" style="background-color:orange; color:#FFFFFF;">orange</option>
<option value="purple" style="background-color:purple; color:#FFFFFF;">purple</option>
<option value="red" style="background-color:red; color:#FFFFFF;">red</option>
<option value="silver" style="background-color:silver; color:#FFFFFF;">silver</option>
<option value="teal" style="background-color:teal; color:#FFFFFF;">teal</option>
<option value="white" style="background-color:white;">white</option>
<option value="yellow"style="background-color:yellow;">yellow</option>
</select>
<input type="button" value="url" onclick="ubbTag('content', '[url]')"/>
<input type="button" value="img" onclick="ubbTag('content', '[img]')"/>
<input type="button" value="email" onclick="ubbTag('content', '[email]')"/>
<input type="button" value="code" onclick="ubbTag('content', '[code]')" />
<input type="button" value="quote" onclick="ubbTag('content', '[quote]')"/>
<input type="button" value="cite" onclick="ubbTag('content', '[cite]')"/>
<input type="button" value="linenum" onclick="ubbTag('content', '[linenum]')"/>
<input type="button" value="b" onclick="ubbTag('content', '[b]')"/>
<input type="button" value="left" onclick="ubbTag('content', '[align=left]')"/>
<input type="button" value="center" onclick="ubbTag('content', '[align=center]')"/>
<input type="button" value="right" onclick="ubbTag('content', '[align=right]')"/>
<input type="button" value="textarea" onclick="ubbTag('content', '[textarea]')"/>
<input type="button" value="pre" onclick="ubbTag('content', '[pre]')"/>
<input type="button" value="xmp" onclick="ubbTag('content', '[xmp]')"/>
<input type="button" value="sub" onclick="ubbTag('content', '[sub]')"/>
<input type="button" value="sup" onclick="ubbTag('content', '[sup]')"/>
<input type="button" value="abbr" onclick="ubbTag('content', '[abbr]')"/>
<input type="button" value="address" onclick="ubbTag('content', '[address]')"/>
<input type="button" value="dl" onclick="ubbTag('content', '[dl][dd]')"/>
<input type="button" value="dt" onclick="ubbTag('content', '[dt]')"/>
<input type="button" value="dd" onclick="ubbTag('content', '[dd]')"/>
<input type="button" value="nl" onclick="ubbTag('content', '[nl][li]')"/>
<input type="button" value="ol" onclick="ubbTag('content', '[ol][li]')"/>
<input type="button" value="ul" onclick="ubbTag('content', '[ul][li]')"/>
<input type="button" value="li" onclick="ubbTag('content', '[li]')"/>
<input type="button" value="floatleft" onclick="ubbTag('content', '[float=left]')"/>
<input type="button" value="floatright" onclick="ubbTag('content', '[float=right]')"/>
<input type="button" value="tagLink" onclick="ubbTag('content', '[taglink]')"/>
<input type="button" value="glLink" onclick="ubbTag('content', '[gllink]')"/> <br/>
<textarea name="content" cols="80" rows="10">aaaaaaaaaa</textarea><br/>
<input type="submit" name="Submit" value="Submit" />
<input type="reset" name="Reset" value="Reset" />
</form>