⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 editor.js

📁 医院网站的后台管理程序
💻 JS
📖 第 1 页 / 共 3 页
字号:
		oResizing.W = oResizing.El.style.width;
		oResizing.H = oResizing.El.style.height;
	}

	if (!history.saved){saveHistory();}
}

function onMouseUp(){
	if (oResizing.El){
		if ((oResizing.El.style.width!=oResizing.W)||(oResizing.El.style.height!=oResizing.H)){
			saveHistory();
		}
	}
}


function doDragEnd(){
	if (!history.saved){saveHistory();}
	var oSelection = eWebEditor.document.selection.createRange();
	var sRangeType = eWebEditor.document.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.document.body.getElementsByTagName("IMG");
		var oRngTemp = eWebEditor.document.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)
			}
		}
	}

	saveHistory();
	return true;
}

function FullPath2SetPath(url){
	if (url.indexOf("://")<0){return url;}
	var s_SitePath = getSitePath();
	if (url.indexOf(s_SitePath) < 0){return url;}

	switch(config.BaseUrl){
	case "0":
		var s_BaseHref = s_SitePath + config.BaseHref;
		return url.substr(s_BaseHref.length);
		break;
	case "1":
		return url.substr(s_SitePath.length);
		break;
	case "2":
		return url;
		break;
	}
}

function getSitePath(){
	var sSitePath = document.location.protocol + "//" + document.location.host;
	if (sSitePath.substr(sSitePath.length-3) == ":80"){
		sSitePath = sSitePath.substring(0,sSitePath.length-3);
	}
	return sSitePath;
}

function GetClipboardHTML() {
	var oDiv = document.getElementById("eWebEditor_Temp_HTML")
	oDiv.innerHTML = "" ;
	
	var oTextRange = document.body.createTextRange() ;
	oTextRange.moveToElementText(oDiv) ;
	oTextRange.execCommand("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(/&nbsp;/, " " );
	
	insertHTML( html ) ;
}

function insertHTML(html) {
	if (isModeView()) {return false;}
	eWebEditor.focus();
	if (eWebEditor.document.selection.type.toLowerCase() != "none"){
		eWebEditor.document.selection.clear() ;
	}
	if (sCurrMode!="EDIT"){
		html=HTMLEncode(html);
	}
	eWebEditor.document.selection.createRange().pasteHTML(html) ; 
}

function setHTML(html, b_NotSaveHistory) {
	ContentEdit.value = html;
	switch (sCurrMode){
	case "CODE":
		eWebEditor.document.designMode="On";
		eWebEditor.document.open();
		eWebEditor.document.write(getStyleEditorHeader());
		eWebEditor.document.body.innerText=html;
		eWebEditor.document.body.contentEditable="true";
		eWebEditor.document.close();
		bEditMode=false;
		break;
	case "EDIT":
		eWebEditor.document.designMode="On";
		eWebEditor.document.open();
		eWebEditor.document.write(getStyleEditorHeader()+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();
		doZoom(nCurrZoomSize);
		bEditMode=true;
		break;
	case "TEXT":
		eWebEditor.document.designMode="On";
		eWebEditor.document.open();
		eWebEditor.document.write(getStyleEditorHeader());
		eWebEditor.document.body.innerText=html;
		eWebEditor.document.body.contentEditable="true";
		eWebEditor.document.close();
		bEditMode=false;
		break;
	case "VIEW":
		eWebEditor.document.designMode="off";
		eWebEditor.document.open();
		eWebEditor.document.write(getStyleEditorHeader()+html);
		eWebEditor.document.body.contentEditable="false";
		eWebEditor.document.close();
		bEditMode=false;
		break;
	}

	eWebEditor.document.body.onpaste = onPaste ;
	eWebEditor.document.body.onhelp = onHelp ;
	eWebEditor.document.body.ondragend = new Function("return doDragEnd();");
	eWebEditor.document.onkeydown = new Function("return onKeyDown(eWebEditor.event);");
	eWebEditor.document.oncontextmenu=new Function("return showContextMenu(eWebEditor.event);");
	eWebEditor.document.onmousedown = new Function("return onMouseDown();");
	eWebEditor.document.onmouseup = new Function("return onMouseUp();");

	if ((borderShown != "0")&&bEditMode) {
		borderShown = "0";
		showBorders();
	}

	if (!b_NotSaveHistory){
		saveHistory();
	}
}

function getHTML() {
	var html;
	if((sCurrMode=="EDIT")||(sCurrMode=="VIEW")){
		html = eWebEditor.document.body.innerHTML;
	}else{
		html = eWebEditor.document.body.innerText;
	}
	if (sCurrMode!="TEXT"){
		if ((html.toLowerCase()=="<p>&nbsp;</p>")||(html.toLowerCase()=="<p></p>")){
			html = "";
		}
	}
	return html;
}

function appendHTML(html) {
	if(isModeView()){return false;}
	if(sCurrMode=="EDIT"){
		eWebEditor.document.body.innerHTML += html;
	}else{
		eWebEditor.document.body.innerText += html;
	}
}

function PasteWord(){
	if(!validateMode()){return;}
	eWebEditor.focus();
	if (!history.saved){saveHistory();}
	if(BrowserInfo.IsIE55OrMore){
		cleanAndPaste( GetClipboardHTML() ) ;
		saveHistory();
	}else if(confirm(lang["MsgNotCompatiblePaste"])){
		format("paste") ;
	}
	eWebEditor.focus();
}

function PasteText(){
	if(!validateMode()){return;}
	eWebEditor.focus();
	if (!history.saved){saveHistory();}
	var sText = HTMLEncode( clipboardData.getData("Text") ) ;
	insertHTML(sText);
	saveHistory();
	eWebEditor.focus();
}

function validateMode() {
	if(sCurrMode=="EDIT"){return true;}
	alert(lang["MsgOnlyInEditMode"]);
	eWebEditor.focus();
	return false;
}

function isModeView(){
	if (sCurrMode=="VIEW"){
		alert(lang["MsgCanotSetInViewMode"]);
		return true;
	}
	return false;
}

function format(what,opt) {
	if(!validateMode()){return;}
	eWebEditor.focus();
	if (!history.saved){saveHistory();}
	if(opt=="RemoveFormat"){
		what=opt;
		opt=null;
	}
	if(opt==null) {
		var s = "";
		switch(what.toLowerCase()){
		case "justifyleft":
			s = "left";
			break;
		case "justifycenter":
			s = "center"
			break;
		case "justifyright":
			s = "right"
			break;
		}

		var b = false;
		if (s){
			var sel = eWebEditor.document.selection.createRange();
			sel.type = eWebEditor.document.selection.type;
			if (sel.type=="Control"){
				var oControl = sel.item(0);
				try{
					oControl.align = s;
					b = true;
				}catch(e){}
			}
		}
		
		if (!b){
			eWebEditor.document.execCommand(what);
		}
	}else{
		eWebEditor.document.execCommand(what,"",opt);
	}
	saveHistory();
	eWebEditor.focus();
}

function formatFont(what, v){
	if (!history.saved){saveHistory();}
	eWebEditor.document.execCommand("fontname","","eWebEditor_Temp_FontName");
	var a_Font = eWebEditor.document.body.getElementsByTagName("FONT");
	for (var i=0; i<a_Font.length; i++){
		var o_Font = a_Font[i];
		if (o_Font.getAttribute("face") == "eWebEditor_Temp_FontName"){
			delInFont(o_Font, what);
			setStyleValue(o_Font, what, v);
			o_Font.removeAttribute("face");
		}
	}
	saveHistory();
}

function setStyleValue(obj, what, v){
	switch(what){
	case "fontname":
		obj.style.fontFamily = v;
		break;
	case "fontsize":
		obj.style.fontSize = v;
		break;
	default:
		break;
	}
}

function delInFont(obj, what){
	var o_Children = obj.children;
	for (var j=0; j<o_Children.length; j++){
		setStyleValue(o_Children[j], what, "");
		delInFont(o_Children[j], what);

		if (o_Children[j].style.cssText==""){
			if ((o_Children[j].tagName=="FONT") || (o_Children[j].tagName=="SPAN")){
				o_Children[j].outerHTML = o_Children[j].innerHTML;
			}
		}
	}
}

function VerifyFocus() {
	if ( eWebEditor )
		eWebEditor.focus();
}

function setMode(NewMode){
	if (NewMode==sCurrMode){return;}

	if (!BrowserInfo.IsIE55OrMore){
		if ((NewMode=="CODE") || (NewMode=="EDIT") || (NewMode=="VIEW")){
			alert(lang["MsgNotCompatibleHtml"]);
			return false;
		}
	}

	if (NewMode=="TEXT"){
		if (sCurrMode==ModeEdit.value){
			if (!confirm(lang["MsgHtmlToText"])){
				return false;
			}
		}
	}

	var sBody = "";
	switch(sCurrMode){
	case "CODE":
		if (NewMode=="TEXT"){
			eWebEditor_Temp_HTML.innerHTML = eWebEditor.document.body.innerText;
			sBody = eWebEditor_Temp_HTML.innerText;
		}else{
			sBody = eWebEditor.document.body.innerText;
		}
		break;
	case "TEXT":
		sBody = eWebEditor.document.body.innerText;
		sBody = HTMLEncode(sBody);
		break;
	case "EDIT":
	case "VIEW":
		if (NewMode=="TEXT"){
			sBody = eWebEditor.document.body.innerText;
		}else{
			sBody = eWebEditor.document.body.innerHTML;
		}
		break;
	default:
		sBody = ContentEdit.value;
		break;
	}

	try{
		document.all["eWebEditor_CODE"].className = "StatusBarBtnOff";
		document.all["eWebEditor_EDIT"].className = "StatusBarBtnOff";
		document.all["eWebEditor_TEXT"].className = "StatusBarBtnOff";
		document.all["eWebEditor_VIEW"].className = "StatusBarBtnOff";
		document.all["eWebEditor_"+NewMode].className = "StatusBarBtnOn";
		}
	catch(e){
		}
	
	sCurrMode = NewMode;
	ModeEdit.value = NewMode;
	setHTML(sBody);
	disableChildren(eWebEditor_Toolbar);

}

function disableChildren(obj){
	if (obj){
		obj.disabled=(!bEditMode);
		for (var i=0; i<obj.children.length; i++){
			disableChildren(obj.children[i]);
		}
	}
}


function showDialog(url, optValidate){
	var sName;
	var nIndex = url.indexOf(".");
	if (nIndex<0){
		sName = url;
		url = url + ".htm";
	}else{
		sName = url.substring(0, nIndex);
	}
	url = "dialog/" + url;
	sName = sName.toLowerCase();
	url = url.toLowerCase();

	if (optValidate) {
		if (!validateMode()) {return;}
	}
	eWebEditor.focus();
	if (!history.saved){saveHistory();}
	var arr = showModalDialog(url, window, "dialogWidth:0px;dialogHeight:0px;help:no;scroll:no;status:no");
	saveHistory();
	eWebEditor.focus();
}


function Maximize() {
	if (!validateMode()) {return;}
	saveHistory();
	window.open("dialog/fullscreen.htm?style="+config.StyleName, 'FullScreen'+sLinkFieldName, 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,fullscreen=yes');
}

function createLink(){
	if (!validateMode()) {return;}
	
	if (eWebEditor.document.selection.type == "Control") {
		var oControlRange = eWebEditor.document.selection.createRange();
		if (oControlRange(0).tagName.toUpperCase() != "IMG") {
			alert(lang["MsgHylnkLimit"]);
			return;
		}
	}
	
	showDialog("hyperlink.htm", true);
}

function HTMLEncode(text){
	text = text.replace(/&/g, "&amp;") ;
	text = text.replace(/"/g, "&quot;") ;
	text = text.replace(/</g, "&lt;") ;
	text = text.replace(/>/g, "&gt;") ;
	text = text.replace(/\ /g,"&nbsp;");
	text = text.replace(/\n/g,"<br>");
	text = text.replace(/\t/g,"&nbsp;&nbsp;&nbsp;&nbsp;");
	return text;
}

function insert(what) {
	if (!validateMode()) {return;}
	eWebEditor.focus();
	saveHistory();
	var sel = eWebEditor.document.selection.createRange();

	switch(what){
	case "excel":
		insertHTML("<object classid='clsid:0002E510-0000-0000-C000-000000000046' id='Spreadsheet1' codebase='file:\\Bob\software\office2000\msowc.cab' width='100%' height='250'><param name='HTMLURL' value><param name='HTMLData' value='&lt;html xmlns:x=&quot;urn:schemas-microsoft-com:office:excel&quot;xmlns=&quot;http://www.w3.org/TR/REC-html40&quot;&gt;&lt;head&gt;&lt;style type=&quot;text/css&quot;&gt;&lt;!--tr{mso-height-source:auto;}td{black-space:nowrap;}.wc4590F88{black-space:nowrap;font-family:Verdana,Arial,Helvetica,sans-serif;mso-number-format:General;font-size:auto;font-weight:auto;font-style:auto;text-decoration:auto;mso-background-source:auto;mso-pattern:auto;mso-color-source:auto;text-align:general;vertical-align:bottom;border-top:none;border-left:none;border-right:none;border-bottom:none;mso-protection:locked;}--&gt;&lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;&lt;x:ExcelWorkbook&gt;&lt;x:ExcelWorksheets&gt;&lt;x:ExcelWorksheet&gt;&lt;x:OWCVersion&gt;9.0.0.2710&lt;/x:OWCVersion&gt;&lt;x:Label Style='border-top:solid .5pt silver;border-left:solid .5pt silver;border-right:solid .5pt silver;border-bottom:solid .5pt silver'&gt;&lt;x:Caption&gt;Microsoft Office Spreadsheet&lt;/x:Caption&gt; &lt;/x:Label&gt;&lt;x:Name&gt;Sheet1&lt;/x:Name&gt;&lt;x:WorksheetOptions&gt;&lt;x:Selected/&gt;&lt;x:Height&gt;7620&lt;/x:Height&gt;&lt;x:Width&gt;15240&lt;/x:Width&gt;&lt;x:TopRowVisible&gt;0&lt;/x:TopRowVisible&gt;&lt;x:LeftColumnVisible&gt;0&lt;/x:LeftColumnVisible&gt; &lt;x:ProtectContents&gt;False&lt;/x:ProtectContents&gt; &lt;x:DefaultRowHeight&gt;210&lt;/x:DefaultRowHeight&gt; &lt;x:StandardWidth&gt;2389&lt;/x:StandardWidth&gt; &lt;/x:WorksheetOptions&gt; &lt;/x:ExcelWorksheet&gt;&lt;/x:ExcelWorksheets&gt; &lt;x:MaxHeight&gt;80%&lt;/x:MaxHeight&gt;&lt;x:MaxWidth&gt;80%&lt;/x:MaxWidth&gt;&lt;/x:ExcelWorkbook&gt;&lt;/xml&gt;&lt;![endif]--&gt;&lt;table class=wc4590F88 x:str&gt;&lt;col width=&quot;56&quot;&gt;&lt;tr height=&quot;14&quot;&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;'> <param name='DataType' value='HTMLDATA'> <param name='AutoFit' value='0'><param name='DisplayColHeaders' value='-1'><param name='DisplayGridlines' value='-1'><param name='DisplayHorizontalScrollBar' value='-1'><param name='DisplayRowHeaders' value='-1'><param name='DisplayTitleBar' value='-1'><param name='DisplayToolbar' value='-1'><param name='DisplayVerticalScrollBar' value='-1'> <param name='EnableAutoCalculate' value='-1'> <param name='EnableEvents' value='-1'><param name='MoveAfterReturn' value='-1'><param name='MoveAfterReturnDirection' value='0'><param name='RightToLeft' value='0'><param name='ViewableRange' value='1:65536'></object>");
		break;
	case "nowdate":
		var d = new Date();
		insertHTML(d.toLocaleDateString());
		break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -