?? editor.js
字號:
/*
main:mothod
<SCRIPT LANGUAGE="JavaScript">
<!--
Editor(document.topic.contenttest.value);
//-->
</SCRIPT>
*/
function Editor(content){
document.write('<iframe name="wrEditor" id="wrEditor" width="608" height="198" src="about:blank"></iframe>');
oEditor = document.wrEditor;
var strHtml = '<html><style>body{font-size:14px;line-height: 20px; margin:2px;}\ntd, a{color:#0000ff; font-size:14px;}</style><body>'+content+'</body></html>';
oEditor.document.open();
oEditor.document.write(strHtml);
oEditor.document.close();
oEditor.document.designMode="On";
oEditor.focus();
}
//清理多余HTML代碼
function cleanHtml(content)
{
content = content.replace(/<p> <\/p>/gi,"")
content = content.replace(/<p><\/p>/gi,"<p>")
content = content.replace(/<div><\/\1>/gi,"")
content = content.replace(/<p>/,"<br>")
content = content.replace(/(<(meta|iframe|frame|span|tbody|layer)[^>]*>|<\/(iframe|frame|meta|span|tbody|layer)>)/gi, "");
content = content.replace(/<\\?\?xml[^>]*>/gi, "") ;
content = content.replace(/o:/gi, "");
content = content.replace(/ /gi, " ");
if(Dvbbs_bTextMode!=1){
content = content.replace(/<img([^>]*) (src\s*=\s*([^\s|>])*)([^>]*)>/gi,"<img $2>");
}
//content = content.replace(/\r\n/g, '');
//content = content.replace(/\n/g, '');
//content = content.replace(/\r/g, '');
//alert(content);
return content;
}
//代碼過濾及JS提取
function FilterScript(content)
{
//content = rCode(content, 'javascript:', '<b>javascript</b> :');
content = content.replace(/<(\w[^div|>]*) class\s*=\s*([^>|\s]*)([^>]*)/gi,"<$1$3") ;
content = content.replace(/<(\w[^font|>]*) style\s*=\s*\"[^\"]*\"([^>]*>)/gi,"<$1 $2") ;
content = content.replace(/<(\w[^>]*) lang\s*=\s*([^>|\s]*)([^>]*)/gi,"<$1$3") ;
var RegExp = /<(script[^>]*)>(.*)<\/script>/gi;
content = content.replace(RegExp, "[code]<$1><br>$2<br><script>[\/code]");
RegExp = /<(\w[^>|\s]*)([^>]*)(on(finish|mouse|Exit|error|click|key|load|change|focus|blur))(.[^>]*)/gi;
content = content.replace(RegExp, "<$1")
RegExp = /<(\w[^>|\s]*)([^>]*)(&#|window\.|javascript:|js:|about:|file:|Document\.|vbs:|cookie| name| id)(.[^>]*)/gi;
content = content.replace(RegExp, "<$1")
//alert(content);
return content;
}
//文字加粗
function bold(){
var sText = oEditor.document.selection.createRange();
if(sText!=""){
oEditor.document.execCommand("bold");
}
}
//傾斜
function italic(){
var sText = oEditor.document.selection.createRange();
if(sText!=""){
oEditor.document.execCommand("italic");
}
}
//下劃線
function underline(){
var sText = oEditor.document.selection.createRange();
if(sText!=""){
oEditor.document.execCommand("underline");
}
}
//超鏈接
function url(){
var sText = oEditor.document.selection.createRange();
if(sText!=""){
oEditor.document.execCommand("createLink");
oEditor.document.execCommand("ForeColor", "false", "#FF0000");
}
}
//取消鏈接
function unurl(){
var sText = oEditor.document.selection.createRange();
if(sText!=""){
oEditor.document.execCommand("unlink");
}
}
//插入圖片
function image(){
var arr = showModalDialog("Editor/include/img.htm", window, "dialogWidth:600px; dialogHeight:200px; status:0; help:0");
if (arr)
{
oEditor.document.body.innerHTML+=arr;
}
oEditor.focus();
}
//插入Flash
function flash(){
var arr = showModalDialog("Editor/include/swf.htm", "", "dialogWidth:400px; dialogHeight:180px; status:0; help:0");
if (arr != null)
{
var ss;
ss=arr.split("*");
path=ss[0];
row=ss[1];
col=ss[2];
var string;
string="<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="+row+" height="+col+"><param name=movie value="+path+"><param name=quality value=high><embed src="+path+" pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width="+row+" height="+col+"></embed></object>"
//string="[dir="+row+","+col+"]"+path+"[/dir]";
oEditor.document.body.innerHTML+=string;
}
oEditor.focus();
}
//插入 當前日期
function insertdate(){
oEditor.focus();
sel=oEditor.document.selection.createRange();
sel.pasteHTML(new Date().toLocaleDateString());
}
//插入 當前時間
function inserttime(){
oEditor.focus();
sel=oEditor.document.selection.createRange();
sel.pasteHTML(new Date().toLocaleTimeString());
}
//插入 表情
function em(){
var arr = showModalDialog("Editor/Emotion.htm", "", "dialogWidth:20em; dialogHeight:10em; status:0;help:0");
if (arr != null){
oEditor.focus()
sel=oEditor.document.selection.createRange();
sel.pasteHTML(arr);
}
}
//插入 MediaPlayer 播放器
function wmv()
{
var arr = showModalDialog("Editor/include/wmv.htm", window, "dialogWidth:400px; dialogHeight:220px; status:0; help:0");
if (arr != null){
var ss;
ss=arr.split("*")
path=ss[0];
autostart=ss[1];
width=ss[2];
height=ss[3];
var string;
//string="<object align=center classid=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95 hspace=5 vspace=5 width="+ width +" height="+ height +"><param name=Filename value="+ path +"><param name=ShowStatusBar value=1><embed type=application/x-oleobject codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701 flename=mp src="+ path +" width="+ width +" height="+ height +"></embed></object>";
string="<EMBED id=MediaPlayer src="+ path +" width="+ width +" height="+ height +" autostart=\""+ autostart +"\" loop=\"false\"></EMBED><p></p>";
oEditor.document.body.innerHTML+=string;
}
else oEditor.focus();
}
//插入 RealPlayer 播放器
function rm(){
var arr = showModalDialog("Editor/include/rm.htm", window, "dialogWidth:400px; dialogHeight:220px; status:0; help:0");
if (arr != null)
{
var ss;
ss=arr.split("*");
path=ss[0];
autostart=ss[3];
width=ss[1];
height=ss[2];
var string;
//string="<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="+row+" height="+col+"><param name=movie value="+path+"><param name=quality value=high><embed src="+path+" pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width="+row+" height="+col+"></embed></object>"
string="<embed src="+ path +" width="+ width +" height="+ height +" type='audio/x-pn-realaudio-plugin' console='Clip1' controls='ImageWindow,ControlPanel,StatusBar' autostart=" +autostart+ " ></EMBED><p></p>"
//string="[rm="+ width +","+ height +","+ autostart +"]"+ path +"[/rm]";
oEditor.document.body.innerHTML+=string;
}
oEditor.focus();
}
/*
參數:left/center/right
*/
function ralign(aStr){
switch(aStr){
case "left":
oEditor.document.execCommand("JustifyLeft");
break;
case "center":
oEditor.document.execCommand("JustifyCenter");
break;
case "right":
oEditor.document.execCommand("JustifyRight");
break;
default:
return false;
}
}
/*
字體顏色
*/
function FontColor(){
var arr = showModalDialog("Editor/include/selcolor.htm", window, "dialogWidth:300px; dialogHeight:300px; status:0; help:0");
if (arr)
{
var sText = oEditor.document.selection.createRange();
if(sText){
oEditor.document.execCommand("ForeColor", "false", arr);
}
}
oEditor.focus();
}
/*
字體背景顏色
*/
function BackColor(){
var arr = showModalDialog("Editor/include/selcolor.htm", window, "dialogWidth:300px; dialogHeight:300px; status:0; help:0");
if (arr)
{
var sText = oEditor.document.selection.createRange();
if(sText){
oEditor.document.execCommand("BackColor", "false", arr);
}
}
oEditor.focus();
}
/*
*/
function FontSize(value){
var sText = oEditor.document.selection.createRange();
if(sText){
oEditor.document.execCommand("FontSize", "false", value);
}
}
/*
*/
function FontName(value){
var sText = oEditor.document.selection.createRange();
if(sText){
oEditor.document.execCommand("FontName", "false", value);
}
}
//取消格式
function unformat(){
var sText = oEditor.document.selection.createRange();
if(sText){
oEditor.document.execCommand("RemoveFormat", false, "");
}
}
function getContent()
{
return correctUrl(oEditor.document.body.innerHTML);
}
function correctUrl(cont)
{
var regExp;
regExp = /<a([^>]*) href\s*=\s*([^\s|>]*)([^>]*)/gi
cont = cont.replace(regExp, "<a href=$2 target=\"_blank\"");
regExp = /<a([^>]*)><\/a>/gi
cont = cont.replace(regExp, "");
return cont;
}
function FormatText(command,option){oEditor.focus();oEditor.document.execCommand(command,true,option);}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -