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

📄 editor.js

📁 论坛建站的源代码
💻 JS
📖 第 1 页 / 共 5 页
字号:
		}
	}
}

//编辑器工具栏各图标按钮
function BBSXPCreateIcon(icon)
{
	var str;
	if (icon[0] == 'YuZi_TEXTCOLOR' || icon[0] == 'YuZi_BGCOLOR') {
		if (icon[0] == 'YuZi_TEXTCOLOR')
			ExecuteCMD = 'ForeColor';
		else
			ExecuteCMD = 'BackColor';
		
		str = '<div style="POSITION: relative;border:1px solid ' + YuZi_TOOLBAR_BG_COLOR +';cursor:pointer;height:20px;width:28px" onmouseover="$(\''+icon[0]+'RightBar\').style.borderLeft = this.style.border=\'1px solid ' + YuZi_MENU_BORDER_COLOR + '\';" onmouseout="$(\''+icon[0]+'RightBar\').style.borderLeft = this.style.border=\'1px solid ' + YuZi_TOOLBAR_BG_COLOR + '\';" title="' + icon[2]  + '">';
		str += '<img src="' + YuZi_SKIN_PATH  + icon[1] +'" onclick="BBSXPExecuteValue(\''+ExecuteCMD+'\',\'YuZi_'+ExecuteCMD+'\');">';
		str += '<img id="'+icon[0]+'Bar" style="BACKGROUND: '+eval("YuZi_"+ExecuteCMD)+'; LEFT: 1px; POSITION: absolute; TOP: 15px" height=4 src="' + YuZi_SKIN_PATH  +'clear.gif" width=16 onclick="BBSXPExecuteValue(\''+ExecuteCMD+'\',\'YuZi_'+ExecuteCMD+'\');">';
		str += '<div id="'+icon[0]+'RightBar" style="POSITION: absolute;left:17px;top:0px;border-left:1px solid '+YuZi_TOOLBAR_BG_COLOR+';height:18px"><img id="'+ icon[0] +'" src="' + YuZi_SKIN_PATH + 'PopMenu.gif" title="' + icon[2]  + '" align="absmiddle" onclick="BBSXPExecute(\''+ icon[0] +'\');"></div>';
		str += '</div>';
	}
	else {
		str = '<img id="'+ icon[0] +'" src="' + YuZi_SKIN_PATH + icon[1] + '" title="' + icon[2]  + 
			'" align="absmiddle" style="border:1px solid ' + YuZi_TOOLBAR_BG_COLOR +';cursor:pointer;height:20px;';
		str += '" onclick="BBSXPExecute(\''+ icon[0] +'\');" '+
			'onmouseover="this.style.border=\'1px solid ' + YuZi_MENU_BORDER_COLOR + '\';" ' +
			'onmouseout="this.style.border=\'1px solid ' + YuZi_TOOLBAR_BG_COLOR + '\';" ';
		str += '>';
	}
	return str;
}
//编辑器工具栏
function BBSXPCreateToolbar()
{
	var htmlData = '<table cellpadding="0" cellspacing="0" border="0" height="26"><tr>';
	
	for (i = 0; i < YuZi_TOP_TOOLBAR_ICON.length; i++) {
		htmlData += '<td style="padding:2px;">' + BBSXPCreateIcon(YuZi_TOP_TOOLBAR_ICON[i]) + '</td>';
	}
		
	htmlData += '</tr></table><table cellpadding="0" cellspacing="0" border="0" height="26"><tr>';
	for (i = 0; i < YuZi_BOTTOM_TOOLBAR_ICON.length; i++) {
		htmlData += '<td style="padding:2px;">' + BBSXPCreateIcon(YuZi_BOTTOM_TOOLBAR_ICON[i]) + '</td>';
	}
		
	htmlData += '</tr></table>';
	return htmlData;
}

function BBSXPWriteFullHtml(documentObj, content)
{
	var editHtmlData = '';
	editHtmlData += '<html>\r\n<head>\r\n<title>BBSXP Editor --Powered By BBSXP</title>\r\n';
	editHtmlData += '<style type="text/css">\r\n\tbody { font-family:Courier New;font-size:12px;margin:2px;}\r\n\tBLOCKQUOTE {BORDER: #cccccc 1px dotted; PADDING: 4px; MARGIN: 16px;}\r\n</style>\r\n';
	editHtmlData += '</head>\r\n<body>\r\n';
	editHtmlData += content;
	editHtmlData += '\r\n</body>\r\n</html>\r\n';
	documentObj.open();
	documentObj.write(editHtmlData);
	documentObj.close();
}

//编辑器主函数
function BBSXPEditor(objName) 
{
	this.objName = objName;
	this.hiddenName = objName;
	this.safeMode;
	this.editorWidth;
	this.editorHeight;
	this.iconPath;
	this.menuBorderColor;
	this.menuBgColor;
	this.menuTextColor;
	this.menuSelectedColor;
	this.toolbarBorderColor;
	this.toolbarBgColor;
	this.formBorderColor;
	this.formBgColor;
	this.buttonColor;
	this.init = function()
	{
		if (this.safeMode) YuZi_SAFE_MODE = this.safeMode;
		if (this.editorWidth) YuZi_WIDTH = this.editorWidth;
		if (this.editorHeight) YuZi_HEIGHT = this.editorHeight;
		if (this.menuBorderColor) YuZi_MENU_BORDER_COLOR = this.menuBorderColor;
		if (this.menuBgColor) YuZi_MENU_BG_COLOR = this.menuBgColor;
		if (this.menuTextColor) YuZi_MENU_TEXT_COLOR = this.menuTextColor;
		if (this.menuSelectedColor) YuZi_MENU_SELECTED_COLOR = this.menuSelectedColor;
		if (this.toolbarBorderColor) YuZi_TOOLBAR_BORDER_COLOR = this.toolbarBorderColor;
		if (this.toolbarBgColor) YuZi_TOOLBAR_BG_COLOR = this.toolbarBgColor;
		if (this.formBorderColor) YuZi_FORM_BORDER_COLOR = this.formBorderColor;
		if (this.formBgColor) YuZi_FORM_BG_COLOR = this.formBgColor;
		if (this.buttonColor) YuZi_BUTTON_COLOR = this.buttonColor;
		YuZi_OBJ_NAME = this.objName;
		YuZi_BROWSER = BBSXPGetBrowser();
	}
	this.show = function()
	{
		this.init();
		var widthStyle = 'width:' + YuZi_WIDTH + ';';
		var heightStyle = 'height:' + YuZi_HEIGHT + ';';
		if (YuZi_BROWSER == '') {
			var htmlData = '<div id="BBSXPEditorIframe" style="' + widthStyle + heightStyle +';background-color:'+ YuZi_FORM_BG_COLOR +'">' +
			'<textarea name="BBSXPCodeForm" id="BBSXPCodeForm" style="' + widthStyle + heightStyle + 
			'padding:0;margin:0;border:1px solid '+ YuZi_FORM_BORDER_COLOR + 
			';font-size:12px;line-height:16px;font-family:'+YuZi_FONT_FAMILY+';background-color:'+ 
			YuZi_FORM_BG_COLOR +';">' + document.getElementsByName(this.hiddenName)[0].value + '</textarea></div>';
			document.open();
			document.write(htmlData);
			document.close();
			return;
		}
		var htmlData = '<style>TD.StatusBarBtnOff {padding:1px 5px;border:1px outset;cursor:pointer;}TD.StatusBarBtnOn {padding:1px 5px;border:1px inset;background-color: #EEEEEE;}</style>';
		
		htmlData += '<div id=BBSXPToolBar style="'+widthStyle+';border:1px solid ' + YuZi_TOOLBAR_BORDER_COLOR + ';border-bottom:0;background-color:'+ YuZi_TOOLBAR_BG_COLOR +'">';
		htmlData += BBSXPCreateToolbar();
		htmlData += '</div><div id="BBSXPEditorIframe" style="' + widthStyle + heightStyle + 
			'border:1px solid '+ YuZi_FORM_BORDER_COLOR +';background-color:'+ YuZi_FORM_BG_COLOR +'">' +
			'<iframe name="BBSXPEditorForm" id="BBSXPEditorForm" style="' + widthStyle + heightStyle + 
			'padding:0;margin:0;border:0;"></iframe>';

		
		htmlData += '<textarea name="BBSXPCodeForm" id="BBSXPCodeForm" style="' + widthStyle + heightStyle + 
				'padding:0;margin:0;border:0;font-size:12px;display:none;line-height:16px;font-family:'+YuZi_FONT_FAMILY+';background-color:'+ 
		YuZi_FORM_BG_COLOR +';" onclick="javascirit:parent.BBSXPDisableMenu();"></textarea></div>';
		
		htmlData += '<table border=0 cellpadding=0 cellspacing=0 height=20 style="margin-top:5px;">';
		htmlData += '<tr>';
		htmlData += '<td class=StatusBarBtnOn id=HtmlEditor_DESIGN onclick="setMode(\'DESIGN\')"><img border=0 src='+YuZi_SKIN_PATH+'modeedit.gif align=absmiddle title="'+YuZi_LANG['DesignMode']+'"></td>';
		htmlData += '<td width=5>&nbsp;</td>';
		htmlData += '<td class=StatusBarBtnOff id=HtmlEditor_CODE onclick="setMode(\'CODE\')"><img border=0 src='+YuZi_SKIN_PATH+'modecode.gif align=absmiddle title="'+YuZi_LANG['CodeMode']+'"></td>';
		htmlData += '<td width=5>&nbsp;</td>';
		htmlData += '<td align=right width=100%><img border=0 src='+YuZi_SKIN_PATH+'expand.gif align=absmiddle onclick=ChangeSize(100) style=cursor:pointer title="'+YuZi_LANG['AddEditorArea']+'"><img border=0 src='+YuZi_SKIN_PATH+'contract.gif align=absmiddle onclick=ChangeSize(-100) style=cursor:pointer title="'+YuZi_LANG['ReduceEditorArea']+'"></td>';
		htmlData += '</tr></table>';

		htmlData +='<div id="Yuzi_TempDiv" style="padding:2px;'+BBSXPGetMenuCommonStyle()+'">Loading...</div>';

		document.open();
		document.write(htmlData);
		document.close();
		if (YuZi_BROWSER == 'IE') {
			YuZi_EDITFORM_DOCUMENT = document.frames("BBSXPEditorForm").document;
		} else {
			YuZi_EDITFORM_DOCUMENT = $('BBSXPEditorForm').contentDocument;
		}

		YuZi_EDITFORM_DOCUMENT.designMode = 'On';
		YuZi_CurrentMode = "DESIGN";
		BBSXPWriteFullHtml(YuZi_EDITFORM_DOCUMENT, document.getElementsByName(eval(YuZi_OBJ_NAME).hiddenName)[0].value);
		var el = YuZi_EDITFORM_DOCUMENT.body;
		
		if (YuZi_EDITFORM_DOCUMENT.addEventListener){
			YuZi_EDITFORM_DOCUMENT.addEventListener('click', BBSXPDisableMenu, false);
			YuZi_EDITFORM_DOCUMENT.addEventListener('keypress', ctlent, true);
		} else if (el.attachEvent){
			el.attachEvent('onclick', BBSXPDisableMenu);
			el.attachEvent('onkeypress', ctlent);
		}
	}
	this.data = function()
	{
		var htmlResult;
		if (YuZi_BROWSER == '') {
			htmlResult = $("BBSXPCodeForm").value;
		}
		else {
			if (YuZi_CurrentMode.toLowerCase() == 'design') {
				htmlResult = YuZi_EDITFORM_DOCUMENT.body.innerHTML;
			}
			else {
				htmlResult = $("BBSXPCodeForm").value;
			}
		}
		BBSXPDisableMenu();
		htmlResult = BBSXPHtmlToXhtml(htmlResult);
		htmlResult = BBSXPClearScriptTag(htmlResult);
		
		htmlResult = ChangeImgPath(htmlResult);
		
		document.getElementsByName(this.hiddenName)[0].value = htmlResult;
		return htmlResult;
	}
}

