📄 post.js
字号:
var sCurrMode
StyleEditorHeader = "<style>BLOCKQUOTE {BORDER-RIGHT: #cccccc 1px dotted; PADDING-RIGHT: 4px; BORDER-TOP: #cccccc 1px dotted; PADDING-LEFT: 4px; PADDING-BOTTOM: 4px; MARGIN: 16px; BORDER-LEFT: #cccccc 1px dotted; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px dotted}</style><script>i=0;function ctlent(eventobject){if(event.ctrlKey && window.event.keyCode==13 && i==0){i=1;parent.document.form.content.value=document.body.innerHTML;parent.document.form.submit();parent.document.form.EditSubmit.disabled=true;}}<\/script><body onkeydown=ctlent()>" ;
// 根据浏览器类型选择编辑器
if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
// IE浏览器
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.write("<table width=100% height=100% cellpadding=2 cellspacing=0 style='border:solid 1px #93BEFF;'><tr id=EditButton style=DISPLAY:block><td align=left colspan=6 style='border-bottom:solid 1px #93BEFF;background-color:#E6F0FF;'>");
document.write("<select onChange=\"FormatText('FormatBlock',this[this.selectedIndex].value);this.selectedIndex=0;\"><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.write("<select onChange=\"FormatText('fontname',this[this.selectedIndex].value);this.selectedIndex=0;\"><option>字体</option>"+YBBFont+"</select> ");
document.write("<select onChange=\"FormatText('fontsize',this[this.selectedIndex].value);this.selectedIndex=0;\"><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.write("<img src=skins/ybb/fgcolor.gif title=\"字体颜色\" align=absmiddle style=cursor:hand onClick=foreColor()>");
document.write("<img src=skins/ybb/fbcolor.gif title=\"突出显示\" align=absmiddle style=cursor:hand onClick=BackColor()>");
document.write("<img src=skins/ybb/InsertImage.gif title=\"插入图片\" align=absmiddle style=cursor:hand onClick=InsertImage()><img src=skins/ybb/table.gif title=\"插入表格\" align=absmiddle style=cursor:hand onClick=fortable() >");
document.write("<img title=\"插入 FLASH、MediaPlayer、RealPlayer 文件\" src=skins/ybb/mp.gif align=absmiddle style=cursor:hand onclick=MediaPlayer()>");
document.write("<img src=skins/ybb/replace.gif title=\"替换\" align=absmiddle style=cursor:hand onClick=replace()>");
document.write("<img title=\"插入表情\" src=skins/ybb/em.gif align=absmiddle style=cursor:hand onclick=em()>");
document.write("<img src=skins/ybb/specialchar.gif title=\"插入特殊字符\" align=absmiddle style=cursor:hand onClick=specialchar()>");
document.write('<img src="skins/ybb/insertdate.gif" title=\"插入今天的日期\" align=absmiddle border="0" style=cursor:hand onClick=insertdate()>');
document.write('<img src="skins/ybb/inserttime.gif" title=\"插入当前的时间\" align=absmiddle border="0" style=cursor:hand onClick=inserttime()><br>');
document.write('<img src="skins/ybb/Break.gif" title=\"换行符\" align=absmiddle border="0" style=cursor:hand onClick=Break()>');
var FormatTextlist="插入输入框 InsertInputText|插入文字输入区 InsertTextArea|插入单选钮 InsertInputRadio|插入复选框 InsertInputCheckbox|插入下拉框 InsertSelectDropdown|插入按钮 InsertButton|粗体 bold|倾斜 italic|下划线 underline|上标 superscript|下标 subscript|删除线 strikethrough|删除文字格式 RemoveFormat|左对齐 Justifyleft|居中 JustifyCenter|右对齐 JustifyRight|两端对齐 justifyfull|编号 insertorderedlist|项目符号 InsertUnorderedList|减少缩进量 Outdent|增加缩进量 indent|普通水平线 InsertHorizontalRule|<br>|段落 InsertParagraph|全选 selectAll|取消选择 unselect|删除当前选中区 Delete|剪切 cut|复制 copy|粘贴 paste|撤消 undo|恢复 redo|插入超链接 createLink|去掉超链接 Unlink|打印 Print"
var list= FormatTextlist.split ('|');
for(i=0;i<list.length;i++) {
if (list[i]=="<br>"){document.write("<br>");
}else{
var TextName= list[i].split (' ');
document.write("<img align=absmiddle width=20 height=20 src=skins/ybb/"+TextName[1]+".gif title="+TextName[0]+" style=cursor:hand onClick=FormatText('"+TextName[1]+"')>");
}
}
document.write("<img title=\"清洁代码\" src=skins/ybb/Cleanup.gif align=absmiddle style=cursor:hand onclick=CleanCode()>");
document.write("</td></tr><tr><td height=100% colspan=6><iframe ID=HtmlEditor MARGINHEIGHT=5 MARGINWIDTH=5 width=100% height=100% ></iframe></td></tr>");
document.write("<tr><td></div><table border=0 cellpadding=0 cellspacing=0 height=20>");
document.write("<tr>");
document.write("<td width=5></td>");
document.write("<td class=StatusBarBtnON id=HtmlEditor_EDIT onclick=setMode('EDIT')><img border=0 src=skins/ybb/modeedit.gif align=absmiddle></td>");
document.write("<td width=5></td>");
document.write("<td class=StatusBarBtnOff id=HtmlEditor_CODE onclick=setMode('CODE')><img border=0 src=skins/ybb/modecode.gif align=absmiddle></td>");
document.write("<td width=5></td>");
document.write("<td class=StatusBarBtnOff id=HtmlEditor_VIEW onclick=setMode('VIEW')><img border=0 src=skins/ybb/modepreview.gif width=50 height=15 align=absmiddle></td>");
document.write("<td width=5></td>");
document.write("<td align=right width=100%><span onClick=setMode('CODE');FormatText('paste');setMode('EDIT') style=cursor:hand><font color=@ff0000>[ 介绍消失,<img border=0 src=skins/ybb/paste.gif>点此处恢复内容 ]</font> </span><img border=0 src=skins/ybb/+.gif align=absmiddle onclick=sizeChange(100) style=cursor:pointer title='增大编辑区'><img border=0 src=skins/ybb/-.gif align=absmiddle onclick=sizeChange(-100) style=cursor:pointer title='减小编辑区'></td>");
document.write("</tr></table>");
document.write("</td></tr></table>");
}else{
// 其他浏览器
document.write ('<iframe ID=HtmlEditor MARGINHEIGHT=5 MARGINWIDTH=5 width=100% height=100%></iframe>')
}
var IframeID=document.getElementById("HtmlEditor").contentWindow;
if (navigator.appVersion.indexOf("MSIE 6.0",0)==-1){IframeID.document.designMode="On"} //可编辑与StyleEditorHeader生效
IframeID.document.open();
IframeID.document.write(StyleEditorHeader+document.form.content.value);
IframeID.document.close();
IframeID.document.body.contentEditable = "True";
IframeID.document.body.style.fontSize="10pt";
// 预览
function Preview()
{
if(IframeID.document.body.innerHTML<1){alert("请输入内容后才能预览!");return false;}
window.open('', 'preview_page', 'resizable,scrollbars,width=750,height=450');
document.preview.content.value=IframeID.document.body.innerHTML;
document.preview.submit()
}
// 调整编辑器的大小
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 "EDIT":
HtmlEditor.document.open();
HtmlEditor.document.write(StyleEditorHeader+html);
HtmlEditor.document.close();
HtmlEditor.document.body.contentEditable="true";
EditButton.style.display = 'block';
break;
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 "VIEW":
HtmlEditor.document.open();
HtmlEditor.document.write(StyleEditorHeader+html);
HtmlEditor.document.close();
HtmlEditor.document.body.contentEditable="false";
EditButton.style.display = 'none';
break;
}
}
// 改变模式:代码、编辑、预览
function setMode(NewMode){
if (NewMode!=sCurrMode){
switch(sCurrMode){
case "EDIT":
sBody = HtmlEditor.document.body.innerHTML;
break;
case "CODE":
sBody = HtmlEditor.document.body.innerText;
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 = IframeID.document.body.innerText;
}else{
html = IframeID.document.body.innerHTML;
}
html = html.replace(/'/gi,"");
html = html.replace(/%/gi,"");
return html;
}
function em(){
var arr = showModalDialog("fun/Emotion.htm", "", "dialogWidth:20em; dialogHeight:9.5em; status:0;help:0");
if (arr != null){
IframeID.focus()
sel=IframeID.document.selection.createRange();
sel.pasteHTML(arr);
}
}
function FormatText(command,option){IframeID.focus();IframeID.document.execCommand(command,true,option);}
function CheckLength(){alert("最大字符为 "+60000+ " 字节\n您的内容已有 "+IframeID.document.body.innerHTML.length+" 字节");}
function emoticon(theSmilie){
IframeID.focus();
sel=IframeID.document.selection.createRange();
sel.pasteHTML("<img src=skins/Emotions/"+theSmilie+".gif>");
}
function CheckForm(form){
if(sCurrMode=="CODE"){alert("编辑器处于代码状态下不能发送内容!");return false;}
form.content.value = getHTML();
window.clipboardData.setData('Text',form.content.value);
MessageLength=IframeID.document.body.innerHTML.length;
if(MessageLength<2){alert("内容不能小于2个字符!");return false;}
if(MessageLength>60000){alert("内容不能超过60000个字符!");return false;}
document.form.EditSubmit.disabled = true;
}
//////替换内容
function replace()
{
var arr = showModalDialog("fun/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 InsertImage(){
url=prompt("请输入图片文件地址:","http://");
if(!url || url=="http://") return;
IframeID.focus();
sel=IframeID.document.selection.createRange();
sel.pasteHTML("<img src="+url+">");
}
function MediaPlayer(){
var arr = showModalDialog("fun/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;
}
function Break(){
IframeID.focus();
sel=IframeID.document.selection.createRange();
sel.pasteHTML("<br>");
}
function insertdate(){
IframeID.focus();
sel=IframeID.document.selection.createRange();
sel.pasteHTML(new Date().toLocaleDateString());
}
function inserttime(){
IframeID.focus();
sel=IframeID.document.selection.createRange();
sel.pasteHTML(new Date().toLocaleTimeString());
}
function specialchar()
{
var arr = showModalDialog("fun/specialchar.htm", "", "dialogWidth:26em; dialogHeight:16em; status:0;help:0");
IframeID.focus();
sel=IframeID.document.selection.createRange();
if (arr != null)sel.pasteHTML(arr);
}
function fortable()
{IframeID.focus();
var range =IframeID.document.selection.createRange();
var arr = showModalDialog("fun/table.htm", "", "dialogWidth:32em; dialogHeight:20em; status:0;help:0");
if (arr != null){
var ss;
ss=arr.split("*")
a=ss[0];
b=ss[1];
c=ss[2];
d=ss[3];
e=ss[4];
f=ss[5];
g=ss[6];
h=ss[7];
var string;
string="<table border="+d+" cellpadding="+e+" cellspacing="+f+" style='border-collapse: collapse' bordercolor="+g+" bgcolor="+h+" width=100 align="+c+">";
for(i=1;i<=a;i++){
string=string+"<tr>";
for(j=1;j<=b;j++){
string=string+"<td width="+100/a+"%></td>";
}
string=string+"</tr>";
}
string=string+"</table>";
range.pasteHTML(string);
}
else IframeID.focus();
}
function BackColor()
{
var arr = showModalDialog("fun/selcolor.htm", "", "dialogWidth:18em; dialogHeight:17.5em; status:0;help:0");
if (arr != null) FormatText('BackColor', arr);
else IframeID.focus();
}
function foreColor()
{
var arr = showModalDialog("fun/selcolor.htm", "", "dialogWidth:18em; dialogHeight:17.5em; status:0;help:0");
if (arr != null) FormatText('forecolor', arr);
else IframeID.focus();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -