editor.js

来自「ASP编写的一个公司网站的源程序」· JavaScript 代码 · 共 91 行

JS
91
字号
var format = "HTML";
var initHTML = "";
var edit;
var RangeType;
function setFocus() {
	textEdit.focus();
}
function selectRange(){
	edit = textEdit.document.selection.createRange();
	RangeType = textEdit.document.selection.type;
}
function execCommand(command) {	
	if (format == "HTML"){
		setFocus();
		selectRange();	
		if ((command == "Undo") || (command == "Redo"))
			document.execCommand(command);
		else{
			if (arguments[1]==null)				
				edit.execCommand(command);
			else
				edit.execCommand(command, false, arguments[1]);}
		textEdit.focus();
		if (RangeType != "Control") edit.select();
	}	
}
function swapModes(Mode) {	
	switch(Mode){
		case 1:
			if (format == "ABC"){
				textEdit.document.body.innerHTML = textEdit.document.body.innerText;
				textEdit.document.body.style.fontFamily = "";
				textEdit.document.body.style.fontSize ="";
			}
			else{
				initHTML = textEdit.document.body.innerHTML;
				initEditor();
			}
			format = "HTML";
			break;	
		case 2:
			if (format == "PREVIEW"){
				initHTML = textEdit.document.body.innerHTML;
				initEditor();
			}	
			textEdit.document.body.innerText = textEdit.document.body.innerHTML;
			textEdit.document.body.style.fontFamily = "Verdana";
			textEdit.document.body.style.fontSize = "9pt";
			format = "ABC";
			break;

		default:
			return(0);
	}
	textEdit.focus();
	return(1);
}


function initEditor() {
	textEdit.document.designMode="On";
	textEdit.document.open();
	textEdit.document.write(initHTML);
	textEdit.document.close();
	initHTML = "";
	if(textEdit.document.styleSheets.length == 0){
		textEdit.document.createStyleSheet();
		var oSS = textEdit.document.styleSheets[0];
		oSS.addRule("TABLE.ubb","border: 1px solid #A9A9A9;FONT-SIZE: 9pt; ");
		oSS.addRule("TD.ubb","border: 1px solid #A9A9A9;FONT-SIZE: 9pt; ");
		oSS.addRule("IMG","border: 0");
		oSS.addRule("BODY","font-size: 9pt");
	}	
}
function init() {
	initEditor();
	with (parent){
		if (loaded){
			parent.status = "";
			/*with (parent.document){
				all.editor.style.display = "block";
				forms[0].body.style.display = "none";
				forms[0].body.title = "";
			}*/
		}
		else
			loaded = 1;	
	}
}
initHTML = parent.parent.strHTML;
window.onload = init

⌨️ 快捷键说明

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