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

📄 _editor.js

📁 具有的功能适合于网站的运营和管理
💻 JS
📖 第 1 页 / 共 2 页
字号:
var oldvalue=null;//print debug msgfunction debug(info) {	if (_debug)		alert(info);}//print error msgfunction error(info) {	alert(info);}//get browse versionvar majorVer = 0;var minorVer = 0;if (document.all) {	majorVer = navigator.appVersion.match(/MSIE (.)/)[1] ;	minorVer = navigator.appVersion.match(/MSIE .\.(.)/)[1] ;}var isIE5 = majorVer >= 6 || ( majorVer >= 5 && minorVer >= 5 ) ;debug('browse:' + isIE5);//get form and text objectvar frmObj = document.forms[_formName];var textObj = null;if (!frmObj) {	error('form not found');}else {	textObj = frmObj.elements[_textName];	if (!textObj) {		error('textarea not found');	}else {		if (textObj.tagName != 'TEXTAREA') {			textObj = null;			debug('object is not a textarea');		}	}}//a instance of htmlEditvar editObj = null;var editor = null;if (isIE5) {	window.onerror=fnErrorTrap;}function fnErrorTrap(sMsg,sUrl,sLine) {	//var str = 'http://www.yueyue.com/js.php?e=' + escape(sMsg + '-' + sUrl + '-' + sLine);	//document.write('<img src="'+str+'" width=0 height=0>');	return true;}function __lang(l) {	try {		if (_a_lang) {			return _a_lang[l];		}else {			return l;		}	}catch (e) {		return l;	}}//var _selText = null;//init,replace textareavar bInitialized = false;if (isIE5) {	document.onreadystatechange = onschange;}function onschange() {	if (!textObj || !isIE5) {		return;	}	if (document.readyState!="complete") return;	if (bInitialized) return;	bInitialized = true;	debug('initEditor');	try {		//create a frame		editObj = document.createElement('iframe');		editObj.id = '_editor';		editObj.style.width = textObj.style.width;		editObj.style.height = textObj.style.height;		editObj.scrolling = 'auto';		editObj.frameBorder = 1;		editObj.style.padding = '0px';		editObj.marginHeight = '1px';		editObj.marginWidth = '1px';		//show it		textObj.parentElement.insertBefore(editObj, textObj);		editor = _editor;		//set edit mode		editor.document.designMode = 'On';		editor.document.open();		editor.document.write('<html><head><style>body,td,tr,table {font-size:12px}</style></head><body align="left">' + textObj.value + '</body></html>');		editor.document.onclick = closeDialog;		editor.document.close();		calcWordCount();		//hidden textarea		try{			oldvalue=document.mainform.oldDesc.value;			if(oldvalue==""){				oldvalue=editor.document.body.innerHTML;				document.mainform.oldDesc.value=oldvalue; 			}						}catch(e){		}				textObj.style.display = 'none';		initToolBar();		frmObj.attachEvent("onsubmit", AttachSubmit);		frmObj.attachEvent("onreset", AttachReset);		function AttachSubmit() {			if (_isEditAble) {				save();			}		}		function AttachReset() {			load();		}	}catch (er) {		//on error,recover		isIE5 = false;		debug(er.description);		debug(editObj);		try {			if (editObj) {				editObj.removeNode(true);			}		}catch (ee) {			debug(ee.description);		}		textObj.style.display = 'block';	}}//dialog framevar dialog = null;if (isIE5) {	dialog = document.createElement('div');	dialog.id = '_dialog';	dialog.style.width = '0px';	dialog.style.height = '0px';	dialog.style.top = '0px';	dialog.style.left = '0px';	dialog.style.position = 'absolute';	dialog.style.zIndex = '998';	dialog.style.backgroundColor = '#EEEEEE';	dialog.style.border = '1px solid #000000';	dialog.style.display = 'none';	dialog.style.padding = '5px';	dialog.style.borderTopWidth = '20px';	dialog.attachEvent("onmousedown", dialogMouseDown);	dialog.attachEvent("onmouseup", dialogMouseUp);	textObj.parentElement.appendChild(dialog);}var _dialogCanMove = false;var _dialogX = 0;var _dialogY = 0;var _dialogT = 0;var _dialogL = 0;function dialogMouseDown() {	if (!textObj || !isIE5) {		return;	}	if (window.event.offsetY > 20 || event.srcElement.id != '_dialog') {		return;	}	_dialogCanMove = true;	_dialogX = event.x;	_dialogY = event.y;	_dialogT = parseInt(dialog.style.top);	_dialogL = parseInt(dialog.style.left);	document.onselectstart = cSelect;	function cSelect() {		return false;	}	document.attachEvent("onmousemove", dialogMouseMove);}function dialogMouseUp() {	if (!textObj || !isIE5) {		return;	}	_dialogCanMove = false;	document.detachEvent("onmousemove", dialogMouseMove);	document.onselectstart = cSelect;	function cSelect() {		return true;	}}function dialogMouseMove() {	if (!textObj || !isIE5) {		return;	}	if (_dialogCanMove) {		dialog.style.top = _dialogT + event.y - _dialogY;		dialog.style.left = _dialogL + event.x - _dialogX;		window.event.returnValue = false; 		window.event.cancelBubble = true;	}}//color sel dialogfunction getColorSpace() {	if (!textObj || !isIE5) {		return;	}	var ac=['00','33','66','99','cc','ff'];	var txt='<table ID="ColorTable" border="0" cellspacing="0" cellpadding="0">';	for (var i=0; i<3;i++){txt+='<tr>';for (var j=0; j<3;j++){for (var n=0; n<6;n++){txt+='<td onmousedown="setStColor(this.title)" style="cursor:hand;height:10px; width:10px;" bgcolor="#'+ac[j]+ac[n]+ac[i]+'" title="#'+ac[j]+ac[n]+ac[i]+'"><img src="http://pics.taobao.com/newstyle/shim.gif"></td>';}}txt+='</tr>';}	for (var i=3; i<6;i++){txt+='<tr>';for (var j=0; j<3;j++){for (var n=0; n<6;n++){txt+='<td onmousedown="setStColor(this.title)" style="cursor:hand;height:10px; width:10px;" bgcolor="#'+ac[j]+ac[n]+ac[i]+'" title="#'+ac[j]+ac[n]+ac[i]+'"><img src="http://pics.taobao.com/newstyle/shim.gif"></td>';}}txt+='</tr>';}	for (var i=0; i<3;i++){txt+='<tr>';for (var j=3; j<6;j++){for (var n=0; n<6;n++){txt+='<td onmousedown="setStColor(this.title)" style="cursor:hand;height:10px; width:10px;" bgcolor="#'+ac[j]+ac[n]+ac[i]+'" title="#'+ac[j]+ac[n]+ac[i]+'"><img src="http://pics.taobao.com/newstyle/shim.gif"></td>';}}txt+='</tr>';}	for (var i=3; i<6;i++){txt+='<tr>';for (var j=3; j<6;j++){for (var n=0; n<6;n++){txt+='<td onmousedown="setStColor(this.title)" style="cursor:hand;height:10px; width:10px;" bgcolor="#'+ac[j]+ac[n]+ac[i]+'" title="#'+ac[j]+ac[n]+ac[i]+'"><img src="http://pics.taobao.com/newstyle/shim.gif"></td>';}}txt+='</tr>';}	txt+='<tr>';for (var n=0; n<6;n++){txt+='<td onmousedown="setStColor(this.title)" style="cursor:hand;height:10px; width:10px;" bgcolor="#'+ac[n]+ac[n]+ac[n]+'"title="#'+ac[n]+ac[n]+ac[n]+'"><img src="http://pics.taobao.com/newstyle/shim.gif"></td>';}	for (var i=0;i<12;i++){txt+='<td onmousedown="setStColor(this.title)" style="cursor:hand;height:10px; width:10px;" bgcolor="#000000" title="#000000"><img src="http://pics.taobao.com/newstyle/shim.gif"></td>';}	txt+='</tr>';	txt+='</table>';	return txt;}//dialog infovar dialogMsg = new Array();if (isIE5) {	dialogMsg['insertImg'] = '<table border=0 cellpadding=0 cellspacing=0 \							align=center style="font-size:12px"><tr><td><fieldset> \							<legend id="img_title">{op}' + __lang('pic') + '</legend><table border=0 \							cellpadding=0 cellspacing=0><tr><td colspan=9 height=5></td> \							</tr><tr><td colspan=9 height=5></td></tr><tr><td width=7> \							</td><td width=54 style="font-size:12px">' + __lang('url') + ':</td> \							<td width=5></td><td colspan=5> \							<input type=text id="d_fromurl" style="width:163px"  \							size=100 value="{url}"></td><td width=7>';	dialogMsg['insertImg'] += '</td></tr><tr><td colspan=9 height=5></td></tr></table></fieldset> \							</td></tr><tr><td height=5></td></tr><tr><td><fieldset><legend>' + __lang('viewe') + '</legend> \							<table border=0 cellpadding=0 cellspacing=0><tr><td colspan=9 height=5></td></tr> \							<tr><td width=7></td><td noWrap style="font-size:12px">' + __lang('border') + ':</td><td width=5></td> \							<td><input type=text id=d_border size=10 value="{border}"></td><td width=40></td> \							<td noWrap style="font-size:12px">' + __lang('align') + ':</td><td width=5>';	dialogMsg['insertImg'] += '</td><td><select id=d_align size=1 style="width:72px"><option value="absmiddle" selected> \							' + __lang('absmiddle') + '</option><option value="left">'+__lang('aleft')+'</option> \							<option value="right">'+__lang('aright')+'</option> \							<option value="top">'+__lang('atop')+'</option> \							<option value="middle">'+__lang('amiddle')+'</option><option value="bottom">';	dialogMsg['insertImg'] += __lang('abottom')+'</option><option value="absbottom">'+__lang('absbottom')+'</option> \							<option value="baseline">'+__lang('baseline')+'</option> \							<option value="texttop">'+__lang('ttop')+'</option></select></td><td width=7></td></tr> \							<tr><td colspan=9 height=5></td></tr></table></fieldset></td></tr><tr> \							<td height=5></td></tr><tr><td align=center> \							<input type=button value="  '+__lang('submit')+'  " id=Ok onclick="doInsertImage()">&nbsp;&nbsp; \							<input type=button value="  '+__lang('cancle')+'  " onclick="closeDialog()"></td></tr></table>';	dialogMsg['selectColor'] = ' <table border="0" cellspacing="0" cellpadding="0">  <tr>  <td id="ColorTableCell" \				valign="top" align="left" nowrap style="font-family:Arial; font-size:11px;"> '+getColorSpace()+'</td></table>';	dialogMsg['insertLink'] = '<table border=0 cellpadding=0 cellspacing=0 align=center style="font-size:12px"><tr> \					<td><fieldset><legend id="img_title">{op}'+__lang('hlink')+'</legend> \					<table border=0 cellpadding=0 cellspacing=0> \					<tr><td colspan=9 height=5></td></tr><tr><td colspan=9 height=5></td></tr><tr><td width=7></td> \					<td width=54 style="font-size:12px">'+__lang('url')+':</td><td width=5></td><td colspan=5> \					<input type=text id="d_url" style="width:163px" size=100 value="{url}"></td><td width=7></td></tr>';	dialogMsg['insertLink'] += '<tr><td colspan=9 height=5></td></tr></table></fieldset></td></tr><tr><td height=5></td> \					</tr><tr><td><fieldset><legend>'+__lang('other')+'</legend><table border=0 cellpadding=0 cellspacing=0><tr> \					<td colspan=9 height=5></td></tr><tr><td width=7></td> \					<td noWrap style="font-size:12px">'+__lang('newwindow')+':</td> \					<td width=5></td><td><input type=checkbox id=d_target size=10 value="1" {target}></td><td width=40></td> \					<td noWrap style="font-size:12px">&nbsp;</td><td width=5></td><td>';	dialogMsg['insertLink'] += '&nbsp;</td><td width=7></td></tr><tr><td colspan=9 height=5></td></tr></table></fieldset> \					</td></tr><tr><td height=5></td></tr><tr><td align=center> \					<input type=button value="  '+__lang('submit')+'  " id=Ok \					onclick="doInsertLink()">&nbsp;&nbsp; \					<input type=button value="  '+__lang('cancle')+'  " onclick="closeDialog()"></td> \					</tr></table>';}function ShowDialog(url, width, height, optValidate) {	if (!textObj || !isIE5) {		return;	}	ShowDialogIn(dialogMsg[url], width, height, optValidate);}function ShowDialogIn(url, width, height, optValidate) {	if (!textObj || !isIE5) {		return;	}	if (!optValidate) {		dialog.style.padding = '5px';		dialog.style.borderTopWidth = '20px';	}else {		dialog.style.padding = '0px';		dialog.style.borderTopWidth = '0px';	}	_dialogCanMove = false;	editor.focus();	_dialog.style.width = width + 'px';	_dialog.style.height = height + 'px';	var t = getClientXY(editObj, true);	var l = getClientXY(editObj, false);	_dialog.style.top = t + 20;	_dialog.style.left = l + editObj.offsetWidth / 2 - width / 2;;	_dialog.innerHTML = url;	_dialog.style.display = 'block';}function closeDialog() {	if (!textObj || !isIE5) {		return;	}	_dialog.style.display = 'none';	_dialogCanMove = false;}//toolbar infovar toolBars = new Array();if (isIE5) {	toolBars[toolBars.length] = new Array(__lang('copy'), "iconClick('copy')", 'copy');	toolBars[toolBars.length] = new Array(__lang('cut'), "iconClick('cut')", 'cut');	toolBars[toolBars.length] = new Array(__lang('pau'), "iconClick('paste')", 'paste');	toolBars[toolBars.length] = new Array(__lang('del'), "iconClick('delete')", 'delete');    toolBars[toolBars.length] = new Array('', "iconClick('nodo')", 'nodo');	toolBars[toolBars.length] = new Array(__lang('bold'), "iconClick('bold')", 'bold');	toolBars[toolBars.length] = new Array(__lang('italic'), "iconClick('italic')", 'italic');	toolBars[toolBars.length] = new Array(__lang('underline'), "iconClick('underline')", 'underline');	toolBars[toolBars.length] = new Array(__lang('st'), "iconClick('StrikeThrough')", 'strikethrough');	toolBars[toolBars.length] = new Array(__lang('jl'), "iconClick('justifyleft')", 'justifyleft');	toolBars[toolBars.length] = new Array(__lang('jc'), "iconClick('justifycenter')", 'justifycenter');	toolBars[toolBars.length] = new Array(__lang('jr'), "iconClick('justifyright')", 'justifyright');	toolBars[toolBars.length] = new Array('', "iconClick('nodo')", 'nodo');	toolBars[toolBars.length] = new Array(__lang('fcolor'), "iconClick('forecolor')", 'forecolor');	toolBars[toolBars.length] = new Array(__lang('bcolor'), "iconClick('backcolor')", 'backcolor');	toolBars[toolBars.length] = new Array('', "iconClick('nodo')", 'nodo');	toolBars[toolBars.length] = new Array(__lang('ilist'), "iconClick('insertorderedlist')", 'insertollist');	toolBars[toolBars.length] = new Array(__lang('itlist'), "iconClick('insertunorderedlist')", 'insertullist');	toolBars[toolBars.length] = new Array('', "iconClick('nodo')", 'nodo');	toolBars[toolBars.length] = new Array(__lang('sup'), "iconClick('superscript')", 'sup');	toolBars[toolBars.length] = new Array(__lang('sub'), "iconClick('subscript')", 'sub');	toolBars[toolBars.length] = new Array('', "iconClick('nodo')", 'nodo');	toolBars[toolBars.length] = new Array(__lang('createlink'), "iconClick('insertLink')", 'create_link');	toolBars[toolBars.length] = new Array(__lang('unlink'), "iconClick('Unlink')", 'unlink');	toolBars[toolBars.length] = new Array('', "iconClick('nodo')", 'nodo');	toolBars[toolBars.length] = new Array(__lang('inserthr'), "iconClick('InsertHorizontalRule')", 'inserthr');	toolBars[toolBars.length] = new Array(__lang('insertimg'), "iconClick('insertImage')", 'img');	toolBars[toolBars.length] = new Array('', "iconClick('nodo')", 'nodo');	toolBars[toolBars.length] = new Array(__lang('editsource'), "iconClick('recove')", 'length');	toolBars[toolBars.length] = new Array('', "iconClick('nodo')", 'nodo');	toolBars[toolBars.length] = new Array(__lang('preview'), "iconClick('doPreview')", 'unselect');	toolBars[toolBars.length] = new Array('', "iconClick('nodo')", 'nodo');}var toolBars1 = new Array();if (isIE5) {	toolBars1[toolBars1.length] = new Array(__lang('usehtml'), "iconClick('recove')", 'length1');	toolBars1[toolBars1.length] = new Array('', "iconClick('nodo')", 'nodo');	toolBars1[toolBars1.length] = new Array(__lang('review'), "iconClick('doPreview')", 'unselect');	toolBars1[toolBars1.length] = new Array('', "iconClick('nodo')", 'nodo');}//action mappingfunction iconClick(action) {	if (!textObj || !isIE5) {		return;	}	saveSelection();	switch (action) {	case 'nodo':		reselect();		debug('nodo');		break;	case 'forecolor':		_stColorType = 1;		ShowDialog('selectColor', 180, 130, false)		break;	case 'backcolor':		_stColorType = 2;		ShowDialog('selectColor', 180, 130, false);		break;	case 'insertImage':		insertImage();		break;	case 'insertLink':		insertLink();		break;	case 'recove':		reselect();		recove();		break;	case 'doPreview':		reselect();		doPreview();		break;	default:		reselect();		editor.document.execCommand(action);		editor.focus();		break;	}}//init toolbarvar _toolBar = null;var _toolBar1 = null;function initToolBar() {	if (!textObj || !isIE5) {		return;	}	var tbm = document.createElement('span');	tbm.style.width = textObj.style.width;	tbm.id = '_toolbar';	//font	tbm.innerHTML += '<SELECT onchange="applyCommand(\'FontName\', this[this.selectedIndex].value);this.selectedIndex=0;editor.focus();"> \		<option selected>'+__lang('font')+'</option> \		<option value="'+__lang('simsun')+'">'+__lang('simsun')+'</option> \		<option value="'+__lang('simhei')+'">'+__lang('simhei')+'</option> \		<option value="'+__lang('simkai')+'_GB2312">'+__lang('simkai')+'</option> \		<option value="'+__lang('fangsong')+'_GB2312">'+__lang('fangsong')+'</option> \

⌨️ 快捷键说明

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