Js Code Used in a symbol plug-in

Source: Internet
Author: User

/**
* @ Author tin555
*/
Function setHTML (html ){
ContentEdit. value = html;
EWebEditor.doc ument. designMode = "On ";
EWebEditor.doc ument. open ();
EWebEditor.doc ument. write (html );
EWebEditor.doc ument. body. contentEditable = "true ";
EWebEditor.document.exe cCommand ("2D-Position", true, true );
EWebEditor.document.exe cCommand ("MultipleSelection", true, true );
EWebEditor.document.exe cCommand ("LiveResize", true, true );
EWebEditor.doc ument. close ();
EWebEditor.doc ument. body. onpaste = onPaste;
// EWebEditor.doc ument. body. onhelp = onHelp;
// EWebEditor.doc ument. body. ondragend = new Function ("return doDragEnd ();");
EWebEditor.doc ument. onkeydown = new Function ("return onKeyDown (eWebEditor. event );");
// EWebEditor.doc ument. oncontextmenu = new Function ("return showContextMenu (eWebEditor. event );");
// EWebEditor.doc ument. onmousedown = new Function ("return onMouseDown ();");
// EWebEditor.doc ument. onmouseup = new Function ("return onMouseUp ();");
}

Function getHTML (){
Var html;

Html = eWebEditor.doc ument. body. innerHTML;


If (html. toLowerCase () = "<p> </p>") | (html. toLowerCase () = "<p> </p> ")){
Html = "";
}

Return html;
}


Function insertHTML (html ){

EWebEditor. focus ();
If (eWebEditor.doc ument. selection. type. toLowerCase ()! = "None "){
EWebEditor.doc ument. selection. clear ();
}
EWebEditor.doc ument. selection. createRange (). pasteHTML (html );
}

Function appendHTML (html ){
If (eWebEditor.doc ument. selection. type. toLowerCase ()! = "None "){
EWebEditor.doc ument. selection. clear ();
}
EWebEditor.doc ument. body. innerHTML + = html;

}


Function doDragEnd (){
Var oSelection = eWebEditor.doc ument. selection. createRange ();
Var sRangeType = eWebEditor.doc ument. selection. type;
If (sRangeType = "Control "){
Var oControl = oSelection. item (0 );
If (oControl. tagName = "IMG "){
OControl. src = FullPath2SetPath (oControl. src );
}
}
If (sRangeType = "Text "){
Var els = eWebEditor.doc ument. body. getElementsByTagName ("IMG ");
Var oRngTemp = eWebEditor.doc ument. body. createTextRange ();
For (var I = 0; I <els. length; I ++ ){
ORngTemp. moveToElementText (els (I ));
If (oSelection. inRange (oRngTemp )){
Els (I). src = FullPath2SetPath (els (I). src)
}
}
}

Return true;
}


Function onKeyDown (event ){
Var n_KeyCode = event. keyCode;
If (n_KeyCode = 13 ){
Return false;
}
}

Var oResizing = new Object;
Function onMouseDown (){
OResizing. El = null;
If (eWebEditor.doc ument. selection. type = "Control "){
Var oControlRange = eWebEditor.doc ument. selection. createRange ();
OResizing. El = oControlRange (0 );
OResizing. W = oResizing. El. style. width;
OResizing. H = oResizing. El. style. height;
}


}

Function GetClipboardHTML (){
Var oDiv = document. getElementById ("eWebEditor_Temp_HTML ");
ODiv. innerHTML = "";
Var oTextRange = document. body. createTextRange ();
OTextRange. moveToElementText (oDiv );
OTextRange.exe cCommand ("Paste ");

Var sData = oDiv. innerHTML;
ODiv. innerHTML = "";

Return sData;
}


Function cleanAndPaste (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 (//,"");

InsertHTML (html );
}
Function onPaste (){
Var sHTML = GetClipboardHTML ();
Var re =/<\ w [^>] * class = "? MsoNormal "? /Gi;
If (re. test (sHTML )){
If (confirm ("the content you want to paste is copied from the Word. Do you want to clear the Word format before pasting? ")){
CleanAndPaste (sHTML );
Return false;
}
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.