📄 edit.js
字号:
con=WBTB_Composition.document.body.innerHTML;
if (i==1)
{
con=WBTB_rCode(con,a,b,true);
}else{
con=WBTB_rCode(con,a,b);
}
WBTB_Composition.document.body.innerHTML=con;
}
else WBTB_Composition.focus();
}
function WBTB_CleanCode() {
editor=WBTB_Composition;
editor.focus();
// 0bject based cleaning
var body = editor.document.body;
for (var index = 0; index < body.all.length; index++) {
tag = body.all[index];
tag.removeAttribute("className","",0);
tag.removeAttribute("style","",0);
}
// Regex based cleaning
var html = editor.document.body.innerHTML;
html = html.replace(/<o:p> <\/o:p>/gi, "");
html = html.replace(/o:/gi, "");
html = html.replace(/<font[^>]*>\s*<\/font>/gi, "");
html = html.replace(/<span>\s*<\/span>/gi, "");
editor.document.body.innerHTML = html;
}
function WBTB_CleanAllHtm() {
editor=WBTB_Composition;
editor.focus();
var body = editor.document.body;
for (var index = 0; index < body.all.length; index++) {
tag = body.all[index];
tag.removeAttribute("className","",0);
tag.removeAttribute("style","",0);
}
// Regex based cleaning
var html = editor.document.body.innerHTML;
html = html.replace(/\<[^>]*>/g,"");
editor.document.body.innerHTML = html;
}
function WBTB_Filterbackpic(content)
{
var RegExp = /style="BACKGROUND-IMAGE[^>]*/ig;
content = content.replace(RegExp, "");
return content;
}
function get_upfilename(filename)
{
var RegExp = /[^\/]*\//ig;
filename =filename.replace(RegExp, "");
return filename;
}
function WBTB_FilterScript(content)
{
content = WBTB_rCode(content, 'javascript:', 'javascript :');
var RegExp = /<script[^>]*>(.|\n)*<\/script>/ig;
content = content.replace(RegExp, "<!-- Script Filtered -->");
return content;
}
function WBTB_cleanHtml()
{
var fonts = WBTB_Composition.document.body.all.tags("FONT");
var curr;
for (var i = fonts.length - 1; i >= 0; i--) {
curr = fonts[i];
if (curr.style.backgroundColor == "#ffffff") curr.outerHTML = curr.innerHTML;
}
}
function WBTB_getPureHtml()
{
var str = "";
str = WBTB_Composition.document.body.innerHTML;
str=WBTB_correctUrl(str);
return str;
}
function WBTB_correctUrl(cont)
{
var url=location.href.substring(0,location.href.lastIndexOf("/")+1);
cont=WBTB_rCode(cont,location.href+"#","#");
cont=WBTB_rCode(cont,url,"");
cont=WBTB_rCode(cont,"<a> </a>","");
var r = new RegExp('(a href=[^>)]*)','gi');
cont=cont.replace(r,"$1 target=_blank");
//var r = new RegExp('(target=_blank target=_blank)','gi');
cont=cont.replace("target=_blank target=_blank","target=_blank");
return cont;
}
var WBTB_bLoad=false
var WBTB_pureText=true
var WBTB_bTextMode=false
WBTB_public_description=new WBTB_Editor
function WBTB_Editor()
{
this.put_HtmlMode=WBTB_setMode;
this.put_value=WBTB_putText;
this.get_value=WBTB_getText;
}
function WBTB_getText()
{
if (WBTB_bTextMode)
return WBTB_Composition.document.body.innerText;
else
{
WBTB_cleanHtml();
return WBTB_Composition.document.body.innerHTML;
}
}
function WBTB_putText(v)
{
if (WBTB_bTextMode)
WBTB_Composition.document.body.innerText = v;
else
WBTB_Composition.document.body.innerHTML = v;
}
function WBTB_InitDocument(hiddenid, charset)
{
if (charset!=null)
WBTB_charset=charset;
if (WBTB_bIsIE5){
var WBTB_bodyTag="<style type=text/css>.quote{margin:5px 20px;border:1px solid #CCCCCC;padding:5px; background:#F3F3F3 }\nbody{boder:0px}.HtmlCode{margin:5px 20px;border:1px solid #CCCCCC;padding:5px;background:#FDFDDF;font-size:14px;font-family:Tahoma;font-style : oblique;line-height : normal ;font-weight:bold;}\nbody{boder:0px}</style></head><BODY bgcolor=\"#FFFFFF\" title=\"Ctrl+Enter直接提交贴子\" onkeydown=\"ctlent();\">";
}else
{
var WBTB_bodyTag="<html><head><style type=text/css>.quote{margin:5px 20px;border:1px solid #CCCCCC;padding:5px; background:#F3F3F3 }\nbody{boder:0px}.HtmlCode{margin:5px 20px;border:1px solid #CCCCCC;padding:5px;background:#FDFDDF;font-size:14px;font-family:Tahoma;font-style : oblique;line-height : normal ;font-weight:bold;}\nbody{boder:0px}</style></head><BODY bgcolor=\"#FFFFFF\">";
}
var editor=WBTB_Composition;
var h=document.getElementById(hiddenid);
/////////////
//editor.document.write ('<html><head>');
//if (WBTB_bIsIE5){
editor.document.write ('<script language="javascript">');
editor.document.write ('var ispost=0;');
editor.document.write (' function ctlent(eventobject)');
editor.document.write (' {');
editor.document.write (' if(event.ctrlKey && window.event.keyCode==13&&ispost==0)');
editor.document.write (' {');
editor.document.write (' ispost=1;');
editor.document.write (' parent.WBTB_CopyData("'+hiddenid+'"); ');
editor.document.write (' parent.document.myform.Submit.disabled=true;');
editor.document.write (' parent.document.myform.Submit2.disabled=true;');
editor.document.write (' parent.document.myform.submit();');
editor.document.write (' }');
editor.document.write (' }');
editor.document.write ('<\/script>');
//}
////////////////
editor.document.designMode="On"
editor.document.open();
editor.document.write(WBTB_bodyTag);
if (h.value!="")
{
editor.document.write(h.value);
}
editor.document.write("</html>");
editor.document.close();
editor.document.body.contentEditable = "True";
editor.document.charset=WBTB_charset;
WBTB_bLoad=true;
WBTB_setStyle();
editor.focus();
//eval("WBTB_Composition.document.body.innerHTML+=(self.opener."+ htmlableID +".checked)?(self.opener."+bodyID+".value):(WBTB_ubb2html(self.opener."+ bodyID +".value))");
}
function WBTB_doSelectClick(str, el) {
var Index = el.selectedIndex;
if (Index != 0){
el.selectedIndex = 0;
WBTB_format(str,el.options[Index].value);
}
}
var WBTB_bIsIE5 = (navigator.userAgent.indexOf("IE 5") > -1) || (navigator.userAgent.indexOf("IE 6") > -1);
var WBTB_edit; //selectRang
var WBTB_RangeType;
var WBTB_selection;
//应用html
function WBTB_specialtype(Mark1, Mark2){
var strHTML;
if (WBTB_bIsIE5) WBTB_selectRange();
if (WBTB_RangeType == "Text"){
if (Mark2==null)
{
strHTML = "<" + Mark1 + ">" + WBTB_edit.htmlText + "</" + Mark1 + ">";
}else{
strHTML = Mark1 + WBTB_edit.htmlText + Mark2;
}
WBTB_edit.pasteHTML(strHTML);
WBTB_Composition.focus();
WBTB_edit.select();
}
}
//选择内容替换文本
function WBTB_InsertSymbol(str1)
{
WBTB_Composition.focus();
if (WBTB_bIsIE5) WBTB_selectRange();
WBTB_edit.pasteHTML(str1);
}
function WBTB_selectRange(){
WBTB_selection = WBTB_Composition.document.selection;
WBTB_edit = WBTB_Composition.document.selection.createRange();
WBTB_RangeType = WBTB_Composition.document.selection.type;
}
function WBTB_rCode(s,a,b,i){
//s原字串,a要换掉pattern,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 WBTB_View()
{
if (WBTB_bTextMode) {
cont=WBTB_Composition.document.body.innerText;
} else {
cont=WBTB_Composition.document.body.innerHTML;
}
cont=WBTB_correctUrl(cont);
bodyTag="<html><head><style type=text/css>.quote{margin:5px 20px;border:1px solid #CCCCCC;padding:5px; background:#F3F3F3 }\nbody{boder:0px}.HtmlCode{margin:5px 20px;border:1px solid #CCCCCC;padding:5px;background:#FDFDDF;font-size:14px;font-family:Tahoma;font-style : oblique;line-height : normal ;font-weight:bold;}\nbody{boder:0px; font-family:Arial; font-size:10.5pt}</style></head><BODY bgcolor=\"#FFFFFF\" >";
if (WBTB_filterScript)
cont=WBTB_FilterScript(cont);
preWin=window.open('preview','','left=0,top=0,width=550,height=400,resizable=1,scrollbars=1, status=1, toolbar=1, menubar=0');
preWin.document.open();
preWin.document.write(bodyTag);
preWin.document.write(cont);
preWin.document.close();
preWin.document.title="Preview";
preWin.document.charset=WBTB_charset;
}
// 修改编辑栏高度
function WBTB_Size(num)
{
var obj=document.all.WBTB_Container;
if (parseInt(obj.height)+num>=300) {
obj.height = parseInt(obj.height) + num;
}
if (num>0)
{
obj.width="100%";
}
}
// 替换特殊字符
function HTMLEncode(text){
text = text.replace(/&/g, "&") ;
text = text.replace(/"/g, """) ;
text = text.replace(/</g, "<") ;
text = text.replace(/>/g, ">") ;
text = text.replace(/'/g, "’") ;
text = text.replace(/\ /g," ");
text = text.replace(/\n/g,"<br>");
text = text.replace(/\t/g," ");
return text;
}
// 拷贝数据到hidden
function WBTB_CopyData(hiddenid)
{
d = WBTB_Composition.document;
if (WBTB_bTextMode)
{
cont=d.body.innerText;
}else{
cont=d.body.innerHTML;
}
cont=WBTB_correctUrl(cont);
if (WBTB_filterScript)
cont=WBTB_FilterScript(cont);
document.getElementById(hiddenid).value = cont;
if (document.getElementById(hiddenid).value == '<P> </P>') //<P> </P>
{
document.getElementById(hiddenid).value = '';
}
}
function WBTB_insert(cons)
{
var WBTB_Composition;
WBTB_Composition.document.body.innerHTML=cons;
}
function WBTB_help()
{
showModalDialog("Editor/help.html", "", "dialogWidth:13.5em; dialogHeight:12.5em; status:0; help:0");
}
function getHTML() {
var html;
html = WBTB_Composition.document.body.innerHTML
return html;
}
function getFocus() {
if ( WBTB_Composition)
WBTB_Composition.focus();
}
// 上传文件成功返回原文件名和保存后的文件名,提供接口
function addUploadFile(sourceFileName, saveFileName){
if (sLinkSourceFileName){
var oSourceFileName = parent.document.getElementsByName(sLinkSourceFileName)[0];
if (oSourceFileName){
if (oSourceFileName.value!=""){
oSourceFileName.value = oSourceFileName.value + "|";
}
oSourceFileName.value = oSourceFileName.value + sourceFileName;
oSourceFileName.fireEvent("onchange");
}
}
if (sLinkSaveFileName){
var oSaveFileName = parent.document.getElementsByName(sLinkSaveFileName)[0];
if (oSaveFileName){
if (oSaveFileName.value!=""){
oSaveFileName.value = oSaveFileName.value + "|";
}
oSaveFileName.value = oSaveFileName.value + saveFileName;
oSaveFileName.fireEvent("onchange");
}
}
}
function ctlent()
{
var ispost=0;
if (DownsysClass_bIsIE5)
{
if(event.ctrlKey && window.event.keyCode==13&&ispost==0)
{
ispost=1;
WBTB_CopyData('Body');
this.document.myform.submit();
}
}
}
//清除表单
function ClearReset()
{
editor.document.body.innerHTML='';
editor.focus();
}
function checklength(theform)
{
alert("您的内容目前有 "+theform.content1.value.length+" 字节。");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -