📄 htmleditor.js
字号:
function ReHTML(text){
text = text.replace(/&/g, "&") ;
text = text.replace(/"/g, '"') ;
text = text.replace(/</g, "<") ;
text = text.replace(/>/g, ">") ;
text = text.replace(/’/g, "'") ;
return text ;
}
function toBr(text){
text = text.replace(/\r/g, "") ;
text = text.replace(/\n/g, "<br>") ;
return text;
}
function toBlank(text){
return text.replace(/\xA0/g, " ");
}
function addScript(text){
return "<pre>"+text+"</pre>";
}
function delScript(text){
text=text.replace("<pre>","");
text=text.replace("</pre>","");
return toBlank(text);
}
function lybbs_inserttable() {
if (!lybbs_validateMode()) return;
IframeID.focus();
var arr = showModalDialog("bbs_commonForward.do?forward=inserttable", window, "dialogWidth:22em; dialogHeight:19em; status:0; help:0;scroll:no;");
if (arr){
IframeID.document.body.innerHTML+=arr;
}
IframeID.focus();
}
function lybbs_CopyData(){
ischeck=true;
if(lybbs_bTextMode==2){
if (lybbs_bIsIE5){
content=IframeID.document.body.innerText;
IframeID.document.body.innerHTML=content;
}else{
var html = IframeID.document.body.ownerDocument.createRange();
html.selectNodeContents(IframeID.document.body);
IframeID.document.body.innerHTML = html.toString();
}
IframeID.focus();
}
try {
openner.theform.content.value=delScript(OSWEBXHTML.GetXHTML(IframeID.document.body));
//support html checked
if(openner.theform.htmlSupport!=null) openner.theform.htmlSupport.checked=true;
return true;
}
catch(ex) {
alert(ex.message);
return false;
}
}
function lybbs_CheckData(){
IframeID.document.charset="GBK";
IframeID.document.body.innerHTML=addScript(toBr(theform.content.value));
try {
theform.content.value=delScript(OSWEBXHTML.GetXHTML(IframeID.document.body));
return true;
}
catch(ex) {
alert(ex.message);
theform.content.value="";
return false;
}
}
function checkattributeName(attributeName){
var Re = new RegExp(/&|\/|<|>|\*|#|:|;|=|\?|\)|\(|%|\[|\]|\$| /gi);
if(Re.test(attributeName)){
return false
}else{
var Re = new RegExp(/[0-9]/gi);
if(Re.test(attributeName.substring(0,1))){
return false
}else{
return true;
}
}
}
var checkword=0;
var OSWEBXHTML=new Object();
OSWEBXHTML.GetXHTML=function(node){
if (window.ActiveXObject){
var prefix = ["MSXML3","MSXML2","MSXML","Microsoft"];
for (var i=0;i<prefix.length;i++) {
try {
this.XML=new ActiveXObject(prefix[i] + ".DOMDocument");
if (XML){
return XML;
}
} catch (e) {}
}
}else{
this.XML=document.implementation.createDocument('', '', null);
Node.prototype.__defineGetter__('xml', OSWEBXHTML._Node_Getxml);
}
this.MainNode=this.XML.appendChild(this.XML.createElement( 'XHTML' ));
this._AppendChildNodes(this.MainNode, node);
var sXHTML=this.MainNode.xml;
sXHTML=sXHTML.replace(/<embed><\/embed>/g,"") ;
return sXHTML.substr(7, sXHTML.length - 15);
}
OSWEBXHTML._Node_Getxml=function(){
var oSerializer=new XMLSerializer();
return oSerializer.serializeToString(this);
}
OSWEBXHTML._AppendChildNodes=function(xmlNode, htmlNode){
var oChildren=htmlNode.childNodes;
var i=0;
while (i < oChildren.length){
i +=this._AppendNode(xmlNode, oChildren[i]);
}
}
OSWEBXHTML._AppendNode=function(xmlNode, htmlNode){
var iAddedNodes=1;
switch (htmlNode.nodeType){
case 1 : var sNodeName=fixtag(htmlNode.nodeName.toLowerCase());
if(sNodeName=='') break;
else if(sNodeName=='plaintext'||sNodeName=='xmp') break;//filter plaintext and xmp to clear
else if(sNodeName=='iframe') break;//filter iframe
else if(sNodeName=='meta') break;//filter iframe
else if(sNodeName=='form') break;//filter iframe
if(checkword==1){
if (sNodeName=='colgroup') break;
}
var oAttributes=htmlNode.attributes;
var oNode=xmlNode.appendChild(this.XML.createElement( sNodeName ));
for (var n=0 ; n < oAttributes.length ; n++){
var oAttribute=oAttributes[n];
if (oAttribute.specified) {
if(oAttribute.nodeName.toLowerCase()=='onerror') {
break;
}
else if (oAttribute.nodeName.toLowerCase()=='style') {
;
}
else if (oAttribute.nodeName.toLowerCase()=='src') {
var nodeValue=escapeUrl(oAttribute.nodeValue+'');
if(checkInvalidUrl(nodeValue)) {
break;
//this._AppendAttribute(oNode,fixtag(oAttribute.nodeName.toLowerCase()+''),'');
}
else {
this._AppendAttribute(oNode, fixtag(oAttribute.nodeName.toLowerCase()+''), nodeValue);
}
}
else {
this._AppendAttribute(oNode, fixtag(oAttribute.nodeName.toLowerCase()+''), oAttribute.nodeValue+'');
}
}
}
/**
var cssText=htmlNode.style.cssText;
if (cssText!='') {
if (navigator.appVersion.indexOf("MSIE")!=-1){
cssText=cssText+';';
}
this._AppendAttribute(oNode, 'style', cssText);
}
**/
if (htmlNode.childNodes.length == 0){
switch (sNodeName){
case "img" :case "input" :case "br" : case "hr" :case "param":break;
default : oNode.appendChild(this.XML.createTextNode( '' ));
break;
}
}
switch (sNodeName){
case "abbr" : if (document.all){
var oNextNode=htmlNode.nextSibling;
while (true){
iAddedNodes++;
if (oNextNode && oNextNode.nodeName !='/ABBR'){
this._AppendNode(oNode, oNextNode);
oNextNode=oNextNode.nextSibling;
}else{
break;
}
}
break;
}
case "area" : if (document.all && ! oNode.attributes.getNamedItem( 'coords' )){
var sCoords=htmlNode.getAttribute('coords', 2);
if (sCoords && sCoords !='0,0,0')
this._AppendAttribute(oNode, 'coords', sCoords);
}
case "img" : if (! oNode.attributes.getNamedItem( 'alt' )) {
this._AppendAttribute(oNode, 'alt', 'img');
}
default :this._AppendChildNodes(oNode, htmlNode);
break;
}
case 3 : if (htmlNode.nodeValue!=null) {
xmlNode.appendChild(this.XML.createTextNode( htmlNode.nodeValue ));
}
break;
default : xmlNode.appendChild(this.XML.createComment( "Element not supported - Type: " + htmlNode.nodeType + " Name: " + htmlNode.nodeName ));
break;
}
return iAddedNodes;
}
OSWEBXHTML._AppendAttribute=function(xmlNode, attributeName, attributeValue){
if(checkattributeName(attributeName) && attributeName.indexOf('_moz') ==-1 && attributeName.substring(0,2)!='on' && attributeValue.indexOf('_moz') ==-1 && attributeName!=''){
if(checkword==1){
if (attributeName=='classname') return;
if (attributeName=='style') return;
if (attributeName=='class') return;
}
if (attributeName=='xstr') return;
if (attributeName=='xnum') return;
if (attributeName=='u1num') return;
var oXmlAtt=this.XML.createAttribute(attributeName);
if ((typeof( attributeValue )=='boolean' && attributeValue == true ) || attributeValue == 'true'){
oXmlAtt.nodeValue=attributeName;
}else{
oXmlAtt.nodeValue=attributeValue;
}
xmlNode.attributes.setNamedItem(oXmlAtt);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -