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

📄 editor.js

📁 功能齐全
💻 JS
📖 第 1 页 / 共 2 页
字号:
var isHTMLMode=false
var iframeobj=new Array();
var selectedobj=new Array("TABLE","TD","BODY");
var winbtn=new Array('sty_new','sty_save','sty_cut','sty_copy','sty_paste','sty_delete','sty_undo','sty_redo','sty_table','sty_image','sty_wlink','sty_Anchor','sty_hr','sty_bold','sty_italic','sty_underline','sty_aleft','sty_center','sty_aright','sty_numlist','sty_bullist','sty_outdent','sty_indent','sty_help');
     //定义所有风格按钮
var temp_winbtn=new Array();//记录风格按钮此次操作之前的className 
var temp_upobj;

function ReturnNumber(str,thekind) //每次输入都要检查是否合法的数字
{
  if (thekind=="1")var newPar=/^[0-9]{0,}%{0,1}$/;
  if (thekind=="2")var newPar=/^[0-9]{0,}([0-9]{0,}|px)$/;
  //if (thekind==3) newPar=/^[0-9]{1,}$/;
  //str=str+String.fromCharCode(event.keyCode);
  if (str=="%"||str=="px") return false;
  return newPar.test(str);
}

function setEnable(objs){//让元素可用
	var Obj=objs.split(",");
	for(i=0;i<Obj.length;i++){
	  object=eval("document.all."+Obj[i]);
	  object.disabled=false;
	}
}

function setDisable(objs){//让元素不可用
	var Obj=objs.split(",");
	for(i=0;iObj.length;i++){
	  object=eval("document.all."+Obj[i]);
	  object.disabled=true;
	}
   
}
//===============================================================================
function SetFormat(obj,what,value){
  //findiframeobj();
  if (arguments[3]){
    if (!ReturnNumber(value,arguments[3]))return;
  }
  if (eval('iframeobj["'+obj+'"]')){
    if (value)eval('iframeobj["'+obj+'"].'+what+'=value');
	else eval('iframeobj["'+obj+'"].removeAttribute("'+what+'")');
	if (what=="align"||what=="vAlign")eval('iframeobj["'+obj+'"].focus()');
  }
}
//===============================================================================
function insertRow(){
   if(iframeobj["TD"]&&iframeobj["TD"].parentElement&&iframeobj["TD"].parentElement.parentElement.parentElement){
	  var newRow=iframeobj["TD"].parentElement.parentElement.parentElement.insertRow(iframeobj["TD"].parentElement.rowIndex);
	  for(i=0;i<iframeobj["TD"].parentElement.cells.length;i++){
		 var newCell=newRow.insertCell();
		 newCell.style.backgroundColor=iframeobj["TD"].style.backgroundColor;
	  }
   }
}

function deleteRow(){
   if(iframeobj["TD"]&&iframeobj["TD"].parentElement&&iframeobj["TD"].parentElement.parentElement.parentElement){
      iframeobj["TD"].parentElement.parentElement.parentElement.deleteRow(iframeobj["TD"].parentElement.rowIndex);
      iframeobj["TD"]="";
   }
}

function insertCell(){
   if(iframeobj["TD"]&&iframeobj["TD"].parentElement&&iframeobj["TD"].parentElement.parentElement.parentElement){
	  for(i=0;iiframeobj["TD"].parentElement.parentElement.parentElement.rows.length;i++){
		var newCell=iframeobj["TD"].parentElement.parentElement.parentElement.rows(i).insertCell();
	    newCell.style.backgroundColor=iframeobj["TD"].style.backgroundColor;
	  }
  }
}

function deleteCell(){
	if(iframeobj["TD"]&&iframeobj["TD"].parentElement.parentElement.parentElement){
	  var CurTab=iframeobj["TD"].parentElement.parentElement.parentElement;
	  var CurCell=iframeobj["TD"];
	      for(i=0;i<CurTab.rows.length;i++) {
			  CurTab.rows(i).deleteCell(CurCell.cellIndex);
		  }
		  iframeobj["TD"]="";
	}
}

function ansyncTD(){//是否所有单元格设为同一背景色
    if(document.all.ansyncTD.checked){
	   var CurTab=iframeobj["TD"].parentElement.parentElement.parentElement;
	   if(CurTab){
	      for(k=0;kCurTab.cells.length;k++){
		     CurTab.cells[k].style.backgroundColor=document.all.TDBG.value;
		  }
	   }
	}
}

function Save(form){
   if(theiframe.document.body.innerText==""){
      alert("请输入内容");theiframe.focus();return false;
   }
   var saveContent=theiframe.document.body.innerHTML;
   saveContent=saveContent.replace("<formx","form");
   saveContent=saveContent.replace("</formx","/form");
   form.Content.value=saveContent;
   opener.document.myform.words.value=saveContent;
   //form.submit();
}

function Reset(form){
  form.Content.value="";
  theiframe.document.body.innerHTML=document.all.oldContent.innerHTML;
}

function web_getCol() {
	var retCol="";
	var bascol = window.showModalDialog("editor/selcolor.html","","dialogWidth:18;dialogHeight:16;dialogTop:50;dialogLeft:250;status:no;");
	if (bascol != null&&bascol != "undefined") {
		retCol = bascol;
	}
    if(retCol.length>=6){
		var Hclr = retCol.charAt(0);
		if( Hclr != "#" )
			retCol = "#" + retCol;
		return retCol;
	} else return null;
 }

function format(what,opt){
	if (opt=="removeFormat"){
		what=opt;
		opt=null;
	}
	if (opt==null){
	  if (what=="bold"||what=="italic"||what=="underline"){
	    if (theiframe.document.selection.createRange().text!="")theiframe.document.execCommand(what);
	  }
	  else theiframe.document.execCommand(what);
	}
	else theiframe.document.execCommand(what,"",opt);

	theiframe.focus();
}

function setMode(){
  isHTMLMode = document.all.htmlMode.checked;
  if (isHTMLMode) {
    document.all.insertPro.style.display = "none";
	if (document.all.formatPro.style.display == "")document.all.formatPro.style.display = "none";
	if (document.all.TabPro.style.display == "")document.all.TabPro.style.display = "none";
	if (document.all.TDPro.style.display == "")document.all.TDPro.style.display = "none";
	if (document.all.ImgPro.style.display == "")document.all.ImgPro.style.display = "none";
	theiframe.document.body.innerText=theiframe.document.body.innerHTML;
	theiframe.document.body.style.fontFamily = "monospace"
	theiframe.document.body.style.fontSize = "10pt"
  } 
  else {
    document.all.insertPro.style.display = "";
	//document.all.formatPro.style.display = "";
    theiframe.document.body.innerHTML=theiframe.document.body.innerText;
    theiframe.document.body.style.fontFamily = ""
    theiframe.document.body.style.fontSize =""
  }
  //theiframe.focus();
}
function beforeinsert(){
	if (theiframe.document.selection.type!="Control")return true;
	else if (!confirm("不能在该对象上插入对象。\n要删除该对象,并插入新对象,请点确定。\n要重置插入点,请按取消。"))return false;
	else {
	    theiframe.document.selection.clear();
		return true;
   }
}
function CreateLink(what){
  if (arguments.length==1){
	if (!beforeinsert())return false;
	theiframe.document.execCommand(what, true);
	document.all.sty_target[0].disabled=false;
	document.all.sty_target[1].disabled=false;
  }
  else if (arguments[1]){
    theiframe.document.execCommand(what,'',arguments[1]);
	document.all.sty_target[0].disabled=false;
	document.all.sty_target[1].disabled=false;
  }
  else {
    //findiframeobj();
	//obj=theiframe.document.selection.createRange().parentElement();
    if (iframeobj["A"]){
	  iframeobj["A"].removeNode();
	  document.all.sty_target[0].selectedIndex=0;
	  document.all.sty_target[0].disabled=true;
	  document.all.sty_target[1].selectedIndex=0;
	  document.all.sty_target[1].disabled=true;
	}
  }
}
function CreateLink_target(what){
  findiframeobj(theiframe.document.selection.createRange().parentElement());
  if (iframeobj["A"]){
    if (what=="")iframeobj["A"].removeAttribute('target');
	else iframeobj["A"].target=what;
  }
  else {
    window.document.all.sty_target[0].selectedIndex='0';
    window.document.all.sty_target[1].selectedIndex='0';
  }
}
function setObjColor(objsrc,obj2src){
	var arr=web_getCol();
	if (arr != null){
	  eval("document.all."+objsrc+".value=arr");
	  eval("document.all."+obj2src+".style.backgroundColor=arr");
	  if(objsrc=="sty_fontcolor_input"){
		  if (theiframe.document.selection.createRange().text!=""){
		    format('forecolor', arr);
		  }
		}
        else if(objsrc=="TabBG"){
          if(iframeobj["TABLE"]!=null) iframeobj["TABLE"].style.backgroundColor=arr;
        }
        else if(objsrc=="TDBG"){
          if(iframeobj["TD"]!=null) iframeobj["TD"].style.backgroundColor=arr;
		  ansyncTD();
        }
	}
	else theiframe.focus();
}
function setObjColor_1(objsrc,obj2src){
	eval("document.all."+obj2src+".style.backgroundColor=document.all."+objsrc+".value");
	if (eval("document.all."+objsrc+".value")){
	  if(objsrc=="sty_fontcolor_input"){
		  if (theiframe.document.selection.createRange().text!=""){
		    format('forecolor', eval("document.all."+objsrc+".value"));
		  }
		}
        else if(objsrc=="TabBG"){
          if(iframeobj["TABLE"]!=null) iframeobj["TABLE"].style.backgroundColor=eval("document.all."+objsrc+".value");
        }
        else if(objsrc=="TDBG"){
          if(iframeobj["TD"]!=null) iframeobj["TD"].style.backgroundColor=eval("document.all."+objsrc+".value");
		  ansyncTD();
        }
	}
	else {
	  if(objsrc=="sty_fontcolor_input"&&iframeobj["FONT"])iframeobj["FONT"].removeAttribute('color')
      else if(objsrc=="TabBG"&&iframeobj["TABLE"])iframeobj["TABLE"].style.backgroundColor="";
	  else if(objsrc=="TDBG"&&iframeobj["TD"])iframeobj["TD"].style.backgroundColor="";
	}
}

