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

📄 dhtmledit.js

📁 一个很好的论坛程序.论坛数据和程序使用最新更新29号动网7.1论坛程序美化优化设置:1.帖子中改变字体大小2.论坛信息变量3.双击下滚
💻 JS
字号:
var Dvbbs_edit;	//selectRang
var Dvbbs_RangeType;
var Dvbbs_selection;
var Dvbbs_filterScript = true;
var Dvbbs_charset="UTF-8";
var Dvbbs_bLoad=false
var Dvbbs_pureText=true
var Dvbbs_bTextMode=1			//默认为Design模式

//预览
function Dvbbs_InitDocument(hiddenid, charset)
{	
	if (charset!=null)
	Dvbbs_charset=charset;
	if (Dvbbs_bIsIE5){
		var Dvbbs_bodyTag="<style type=text/css>.quote{margin:5px 20px;border:1px solid #CCCCCC;padding:5px; background:#F3F3F3 }\nbody{boder:0px}.HtmlCode{margin:5px 20px;border:1px solid #CCCCCC;padding:5px;background:#FDFDDF;font-size:14px;font-family:Tahoma;font-style : oblique;line-height : normal ;font-weight:bold;}\nbody{boder:0px}</style></head><BODY bgcolor=\"#FFFFFF\" title=\"Ctrl+Enter直接提交贴子\" onkeydown=\"ctlent();\">";
	}else
	{
		var Dvbbs_bodyTag="<style type=text/css>.quote{margin:5px 20px;border:1px solid #CCCCCC;padding:5px; background:#F3F3F3 }\nbody{boder:0px}.HtmlCode{margin:5px 20px;border:1px solid #CCCCCC;padding:5px;background:#FDFDDF;font-size:14px;font-family:Tahoma;font-style : oblique;line-height : normal ;font-weight:bold;}\nbody{boder:0px}</style></head><BODY bgcolor=\"#FFFFFF\">";
	}
	var h=document.getElementById(hiddenid).value;
	if (navigator.appVersion.indexOf("MSIE 6.0",0)==-1){
	IframeID.document.designMode="On"
	}
	IframeID.document.open();
	IframeID.document.write ('<html><head>');
	if (Dvbbs_bIsIE5){
	IframeID.document.write ('<script language="javascript">');
	IframeID.document.write ('var ispost=0;');
	IframeID.document.write ('	function ctlent(eventobject)');
	IframeID.document.write ('	{');
	IframeID.document.write ('		if(event.ctrlKey && window.event.keyCode==13&&ispost==0)');
	IframeID.document.write ('		{');
	IframeID.document.write ('			ispost=1;');
	IframeID.document.write ('			parent.Dvbbs_CopyData("'+hiddenid+'"); ');
	IframeID.document.write ('			parent.document.Dvform.submit();');
	IframeID.document.write ('		}');
	IframeID.document.write ('	}');
	IframeID.document.write ('<\/script>');
	}
	IframeID.document.write(Dvbbs_bodyTag);
	if (h!="")
	{
		h=Dvbbs_FilterScript(h)
		IframeID.document.write(h);
	}
	IframeID.document.write("</body>");
	IframeID.document.write("</html>");
	IframeID.document.close();
	IframeID.document.body.contentEditable = "True";
	IframeID.document.charset=Dvbbs_charset;
	Dvbbs_bLoad=true;
	Dvbbs_setStyle();
}

function Dvbbs_setMode(n)
{
	Dvbbs_bTextMode=n
	var cont;
	var Dvbbs_Toolbar0=document.getElementById("ExtToolbar0");
	var Dvbbs_Toolbar1=document.getElementById("ExtToolbar1");
	var Dvbbs_Toolbar2=document.getElementById("ExtToolbar2");
	var Dvbbs_Toolbar3=document.getElementById("old_Toolbars");
	if (n==1)
	{
		Dvbbs_Toolbar0.style.display="";
		Dvbbs_Toolbar1.style.display="";
		Dvbbs_Toolbar2.style.display="";
		Dvbbs_Toolbar3.style.display="none";		//ubb工具栏关闭
		if (document.getElementById("Dvbbs_TabHtml").className=="Dvbbs_TabOn"){
			if (Dvbbs_bIsIE5){
				cont=IframeID.document.body.innerText;
				cont=Dvbbs_correctUrl(cont);
				if (Dvbbs_filterScript)
				cont=Dvbbs_FilterScript(cont);
				IframeID.document.body.innerHTML=cont;
			}else{
				var html = IframeID.document.body.ownerDocument.createRange();
				html.selectNodeContents(IframeID.document.body);
				IframeID.document.body.innerHTML = html.toString();
			}
		}
	}
	else if (n==2) 
	{
		if (canusehtml=="1")
		{
			Dvbbs_Toolbar0.style.display="none";	//关闭工具栏
			Dvbbs_Toolbar1.style.display="none";
			Dvbbs_Toolbar2.style.display="none";
			Dvbbs_Toolbar3.style.display="none";	//关闭UBB
			Dvbbs_cleanHtml();
			cont=IframeID.document.body.innerHTML;
			cont=Dvbbs_correctUrl(cont);
			if (Dvbbs_filterScript){cont=Dvbbs_FilterScript(cont);}
			if (Dvbbs_bIsIE5){					//IE
				IframeID.document.body.innerText=cont;
			}else{								//Nc
				var html=document.createTextNode(cont);
    			IframeID.document.body.innerHTML = "";
    			IframeID.document.body.appendChild(html);
			}
		}else{
		alert("您不能使用这个功能!")
		}
	}
	else if (n==3)
	{
		Dvbbs_Toolbar0.style.display="";
		Dvbbs_Toolbar1.style.display="none";
		Dvbbs_Toolbar2.style.display="none";
		Dvbbs_Toolbar3.style.display="";
		var mhtml=document.getElementById("Dvbbs_TabHtml");
		var mdesign=document.getElementById("Dvbbs_TabDesign");
		if (mhtml.className=="Dvbbs_TabOn")
		{
			if (Dvbbs_bIsIE5){
				cont=IframeID.document.body.innerText;
				cont=Dvbbs_correctUrl(cont);
				if (Dvbbs_filterScript)
				cont=Dvbbs_FilterScript(cont);
				IframeID.document.body.innerHTML=cont;
			}else{
				var html = IframeID.document.body.ownerDocument.createRange();
				html.selectNodeContents(IframeID.document.body);
				IframeID.document.body.innerHTML = html.toString();
			}
		}
	}

	Dvbbs_setTab(n);
	Dvbbs_setStyle();
	IframeID.focus();
}

function Dvbbs_setTab(n)
{
	//html和design按钮的样式更改
	var mhtml=document.getElementById("Dvbbs_TabHtml");
	var mdesign=document.getElementById("Dvbbs_TabDesign");
	var mOldTool=document.getElementById("Dvbbs_TabOldTools");
	if (n==1)
	{
		mhtml.className="Dvbbs_TabOff";
		mdesign.className="Dvbbs_TabOn";
		mOldTool.className="Dvbbs_TabOff";
	}
	else if (n==2)
	{
		mhtml.className="Dvbbs_TabOn";
		mdesign.className="Dvbbs_TabOff";
		mOldTool.className="Dvbbs_TabOff";

	}
	else if (n==3)
	{
		mhtml.className="Dvbbs_TabOff";
		mdesign.className="Dvbbs_TabOff";
		mOldTool.className="Dvbbs_TabOn";
	}
}

function Dvbbs_setStyle()
{
	//var bs = IframeID.document.body.runtimeStyle;
	var bs = IframeID.document.body.style;
	//根据mode设置iframe样式表	
	if (Dvbbs_bTextMode==2) {
		bs.fontFamily="Arial";
		bs.fontSize="10pt";
	}else{
		bs.fontFamily="Arial";
		bs.fontSize="10.5pt";
	}
	bs.scrollbar3dLightColor= '#D4D0C8';
	bs.scrollbarArrowColor= '#000000';
	bs.scrollbarBaseColor= '#D4D0C8';
	bs.scrollbarDarkShadowColor= '#D4D0C8';
	bs.scrollbarFaceColor= '#D4D0C8';
	bs.scrollbarHighlightColor= '#808080';
	bs.scrollbarShadowColor= '#808080';
	bs.scrollbarTrackColor= '#D4D0C8';
	bs.border='0';
}