//初始化编辑器
var editor = new BBSXPEditor("editor");
editor.hiddenName = "Body";
editor.show();

function ChangeImgPath(str){
	var url = location.href;
	var siteUrl = url.split("/");
	siteUrl.length = siteUrl.length-1;
	var siteStr = siteUrl.join("/") +"/";
	var re=new RegExp(siteStr,'ig');
	
	return str.replace(re,"");
}

// 预览
function Preview()
{
	editor.data();
	Subject=document.form.Subject;
	Body=document.form.Body;

 	if(typeof(Subject) != "undefined" ){
		if(Subject.value.length<2){alert(YuZi_LANG['SubjectMinLen']);return false;}
  	}

 	if(typeof(Body) != "undefined" ){
		if(Body.value.length<2){alert(YuZi_LANG['BodyMinLen']);return false;}
		if(Body.value.length>60000){alert(YuZi_LANG['BodyMaxLen']);return false;}
  	}

	$('Preview').style.display = '';
	Ajax_CallBack('form','Preview','Loading.asp?menu=Preview');
	window.location="#Preview";
}

//内容提交
function CheckForm() {
	if(YuZi_CurrentMode.toLowerCase() != 'design'){
		alert(YuZi_LANG['CurrentMode']);
		return false;
	}
	
	editor.data();
	Subject=document.form.Subject;
	Body=document.form.Body;
	VerifyCode=document.form.VerifyCode;
	Category=document.form.Category;


 	if(typeof(Category) != "undefined" ){
		if(Category.value.length>25){alert(YuZi_LANG['CategoryMaxLen']);return false;}
  	}

 	if(typeof(Subject) != "undefined" ){
		if(Subject.value.length<2){alert(YuZi_LANG['SubjectMinLen']);return false;}
		if(Subject.value.length>100){alert(YuZi_LANG['SubjectMaxLen']);return false;}
  	}

 	if(typeof(Body) != "undefined" ){
		if(Body.value.length<2){alert(YuZi_LANG['BodyMinLen']);return false;}
		if(Body.value.length>60000){alert(YuZi_LANG['BodyMaxLen']);return false;}
		Body.value=decodeURIComponent(Body.value);
  	}
	
	if(typeof(document.form.Description) != "undefined"){
		document.form.Description.value = ClearCode(Body.value,2);
	}
	
	if(typeof(document.form.Tags) != "undefined"){
		Tags = document.form.Tags.value;
		TagsArray = Tags.split(',');
		if (TagsArray.length > 5){
			alert('您最多只能添加 5 个标签。');
			return false;
		}
		for (var i=0; i<TagsArray.length;i++) {
			if(TagsArray[i].length > 25){
				alert('每个标签的长度不能大于 25 个字符');
				return false;
			}
		}
	}
	
 	if(typeof(document.form.RequireEditNotes) != "undefined" ){
		if(document.form.EditNotes.value.length<2){alert('请输入帖子编辑原因');return false;}
  	}
	
	if(typeof(VerifyCode) != "undefined"){
		if(VerifyCode.value.length<4){alert(YuZi_LANG['VerifyCode']);return false;}
  	}
}
//检测文章长度
function CheckLength(){
	editor.data();
	MessageLength=document.form.Body.value.length;
	alert("最大字符为 "+60000+ " 字节\n您的内容已有 "+MessageLength+" 字节");
}