function fortable(){
  if (!beforeinsert())return false;
  theiframe.focus();
  var string;
  TablePro=window.showModalDialog("editor/table.html","","dialogWidth:27;dialogHeight:13;dialogTop:50;dialogLeft:250;status:no;");
  if (TablePro!=null){
	 var string="<table  border='"+TablePro[5]+"' width='"+TablePro[4]+"' cellspacing='"+TablePro[2]+"' cellpadding='"+TablePro[3]+"'>";
     for(i=1;i<=TablePro[0];i++){
			string=string+"<tr>";
			for(j=1;j<=TablePro[1];j++){
			   string=string+"<td></td>";
			}
			string=string+"</tr>";
		}
		 string=string+"</table>";
		 theiframe.document.selection.createRange().pasteHTML(string);
  } else theiframe.focus();
}

function insertimg()
{
//window.open('editor/Image_index.php','','width=500,height=230');
if (!beforeinsert())return false;
var arr = showModalDialog("editor/insertimg.htm", "", "dialogWidth:28;dialogHeight:10;dialogTop:50;dialogLeft:250;status:no;");
if (arr)format('InsertImage',arr);
else theiframe.focus();
}

function insert_anchor(){
if (!beforeinsert())return false;
var arr = showModalDialog("editor/insertanchor.htm", "", "dialogWidth:300px;dialogHeight:110px;dialogTop:50;dialogLeft:250;status:no;");
if (arr)theiframe.document.selection.createRange().pasteHTML("<a name='"+arr+"'></a>");
else theiframe.focus();
}
//以下函数设置如同windows一样的按钮风格
function doSelectClick(str, el) {
	if (el.selectedIndex != 0){
		//if (el.id == "special_type")specialtype(el.options[Index].value);
		format(str,el.options[el.selectedIndex].value);
	}
	else {
	  if (iframeobj["PRE"])iframeobj["PRE"].removeNode();
	  else if (iframeobj["H1"])iframeobj["H1"].removeNode();
	  else if (iframeobj["H2"])iframeobj["H2"].removeNode();
	  else if (iframeobj["H3"])iframeobj["H3"].removeNode();
	  else if (iframeobj["H4"])iframeobj["H4"].removeNode();
	}
}

function specialtype(el){
	var strHTML;
	  if (el.selectedIndex==0){
	    if (iframeobj["SUP"])iframeobj["SUP"].removeNode();
	    else if (iframeobj["SUB"])iframeobj["SUB"].removeNode();
	    else if (iframeobj["DEL"])iframeobj["DEL"].removeNode();
	    else if (iframeobj["BLINK"])iframeobj["BLINK"].removeNode();
	    else if (iframeobj["BIG"])iframeobj["BIG"].removeNode();
	    else if (iframeobj["SMALL"])iframeobj["SMALL"].removeNode();
	  }
	  else {

⌨️ 快捷键说明

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