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

📄 editor2.js

📁 oa 源码
💻 JS
📖 第 1 页 / 共 5 页
字号:
	var sType=oEditor.document.selection.type;

	if(sType=="None")
		obj.arrUndoList[0]=[oEditor.document.body.innerHTML,
			oEditor.document.selection.createRange().getBookmark(),"None"];
	else if(sType=="Text")
		obj.arrUndoList[0]=[oEditor.document.body.innerHTML,
			oEditor.document.selection.createRange().getBookmark(),"Text"];
	else if(sType=="Control")
		{
		oSel.item(0).selThis="selThis";
		obj.arrUndoList[0]=[oEditor.document.body.innerHTML,null,"Control"];
		oSel.item(0).removeAttribute("selThis",0);
		}
	this.arrRedoList=[];//clear redo list

	if(this.btnUndo) makeEnableNormal(eval("document.all.btnUndo"+this.oName));
	if(this.btnRedo) makeDisabled(eval("document.all.btnRedo"+this.oName));
	}
function doUndo()
	{
	var oEditor=eval("idContent"+this.oName);
	var obj=eval(this.oName);
	if(!obj.arrUndoList[0])return;
	//~~~~
	for(var i=20;i>1;i--)obj.arrRedoList[i-1]=obj.arrRedoList[i-2];
	var oSel=oEditor.document.selection.createRange();
	var sType=oEditor.document.selection.type;
	if(sType=="None")
		this.arrRedoList[0]=[oEditor.document.body.innerHTML,
			oEditor.document.selection.createRange().getBookmark(),"None"];
	else if(sType=="Text")
		this.arrRedoList[0]=[oEditor.document.body.innerHTML,
			oEditor.document.selection.createRange().getBookmark(),"Text"];
	else if(sType=="Control")
		{
		oSel.item(0).selThis="selThis";
		this.arrRedoList[0]=[oEditor.document.body.innerHTML,null,"Control"];
		oSel.item(0).removeAttribute("selThis",0);
		}
	//~~~~
	sHTML=obj.arrUndoList[0][0];
	var arrA = String(sHTML).match(/<A[^>]*>/ig);
	if(arrA)
		for(var i=0;i<arrA.length;i++)
			{
			sTmp = arrA[i].replace(/href=/,"href_iwe=");
			sHTML=String(sHTML).replace(arrA[i],sTmp);
			}
	var arrB = String(sHTML).match(/<IMG[^>]*>/ig);
	if(arrB)
		for(var i=0;i<arrB.length;i++)
			{
			sTmp = arrB[i].replace(/src=/,"src_iwe=");
			sHTML=String(sHTML).replace(arrB[i],sTmp);
			}
	var arrC = String(sHTML).match(/<AREA[^>]*>/ig);
	if(arrC)
		for(var i=0;i<arrC.length;i++)
			{
			sTmp = arrC[i].replace(/href=/,"href_iwe=");
			sHTML=String(sHTML).replace(arrC[i],sTmp);
			}
	oEditor.document.body.innerHTML=sHTML;
	for(var i=0;i<oEditor.document.all.length;i++)
		{
		if(oEditor.document.all[i].getAttribute("href_iwe"))
			{
			oEditor.document.all[i].href=oEditor.document.all[i].getAttribute("href_iwe");
			oEditor.document.all[i].removeAttribute("href_iwe",0);
			}
		if(oEditor.document.all[i].getAttribute("src_iwe"))
			{
			oEditor.document.all[i].src=oEditor.document.all[i].getAttribute("src_iwe");
			oEditor.document.all[i].removeAttribute("src_iwe",0);
			}
		}
	//*** RUNTIME STYLES ***
	this.runtimeBorder(false);
	this.runtimeStyles();
	//***********************
	var oRange=oEditor.document.body.createTextRange();
	if(obj.arrUndoList[0][2]=="None")
		{
		oRange.moveToBookmark(obj.arrUndoList[0][1]);
		oRange.select(); //di-disable, spy tdk select all? tdk perlu utk undo
		}
	else if(obj.arrUndoList[0][2]=="Text")
		{
		oRange.moveToBookmark(obj.arrUndoList[0][1]);
		oRange.select();
		}
	else if(obj.arrUndoList[0][2]=="Control")
		{
		for(var i=0;i<oEditor.document.all.length;i++)
			{
			if(oEditor.document.all[i].selThis=="selThis")
				{
				var oSelRange=oEditor.document.body.createControlRange();
				oSelRange.add(oEditor.document.all[i]);
				oSelRange.select();
				oEditor.document.all[i].removeAttribute("selThis",0);
				}
			}
		}
	//~~~~
	for(var i=0;i<19;i++)obj.arrUndoList[i]=obj.arrUndoList[i+1];
	obj.arrUndoList[19]=null;
	realTime(this.oName);
	}
