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

📄 editor.js

📁 SK信息采集2.0功能介绍: 1.可针对任何静态网页,动态网页进行采集。包括htm,html,shtml,ASP,ASPX,JSP,PHP等。 2.增加自定文件采集.用户可采集网页中的所有文件.
💻 JS
📖 第 1 页 / 共 3 页
字号:
bInitialized=false;
var DocPopupContextMenu = null;
DocPopupContextMenu = window.createPopup();
var SelectedTD=null;
var SelectedTR=null;
var SelectedTBODY=null;
var SelectedTable=null;
function SetEditAreaStyle()
{  KS_EditArea.document.open();
   KS_EditArea.document.write('<head><link href="'+InstallDir+'Editor/Editor_Style.CSS" type="text/css" rel="stylesheet"></head>');
   KS_EditArea.document.close();
}
function InitBtn(btn) 
{
	btn.onmouseover = ImageBtnMouseOver;
	btn.onmouseout = BtnMouseOut;
	btn.onmousedown = BtnMouseDown;
	btn.onmouseup = BtnMouseOut;
	btn.ondragstart = YCancelEvent;
	btn.onselectstart = YCancelEvent;
	btn.onselect = YCancelEvent;
	btn.disabled=false;
	return true;
}
function InsertMorePage(Index)
{
	KS_EditArea.focus();
	InsertHTMLStr('[NextPage]');
	KS_EditArea.focus();
}

function ImageBtnMouseOver() 
{
	var image = event.srcElement;
	image.className = "ToolBtnMouseOver";
	event.cancelBubble = true;
}

function BtnMouseOut() 
{
	var image = event.srcElement;
	image.className = "Btn";
	event.cancelBubble = true;
}

function BtnMouseDown() 
{
	var image = event.srcElement;
	image.className = "ToolBtnMouseDown";
	event.cancelBubble = true;
	event.returnValue=false;
	return false;
}

function YCancelEvent() 
{
	event.returnValue=false;
	event.cancelBubble=true;
	return false;
}
function LoadEditFile(Style)
{   //接收Style确定右键是否出现新闻属性
	KS_EditArea.document.body.contentEditable="true";
	KS_EditArea.document.onmouseup=new Function("return SearchObject(KS_EditArea.event);");
	KS_EditArea.document.oncontextmenu=new Function("return ShowMouseRightMenu(KS_EditArea.event,"+Style+");");
	KS_EditArea.focus();
}
var CurrMode='EDIT';
function setMode(NewMode,Style,ReplaceStr,InstallStr,AdminDirStr)   
{  var AdminBadStr="\\/"+AdminDirStr+"([A-Z]|[a-z]|\\/|)*.asp([A-Z]|[a-z]||\\?|=|&|;|[0-9])*#";
	 if (NewMode!=CurrMode)   
	 {   
		if (NewMode=='TEXT')
		{if (!confirm("警告!切换到纯文本模式会丢失您所有的HTML格式,您确认切换吗?")) return false;}
		    var sBody='';
		    switch(CurrMode)
		     {
			   case "CODE":
				    if (NewMode=="TEXT") sBody=KS_EditArea.document.body.innerText;
				    else sBody=KS_EditArea.document.body.innerText;
				    break;
			   case "TEXT":
				   sBody=KS_EditArea.document.body.innerText;
				   sBody=HTMLEncode(sBody);
				break;
			   case "EDIT":
			   case "VIEW":
				  if (NewMode=="TEXT") sBody=KS_EditArea.document.body.innerText;
				   else sBody=KS_EditArea.document.body.innerHTML;
				  break;
		    }
			sBody=sBody.replace(eval("/"+ReplaceStr+InstallStr+"/g"),'/');
			sBody=sBody.replace(eval("/"+ReplaceStr+"/g"),'');
			sBody=sBody.replace(eval("/"+AdminBadStr+"/g"),'#');
		    document.all["editor_CODE"].className='ModeBarBtnOff';
	     	document.all["editor_EDIT"].className='ModeBarBtnOff';
		    document.all["editor_TEXT"].className='ModeBarBtnOff';
		    document.all["editor_VIEW"].className='ModeBarBtnOff';
		    document.all["editor_"+NewMode].className='ModeBarBtnOn';
	 switch (Style)
     { case 2:
	   case 3:
		var documentElementStr='<html>'+KS_EditArea.document.documentElement.innerHTML+'</html>';
		switch (NewMode)
		{
			case "CODE":
				KS_EditArea.document.designMode="On";
				KS_EditArea.document.open();
				KS_EditArea.document.write(documentElementStr);
				KS_EditArea.document.body.innerText=sBody;
				KS_EditArea.document.body.contentEditable="true";
				KS_EditArea.document.close();
				DisabledAllBtn(true);
				break;
			case "EDIT":
				KS_EditArea.document.designMode="On";
				KS_EditArea.document.open();
				KS_EditArea.document.write(documentElementStr);
				KS_EditArea.document.body.innerHTML=sBody;
				KS_EditArea.document.body.contentEditable="true";
				KS_EditArea.document.close();
				ShowTableBorders();
				DisabledAllBtn(false);
				break;
			case "TEXT":
				KS_EditArea.document.designMode="On";
				KS_EditArea.document.open();
				KS_EditArea.document.write(documentElementStr);
				KS_EditArea.document.body.innerText=sBody;
				KS_EditArea.document.body.contentEditable="true";
				KS_EditArea.document.close();
				DisabledAllBtn(true);
				break;
			case "VIEW":
				KS_EditArea.document.designMode="off";
				KS_EditArea.document.open();
				KS_EditArea.document.write(documentElementStr);
				KS_EditArea.document.body.innerHTML=sBody;
				KS_EditArea.document.body.contentEditable="false";
				KS_EditArea.document.close();
				DisabledAllBtn(true);
				break;
		}
		CurrMode=NewMode;
		if (NewMode!='EDIT') EmptyShowObject(true);
		else {EmptyShowObject(false);LoadEditFile(Style);}
		break;
	  default :
		    switch (NewMode)
		    {
		    	case "CODE":
				  KS_EditArea.document.designMode="On";
				  KS_EditArea.document.open();
				  KS_EditArea.document.write("<head><link href="+InstallDir+"Editor/Editor_Style.CSS type=text/css rel=stylesheet></head><body MONOSPACE>"+sBody);
				  KS_EditArea.document.body.innerText=sBody;
				  KS_EditArea.document.body.contentEditable="true";
				  LoadEditFile(Style);
				  KS_EditArea.document.close();
				  DisabledAllBtn(true);
				  break;
			    case "EDIT":
				  KS_EditArea.document.designMode="On";
				  KS_EditArea.document.open();
				  KS_EditArea.document.write("<head><link href="+InstallDir+"Editor/Editor_Style.CSS type=text/css rel=stylesheet></head><body MONOSPACE>"+sBody);
			      KS_EditArea.document.body.contentEditable="true";
				  KS_EditArea.document.execCommand("2D-Position",true,true);
				  KS_EditArea.document.execCommand("MultipleSelection", true, true);
				  KS_EditArea.document.execCommand("LiveResize", true, true);
				  LoadEditFile(Style);
				  KS_EditArea.document.close();
				  ShowTableBorders();
				  DisabledAllBtn(false);
				  break;
			    case "TEXT":
				  KS_EditArea.document.designMode="On";
				  KS_EditArea.document.open();
			      KS_EditArea.document.write("<head><link href="+InstallDir+"Editor/Editor_Style.CSS type=text/css rel=stylesheet></head><body MONOSPACE>"+sBody);
				  KS_EditArea.document.body.innerText=sBody;
				  KS_EditArea.document.body.contentEditable="true";
				  LoadEditFile(Style);
				  KS_EditArea.document.close();
				  DisabledAllBtn(true);
				  break;
			    case "VIEW":
				  KS_EditArea.document.designMode="off";
				  KS_EditArea.document.open();
				  KS_EditArea.document.write("<head><link href="+InstallDir+"Editor/Editor_Style.CSS type=text/css rel=stylesheet></head><body MONOSPACE>"+sBody);
				  KS_EditArea.document.body.contentEditable="false";
				  KS_EditArea.document.close();
				  DisabledAllBtn(true);
				break;
		    }
		  CurrMode=NewMode;
		  EmptyShowObject(true);
    }
   }
	KS_EditArea.focus();
}
function EmptyShowObject(Flag)
{
	document.all.ShowObject.disabled=Flag;
}
	// 替换特殊字符
