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

📄 script_editor.js

📁 IBM RSA下的JSF开发示例
💻 JS
📖 第 1 页 / 共 5 页
字号:
function IBM_RTE_undo(editorName){	if (backup.length != 1){		if(index == 0) 			return;		if(flag == false)		IBM_RTE_backup(editorName);	 	IBM_RTE_getDocument(editorName).body.innerHTML = backup[index - 1];		index = index - 1;	}	else{	 if(flag == false){		IBM_RTE_backup(editorName);// takes care of first backup if triggers not used		IBM_RTE_getDocument(editorName).body.innerHTML = "";				index = index - 1;		}	}		 flag = index + 1;}function IBM_RTE_redo(editorName){		if(index == backup.length - 1) return;	//end of backup array	IBM_RTE_getDocument(editorName).body.innerHTML = backup[index + 1];	index = index + 1;	flag 	  = index + 1;}function IBM_RTE_delayedBak() { if(backup[backup.length - 1] == "") IBM_RTE_backup(editorNameSaved);  else   if(IBM_RTE_getDocument(editorNameSaved).body.innerHTML != backup[backup.length - 1])    IBM_RTE_backup(editorNameSaved);}function IBM_RTE_printBackup(){	for(var i=0; i <= index; i++)	 alert("<<" + i + ">>  " + backup[i]);}function IBM_RTE_doAccessibleCompliant(editorName, buttonElement, locale, images, directory, isBidi) {        IBM_RTE_getWindow(editorName).focus();	// calculate the position for the dialog relative to the parent window    var winx = IBM_RTE_isMozilla() ? window.screenX : window.screenLeft;    var winy = IBM_RTE_isMozilla() ? window.screenY : window.screenTop;    var winw = IBM_RTE_isMozilla() ? window.innerWidth : IBM_RTE_getDocument(editorName).body.offsetWidth;    var winh = IBM_RTE_isMozilla() ? window.innerHeight: IBM_RTE_getDocument(editorName).body.offsetHeight;    var w = 450;    var h = 230;    var x = (winw-w)/2+winx;    var y = (winh-h)/2+winy;    var rand = Math.round(Math.random()*100000000000000000);    var winID = "Toxhtml_"+rand;    var flags = "screenX="+x+",screenY="+y+",left="+x+",top="+y+",width="+w+",height="+h+",resizable=yes,status=no,scrollbars=no,dependent=yes,modal=yes";	var xhtmlWin = window.open(directory + 'makeAccessibilityCompliant.jsp?locale=' + locale + '&images=' + images + '&editorName=' + editorName + '&directory=' + directory + '&isBidi=' + isBidi, winID, flags);	xhtmlWin.focus();}function addXMPTags(iHTML, remove){	if(remove == true){		if(iHTML.match(/<xmp id=9669 contentEditable=false style=\"DISPLAY: inline\"><\/xmp>/i) != null){			iHTML = iHTML.replace(/<xmp id=9669 contentEditable=false style=\"DISPLAY: inline\"><\/xmp>/i, "");		}	return iHTML;	}else{		if(iHTML.match(/<xmp id=9669 contentEditable=false style=\"DISPLAY: inline\"><\/xmp>/i) == null){					iHTML = "<xmp id=9669 contentEditable=false style=\"DISPLAY: inline\"></xmp>" + iHTML;		}		return iHTML;	}}// only for geckovar currentParam = -1;var notnull = false;var doneNodes = null;var same_val_across_range_nodes = null;function checkOverlap(selRange, editorName, which){	if(IBM_RTE_isMozilla()){		var bodyNode = IBM_RTE_getDocument(editorName).body;				currentParam = -1;		notnull = false;		doneNodes = new Array();		same_val_across_range_nodes = null;		crawlDomTree(editorName, bodyNode, selRange, which);				if(notnull == true){// display --font--			return "notnull";		}else if(same_val_across_range_nodes != null){// there are > 1 text nodes, but all have same font face			return same_val_across_range_nodes;		}else{			return null;		}	}}function crawlDomTree(editorName, currentElement, selRange, which){	if (currentElement){		var j;		var i=0;		var currentElementChild=currentElement.childNodes[i];				if(currentElementChild != null && currentElementChild.nodeType == 3){			if(! checkElementAgain(currentElementChild)){				var gotParam = MozillaIsNodeInRange(editorName, currentElementChild, selRange, which);				doneNodes[doneNodes.length] = currentElementChild;				if(currentParam == -1){					currentParam = gotParam;				}else	if(gotParam != -1 && gotParam != currentParam && notnull == false){							if(notnull == false){								notnull = true; //display --font--							}				}else if(gotParam != -1 && gotParam != null){					same_val_across_range_nodes = gotParam;				}			}		}				while (currentElementChild){			crawlDomTree(editorName, currentElementChild, selRange, which);			i++;			currentElementChild=currentElement.childNodes[i];		}	}}function checkElementAgain(node){	for(var xxx=0; xxx < doneNodes.length; xxx++){		if(doneNodes[xxx] == node){			return true;		}	}	return false;}function MozillaIsNodeInRange(editorName, node, selRange, which){	var bodyRange = IBM_RTE_getDocument(editorName).createRange();	bodyRange.setStartBefore(node);	bodyRange.setEndAfter(node);	if(bodyRange.compareBoundaryPoints(0, selRange) >= 0 &&	   bodyRange.compareBoundaryPoints(3, selRange) <= 0){				return MozillaGetParam(node, which); //yep, in range :)	}else if(selRange.compareBoundaryPoints(3, bodyRange) <= 0 &&		bodyRange.compareBoundaryPoints(0, selRange) <= 0 ){				return MozillaGetParam(node, which); //yep, in range :)	}	return -1;}function MozillaGetParam(node, which){	if(which == 1){			while(node.nodeName != "BODY"){				if(node.nodeName == "P"){					if(node.style.fontFamily != "" && node.style.fontFamily != null){							var mE = MozillaEval(node.style.fontFamily, 1);							return mE;					}				}else if(node.nodeName == "SPAN"){						if(node.style.fontFamily != "" && node.style.fontFamily != null){							mE1 = MozillaEval(node.style.fontFamily, 1);							return mE1;						}				}else if(node.nodeName == "FONT"){					if(node.getAttribute("face") != "" && node.getAttribute("face") != null){							return MozillaEval(node.getAttribute("face"), 1);					}				}				node = node.parentNode;			}		return null;	}else{//size		while(node.nodeName != "BODY"){			if(node.nodeName == "FONT"){				return MozillaEval(node.getAttribute("size"), 0);			}			node = node.parentNode;		}		return null;	}}function MozillaEval(fontParam, which){	var fontFaces = new Array("Arial", "Bookman", "Courier", "Garamond", "Lucida Console", "Symbol", "Tahoma", "Times", "Trebuchet", "Verdana");	var altFontFaces = new Array("arial,helvetica,sans-serif", "bookman old style,new york,times,serif","courier,monaco,monospace,sans-serif","garamond,new york,times,serif", "lucida console,sans-serif", "symbol,fantasy", "tahoma,new york,times,serif", "times new roman,new york,times,serif", "trebuchet ms,helvetica,sans-serif", "verdana,helvetica,sans-serif");	var fontSizes = new Array("7pt", "9pt", "12pt", "14pt", "18pt", "24pt");	if(which == 1){//face		if(fontParam != null){			fontParam = fontParam.replace(/,[ ]*/gi, ",");		}		var face;		for(var xxx = 0; xxx < fontFaces.length; xxx++){			if(fontParam.toLowerCase() == fontFaces[xxx].toLowerCase() || 			   fontParam.toLowerCase() == altFontFaces[xxx].toLowerCase()){				return fontFaces[xxx];			}		}	}else{//size		if(fontParam > 0 && fontParam < 7){			pt = fontSizes[fontParam - 1];		}else{			fontParam = 3;			fontParam = "12pt";			pt = "12pt";		}		return fontParam;	}}// only for geckofunction geckoTableDelete(editorName){	var rng = IBM_RTE_getSelectionRange(editorName);	var parNode = rng.startContainer;	/**	 * if (parNode is a text node){ 	 *	 nothing  to do	 * } else if(node at startOffset-1 is a table node){	 *				delete it baby!	 *          }	 * }	 */	if(parNode.nodeType != 3){		if(parNode.hasChildNodes){									var children = parNode.childNodes;						if(children[rng.startOffset-1].tagName == "P"){  				var childChildren = children[rng.startOffset-1].childNodes;				if(childChildren.length != 0){					if(childChildren[childChildren.length - 1].tagName == "TABLE"){						children[rng.startOffset-1].removeChild(childChildren[childChildren.length - 1]);					}				}			} else if(children[rng.startOffset-1].tagName == "TABLE"){  						parNode.removeChild(children[rng.startOffset-1]);			}		}	}else if(rng.startOffset == 0){		var textNode  = parNode;		var parent      = parNode.parentNode;		/**		 * now, recursively try to find the leftSibling		 *		 */				deleteLeftSibling(parent, textNode);	}}function deleteLeftSibling(parent, curNode){	// check if for the parent, the first child is curNode - else go one level up	var children = parent.childNodes;	if(children[0] == curNode && parent.tagName != "BODY"){			deleteLeftSibling(parent.parentNode, parent);	}else{		if(curNode.tagName != "BODY"){			var leftSibling = null;			for(var xxx = 1; xxx < children.length; xxx++){				if(children[xxx] == curNode){					leftSibling = children[xxx - 1];					break;				}			}						if(leftSibling.tagName == "P"){  				var children = leftSibling.childNodes;				if(children.length != 0){					if(children[children.length - 1].tagName == "TABLE"){						leftSibling.removeChild(children[children.length - 1]);					}				}			} else if(children[rng.startOffset-1].tagName == "TABLE"){  						parNode.removeChild(children[rng.startOffset-1]);			}			if(leftSibling.tagName == "TABLE"){				parent.removeChild(leftSibling);			}		}	}}function printNodes(siblings){	for(var xxx=0; xxx < siblings.length; xxx++){		alert(siblings[xxx].tagName);	}}// gecko only: backspace table deletefunction IBM_RTE_removeDanglingP_BR(editorName){	var bodyNode     = IBM_RTE_getDocument(editorName).body;	var bodyChildren = bodyNode.childNodes;	var xmpString     = "<xmp id=9669 contentEditable=false style=\"DISPLAY: inline\"></xmp>";	/**	 * IE will always have one node for this case - <P>&nbsp;</P>	 * Mozilla #@#@#$ has a bit more:	 *		<br>[#text]	 *     <p style=".."><br></p>[#text]	 *     <p style".."><br><br></p>[#text]	 */	if(IBM_RTE_isMozilla()){		switch(bodyChildren.length){			case 1:						if(bodyChildren[0].nodeName.toLowerCase() == "br"){							bodyNode.removeChild(bodyChildren[0]);							return true; // we removed a <BR> node, so add one before toggling back to view mode.						}else if(bodyChildren[0].nodeName.toLowerCase() == "p"){ 							var pKids = bodyChildren[0].childNodes;							switch(pKids.length){								case 1:									if(pKids[0].nodeName.toLowerCase() == "br"){										bodyNode.removeChild(bodyChildren[0]);										return true;									}								case 2:									if(pKids[0].nodeName.toLowerCase() == "br" && 									   pKids[1].nodeName.toLowerCase() == "br" ){										bodyNode.removeChild(bodyChildren[0]);										return true;									}							}							return false;						}else {								return false;						}			case 2: // two nodes, one #text and one <BR> or <BR> inside a <P>						var textNode = null						var otherNode = null;						if(bodyChildren[0].nodeName == "#text"){							textNode = bodyChildren[0];							otherNode = bodyChildren[1];						}else if(bodyChildren[1].nodeName == "#text"){									textNode = bodyChildren[1];									otherNode = bodyChildren[0];						}						var removeOtherNode = false;						if(textNode != null && textNode.data == "\n"){ // assure an empty text node							if(otherNode.nodeName.toLowerCase() == "br"){								removeOtherNode = true;							}else 	if(otherNode.nodeName.toLowerCase() == "p"){								// two cases, innerHTML can be <br> or <br><br>								var kids = otherNode.childNodes;								if(kids.length == 1){									if(kids[0].nodeName.toLowerCase() == "br"){										removeOtherNode = true;									}								}else if(kids.length == 2){									if(kids[0].nodeName.toLowerCase() == "br" &&									   kids[1].nodeName.toLowerCase() == "br"){											removeOtherNode = true;									}								}							}else if(otherNode.nodeName.toLowerCase() == "style" &&							   otherNode.innerHTML == ""){								removeOtherNode = true;							}							if(removeOtherNode){								bodyNode.removeChild(otherNode);								return true;							}							return false;						}			}	}else{		switch(bodyChildren.length){			case 1: 				 if(bodyChildren[0] != null &&					bodyChildren[0].nodeType != 3 &&				   bodyChildren[0].tagName.toLowerCase() != "p" && 				  (bodyChildren[0].innerHTML == "" || 				   bodyChildren[0].innerHTML.toLowerCase() == xmpString.toLowerCase())){ // IE						bodyNode.removeChild(bodyChildren[0]);						return false; // always!				}			case 2:				if(bodyChildren[0] != null &&				   bodyChildren[1] !=

⌨️ 快捷键说明

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