?? post.js
字號:
var sCurrMode
//根據(jù)瀏覽器類型選擇編輯器
if (navigator.appName == "Microsoft Internet Explorer"){
HtmlEdit()
var IframeID=frames["HtmlEditor"];
if (navigator.appVersion.indexOf("MSIE 6.0",0)==-1){IframeID.document.designMode="On";}
IframeID.document.open();
IframeID.document.close();
IframeID.document.body.contentEditable = "True";
IframeID.document.body.innerHTML=document.getElementById("content").value;
}else{
document.write ('<iframe ID=HtmlEditor MARGINHEIGHT=5 MARGINWIDTH=5 width=100% height=100%></iframe>')
HtmlEditor=document.getElementById("HtmlEditor").contentWindow;
HtmlEditor.document.designMode="On"
HtmlEditor.document.open();
HtmlEditor.document.close();
HtmlEditor.document.body.contentEditable = "True";
}
function HtmlEdit(){
YBBCOLOR="<option style=COLOR:#ffffff;BACKGROUND-COLOR:black value=#000000>Black</option> <option style=BACKGROUND-COLOR:gray value=#808080>Gray</option> <option style=BACKGROUND-COLOR:darkgray value=#A9A9A9>DarkGray</option> <option style=BACKGROUND-COLOR:lightgrey value=#D3D3D3>LightGray</option> <option style=BACKGROUND-COLOR:white value=#FFFFFF>White</option> <option style=BACKGROUND-COLOR:aquamarine value=#7FFFD4>Aquamarine</option> <option style=BACKGROUND-COLOR:blue value=#0000FF>Blue</option> <option style=COLOR:#ffffff;BACKGROUND-COLOR:navy value=#000080>Navy</option> <option style=COLOR:#ffffff;BACKGROUND-COLOR:purple value=#800080>Purple</option> <option style=BACKGROUND-COLOR:deeppink value=#FF1493>DeepPink</option> <option style=BACKGROUND-COLOR:violet value=#EE82EE>Violet</option> <option style=BACKGROUND-COLOR:pink value=#FFC0CB>Pink</option> <option style=COLOR:#ffffff;BACKGROUND-COLOR:darkgreen value=#006400>DarkGreen</option> <option style=COLOR:#ffffff;BACKGROUND-COLOR:green value=#008000>Green</option> <option style=BACKGROUND-COLOR:yellowgreen value=#9ACD32>YellowGreen</option> <option style=BACKGROUND-COLOR:yellow value=#FFFF00>Yellow</option> <option style=BACKGROUND-COLOR:orange value=#FFA500>Orange</option> <option style=BACKGROUND-COLOR:red value=#FF0000>Red</option> <option style=BACKGROUND-COLOR:brown value=#A52A2A>Brown</option> <option style=BACKGROUND-COLOR:burlywood value=#DEB887>BurlyWood</option> <option style=BACKGROUND-COLOR:beige value=#F5F5DC>Beige</option>"
YBBFont="<option value='宋體'>宋體</option> <option value='黑體'>黑體</option> <option value='仿宋_GB2312'>仿宋_GB2312</option> <option value='楷體_GB2312'>楷體_GB2312</option> <option value='隸書'>隸書</option> <option value='幼圓'>幼圓</option> <option value='新宋體'>新宋體</option><option value='Arial'>Arial</option><option value='Courier New'>Courier New</option><option value='Garamond'>Garamond</option><option value='Georgia'>Georgia</option><option value='Tahoma'>Tahoma</option><option value='Times New Roman'>Times</option><option value='Verdana'>Verdana</option>"
document.writeln("<table width=100% height=100% cellpadding=2 cellspacing=0><tr id=EditButton style=DISPLAY:block><td align=left colspan=6>");
document.writeln("<select onChange=\"FormatText('FormatBlock',this[this.selectedIndex].value);\"><option>段落</option><option value=\"<P>\">正文</option><option value=\"<H1>\">標題一</option><option value=\"<H2>\">標題二</option><option value=\"<H3>\">標題三</option><option value=\"<H4>\">標題四</option><option value=\"<H5>\">標題五</option><option value=\"<H6>\">標題六</option><option value=\"<PRE>\">預設格式</option></select>");
document.writeln("<select name=\"selectFont\" onChange=\"FormatText('fontname', selectFont.options[selectFont.selectedIndex].value);\"><option>字體</option>"+YBBFont+"</select> <select onChange=\"FormatText('fontsize',this[this.selectedIndex].value);\" name=\"D2\"><option>大小</option><option value=1>1</option><option value=2>2</option><option value=3>3</option><option value=4>4</option><option value=5>5</option><option value=6>6</option><option value=7>7</option></select>");
document.writeln("<select onChange=\"FormatText('forecolor',this[this.selectedIndex].value);\"><option>文字顏色</option>"+YBBCOLOR+"</select> <select onChange=\"FormatText('BackColor',this[this.selectedIndex].value);\"><option>文字背景顏色</option>"+YBBCOLOR+"</select>");
document.writeln("<img src=ybb/replace.gif alt=\"替換\" align=absmiddle style=cursor:hand onClick=replace()>");
document.writeln("<img src=ybb/img.gif alt=\"插入圖片\" align=absmiddle style=cursor:hand onClick=img()>");
document.writeln("<img src=ybb/img.gif alt=\"插入X光圖片\" align=absmiddle style=cursor:hand onClick=imgxray()>");
document.writeln("<img alt=\"清理HTML代碼\" src=ybb/cleancode.gif align=absmiddle style=cursor:hand onclick=CleanCode()><br>");
var FormatTextlist="粗體 bold|傾斜 italic|下劃線 underline|上標 superscript|下標 subscript|刪除線 strikethrough|刪除文字格式 RemoveFormat|左對齊 justifyleft|居中 justifycenter|右對齊 justifyright|兩端對齊 justifyfull|編號 insertorderedlist|項目符號 insertunorderedlist|減少縮進量 outdent|增加縮進量 indent|普通水平線 inserthorizontalrule|剪切 cut|復制 copy|粘貼 paste|撤消 undo|恢復 redo|全選 selectAll|取消選擇 unselect|刪除當前選中區(qū) delete|插入超鏈接 createLink|去掉超鏈接 unlink"
var list= FormatTextlist.split ('|');
for(i=0;i<list.length;i++) {
var TextName= list[i].split (' ');
document.write(" <img align=absmiddle src=ybb/"+TextName[1]+".gif alt="+TextName[0]+" style=cursor:hand onClick=FormatText('"+TextName[1]+"')> ");
}
document.writeln("</td></tr><tr><td height=100% colspan=6><iframe ID=HtmlEditor MARGINHEIGHT=5 MARGINWIDTH=5 width=100% height=100%></iframe></td></tr>");
document.writeln("<tr><td></div><table border=0 cellpadding=0 cellspacing=0 height=20>");
document.writeln("<tr>");
document.writeln("<td width=5></td>");
document.writeln("<td class=StatusBarBtnON id=HtmlEditor_EDIT onclick=setMode('EDIT')><img border=0 src=ybb/modeedit.gif align=absmiddle></td>");
document.writeln("<td width=5></td>");
document.writeln("<td class=StatusBarBtnOff id=HtmlEditor_CODE onclick=setMode('CODE')><img border=0 src=ybb/modecode.gif align=absmiddle></td>");
document.writeln("<td width=5></td>");
document.writeln("<td class=StatusBarBtnOff id=HtmlEditor_VIEW onclick=setMode('VIEW')><img border=0 src=ybb/modepreview.gif width=50 height=15 align=absmiddle></td>");
document.writeln("<td width=5></td>");
document.writeln("<td align=right width=100%><img border=0 src=ybb/+.gif align=absmiddle onclick=sizeChange(100) style=cursor:pointer alt='增大編輯區(qū)'><img border=0 src=ybb/-.gif align=absmiddle onclick=sizeChange(-100) style=cursor:pointer alt='減小編輯區(qū)'></td>");
document.writeln("</tr></table>");
document.writeln("</td></tr></table>");
}
// 調整編輯器的大小
function sizeChange(size){
var obj=document.getElementById("HtmlEditor");
obj.height = (parseInt(obj.offsetHeight) + size);
if (parseInt(obj.offsetHeight)< 200 ){obj.height ="100%"}
}
// 設置編輯器的內容
function setHTML(html) {
IframeID.document.body.innerHTML = html;
switch (sCurrMode){
case "CODE":
HtmlEditor.document.open();
HtmlEditor.document.write(html);
HtmlEditor.document.close();
HtmlEditor.document.body.innerText=html;
HtmlEditor.document.body.contentEditable="true";
EditButton.style.display = 'none';
break;
case "EDIT":
HtmlEditor.document.open();
HtmlEditor.document.write(html);
HtmlEditor.document.close();
HtmlEditor.document.body.contentEditable="true";
EditButton.style.display = 'block';
break;
case "VIEW":
HtmlEditor.document.open();
HtmlEditor.document.write(html);
HtmlEditor.document.close();
HtmlEditor.document.body.contentEditable="false";
EditButton.style.display = 'none';
break;
}
}
// 改變模式:代碼、編輯、預覽
function setMode(NewMode){
if (NewMode!=sCurrMode){
switch(sCurrMode){
case "CODE":
sBody = HtmlEditor.document.body.innerText;
break;
case "EDIT":
sBody = HtmlEditor.document.body.innerHTML;
break;
case "VIEW":
sBody = HtmlEditor.document.body.innerHTML;
break;
default:
sBody = IframeID.document.body.innerHTML;
break;
}
// 換圖片
try{
document.all["HtmlEditor_CODE"].className = "StatusBarBtnOff";
document.all["HtmlEditor_EDIT"].className = "StatusBarBtnOff";
document.all["HtmlEditor_VIEW"].className = "StatusBarBtnOff";
document.all["HtmlEditor_"+NewMode].className = "StatusBarBtnOn";
}
catch(e){
}
sCurrMode = NewMode;
setHTML(sBody);
}
}
// 取編輯器的內容
function getHTML() {
var html;
if(sCurrMode=="CODE"){
html = HtmlEditor.document.body.innerText;
}else{
html = HtmlEditor.document.body.innerHTML;
}
return html;
}
function FormatText(command,option){IframeID.focus();IframeID.document.execCommand(command,true,option);}
function CheckLength(){alert("最大字符為 "+60000+ " 字節(jié)\n您的內容已有 "+IframeID.document.body.innerHTML.length+" 字節(jié)");}
function CheckForm(){
document.getElementById("content").value = getHTML();
MessageLength=IframeID.document.body.innerHTML.length;
if(MessageLength<2){alert("內容不能小于2個字符!");return false;}
if(MessageLength>60000){alert("內容不能超過60000個字符!");return false;}
}
//////替換內容
function replace()
{
var arr = showModalDialog("../JS/Replace.htm", "", "dialogWidth:22em;dialogHeight:10em;status:0;help:0");
if (arr != null){
var ss;
ss = arr.split("*")
a = ss[0];
b = ss[1];
i = ss[2];
con = IframeID.document.body.innerHTML;
if (i == 1)
{
con = bbsxp_rCode(con,a,b,true);
}else{
con = bbsxp_rCode(con,a,b);
}
IframeID.document.body.innerHTML = con;
}
else IframeID.focus();
}
function bbsxp_rCode(s,a,b,i){
a = a.replace("?","\\?");
if (i==null)
{
var r = new RegExp(a,"gi");
}else if (i) {
var r = new RegExp(a,"g");
}
else{
var r = new RegExp(a,"gi");
}
return s.replace(r,b);
}
//////替換內容結束
function imgxray(){
url=prompt("請輸入上傳地圖片文件名:","");
if(!url || url=="http://") return;
IframeID.focus();
sel=IframeID.document.selection.createRange();
sel.pasteHTML("<img style=filter:xray src=../UploadPhoto/"+url+">");
}
function img(){
url=prompt("請輸入上傳地圖片文件名:","");
if(!url || url=="http://") return;
IframeID.focus();
sel=IframeID.document.selection.createRange();
sel.pasteHTML("<img src=../UploadPhoto/"+url+">");
}
function MediaPlayer(){
var arr = showModalDialog("inc/MediaPlayer.htm", "", "dialogWidth:22em; dialogHeight:10.5em; status:0;help:0");
if (arr != null){
IframeID.focus()
sel=IframeID.document.selection.createRange();
sel.pasteHTML(arr);
}
}
function CleanCode(){
var body = IframeID.document.body;
var html = IframeID.document.body.innerHTML;
html = html.replace(/\<p>/gi,"[$p]");
html = html.replace(/\<\/p>/gi,"[$\/p]");
html = html.replace(/\<br>/gi,"[$br]");
html = html.replace(/\<[^>]*>/g,"");
html = html.replace(/\[\$p\]/gi,"<p>");
html = html.replace(/\[\$\/p\]/gi,"<\/p>");
html = html.replace(/\[\$br\]/gi,"<br>");
IframeID.document.body.innerHTML = html;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -