📄 htmleditor.asp
字号:
<HEAD>
<META http-equiv="Content-Type" content="text/html;Charset=GB2312">
<SCRIPT>
var L_DEFAULTHTML_TEXT="<DIV></DIV>";
function _CFont(szDef,szText,bSymbol)
{
return new Array(szDef,szText,bSymbol);
}
defaultFonts=new Array();
defaultFonts[0] = _CFont("Geneva,Arial,Sans-serif","Arial",false);
defaultFonts[1] = _CFont("Arial Black,Geneva,Arial,Sans-serif","Arial Black",false);
defaultFonts[2] = _CFont("Courier New,Courier,Monospace","Courier New",false);
defaultFonts[3] = _CFont("Times New Roman,Times,Serif","Times New Roman",false);
defaultFonts[4] = _CFont("Verdana,Geneva,Arial,Sans-serif","Verdana",false);
defaultFonts[5] = _CFont("Lucida Handwriting,Cursive","Lucida Handwriting",false);
defaultFonts[6] = _CFont("Garamond,Times,Serif","Garamond",false);
defaultFonts[7] = _CFont("Webdings","Webdings",true);
defaultFonts[8] = _CFont("Wingdings","Wingdings",true);
defaultFonts[9] = _CFont("宋体","宋体",false);
defaultFonts[10] = _CFont("黑体","黑体",false);
defaultFonts[11] = _CFont("细明体","细明体",false);
var L_TOOLBARGIF_TEXT="<%=Application("ROOTPATH")%>include/rte.gif";
var aSizes=new Array(25,25,25,8,25,25,8,25,25,25,8,52,52,52,8,25,25,25,8,25,25,25,8,25,25,25,25,8,25);
var isIE4=(navigator.appVersion.indexOf("MSIE 4")>0)
function setHTML(szHTML)
{
if(szHTML=="")szHTML=L_DEFAULTHTML_TEXT
if(g_state.bMode)
idEditbox.document.body.innerHTML=szHTML
else
idEditbox.document.body.innerText=szHTML
if(g_state.bLoaded)setSelection(true)
}
function getHTML()
{
var szRet=(g_state.bMode?_CUtil_TrimCR(_CUtil_CleanHTML()):_CUtil_TrimCR(idEditbox.document.body.innerText))
return szRet
}
function getText()
{
var szRet=""
if(g_state.bMode)
szRet=idEditbox.document.body.innerText
else
{
setMode(true)
szRet=idEditbox.document.body.innerText
setMode(false)
}
return szRet
}
function getBody()
{
var oRet=idEditbox.document.body
return oRet
}
function getWidth()
{
var nRet=document.body.offsetWidth
return nRet
}
function getHeight()
{
var nRet=document.body.offsetHeight
return nRet
}
function insertHTML(szHTML)
{
var sType
var sel=g_state.GetSelection()
sType=sel.type
if(g_state.bMode)
{
if(sType=="Control")
sel.item(0).outerHTML=szHTML
else
sel.pasteHTML(szHTML)
}
else
sel.text=szHTML
g_state.selection=null
}
function appendHTML(szHTML)
{
if(g_state.bMode)
idEditbox.document.body.insertAdjacentHTML("beforeEnd",szHTML)
else
idEditbox.document.body.insertAdjacentText("beforeEnd",szHTML)
}
function setBGColor(szValue)
{
g_state.bgColor=szValue
idEditbox.document.body.bgColor=g_state.bgColor
}
function setSelection(bDir)
{
var tr=idEditbox.document.body.createTextRange()
tr.collapse(bDir)
tr.select()
g_state.SaveSelection()
}
function setDefaultStyle(szValue)
{
g_state.css=szValue
if(g_state.bMode)
idEditbox.document.body.style.cssText=g_state.css
}
function setSkin(szSkin)
{
if(szSkin==null)
document.styleSheets.skin.cssText=g_state.defaultSkin
else
document.styleSheets.skin.cssText=szSkin
document.styleSheets.skin.disabled=false
}
function setToolbar(id,g_state)
{
var el=document.all[id]
if(el)
el.style.display=(g_state)?"":"none"
if(id=="tbmode")
{
_setSize()
}
}
function setMode(bMode)
{
if(bMode!=g_state.bMode)
{
g_state.bMode=bMode
var objBody=idEditbox.document.body
if(!bMode&&!g_state.bMode)
{
objBody.bgColor=objBody.style.cssText="#FFFFFF"
if(g_state.customButtons)
idStandardBar.style.display="none"
else
idToolbar.style.display="none"
objBody.innerText=idEditbox.document.body.innerHTML
objBody.className="textMode"
}
if((bMode)&&(g_state.bMode))
{
setDefaultStyle(g_state.css)
setBGColor(g_state.bgColor)
objBody.className=idStandardBar.style.display=idToolbar.style.display=""
objBody.innerHTML=idEditbox.document.body.innerText
}
_setSize()
cbMode.checked=!bMode
setSelection(true)
}
return bMode
}
function _Format(szHow,szValue)
{
var oSel=g_state.GetSelection()
var sType=oSel.type
var oTarget=(sType=="None"?idEditbox.document:oSel)
var oBlock=(oSel.parentElement!=null?_CUtil_GetBlock(oSel.parentElement()):oSel.item(0))
switch(szHow)
{
case "Justify":
if(oBlock)
{
oBlock.style.textAlign=""
if(((oBlock.tagName=="TABLE")||(oBlock.tagName=="IMG"))&&(("left"==oBlock.align)&&("Left"==szValue)))
{
oBlock.align=""
break;
}
oBlock.align=szValue
if((oBlock.tagName=="HR")||((oBlock.tagName=="IMG")&&szValue!="Center"))break;
}
szHow=szHow+szValue
szValue=""
default:
oTarget.execCommand(szHow,false,szValue)
break
}
g_state.RestoreSelection()
return true
}
function _pageReady()
{
idEditbox.document.body.onblur=idEditbox.onblur=g_state.SaveSelection
idEditbox.document.onkeydown=_Editor_KeyDownHandler
idEditbox.document.onmousedown=_Editor_ClickHandler
idEditbox.document.ondblclick=_Editor_DblClickHandler
idEditbox.document.body.oncontextmenu=new Function("return false")
if(g_state.szSearch!="")
idPopup.document.domain=idEditbox.document.domain=document.domain=g_state.szSearch
else
{
g_state.szSearch=_CUtil_DomainSuffix(location.hostname)
if(g_state.szSearch!="")idPopup.document.domain=idEditbox.document.domain=document.domain=parent.document.domain=g_state.szSearch
}
if(document.styleSheets.skin.disabled)setSkin(null)
_setSize()
idEditor.style.visibility=""
g_state.bLoaded=true
setBGColor(g_state.bgColor)
}
function _initEditor()
{
g_state=new _CState()
window.onresize=_setSize
var sz=""
sz+="<STYLE>A{text-decoration:none}\nTD{font-size:14.9px}\n.textMode{border-top: 1px black solid;font-size:14.9px}\n.NOBORDER TD{border:1px gray solid}BODY{border:1px black solid;border-top:none;font-size:14.9px}</STYLE><BODY ONCONTEXTMENU=\"return false\">"+L_DEFAULTHTML_TEXT+"</BODY>"
_CPopup_Init()
idEditbox.document.designMode="on"
idEditbox.document.open("text/html","replace")
idEditbox.document.write(sz)
idEditbox.document.close()
setTimeout("_pageReady()",100)
}
function _Editor_ClickHandler()
{
g_state.selection=null
}
function _Editor_KeyDownHandler()
{
var ev=this.parentWindow.event
if((ev.keyCode==78||ev.keyCode==72)&&ev.ctrlKey)
{
if(ev.keyCode==78)
window.open(parent.location)
ev.keyCode=0;ev.returnValue=false
}
if(ev.keyCode==9)
g_state.SaveSelection()
else
g_state.selection=null
}
function _Editor_DblClickHandler()
{
var el=this.parentWindow.event.srcElement
if(el.tagName=="IMG")
{
el.removeAttribute("width")
el.removeAttribute("height")
el.style.removeAttribute("width")
el.style.removeAttribute("height")
el.width=el.width
el.height=el.height
}
if(el.tagName=="TABLE")
_CPopup_Show('Table')
}
function _setSize()
{
document.all.idEditbox.style.pixelHeight=document.body.clientHeight - idToolbar.offsetHeight - document.all.idMode.offsetHeight
document.all.idPopup.style.pixelLeft=(document.body.clientWidth - idPopup.document.all.puRegion.offsetWidth)/ 2
}
function _drawToolbar()
{
var aIds=new Array("cut","copy","paste","bar1","undo","redo","bar2","link","table","image","bar3","formatblock","fontstyle","fontsize","bar4","bold","italic","underline","bar5","left","center","right","bar6","orderedlist","unorderedlist","outdent","indent","bar7","textcolor")
var aTips=new Array("剪切","复制","粘贴","","撤销","恢复","","超链接","插入表格","插入图片","","字体格式","字体","字体尺寸","","加粗","斜体","下划线","","左对齐","居中","右对齐","","编号","项目符号","减少缩进","增加缩进","","字体颜色")
var aCommand=new Array("_Format('cut')","_Format('copy')","_Format('paste')",null,"_Format('undo')","_Format('redo')",null,"_CPopup_Show('Link')","_CPopup_Show('Table')","_CPopup_Show('Image')",null,"_CPopup_Show('formatblock')","_CPopup_Show('font')","_CPopup_Show('fontsize')",null,"_Format('bold')","_Format('italic')","_Format('underline')",null,"_Format('Justify','Left')","_Format('Justify','Center')","_Format('Justify','Right')",null,"_Format('insertorderedlist')","_Format('insertunorderedlist')","_Format('outdent')","_Format('indent')",null,"_CPopup_Show('ForeColor')")
var sz="<DIV ID=idStandardBar><NOBR>",iLeft=0,iHeight=24
for(var i=0 ;i<aSizes.length;i++)
{
sz+="<SPAN CLASS=tbButton ONKEYPRESS=\"if(event.keyCode==13){"+aCommand[i]+";event.keyCode=0}\" ID=\"tb"+aIds[i]+"\" STYLE=\"width:"+aSizes[i]+";height:"+iHeight+"\">" +"<SPAN STYLE=\"position:absolute;width:"+aSizes[i]+";height:"+iHeight+";clip:rect(0 "+aSizes[i]+" "+iHeight+" 0)\"><IMG ALT=\""+aTips[i]+"\" TITLE=\""+aTips[i]+"\" ONCLICK=\""+aCommand[i]+";event.cancelBubble=true\" ONMOUSEDOWN=\"if(event.button==1)this.style.pixelTop=-"+(iHeight*2)+"\" ONMOUSEOVER=\"this.style.pixelTop=-"+iHeight+"\" ONMOUSEOUT=\"this.style.pixelTop=0\" ONMOUSEUP=\"this.style.pixelTop=-"+iHeight+"\" SRC=\""+L_TOOLBARGIF_TEXT+"\" STYLE=\"position:absolute;top:0;left:-"+iLeft+"\"></SPAN></SPAN>" +(aTips[i]==""?"</NOBR><NOBR>":"")
iLeft+=aSizes[i]
}
sz+="</NOBR>"
document.write(sz+"</DIV>")
}
function _drawModeSelect()
{
var sz="<TABLE CELLSPACING=0 CELLPADDING=0 ID=idMode><TR><TD><INPUT TYPE=checkbox ID=cbMode ONCLICK=\"setMode(!this.checked)\" tabindex=\"-1\"></TD><TD><LABEL FOR=cbMode>直接使用 HTML 语法书写。</LABEL></TD></TR></TABLE>"
var sz="<TABLE CELLSPACING=0 CELLPADDING=0 ID=idMode><TR><TD><input type=hidden ID=cbMode></TD></TR></TABLE>"
document.write(sz)
cbMode.checked=false
}
function _CState()
{
this.selection=null
this.bMode=true
this.customButtons=false
this.css=this.bgColor="#FFFFFF"
this.defaultSkin=document.styleSheets.skin.cssText
this.popupSkin=document.styleSheets.popupSkin.cssText
this.szSearch=location.search.substring(1)
this.aBindings=new Array()
this.aListPopups=new Object()
this.aCache=new Object()
this.bLoaded=false
this.oPhoto=null
this.RestoreSelection=_CState_RestoreSelection
this.GetSelection=_CState_GetSelection
this.SaveSelection=_CState_SaveSelection
}
function _CState_RestoreSelection()
{
if(this.selection)
this.selection.select()
}
function _CState_GetSelection()
{
var oSel=this.selection
if(!oSel)
{
oSel=idEditbox.document.selection.createRange()
oSel.type=idEditbox.document.selection.type
}
return oSel
}
function _CState_SaveSelection()
{
g_state.selection=idEditbox.document.selection.createRange()
if(!g_state.selection)
g_state.selection=new Object
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -