📄 editor.js
字号:
var IframeID;
var IsCode
IsCode="No"
function HtmlEdit(){
document.writeln("<div><select name=\"selectFont1\" onchange=\"Insert(this[this.selectedIndex].value);this.selectedIndex=0;\"><option selected>特殊贴↓</option><option value=\"[COIN=1000]内容[/COIN]\">金钱可见</option><option value=\"[GRADE=1]内容[/GRADE]\">等级可见</option><option value=\"[REPLY]内容[/REPLY]\">回复可见</option><option value=\"[USERNAME=昵称]内容[/USERNAME]\">指定读者</option><option value=\"[MARK=3]内容[/MARK]\">Y 币可见</option><option value=\"[BUYPOST=100]内容[/BUYPOST]\">付费可见</option><option value=\"[DATE=2006-10-1]内容[/DATE]\">日期可见</option><option value=\"[SEX=1]内容[/SEX]\">性别可见</option><option value=\"[LOGIN]内容[/LOGIN]\">登陆可见</option></select>");
document.writeln("<select name=\"selectFont\" onChange=\"FormatText('fontname',this[this.selectedIndex].value);\"><option selected>字体<option value=\"removeFormat\">默认字体<option value=\"宋体\">宋体<option value=\"黑体\">黑体<option value=\"隶书\">隶书<option value=\"幼圆\">幼圆<option value=\"楷体_GB2312\">楷体<option value=\"仿宋_GB2312\">仿宋<option value=\"新宋体\">新宋体<option value=\"华文彩云\">华文彩云<option value=\"华文仿宋\">华文仿宋<option value=\"华文新魏\">华文新魏<option value=\"Arial\">Arial<option value=\"Arial Black\">Arial Black<option value=\"Arial Narrow\">Arial Narrow<option value=\"Century\">Century<option value=\"Courier New\">Courier New<option value=\"Georgia\">Georgia<option value=\"Impact\">Impact<option value=\"Lucida Console\">Lucida Console<option value=\"MS Sans Serif\">MS Sans Serif<option value=\"System\">System<option value=\"Symbol\">Symbol<option value=\"Tahoma\">Tahoma<option value=\"Times New Roman\">Times New Roman <option value=\"Verdana\">Verdana<option value=\"Webdings\">Webdings<option value=\"Wingdings\">Wingdings</option></select> <select onChange=\"FormatText('fontsize',this[this.selectedIndex].value);\" name=\"D2\"><option class=\"heading\" selected>字号<option value=1>一号<option value=2>二号<option value=3>三号<option value=4>四号<option value=5>五号<option value=6>六号<option value=7>七号</option></select>");
document.writeln("<img id=\"backcolor\" src=images\/edit\/fbcolor.gif alt=\"突出颜色\" title=\"突出颜色\" align=absmiddle style=\"cursor:pointer;width:16px;height:16px;\" onClick=\"color(\'backcolor\')\">");
document.writeln("<img id=\"forecolor\" src=images\/edit\/fgcolor.gif alt=\"字体颜色\" title=\"字体颜色\" align=absmiddle style=\"cursor:pointer;width:16px;height:16px;\" onClick=\"color(\'forecolor\')\">");
document.writeln("<img align=absmiddle src=images\/edit\/separator.gif>");
document.writeln("<img alt=\"插入FLASH文件\" src=images\/edit\/swf.gif align=absmiddle style=\"cursor:pointer;width:16px;height:16px;\" onclick=flash()>");
document.writeln("<img alt=\"插入Media Player文件\" src=images\/edit\/mp.gif align=absmiddle style=\"cursor:pointer;width:16px;height:16px;\" onclick=MediaPlayer()>");
document.writeln("<img alt=\"插入RealPlayer文件\" src=images\/edit\/rm.gif align=absmiddle style=\"cursor:pointer;width:16px;height:16px;\" onclick=RealPlay()><br>");
document.writeln("<img src=images\/edit\/code.gif alt=\"代码\" title=\"代码\" align=absmiddle style=\"cursor:pointer;width:16px;height:16px;\" onClick=Insert(\"[code]内容[/code]\")>");
document.writeln("<img src=images\/edit\/replace.gif alt=\"替换\" title=\"替换\" align=absmiddle style=\"cursor:pointer;width:16px;height:16px;\" onClick=replace()>");
document.writeln("<img align=absmiddle src=images\/edit\/table.gif alt=\"插入表格\" title=\"插入表格\" style=\"cursor:pointer;width:16px;height:16px;\" onClick=inserttable()>");
document.writeln("<img src=images\/edit\/img.gif alt=\"插入图片\" title=\"插入图片\" align=absmiddle style=\"cursor:pointer;width:16px;height:16px;\" onClick=img()>");
FormatTextlist="-|粗体 bold|倾斜 italic|下划线 underline|删除线 strikethrough|上标 superscript|下标 subscript|删除文字格式 RemoveFormat|-|左对齐 Justifyleft|居中 JustifyCenter|右对齐 JustifyRight|-|编号 insertorderedlist|项目符号 InsertUnorderedList|减少缩进量 Outdent|增加缩进量 indent|-|插入超链接 createLink|去掉超链接 Unlink|普通水平线 InsertHorizontalRule"
list= FormatTextlist.split ('|');
for(i=0;i<list.length;i++){
if (list[i]=="-"){document.write("<img align=\"absmiddle\" src=\"images\/edit\/separator.gif\" />");
}else{
var TextName= list[i].split (' ');
if ((i==2 || i==3 ||i==4)&&(ns6)){
//document.write(" <img align=absmiddle src=images\/edit\/"+TextName[1]+"1.gif alt="+TextName[0]+" style=\"width:16px;height:16px;\" >");
}
else{
document.write(" <img align=\"absmiddle\" src=\"images\/edit\/"+TextName[1]+".gif\" alt=\""+TextName[0]+"\" title=\""+TextName[0]+"\" style=\"cursor:pointer;width:16px;height:16px;\" onClick=\"FormatText('"+TextName[1]+"')\" \/> ");
}
}
}
document.writeln("<div><iframe ID=\"edit\" MARGINHEIGHT=\"5\" MARGINWIDTH=\"5\" width=\"99%\" height=\"250\"><\/iframe><\/div>");
document.writeln("<div style=\"float:right;\"><span id=\"CNo\" style=\"height:21\" ><img id=\"CNo\" width=\"52\" height=\"21\" src=\"images\/edit\/codeA.gif\" onClick=\"setCode(\'No\')\" ></span><span style=\"height:21\" id=\"CYes\"><img src=\"images\/edit\/codeB.gif\" width=\"52\" height=\"21\" onClick=setCode(\'Yes\')></span> <img src=\"Images\/plus.gif\" style=\"cursor:pointer\" onclick=\"textarea_Size(250,document.getElementById(\'edit\'))\" alt=\"增加编辑框的高度\" \/> <img src=\"Images\/minus.gif\" style=\"cursor:pointer\" onclick=\"textarea_Size(-250,document.getElementById(\'edit\'))\" alt=\"减小输入框的高度\" \/><\/div>");
document.writeln("<div id=\"MaoDiv\" style=\"background:#FFFFFF;position: absolute; width:570px; height:160px; display:none;\"><iframe id=\"MView\" name=\"MView\" src=\"about:blank\" frameborder=\"0\" scrolling=\"no\" valign=\"top\" width=\"100%\" height=\"100%\"><\/iframe><\/div>");
if (ns6){
IframeID=document.getElementById("edit").contentWindow;
document.writeln("<div id=\"colorpalette\" style=\"position: absolute;visibility: hidden;width:201px;height:151px;left:400px;top:350px\" ><iframe src=\"images/edit/colors.htm\" frameborder=\"0\" scrolling=\"no\" width=\"100%\" height=\"100%\" ><\/iframe><\/div>");
document.addEventListener("mousedown", dismisscolorpalette, true);
IframeID.document.addEventListener("mousedown", dismisscolorpalette, true);
document.addEventListener("keypress", dismisscolorpalette, true);
IframeID.document.addEventListener("keypress", dismisscolorpalette, true);
}else{
IframeID=frames["edit"];
}
document.getElementById("CYes").style.border="1px outset"
document.getElementById("CNo").style.border="1px inset"
document.getElementById("CYes").style.cursor="pointer"
if (navigator.appVersion.indexOf("MSIE 6.0",0)==-1){IframeID.document.designMode="On"}
IframeID.document.open();
IframeID.document.write ('<html><head><style type=text/css>.quote{margin:5px 20px;padding:5px; background:#EEEEEF;border:1px solid #CCC ;}\nbody{boder:0px}.HtmlCode{margin:5px 20px;border:1px solid #CCCCCC;padding:5px;background:#FDFDDF;}</style><script language=\"JavaScript\">i=0;function ctlent(event){if((event.ctrlKey && event.keyCode == 13) || (event.altKey && event.keyCode == 83))if(i==0){i=1;parent.checkform()}}<\/script></head><body onkeydown=\"ctlent(event)\"></body></html>');
IframeID.document.close();
IframeID.document.body.style.fontSize="14px";
IframeID.document.body.style.background="#FFFFFF"
IframeID.document.body.contentEditable = "True";
IframeID.document.body.innerHTML=document.getElementById("content").value;
}
function dismisscolorpalette(){document.getElementById("colorpalette").style.visibility="hidden";}
function cleanHtml(){
if(IsCode=="Yes")setCode("No");
sYxBBs=IframeID.document.body.innerHTML
sYxBBs = sYxBBs.replace(/<a([^>]*) href\s*=\s*([^\s|>]*)([^>]*)/gi, "<a href=$2 target=\"_blank\" ");
sYxBBs = sYxBBs.replace(/<a([^>]*)><\/a>/gi, "")
sYxBBs = sYxBBs.replace(/<p> <\/p>/gi,"")
sYxBBs = sYxBBs.replace(/<p><\/p>/gi,"<p>")
sYxBBs = sYxBBs.replace(/<div><\/\1>/gi,"")
sYxBBs = sYxBBs.replace(/(\r\n){10,}/gi,"$1")
sYxBBs = sYxBBs.replace(/(<br>\s*){10,}/gi,"<br>")
sYxBBs = sYxBBs.replace(/(<(meta|iframe|frame|span|tbody|layer)[^>]*>|<\/(iframe|frame|meta|span|tbody|layer)>)/gi, "");
sYxBBs = sYxBBs.replace(/<\\?\?xml[^>]*>/gi, "") ;
sYxBBs = sYxBBs.replace(/ /gi, " ");
sYxBBs = sYxBBs.replace(/.width>/gi, ".width@YxBBs@");
sYxBBs = sYxBBs.replace(/.height>/gi, ".height@YxBBs@");
sYxBBs = sYxBBs.replace(/<img([^>]*) (src\s*=([^\s|>])*)([^>]*)>/gi,"<img $2>");
sYxBBs = sYxBBs.replace(/.width@YxBBs@/gi, ".width>");
sYxBBs = sYxBBs.replace(/.height@YxBBs@/gi, ".height>");
sYxBBs = sYxBBs.replace(/<([^>]*) id\s*=\s*(content|caption)([^>]*)>/gi,"<$1$3>");
sYxBBs = sYxBBs.replace(/(<(div|span|table) style\s*=\s*[^>]*)(position\s*:\s*absolute)([^>]*>)/gi, "$1$4");
return sYxBBs;
}
function setHTML(html) {
switch (IsCode){
case "Yes":
if(ns6){
var Yx=document.createTextNode(html);
IframeID.document.body.innerHTML = "";
IframeID.document.body.appendChild(Yx);
}
else{
IframeID.document.body.innerText=html;
}
document.getElementById("CNo").style.border="1px outset"
document.getElementById("CNo").style.cursor="pointer"
document.getElementById("CYes").style.border="1px inset"
document.getElementById("CYes").style.cursor=""
document.getElementById("EditorB").style.display = 'none';
break;
case "No":
if(ns6){
var Yx= IframeID.document.body.ownerDocument.createRange();
Yx.selectNodeContents(IframeID.document.body);
IframeID.document.body.innerHTML = Yx.toString();
}else{
IframeID.document.body.innerHTML = html;
}
document.getElementById("CYes").style.cursor="pointer"
document.getElementById("CYes").style.border="1px outset"
document.getElementById("CNo").style.border="1px inset"
document.getElementById("CNo").style.cursor=""
document.getElementById("EditorB").style.display = 'block';
break;
}
}
function setCode(ast){
if (ast!=IsCode){
switch(IsCode){
case "Yes":
Yx=IframeID.document.body.innerText;
break;
case "No":
Yx = IframeID.document.body.innerHTML;
break;
}
IsCode = ast;
setHTML(Yx)
}
}
function Insert(theSmilie){
IframeID.focus();
if(ns6){
IframeID.document.body.innerHTML+=theSmilie
}else{
sel=IframeID.document.selection.createRange();
sel.pasteHTML(theSmilie);
}
}
function inserttable(){
if(ns6){
e = document.getElementById("edit");
rowstext = prompt("创建表格,请输入表格的行数:",2);
colstext = prompt("创建表格,请输入表格的列数:",2);
rows = parseInt(rowstext);
cols = parseInt(colstext);
if ((rows > 0) && (cols > 0)) {
table = e.contentWindow.document.createElement("table");
table.setAttribute("border", "1");
table.setAttribute("cellpadding", "2");
table.setAttribute("cellspacing", "2");
tbody = e.contentWindow.document.createElement("tbody");
for (var i=0; i < rows; i++) {
tr =e.contentWindow.document.createElement("tr");
for (var j=0; j < cols; j++) {
td =e.contentWindow.document.createElement("td");
br =e.contentWindow.document.createElement("br");
td.appendChild(br);
tr.appendChild(td);
}
tbody.appendChild(tr);
}
table.appendChild(tbody);
insertNodeAtSelection(e.contentWindow, table);
}
IframeID.focus();
}else{
var arr = showModalDialog("images/edit/table.html", window, "dialogWidth:22em; dialogHeight:22em; status:0; help:0;scroll:no;");
if (arr)
{
IframeID.document.body.innerHTML+=arr;
}
IframeID.focus();
}
}
function insertNodeAtSelection(win, insertNode)
{
var sel = win.getSelection();
var range = sel.getRangeAt(0);
sel.removeAllRanges();
range.deleteContents();
var container = range.startContainer;
var pos = range.startOffset;
range=document.createRange();
if (container.nodeType==3 && insertNode.nodeType==3) {
container.insertData(pos, insertNode.nodeValue);
range.setEnd(container, pos+insertNode.length);
range.setStart(container, pos+insertNode.length);
} else {
var afterNode;
if (container.nodeType==3) {
var textNode = container;
container = textNode.parentNode;
var text = textNode.nodeValue;
var textBefore = text.substr(0,pos);
var textAfter = text.substr(pos);
var beforeNode = document.createTextNode(textBefore);
afterNode = document.createTextNode(textAfter);
container.insertBefore(afterNode, textNode);
container.insertBefore(insertNode, afterNode);
container.insertBefore(beforeNode, insertNode);
container.removeChild(textNode);
} else {
afterNode = container.childNodes[pos];
container.insertBefore(insertNode, afterNode);
}
range.setEnd(afterNode, 0);
range.setStart(afterNode, 0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -