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

📄 editor.js

📁 php 开发的内容管理系统
💻 JS
📖 第 1 页 / 共 2 页
字号:
						value=(bodyAttrs[i]);
					
						//correct hex colour values
						value=value.replace(/#([0-9]|[a-f])/gi, "$1");
					
						//delete non necessary quotes 
						//(funny, if I don't delete quotes in colour values, gecko lies)
						value=value.replace(/['"](.*)['"]/gi, "$1");
						bodyHTML.setAttribute(attribute,value,0);
					}
				}
			}
		}
		else doc.body.innerHTML = text;

		//show editor
		document.getElementById("iframe"+id).style.display="block";
		document.getElementById("toolbar"+id).style.display="block";
		//hide textarea
		document.getElementById(id).style.display="none";
		//enable design mode again for gecko
		if (!isie){doc.designMode="On";doc.execCommand("usecss",false,true);}
	}
};

function getAnchors(id)
{
	text=XK_codeCleaner(document.getElementById("iframe"+id).contentWindow.document.body.innerHTML);
	var result=new Array(); 
	result=text.match(/<a name=\"(.*?)\"><\/a>/gi);
	return result;
}

function XK_floatingToolbar(id,skin)
{
	var ft=JSFX_FloatDiv("toolbar"+id, 200,200);
	if (document.getElementById("toolbar"+id).className!=skin+"floatingToolBar")
	{	
		XK_hideMenus();		
		document.getElementById("toolbar"+id).className=skin+"floatingToolBar";
		document.getElementById("maximizeButton"+id).style.display="none";
		ft.floatIt();
	}
	else
	{
		document.getElementById("toolbar"+id).className=skin+"toolbarBackCell";
		document.getElementById("maximizeButton"+id).style.display="";
		ft.cancelFloat();

	}
};

function XK_getImg(id) 
{
	var doc= document.getElementById("iframe"+id).contentWindow;
	if(isie)
	{
		if (doc.document.selection.type == 'Control')
    	{ 
			var tControl = doc.document.selection.createRange();
			if (tControl(0).tagName.toLowerCase() == 'img') return(tControl(0));
    		else return(null);
    	}
			else
    		{
      			return(null);
    		}
    }
    else
    {
    	var range = doc.getSelection().getRangeAt(0);
		var container = range.startContainer;
		var pos = range.startOffset;
		var imageNode = null;
	
		if (container.tagName) 
		{
			var images = container.getElementsByTagName('IMG');
			if (container.childNodes[pos].tagName == 'IMG') node = container.childNodes[pos];
			return node;
		}
		else return; 
    }   	
};

function XK_imageProps(id,img)
{
    var node=XK_getImg(id);  
    if(node==null)return; 
	
	if(img!=null)
	{
    	if(img["alt"])node.setAttribute('alt',img["alt"]);
		if(img["src"])node.setAttribute('src',img["src"]);
		if(img["width"]){node.style.width = img["width"];node.removeAttribute('width',0);}
		if(img["height"]){node.style.height = img["height"];node.removeAttribute('height',0);}		
		if(img["vspace"])node.vspace = img["vspace"];else node.removeAttribute('vspace',0);
		if(img["hspace"])node.hspace = img["hspace"];else node.removeAttribute('hspace',0);
		if(img["align"])node.setAttribute('align',img["align"]);else node.removeAttribute('align',0);
		if(img["className"])node.className = img["className"];else node.removeAttribute('className',0);
		
		//margin style
		node.style.marginLeft			= img["marginLeft"];
		node.style.marginRight			= img["marginRight"];
		node.style.marginTop			= img["marginTop"];
		node.style.marginBottom			= img["marginBottom"];
		
		//borders style
      	node.style.borderLeftStyle 		= img["borderLeftStyle"];
      	node.style.borderRightStyle 	= img["borderRightStyle"];
      	node.style.borderTopStyle 		= img["borderTopStyle"];
      	node.style.borderBottomStyle 	= img["borderBottomStyle"]; 	
      	
      	//borders Width
      	node.style.borderLeftWidth 		= img["borderLeftWidth"];
      	node.style.borderRightWidth 	= img["borderRightWidth"];
      	node.style.borderTopWidth 		= img["borderTopWidth"];
      	node.style.borderBottomWidth 	= img["borderBottomWidth"];
			
		//borders Color
      	node.style.borderLeftColor 		= img["borderLeftColor"];
      	node.style.borderRightColor 	= img["borderRightColor"];
      	node.style.borderTopColor 		= img["borderTopColor"];
      	node.style.borderBottomColor 	= img["borderBottomColor"];

		return;
	}
	else
	{
    	var image 				= 	new Object();
    	image["alt"]			=	node.getAttribute('alt');
		image["src"]			=	node.getAttribute('src');
		image["width"]			=	node.width;	
		image["height"]			=	node.height;
		image["vspace"]			=	node.vspace;	
		image["hspace"]			=	node.hspace;
		image["className"]		=	node.className;
		
		image["align"]			=	node.getAttribute('align');
		image["marginLeft"]		=	node.style.marginLeft;
		image["marginRight"]	=	node.style.marginRight;
		image["marginTop"]		=	node.style.marginTop;
		image["marginBottom"]	=	node.style.marginBottom;
		
		//borders style
      	image["borderLeftStyle"] 	= node.style.borderLeftStyle; 
    	image["borderRightStyle"]	= node.style.borderRightStyle;
      	image["borderTopStyle"]		= node.style.borderTopStyle;
      	image["borderBottomStyle"] 	= node.style.borderBottomStyle;  	
      	
      	//borders Width
		image["borderLeftWidth"]	= node.style.borderLeftWidth; 
		image["borderRightWidth"]	= node.style.borderRightWidth;
		image["borderTopWidth"]		= node.style.borderTopWidth;
		image["borderBottomWidth"]	= node.style.borderBottomWidth;
				
		//borders Color
		if(isie)
		{
			image["borderLeftColor"]	= node.style.borderLeftColor;
			image["borderRightColor"]	= node.style.borderRightColor;
			image["borderTopColor"] 	= node.style.borderTopColor; 
			image["borderBottomColor"]	= node.style.borderBottomColor;
		}
		else
		{
			image["borderLeftColor"]	= (node.style.borderLeftColor)?XK_RgbToHex(node.style.borderLeftColor):node.style.borderLeftColor;			
			image["borderRightColor"]	= (node.style.borderRightColor)?XK_RgbToHex(node.style.borderRightColor):node.style.borderRightColor;
			image["borderTopColor"] 	= (node.style.borderTopColor)?XK_RgbToHex(node.style.borderTopColor):node.style.borderTopColor; 
			image["borderBottomColor"]	= (node.style.borderBottomColor)?XK_RgbToHex(node.style.borderBottomColor):node.style.borderBottomColor;
		}


 		return (image);
 	}
    
};

function XK_hideToolbar(id,url)
{
	var doc=document.getElementById("buttons"+id).style.display;
	if(doc=="none")
	{
		document.getElementById("buttons"+id).style.display="";
	}
	else
	{ 
		document.getElementById("buttons"+id).style.display="none";
	}
};

//Shows/Hides a Div Layer
function XK_showHideDiv(id,buttonId,divId)
{
	var divid=divId+id;
	buttonElement=document.getElementById(buttonId+id);
	document.getElementById(divid).style.left=XK_getOffsetLeft(buttonElement) + "px";
	document.getElementById(divid).style.top=(XK_getOffsetTop(buttonElement) + buttonElement.offsetHeight) + "px";
	if(document.getElementById(divid).style.display=="none")
	{
		document.getElementById(divid).style.display="";
	}
	else document.getElementById(divid).style.display="none";
};



function XK_hideMenus()
{
  var men=new Array();
  
  if(!isie)men = document.getElementsByName("XoopsKToolbarDivs");
  //stupid iexplore, getElementsByName doesn't run at all
  else men = getElementsByNameAndTag("XoopsKToolbarDivs", "div");
  for (var i=0; i < men.length; i++) 
  {
      try{document.getElementById(men[i].id).style.display="none";}catch(e){};  
  }
}

//USEFUL FUNCTIONS

var timeout;
function JSFX_FloatDiv(id, sx, sy)
{
	var ns = (navigator.appName.indexOf("Netscape") != -1);
	var d = document;
	var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	var px = document.layers ? "" : "px";
	window[id + "_obj"] = el;
	if(d.layers)el.style=el;
	el.cx = el.sx = sx;el.cy = el.sy = sy;
	el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};
	el.floatIt=function()
	{
		var pX, pY;		
		pX = (this.sx >= 0) ? 0 : ns ? innerWidth : 
		document.documentElement && document.documentElement.clientWidth ?document.documentElement.clientWidth : document.body.clientWidth;
		pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ?document.documentElement.scrollTop : document.body.scrollTop;
		if(this.sy<0) pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
		this.cx += (pX + this.sx - this.cx)/8;this.cy += (pY + this.sy - this.cy)/2;
		this.sP(this.cx, this.cy);		
		timeout=setTimeout(this.id + "_obj.floatIt()", 40);
	};
	el.cancelFloat=function()
	{
		clearTimeout(timeout);
	};
	
	return el;
};

function XK_AppendCss(id,css,name)
{
	if (css=="")return false;
	var doc = document.getElementById("iframe"+id).contentWindow.document;
	var stylesheet = doc.createElement( 'link' ) ;
	stylesheet.setAttribute('href',css);
	stylesheet.setAttribute('rel','stylesheet');
	stylesheet.setAttribute('type','text/css');
	stylesheet.setAttribute('id','name'+id);
	doc.getElementsByTagName('head')[0].appendChild( stylesheet );
};

function XK_DeleteCss(id,name)
{
	var doc = document.getElementById("iframe"+id).contentWindow.document;
	var node=doc.getElementById('name'+id);
	if (node.parentNode)
   	node.parentNode.removeChild(node);
   	//stupid iexplore, doesn't refresh
   	if(isie)doc.body.innerHTML=doc.body.innerHTML;
};

function getElementsByNameAndTag(name, tag) 
{
	var tam, list, tags;         
	list = new Array();
	tam = 0;
	tags = document.getElementsByTagName(tag);
	for(i = 0; i<tags.length; i++) 
	{
		if (tags[i].getAttribute("name")==name) 
		list[tam++] = tags[i];        
    }
	return list;
}

function XK_attachEvent(doc,event,func)
{
	if (isie)doc.attachEvent("on"+event, func, true);
	else doc.addEventListener(event, func, true);
}

function XK_createRange(id)
{
	if(isie)
		{
       	 //retrieve selected range
       	 var sel=document.getElementById("iframe"+id).contentWindow.document.selection;
       	 if(sel!=null)
			{
       	     var newselectionRange=sel.createRange();
       	     newselectionRange.select();
			}
    	return (newselectionRange);
		}
		
	else 
	{	
		range=document.createRange();
		return (range);
	}
		
	selection = doc.window.getSelection();       
	doc.focus();
};

//doesn't run well if used with elements into a div with relative position
function XK_getOffsetLeft(elm) {
	var mOffsetLeft = elm.offsetLeft;
	var mOffsetParent = elm.offsetParent;
	
	while(mOffsetParent) {
		mOffsetLeft += mOffsetParent.offsetLeft;
		mOffsetParent = mOffsetParent.offsetParent;
	}
	return mOffsetLeft;
};

function XK_getOffsetTop(elm) {
	var mOffsetTop = elm.offsetTop;
	var mOffsetParent = elm.offsetParent;
	
	while(mOffsetParent){
		mOffsetTop += mOffsetParent.offsetTop;
		mOffsetParent = mOffsetParent.offsetParent;
	}
	return mOffsetTop;
};

function XK_openPopup(url,name,width,height) 
{
	if(isie)
	{
		var Iwidth=width+30;
		var Iheight=height+40;
		var options = "dialogwidth:" + Iwidth +"px; dialogheight:" + Iheight +"px;top= "+(screen.height-height)/2+"px;left= "+(screen.width-width)/2+"px;toolbar=no;location=no;directories=no;status=no;menubar=no;scrollbars=no;resizable=no;copyhistory=no;";
		var new_window = window.showModalDialog(url, self, options);	
	}
	else 
	{
		var options = "width=" + width + ",height=" + height + ",top= "+(screen.height-height)/2+"px,left= "+(screen.width-width)/2+"px,dependable=yes, modal=yes, toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no";
		var new_window = window.open(url, name, options);
	}
};

//inserts html into iframe
function XK_insertHTML(html,id) 
{
	var doc= document.getElementById("iframe"+id).contentWindow;
	var range= XK_createRange(id);
	doc.focus();
    if (isie) 
    {
        try {
            	range.pasteHTML(html); 
				range.select();
				range.moveEnd("character", 1);
				range.moveStart("character", 1);
				range.collapse(false);
        	} catch (e) {}
    } 
    else 
    {
        selection = doc.window.getSelection();       
        doc.focus();

        if (selection) 
        {
            try{range = selection.getRangeAt(0)}catch(e){};
        } 
        else range = doc.document.createRange();

        var fragment = doc.document.createDocumentFragment();
        var div = doc.document.createElement("div");
        div.innerHTML = html;

        while (div.firstChild) {
            fragment.appendChild(div.firstChild);
        }

        selection.removeAllRanges();
        range.deleteContents();

        var node = range.startContainer;
        var pos = range.startOffset;

        switch (node.nodeType) {
            case 3:
                if (fragment.nodeType == 3) {
                    node.insertData(pos, fragment.data);
                    range.setEnd(node, pos + fragment.length);
                    range.setStart(node, pos + fragment.length);
                } else {
                    node = node.splitText(pos);
                    node.parentNode.insertBefore(fragment, node);
                    range.setEnd(node, pos + fragment.length);
                    range.setStart(node, pos + fragment.length);
                }
                break;

            case 1:
                node = node.childNodes[pos];
                if(node==null)break;
                node.parentNode.insertBefore(fragment, node);                 
                range.setEnd(node, pos + fragment.length);
                range.setStart(node, pos + fragment.length);
                break;
        }
        selection.addRange(range);
    }
};

function XK_over(id,color)
{
	document.getElementById('colortextf'+id).style.backgroundColor =color;
	document.getElementById('showc'+id).value =color;
};

//returns selected text on iframe
function XK_getSelectedText(id)
{
	var newselectionRange= XK_createRange(id);
	if(isie)
	{	
		var text=newselectionRange.htmlText;
    }
	else
	{
		var e = document.getElementById("iframe"+id);
		var text = e.contentWindow.getSelection();
	}
	return text;
};

//to know if a range is inside a tag for iexplore
function XK_isInsideThisTag(id,tagname)
{
	if (isie)
	{
		var range= XK_createRange(id);
	    var element = range.parentElement();
	    var tag = element.tagName.toLowerCase();
	    while ((tag!="body") && (tag!=tagname.toLowerCase()))
	    {
		   element = element.parentElement;
		   tag = element.tagName.toLowerCase();
	    }
	    if (tag==tagname.toLowerCase()) return (tag);
	    else return false;
	}
};

function XK_cancelBubble(event) 
{
	if(!isie){event.preventDefault();event.stopPropagation();}
	else{event.cancelBubble = true;event.returnValue = false;} 
};

//THE END.
//Note: funny liar browsers

// used by system_imagemanager.html
function XoopsEditor_InsertImage(id,src,alt,align)
{
	return XK_InsertImage(id,src,alt,align);
}

⌨️ 快捷键说明

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