function Dvbbs_CopyData(hiddenid)
{
	d	=	IframeID.document;
	if (Dvbbs_bTextMode==2)
	{
	cont=d.body.innerText;
	}else{
	cont=d.body.innerHTML;  
	}
	var ChekEmptyCode=Dvbbs_ChekEmptyCode(cont);
	if (ChekEmptyCode=='' || ChekEmptyCode==null)
	{
		cont='';
	}
	else{
		cont=Dvbbs_correctUrl(cont);
		if (Dvbbs_filterScript)
		cont=Dvbbs_FilterScript(cont);
	}
	document.getElementById(hiddenid).value = cont;
}

function Dvbbs_validateMode()
{
	if (Dvbbs_bTextMode!=2) return true;
	alert("请取消“查看HTML源代码”选项再使用系统编辑功能或者提交!");
	IframeID.focus();
	return false;
}

function Dvbbs_CleanCode() {
	var editor=IframeID;
	editor.focus();
	if (Dvbbs_bIsIE5){
	// 0bject based cleaning
		var body = editor.document.body;
		for (var index = 0; index < body.all.length; index++) {
			tag = body.all[index];
		//*if (tag.Attribute["className"].indexOf("mso") > -1)
			tag.removeAttribute("className","",0);
			tag.removeAttribute("style","",0);
		}
	// Regex based cleaning
		var html = editor.document.body.innerHTML;
		html = html.replace(/\<[^>]*>/g,"");        ///过滤其它所有"<...>"标签
		editor.document.body.innerHTML = html;
	}else
	{
		var html = IframeID.document.body.ownerDocument.createRange();
		html.selectNodeContents(IframeID.document.body);
		IframeID.document.body.innerHTML = html.toString();
	}
}

function Dvbbs_ChekEmptyCode(html) {
	html = html.replace(/\<[^>]*>/g,"");        ///过滤其它所有"<...>"标签
	html = html.replace(/&nbsp;/gi, "");
	html = html.replace(/o:/gi, "");
	html = html.replace(/\s/gi, "");
	return html;
}


var colour
function FormatText(command, option) {	
var codewrite
if (Dvbbs_bIsIE5){
		if (option=="removeFormat"){
		command=option;
		option=null;}
		IframeID.focus();
	  	IframeID.document.execCommand(command, false, option);
		Dvbbs_pureText = false;
		IframeID.focus();
		
}else{
		if ((command == 'forecolor') || (command == 'backcolor')) {
			parent.command = command;
			buttonElement = document.getElementById(command);
			IframeID.focus();
			document.getElementById("colourPalette").style.left = getOffsetLeft(buttonElement) + "px";
			document.getElementById("colourPalette").style.top = (getOffsetTop(buttonElement) + buttonElement.offsetHeight) + "px";
		
			if (document.getElementById("colourPalette").style.visibility=="hidden")
				{document.getElementById("colourPalette").style.visibility="visible";
			}else {
				document.getElementById("colourPalette").style.visibility="hidden";
			}
		
			//get current selected range
			var sel = IframeID.document.selection; 
			if (sel != null) {
				colour = sel.createRange();
			}
		}
		else{
		IframeID.focus();
	  	IframeID.document.execCommand(command, false, option);
		Dvbbs_pureText = false;
		IframeID.focus();
		}
	}

}

function setColor(color) {	
	IframeID.focus();
	IframeID.document.execCommand(parent.command, false, color);
	IframeID.focus();
	document.getElementById("colourPalette").style.visibility="hidden";
}

function FormatUrl(html)
{
	var regExp = /<a.*href=\"(.*)\"[^>]*>/gi;
	html = html.replace(regExp,"<a href=$1 target=\"_blank\" >")
  return html;
}

//Dvbbs_InitDocument("Body","GB2312");

⌨️ 快捷键说明

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