//Ctrl + Enter 发帖
function ctlent(event){
	if(YuZi_CurrentMode.toLowerCase() != 'design'){
		alert(YuZi_LANG['CurrentMode']);
		return false;
	}
	else if((event.ctrlKey && (event.keyCode==13 || event.keyCode==10)) || (event.altKey && event.keyCode == 83)){
		parent.document.form.EditSubmit.click();
	}
}



// Upadate at 2008-1-16
document.write('<style type="text/css">.autosave { behavior: url(#default#userdata);}</style>');
document.write('<div id=AutoSave class="autosave"></div>');
var UserDataObject = document.getElementById('AutoSave');
window.onbeforeunload = function () {saveData()};

function saveData() {
	editor.data();
	PostBody = document.form.Body.value;
	if(!PostBody) return;
	
	var formdata = '';
	formdata += 'Body' + String.fromCharCode(9) + 'Editor_Frame' + String.fromCharCode(9) + 'DocumentFrame' + String.fromCharCode(9) + PostBody + String.fromCharCode(9, 9);
	for(var i = 0; i < document.form.elements.length; i++) {
		var el = document.form.elements[i];
		if(el.name != '' && (el.tagName == 'TEXTAREA' || el.tagName == 'INPUT' && (el.type == 'text' || el.type == 'checkbox' || el.type == 'radio')) && el.name.substr(0, 6) != 'attach') {
			var elvalue = el.value;
			if((el.type == 'checkbox' || el.type == 'radio') && !el.checked) {
				continue;
			}
			formdata += el.name + String.fromCharCode(9) + el.tagName + String.fromCharCode(9) + el.type + String.fromCharCode(9) + elvalue + String.fromCharCode(9, 9);
		}
	}
	ResponseUserData(formdata);
}

function RestoreData() {
	var message = RequestUserData();
	if(InArray(message, ['', 'null', 'false', null, false])) {
		alert('对不起,暂时没有可以恢复的数据!');
		return;
	}
	if(!window.confirm('此操作将覆盖当前表单内容,确定要恢复数据吗?')) {
		return;
	}

	var formdata = message.split(/\x09\x09/);
	for(var i = 0; i < document.form.elements.length; i++) {
		var el = document.form.elements[i];
		if(el.name != '' && (el.tagName == 'TEXTAREA' || el.tagName == 'INPUT' && (el.type == 'text' || el.type == 'checkbox' || el.type == 'radio'))) {
			for(var j = 0; j < formdata.length; j++) {
				var ele = formdata[j].split(/\x09/);
				if(ele[0] == 'Body') {
					YuZi_EDITFORM_DOCUMENT.designMode = 'On';
					setMode('DESIGN');
					BBSXPWriteFullHtml(YuZi_EDITFORM_DOCUMENT, ele[3]);
				}
				else if(ele[0] == el.name) {
					elvalue = typeof(ele[3]) != "undefined" ? ele[3] : '';
					if(ele[1] == 'INPUT') {
						if(ele[2] == 'text') {
							el.value = elvalue;
						} else if((ele[2] == 'checkbox' || ele[2] == 'radio') && ele[3] == el.value) {
							el.checked = true;
							EvalEvent(el);
				

⌨️ 快捷键说明

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