一个符号插入器 中用到的js代码

时间:2021-05-25

/**
*@authortin555
*/
functionsetHTML(html){
ContentEdit.value=html;
eWebEditor.document.designMode="On";
eWebEditor.document.open();
eWebEditor.document.write(html);
eWebEditor.document.body.contentEditable="true";
eWebEditor.document.execCommand("2D-Position",true,true);
eWebEditor.document.execCommand("MultipleSelection",true,true);
eWebEditor.document.execCommand("LiveResize",true,true);
eWebEditor.document.close();
eWebEditor.document.body.onpaste=onPaste;
//eWebEditor.document.body.onhelp=onHelp;
//eWebEditor.document.body.ondragend=newFunction("returndoDragEnd();");
eWebEditor.document.onkeydown=newFunction("returnonKeyDown(eWebEditor.event);");
//eWebEditor.document.oncontextmenu=newFunction("returnshowContextMenu(eWebEditor.event);");
//eWebEditor.document.onmousedown=newFunction("returnonMouseDown();");
//eWebEditor.document.onmouseup=newFunction("returnonMouseUp();");
}

functiongetHTML(){
varhtml;

html=eWebEditor.document.body.innerHTML;


if((html.toLowerCase()=="<p>&nbsp;</p>")||(html.toLowerCase()=="<p></p>")){
html="";
}

returnhtml;
}


functioninsertHTML(html){

eWebEditor.focus();
if(eWebEditor.document.selection.type.toLowerCase()!="none"){
eWebEditor.document.selection.clear();
}
eWebEditor.document.selection.createRange().pasteHTML(html);
}

functionappendHTML(html){
if(eWebEditor.document.selection.type.toLowerCase()!="none"){
eWebEditor.document.selection.clear();
}
eWebEditor.document.body.innerHTML+=html;

}


functiondoDragEnd(){
varoSelection=eWebEditor.document.selection.createRange();
varsRangeType=eWebEditor.document.selection.type;
if(sRangeType=="Control"){
varoControl=oSelection.item(0);
if(oControl.tagName=="IMG"){
oControl.src=FullPath2SetPath(oControl.src);
}
}
if(sRangeType=="Text"){
varels=eWebEditor.document.body.getElementsByTagName("IMG");
varoRngTemp=eWebEditor.document.body.createTextRange();
for(vari=0;i<els.length;i++){
oRngTemp.moveToElementText(els(i));
if(oSelection.inRange(oRngTemp)){
els(i).src=FullPath2SetPath(els(i).src)
}
}
}

returntrue;
}


functiononKeyDown(event){
varn_KeyCode=event.keyCode;
if(n_KeyCode==13){
returnfalse;
}
}

varoResizing=newObject;
functiononMouseDown(){
oResizing.El=null;
if(eWebEditor.document.selection.type=="Control"){
varoControlRange=eWebEditor.document.selection.createRange();
oResizing.El=oControlRange(0);
oResizing.W=oResizing.El.style.width;
oResizing.H=oResizing.El.style.height;
}


}

functionGetClipboardHTML(){
varoDiv=document.getElementById("eWebEditor_Temp_HTML");
oDiv.innerHTML="";
varoTextRange=document.body.createTextRange();
oTextRange.moveToElementText(oDiv);
oTextRange.execCommand("Paste");

varsData=oDiv.innerHTML;
oDiv.innerHTML="";

returnsData;
}


functioncleanAndPaste(html){
html=html.replace(/<\/?SPAN[^>]*>/gi,"");
html=html.replace(/<(\w[^>]*)class=([^|>]*)([^>]*)/gi,"<$1$3");
html=html.replace(/<(\w[^>]*)style="([^"]*)"([^>]*)/gi,"<$1$3");
html=html.replace(/<(\w[^>]*)lang=([^|>]*)([^>]*)/gi,"<$1$3");
html=html.replace(/<\\?\?xml[^>]*>/gi,"");
html=html.replace(/<\/?\w+:[^>]*>/gi,"");
html=html.replace(/&nbsp;/,"");

insertHTML(html);
}
functiononPaste(){
varsHTML=GetClipboardHTML();
varre=/<\w[^>]*class="?MsoNormal"?/gi;
if(re.test(sHTML)){
if(confirm("你要粘贴的内容好象是从Word中拷出来的,是否要先清除Word格式再粘贴?")){
cleanAndPaste(sHTML);
returnfalse;
}
}
}

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章