function doRedo()
	{
	var oEditor=eval("idContent"+this.oName);
	var obj=eval(this.oName);
	if(!obj.arrRedoList[0])return;
	//~~~~
	for(var i=20;i>1;i--)obj.arrUndoList[i-1]=obj.arrUndoList[i-2];
	var oSel=oEditor.document.selection.createRange();
	var sType=oEditor.document.selection.type;
	if(sType=="None")
		obj.arrUndoList[0]=[oEditor.document.body.innerHTML,
			oEditor.document.selection.createRange().getBookmark(),"None"];
	else if(sType=="Text")
		obj.arrUndoList[0]=[oEditor.document.body.innerHTML,
			oEditor.document.selection.createRange().getBookmark(),"Text"];
	else if(sType=="Control")
		{
		oSel.item(0).selThis="selThis";
		this.arrUndoList[0]=[oEditor.document.body.innerHTML,null,"Control"];
		oSel.item(0).removeAttribute("selThis",0);
		}
	//~~~~
	sHTML=obj.arrRedoList[0][0];
	var arrA = String(sHTML).match(/<A[^>]*>/ig);
	if(arrA)
		for(var i=0;i<arrA.length;i++)
			{
			sTmp = arrA[i].replace(/href=/,"href_iwe=");
			sHTML=String(sHTML).replace(arrA[i],sTmp);
			}
	var arrB = String(sHTML).match(/<IMG[^>]*>/ig);
	if(arrB)
		for(var i=0;i<arrB.length;i++)
			{
			sTmp = arrB[i].replace(/src=/,"src_iwe=");
			sHTML=String(sHTML).replace(arrB[i],sTmp);
			}
	var arrC = String(sHTML).match(/<AREA[^>]*>/ig);
	if(arrC)
		for(var i=0;i<arrC.length;i++)
			{
			sTmp = arrC[i].replace(/href=/,"href_iwe=");
			sHTML=String(sHTML).replace(arrC[i],sTmp);
			}
	oEditor.document.body.innerHTML=sHTML;
	for(var i=0;i<oEditor.document.all.length;i++)
		{
		if(oEditor.document.all[i].getAttribute("href_iwe"))
			{
			oEditor.document.all[i].href=oEditor.document.all[i].getAttribute("href_iwe");
			oEditor.document.all[i].removeAttribute("href_iwe",0);
			}
		if(oEditor.document.all[i].getAttribute("src_iwe"))
			{
			oEditor.document.all[i].src=oEditor.document.all[i].getAttribute("src_iwe");
			oEditor.document.all[i].removeAttribute("src_iwe",0);
			}
		}
	//*** RUNTIME STYLES ***
	this.runtimeBorder(false);
	this.runtimeStyles();
	//***********************
	var oRange=oEditor.document.body.createTextRange();
	if(obj.arrRedoList[0][2]=="None")
		{
		oRange.moveToBookmark(obj.arrRedoList[0][1]);
		//oRange.select(); //di-disable, sph tdk select all, utk redo perlu
		}
	else if(obj.arrRedoList[0][2]=="Text")
		{
		oRange.moveToBookmark(obj.arrRedoList[0][1]);
		oRange.select();
		}
	else if(obj.arrRedoList[0][2]=="Control")
		{
		for(var i=0;i<oEditor.document.all.length;i++)
			{
			if(oEditor.document.all[i].selThis=="selThis")
				{
				var oSelRange = oEditor.document.body.createControlRange();
				oSelRange.add(oEditor.document.all[i]);
				oSelRange.select();
				oEditor.document.all[i].removeAttribute("selThis",0);
				}
			}
		}
	//~~~~
	for(var i=0;i<19;i++)obj.arrRedoList[i]=obj.arrRedoList[i+1];
	obj.arrRedoList[19]=null;
	realTime(this.oName);
	}


/*********************
	RENDER
**********************/
function RENDER(sPreloadHTML)
	{
	/*** Tetap Ada (For downgrade compatibility) ***/
	if(sPreloadHTML.substring(0,4)=="<!--" &&
		sPreloadHTML.substring(sPreloadHTML.length-3)=="-->")
		sPreloadHTML=sPreloadHTML.substring(4,sPreloadHTML.length-3);

	if(sPreloadHTML.substring(0,4)=="<!--" &&
		sPreloadHTML.substring(sPreloadHTML.length-6)=="--&gt;")
		sPreloadHTML=sPreloadHTML.substring(4,sPreloadHTML.length-6);

	/*** Converting back HTML-encoded content (kalau tdk encoded tdk masalah) ***/
	sPreloadHTML=sPreloadHTML.replace(/&lt;/g,"<");
	sPreloadHTML=sPreloadHTML.replace(/&gt;/g,">");
	sPreloadHTML=sPreloadHTML.replace(/&amp;/g,"&");
	sPreloadHTML=sPreloadHTML.replace(/&quot;/g,"\"");

	/*** features ***/
	var bUseFeature=false;
	if(this.features.length>0)
		{
		bUseFeature=true;
		for(var i=0;i<this.buttonMap.length;i++)
			eval(this.oName+".btn"+this.buttonMap[i]+"=true");//ex: oEdit1.btnStyleAndFormatting=true (no problem), oEdit1.btn|=true (no problem), oEdit1.btnBRK=true (no problem)

		this.btnTextFormatting=false;this.btnListFormatting=false;
		this.btnBoxFormatting=false;this.btnParagraphFormatting=false;
		this.btnCssText=false;this.btnStyles=false;
		for(var j=0;j<this.features.length;j++)
			eval(this.oName+".btn"+this.features[j]+"=true");//ex: oEdit1.btnTextFormatting=true

		for(var i=0;i<this.buttonMap.length;i++)
			{
			sButtonName=this.buttonMap[i];
			bBtnExists=false;
			for(var j=0;j<this.features.length;j++)
				if(sButtonName==this.features[j])bBtnExists=true;//ada;

			if(!bBtnExists)//tdk ada; set false
				eval(this.oName+".btn"+sButtonName+"=false");//ex: oEdit1.btnBold=false, oEdit1.btn|=false (no problem), oEdit1.btnBRK=false (no problem)
			}
		//Remove:"TextFormatting","ListFormatting",dst.=>tdk perlu(krn diabaikan)
		this.buttonMap=this.features;
		}
	/*** /features ***/

	this.preloadHTML=sPreloadHTML;
	var sHTMLDropMenus="";
	var sHTMLIcons="";
	var sTmp="";

	for(var i=0;i<this.buttonMap.length;i++)
		{
		sButtonName=this.buttonMap[i];
		switch(sButtonName)
			{
			case "|":
				sHTMLIcons+=this.writeBreakSpace();
				break;
			case "BRK":
				sHTMLIcons+="</td></tr></table><table cellpadding=0 cellspacing=0><tr><td dir=ltr>";
				break;
			case "Save":
				if(this.btnSave)sHTMLIcons+=this.writeIconStandard("btnSave"+this.oName,this.oName+".onSave()","btnSave.gif",getText("Save"));
				break;
			case "Preview":
				if(this.btnPreview)
					{
					sHTMLIcons+=this.writeIconStandard("btnPreview"+this.oName,this.oName+".dropShow(this,dropPreview"+this.oName+")","btnPreview.gif",getText("Preview"));
					var arrPreviewSize=[[640,480],[800,600],[1024,768]];
					sTmp="";
					for(var j=0;j<arrPreviewSize.length;j++)
						{
						sTmp+= "<tr><td onclick=\"dropPreview"+this.oName+".style.display='none';setActiveEditor('"+this.oName+"');modalDialogShow('"+this.scriptPath+"preview.htm',"+arrPreviewSize[j][0]+","+arrPreviewSize[j][1]+");\" "+
							"style=\"padding:2px;padding-top:1px;font-family:Tahoma;font-size:11px;color:black;\" "+
							"onmouseover=\"this.style.backgroundColor='#708090';this.style.color='#FFFFFF';\" "+
							"onmouseout=\"this.style.backgroundColor='';this.style.color='#000000';\" unselectable=on>"+arrPreviewSize[j][0]+"x"+arrPreviewSize[j][1]+"</td></tr>";
						}
					sHTMLDropMenus+="<table id=dropPreview"+this.oName+" cellpadding=0 cellspacing=0 "+
						"style='z-index:1;display:none;position:absolute;border:#716F64 1px solid;"+

⌨️ 快捷键说明

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