function HTMLEncode(text){
	text = text.replace(/&/g, "&amp;") ;
	text = text.replace(/"/g, "&quot;") ;
	text = text.replace(/</g, "〈") ;
	text = text.replace(/>/g, "〉") ;
	text = text.replace(/'/g, "&#146;") ;
	text = text.replace(/\ /g,"&nbsp;");
	text = text.replace(/\n/g,"<br>");
	text = text.replace(/\t/g,"&nbsp;&nbsp;&nbsp;&nbsp;");
	return text;
}
function ShowMouseRightMenu(event,Style)
{
	var width=0;
	var height=0;
	var lefter=event.clientX;
	var topper=event.clientY;
	var ObjPopDocument=DocPopupContextMenu.document;
	var ObjPopBody=DocPopupContextMenu.document.body;
	var MenuStr='';
	width+=138;
	height+=120;
		//判断是否是文章管理调用,若是增加一些功能
   if ((Style==1)&&(CurrMode=='EDIT'))
   	{	
       //判断是否有图片选中,有则初始化快捷菜单
       if (ImageSelected())
		{
         height+=16;
	     MenuStr+=GetMenuFunRowStr("SetPicArticle()", "设置为图片文章","Pic_Aritlce.gif");
		 MenuStr+=GetMenuSplitRowStr();			
		}
		//判断是否有选中的文本,有则初始化快捷菜单
        var RangeType = KS_EditArea.document.selection.type;	
        if (RangeType=="Text")  
	    { height+=155;
          MenuStr+=GetMenuFunRowStr("SetNewsAttribute(1)", "设置为正标题","News_Title.gif");
		  MenuStr+=GetMenuFunRowStr('SetNewsAttribute(2)','设置为副标题','News_SubTitle.gif');
    	  MenuStr+=GetMenuFunRowStr('SetNewsAttribute(3)','设置为关键字','News_Keyword.gif');
		  MenuStr+=GetMenuSplitRowStr();
		  MenuStr+=FormatMenuRow("bold", "加粗","bold.gif");
		  MenuStr+=FormatMenuRow("italic", "斜体","italic.gif");
		  MenuStr+=FormatMenuRow("underline", "下划线","underline.gif");
	      MenuStr+=GetMenuFunRowStr("TextColor()", "文字颜色","TextColor.gif");
		  MenuStr+=GetMenuFunRowStr("TextBGColor()", "文字背景色","fgbgcolor.gif");
		  MenuStr+=GetMenuSplitRowStr();
	   }
	}
    MenuStr+=FormatMenuRow("cut", "剪切","Cut.gif");
	MenuStr+=FormatMenuRow("copy", "复制","Copy.gif");
	MenuStr+=FormatMenuRow("paste", "粘贴","Paste.gif");
	MenuStr+=FormatMenuRow("delete", "删除","Del.gif");
	MenuStr+=GetMenuSplitRowStr();

	MenuStr+=FormatMenuRow("selectall", "全选","SelectAll.gif");
	MenuStr+=GetMenuFunRowStr("SearchStr('"+InstallDir+"')",'查找替换...','find.gif');
	MenuStr="<TABLE border=0 cellpadding=0 cellspacing=0 width=111><tr><td width=111 class=RightBg><TABLE border=0 cellpadding=0 cellspacing=0 style=\"font-size:9pt;\">"+MenuStr
	MenuStr=MenuStr+"<\/TABLE><\/td><\/tr><\/TABLE>";
	MenuStr="<TABLE Border=0 cellpadding=0 cellspacing=0 class=Menu width=138><tr><td width=20 bgcolor=#0072BC><img src="+InstallDir+"Editor/images/about.gif><\/td><td>"+MenuStr+"<\/td><\/tr><\/TABLE>"
	ObjPopDocument.open();
	ObjPopDocument.write("<head><link href='"+InstallDir+"Editor/ContextMenu.css' type=\"text/css\" rel=\"stylesheet\"></head><body scroll=\"no\" onConTextMenu=\"event.returnValue=false;\">"+MenuStr);
	ObjPopDocument.close();
	height+=5;
	if(lefter+width > document.body.clientWidth) lefter=lefter-width;
	DocPopupContextMenu.show(lefter, topper, width, height, KS_EditArea.document.body);
	return false;
}
//返用户自定义的方法或函数
function GetMenuFunRowStr(FunStr,MenuDescription,MenuImage)
{  var MenuFunRowStr='';
	MenuFunRowStr="<tr><td align=center valign=middle><TABLE border=0 cellpadding=0 cellspacing=0 width=111><tr><td valign=middle height=18 class=MouseOut onMouseOver=this.className='MouseOver'; onMouseOut=this.className='MouseOut';";
	MenuFunRowStr+=" onClick=\"parent."+FunStr+";parent.DocPopupContextMenu.hide();\">";
	if (MenuImage!="")
	{
		MenuFunRowStr+="&nbsp;<img border=0 src='"+InstallDir+"editor/images/"+MenuImage+"' align=absmiddle>&nbsp;";
	}
	else
	{
		MenuFunRowStr+="&nbsp;";
	}
	MenuFunRowStr+=MenuDescription+"<\/td><\/tr><\/TABLE><\/td><\/tr>";
	return MenuFunRowStr;

}
//分隔线
function GetMenuSplitRowStr()
{
  	var MenuSplitRowStr='';
    MenuSplitRowStr="<tr><td height=1 bgcolor=#cccccc></td></tr>";
	return  MenuSplitRowStr;
}
//返回系统方法或函数
function GetMenuRowStr(DisabledStr, MenuOperation, MenuImage, MenuDescripion)
{
	var MenuRowStr='';
	MenuRowStr="<tr><td align=center valign=middle><TABLE border=0 cellpadding=0 cellspacing=0 width=111><tr "+DisabledStr+"><td valign=middle height=18 class=MouseOut onMouseOver=this.className='MouseOver'; onMouseOut=this.className='MouseOut';";
	if (DisabledStr==''){
		MenuRowStr += " onclick=\"parent."+MenuOperation+";parent.DocPopupContextMenu.hide();\"";
	}
	MenuRowStr+=">"
	if (MenuImage!="")
	{
		MenuRowStr+="&nbsp;<img border=0 src='"+InstallDir+"editor/images/"+MenuImage+"' align=absmiddle "+DisabledStr+">&nbsp;";
	}
	else
	{
		MenuRowStr+="&nbsp;";
	}
	MenuRowStr+=MenuDescripion+"<\/td><\/tr><\/TABLE><\/td><\/tr>";
	return MenuRowStr;

}
function FormatMenuRow(MenuStr,MenuDescription,MenuImage)
{
	var DisabledStr='';
	var ShowMenuImage='';
	if (!KS_EditArea.document.queryCommandEnabled(MenuStr))
	{
		DisabledStr="disabled";
	}
	var MenuOperation="Format('"+MenuStr+"')";
	if (MenuImage)
	{
		ShowMenuImage=MenuImage;
	}
	return GetMenuRowStr(DisabledStr,MenuOperation,ShowMenuImage,MenuDescription)
}
function SearchObject()
{
	UpdateToolbar();
}
function MouseRightMenuItem(CommandString, CommandId)
{
	this.CommandString = CommandString;
	this.CommandId = CommandId;
}
function GetKS_EditAreaSelectionType()
{
	return KS_EditArea.document.selection.type;
}
var ContextMenu = new Array();
function ExeEditAttribute(InstallDir)
{
	OpenWindow(InstallDir+'Editor/AttributeWindow.asp',360,120,window)
	KS_EditArea.focus();
}
function InsertHTMLStr(Str)
{
	KS_EditArea.focus();
	if (KS_EditArea.document.selection.type.toLowerCase() != "none")
	{
		KS_EditArea.document.selection.clear() ;
	}
	KS_EditArea.document.selection.createRange().pasteHTML(Str) ; 
	KS_EditArea.focus();
	ShowTableBorders();
}
function QueryCommand(CommandID)
{
	var State=KS_EditArea.QueryStatus(CommandID)
	if (State==3) return true;
	else return false;
}
function Format(Operation,Val) 
{
	KS_EditArea.focus();
	if (Val=="RemoveFormat")
	 {
		Operation=Val;

⌨️ 快捷键说明

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