📄 script_editor.js
字号:
newNode.setAttribute("align", "center"); var newChild = IBM_RTE_getDocument(editorName).createElement("HR"); newNode.appendChild(newChild); newNode.style.pageBreakBefore = "always"; //Use Koranteng's insertNodeIntoRange() utility function to insert the pagebreak node. rng.deleteContents(); var container = rng.startContainer; var pos = rng.startOffset; var afterNode = null; if (container.nodeType == 3) { // when inserting into a textnode // we create 2 new textnodes // and put the insertNode in between var textNode = container; container = textNode.parentNode; var text = textNode.nodeValue; // split the text var textBefore = text.substr(0, pos); var textAfter = text.substr(pos); var beforeNode = IBM_RTE_getDocument(editorName).createTextNode(textBefore); afterNode = IBM_RTE_getDocument(editorName).createTextNode(textAfter); // insert the 3 new nodes before the old one container.insertBefore(afterNode, textNode); container.insertBefore(newNode, afterNode); container.insertBefore(beforeNode, newNode); // remove the old node container.removeChild(textNode); } else { // else simply insert the node // Somehow, after the new node is inserted, the rest of the container is selected and // deselecting everyting does not seem to work. Mozilla problem ??? afterNode = container.childNodes[pos]; container.insertBefore(newNode, afterNode); } if(afterNode != null) { rng.setEnd(afterNode, 0); rng.setStart(afterNode, 0); } } else { newNode.id = pageBreakID; newNode.align = "center"; newNode.innerText = "------------ Page Break ------------"; newNode.contentEditable = false; newNode.disabled = true; rng.pasteHTML(newNode.outerHTML); //It is strange that I can't set the pagebreak style before it is inserted. var pbNode = IBM_RTE_getDocument(editorName).getElementById(pageBreakID); pbNode.style.pageBreakBefore = "always"; }}// When pagebreak indicators are inserted, a new getEditorContent will be // needed to remove the indicators for print.function IBM_RTE_getEditorContentPrint(editorName, mode) { var text = ""; var divNodes = IBM_RTE_getDocument(editorName).getElementsByTagName("div"); if (IBM_RTE_isMozilla()) { for(i=0; i<divNodes.length; i++) { if (divNodes[i].id.substring(0, 10) == "pagebreak_") { var childNode = divNodes[i].childNodes[0]; divNodes[i].removeChild(childNode); } } } else { for(i=0; i<divNodes.length; i++) { if (divNodes[i].id.substring(0, 10) == "pagebreak_") { text = divNodes[i].innerText; divNodes[i].innerText = ""; } } } var editorCnt = IBM_RTE_getEditorContentPrint2(editorName, IBM_RTE_getEditorMode(editorName)); if (IBM_RTE_isMozilla()) { for(i=0; i<divNodes.length; i++) { if (divNodes[i].id.substring(0, 10) == "pagebreak_") { var newChild = IBM_RTE_getDocument(editorName).createElement("HR"); divNodes[i].appendChild(newChild); } } } else { for(i=0; i<divNodes.length; i++) { if (divNodes[i].id.substring(0, 10) == "pagebreak_") { divNodes[i].innerText = text; } } } return editorCnt;}function IBM_RTE_getEditorContentPrint2(editorName, mode) { if (IBM_RTE_getEditorMode(editorName) == 0){ iHTML = IBM_RTE_getDocument(editorName).body.innerHTML; IBM_RTE_getDocument(editorName).body.innerText = iHTML; iText = IBM_RTE_getDocument(editorName).body.innerText; IBM_RTE_getDocument(editorName).body.innerHTML = iText; iHTML = IBM_RTE_getDocument(editorName).body.innerHTML; } else if (IBM_RTE_getEditorMode(editorName) == 1) { if (IBM_RTE_isMozilla()) { var html = IBM_RTE_getDocument(editorName).body.ownerDocument.createRange(); html.selectNodeContents(IBM_RTE_getDocument(editorName).body); iHTML = html.toString(); } else { iHTML = IBM_RTE_getDocument(editorName).body.innerText; } } return iHTML;}function IBM_RTE_doPrint(editorName, fileName) { cnt = IBM_RTE_getEditorContentPrint(editorName, 0); if (IBM_RTE_isMozilla()) //making the image URLs absolute cnt = IBM_RTE_Mozilla_putAbsoluteURLs(editorName,cnt); var win = window.open(fileName, "printPreview", "width=600,height=400,menubar=yes,location=no");}function IBM_RTE_Mozilla_putAbsoluteURLs(editorName,cnt){ Text1 = cnt; var url = IBM_RTE_getDocument(editorName).URL; url = url.substring(0,url.lastIndexOf('/')); var matchesImg = Text1.match(/<img .*?src=(['"])[^\1]*?\1[\/]?>/gi); xx = 0; if(matchesImg != null) while(true){ if(matchesImg[xx] == null) break; var Smatch = matchesImg[xx]; var cmpts = matchesImg[xx].match(/src=(["'])([^\1]*?)\1/i); var quot = cmpts[1]; var src = cmpts[2]; if(quot == "'"){ var str2 = "" + "\""; var re2 = new RegExp(str2.toString(),"g"); temp = "src='" + url+"/"+src + "' "; matchesImg[xx] = matchesImg[xx].replace(/src=(["'])([^\1]*?)\1/i, temp); // now replace matches[xx] in Text1 var str9 = "" + Smatch.replace(/\\/g,"\\\\").replace(re2, "\\\"").replace(/\//,"\\\/"); var re9 = new RegExp(str9.toString(),"g"); Text1 = Text1.replace(re9, matchesImg[xx].toString()); } else{ var str10 = "" + "\""; var re10 = new RegExp(str10.toString(),"g"); temp = "src=\"" + url+"/"+src + "\" "; matchesImg[xx] = matchesImg[xx].replace(/src=(["'])([^\1]*?)\1/i, temp); // now replace matches[xx] in Text1 var str11 = "" + Smatch.replace(/\\/g,"\\\\").replace(re10, "\\\"").replace(/\//g,"\\\/"); var re11 = new RegExp(str11.toString(),"g"); Text1 = Text1.replace(re11, matchesImg[xx].toString()); } xx++; } return Text1;}function IBM_RTE_paraSupport(editorName, buttonElement, locale, images, directory, isBidi){ IBM_RTE_getWindow(editorName).focus(); if(!IBM_RTE_isMozilla()){ if(isAccessible) this.opener.IBM_RTE_backup(editorName); else IBM_RTE_backup(editorName); } // 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 = 330; var h = 330; var x = (winw-w)/2+winx; var y = (winh-h)/2+winy; var rand = Math.round(Math.random()*100000000000000000); var winID = "paraSupport_"+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 paraWin = window.open(directory + 'paraSupport.jsp?locale=' + locale + '&images=' + images + '&editorName=' + editorName + '&isBidi=' + isBidi+ '&isAccessible='+isAccessible,winID, flags); paraWin.focus();}function IBM_RTE_findReplace(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 = "FindReplace_"+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"; if(IBM_RTE_isMozilla()){ var win = IBM_RTE_getWindow(editorName); win.getSelection().collapse(IBM_RTE_getDocument(editorName).body,0); } var findReplWin = window.open(directory + 'findReplace.jsp?locale=' + locale + '&images=' + images + '&editorName=' + editorName + '&isAccessible=' + isAccessible+ '&isBidi=' + isBidi, winID, flags); findReplWin.focus();}//I don't like this way of restoring comments in Mozilla. It is a hack, //not a solution. However, since Mozilla currently does not support contentEditable//attribute, we probably have to use Mozilla properrietary technologies to mimic IE //functions.function IBM_RTE_MozillaRestoreComments(editorName) { if (IBM_RTE_isMozilla()) { var commentNodes = IBM_RTE_getDocument(editorName).getElementsByTagName("description"); for (var i = 0; i < commentNodes.length; i++){ var cmtStyle = commentNodes[i].getAttribute("style"); var XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; var newNode = IBM_RTE_getDocument(editorName).createElementNS(XULNS, "description"); newNode.setAttribute("value", commentNodes[i].getAttribute("value")); commentNodes[i].parentNode.replaceChild(newNode, commentNodes[i]); if (cmtStyle != "display: none;"){ cmtStyle = "display:block; padding:5px; color:red !important; font-style: italic; font-size: 10pt;" } newNode.setAttribute("style", cmtStyle); } }}function IBM_RTE_getCell(editorName){ var selRange = IBM_RTE_getSelectionRange(editorName); if(selRange == null)return null; if( selRange.text == null)return null; var currentRow= selRange.parentElement(); if(currentRow.tagName=="TD" || currentRow.tagName=="TH"){ return currentRow; }else{ return null; }}function isBlank(val){ if(val==null){return true;} for(var i=0;i<val.length;i++) { if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;} } return true;}function IBM_RTE_changeContent(editorName){var iHTML = IBM_RTE_getDocument(editorName).body.innerHTML;iHTML= iHTML.replace(/\<TD\>\<\/TD\>/g, "<TD> </TD>");IBM_RTE_getDocument(editorName).body.innerHTML=iHTML;}function IBM_RTE_validateAnchorTags(editorName, anchor){ var quot; var i; var index; var attrList = new Array(" type=", " name="," hreflang="," rel="," rev="," accesskey="," shape="," coords="," tabindex="," onfocus="," onblur=", " onclick="," ondblclick="," onmouseup="," onmousedown="," onmouseover="," onmousemove="," onmouseout="," onkeypress="," onkeydown="," onkeyup="," id="," title="," lang="," dir="," class="," target="); var hrefIndex = anchor.indexOf("href="); if(hrefIndex == -1) return anchor; if((index = anchor.indexOf("<",hrefIndex)) == -1) index = hrefIndex; else if((index = anchor.indexOf("/>")) == -1) return anchor; if(anchor.charAt(hrefIndex+5) != "\"") if(anchor.charAt(hrefIndex+5) != "\'") anchor = anchor.substring(0, hrefIndex+5) + "\"" + anchor.substring(hrefIndex+5); if(anchor.charAt(hrefIndex+5) == "\"") quot = "\""; else quot = "\'"; index = anchor.indexOf(" charset=",hrefIndex); for(i=0; i<attrList.length; i++) if((anchor.indexOf(attrList[i],hrefIndex) < index && index != -1) || index == -1) if(anchor.indexOf(attrList[i],hrefIndex) != -1) index = anchor.indexOf(attrList[i],hrefIndex); if(index != -1) { if(anchor.charAt(index-1) != quot) { if(anchor.charAt(index-1) == "\"") anchor = anchor.substring(0,index-1) + quot + anchor.substring(index); else if(anchor.charAt(index-1) == "\'") anchor = anchor.substring(0,index-1)+quot+anchor.substring(index); else { var xx=index; var flag = false; for(xx; xx > hrefIndex+5; xx--){ if(anchor.charAt(xx) == " ") continue; if(anchor.charAt(xx) == "\"" || anchor.charAt(xx) == "'" ) return anchor; else return (anchor.substring(0, xx+1) + quot + anchor.substring(xx+1)); } } } } else { var al = anchor.length; if(anchor.charAt(al-2) != quot) { if(anchor.charAt(al-2) == "\"") anchor = anchor.substring(0,al-2)+quot+">"; else if(anchor.charAt(al-2) == "\'") anchor = anchor.substring(0,al-2)+quot+">"; else anchor = anchor.substring(0,al-1)+quot+">"; } } return anchor;}function isCustomTag(str){ var match = new String(str); str3 = "href="\""; str4 = "src="\""; str5 = "href=\"\""; str6 = "src=\"\""; if(match.indexOf(str3) == -1) if(match.indexOf(str4) == -1) if(match.indexOf(str5) == -1) if(match.indexOf(str6) == -1) return false; return true;}var index = 0; var flag = false; var backup = new Array();function IBM_RTE_backup(editorName){ // called on triggers if(flag){ var removed = backup.splice(flag, backup.length - flag); for (var i = 0; i < removed.length; i++) delete removed[i]; } backup[backup.length] = IBM_RTE_getDocument(editorName).body.innerHTML; index = backup.length - 1; flag = false;}function IBM_RTE_handler(event) {// events triggering backup - space, backspace, return, del if (event) { switch (event.keyCode) { case 32: //space break; case 8://back IBM_RTE_backup(editorNameSaved); break; case 13://return IBM_RTE_backup(editorNameSaved); break; case 46://delete IBM_RTE_backup(editorNameSaved); break; default: return; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -