var reBlockElements = /^(HTML|HEAD|BODY|BR|TITLE|TABLE|SCRIPT|TR|TBODY|P|DIV|H1|H2|H3|H4|H5|H6|ADDRESS|PRE|OL|UL|LI)$/i;
// Some methods of this class is in the editor_php.js/editor_aspx.js
function BXNode(parent)
{
this.oParent = parent;
this.iLevel = 0;
if(parent)
{
parent.arNodes[parent.arNodes.length] = this;
this.iLevel = parent.iLevel+1;
}
this.arNodes = [];
this.arAttributes = {};
this.type = null;
this.text = "";
}
BXNode.prototype = {
GetHTML: function(bFormatted)
{
//try{
var id = this.arAttributes["id"];
if (id)
{
var bxTag = this.pParser.pMainObj.GetBxTag(id);
if(bxTag.tag)
{
switch(bxTag.tag)
{
case 'img':
if (!bxTag.params)
return '';
// width, height
var
w = this.arStyle.width || this.arAttributes.width || '',
h = this.arStyle.height || this.arAttributes.height || '';
if (~w.indexOf('%'))
w = parseInt(w) + '%';
if (~h.indexOf('%'))
h = parseInt(h) + '%';
if (w && !isNaN(w))
bxTag.params.width = w;
if (h && !isNaN(h))
bxTag.params.height = h;
bxTag.params['class'] = this.arAttributes['class'] ||'';
bxTag.params['align'] = this.arAttributes['align'] ||'';
var i, res = '';
return res;
case 'a':
if (!bxTag.params)
return '';
bxTag.params['class'] = this.arAttributes['class'] ||'';
var i, res = '';
for(i = 0; i < this.arNodes.length; i++)
res += this.arNodes[i].GetHTML(bFormatted);
res += '';
if (bxTag.params.noindex)
res = '';
return res;
case 'php':
var pMainObj = this.pParser.pMainObj;
if (pMainObj.bDotNet || (pMainObj.limit_php_access && pMainObj.pComponent2Taskbar))
break;
return bxTag.params.value;
case 'noscript':
case 'noindex':
var res = "", i;
for(i = 0; i < this.arNodes.length; i++)
res += this.arNodes[i].GetHTML(bFormatted);
return "<" + bxTag.tag + ">" + res + "" + bxTag.tag + ">";
case 'break':
return '';
case 'break_page':
return '
';
case 'hr':
if (!BX.browser.IsIE() && bxTag.params && bxTag.params.value)
return bxTag.params.value;
break;
case 'flash':
if (!bxTag.params)
return '';
var i, res = '';
return res;
case 'cursor':
return '#BXCURSOR#';
default:
var customRes = this.CustomUnParse();
if (customRes)
return customRes;
// Symbols
if (this.pParser.arSym[bxTag.tag])
return this.pParser.arSym[bxTag.tag][0];
// comments, script
if (bxTag.params && bxTag.params.value)
return '\n' + bxTag.params.value + '\n';
}
}
}
if(this.arAttributes["_moz_editor_bogus_node"])
return '';
var f;
this.bDontUseSpecialchars = false;
for (var i = 0, l = arNodeUnParsers.length; i < l; i++)
{
f = arNodeUnParsers[i];
if (f && typeof(f) == 'function')
f(this, this.pParser.pMainObj);
}
res = this.GetHTMLLeft();
var bNewLine = false;
var sIndent = '';
if(bFormatted && this.type != 'text')
{
if(reBlockElements.test(this.text) && !(this.oParent && this.oParent.text && this.oParent.text.toLowerCase() == 'pre'))
{
for(var j = 0; j < this.iLevel - 3; j++)
sIndent += " ";
bNewLine = true;
res = "\r\n" + sIndent + res;
}
}
for(var i=0; i< this.arNodes.length; i++)
res += this.arNodes[i].GetHTML(bFormatted);
res += this.GetHTMLRight();
if(bNewLine)
res += "\r\n" + (sIndent=='' ? '' : sIndent.substr(2));
return res;
//}catch(e){_alert("Error BXNode.prototype.GetHTML : \n type = "+this.type+"\ntext = "+this.text);}
},
CustomUnParse: function(res)
{
if (!res)
res = false;
var fUnParser, i, l;
for (i = 0, l = arBXTaskbars.length; i < l; i++)
{
fUnParser = window[arBXTaskbars[i].name].prototype.UnParseElement;
if (fUnParser)
arUnParsers.push(fUnParser);
}
for (var j = 0; j < arUnParsers.length; j++)
{
fUnParser = arUnParsers[j];
if (fUnParser)
{
res = fUnParser(this, this.pParser.pMainObj);
if (res !== false)
break;
}
}
return res;
},
IsPairNode: function()
{
return (this.text.substr(0, 1) != 'h' && this.text != 'br' && this.text != 'img' && this.text != 'input');
},
GetHTMLLeft: function()
{
if(this.type == 'text')
return this.bDontUseSpecialchars ? this.text : bxhtmlspecialchars(this.text);
var atrVal, attrName, res;
if(this.type == 'element')
{
res = "<"+this.text;
for(attrName in this.arAttributes)
{
atrVal = this.arAttributes[attrName];
if(attrName.substring(0,4).toLowerCase() == '_moz')
continue;
if(this.text.toUpperCase()=='BR' && attrName.toLowerCase() == 'type' && atrVal == '_moz')
continue;
if(attrName == 'style')
{
if (atrVal.length > 0 && atrVal.indexOf('-moz') != -1)
atrVal = BX.util.trim(atrVal.replace(/-moz.*?;/ig, '')); // Kill -moz* styles from firefox
if (this.text == 'td')
{
// Kill border-image: none; styles from firefox for
atrVal = BX.util.trim(atrVal.replace(/border-image:\s*none;/ig, '')); //
// kill border-color: for ie
atrVal = BX.util.trim(atrVal.replace(/border-bottom-color:\s*;?/ig, ''));
atrVal = BX.util.trim(atrVal.replace(/border-top-color:\s*;?/ig, ''));
atrVal = BX.util.trim(atrVal.replace(/border-right-color:\s*;?/ig, ''));
atrVal = BX.util.trim(atrVal.replace(/border-left-color:\s*;?/ig, ''));
}
if(atrVal.length <= 0)
continue;
}
res += ' ' + attrName + '="' + (this.bDontUseSpecialchars ? atrVal : bxhtmlspecialchars(atrVal)) + '"';
}
if(this.arNodes.length <= 0 && !this.IsPairNode())
return res+" />";
return res+">";
}
return "";
},
GetHTMLRight: function()
{
if(this.type == 'element' && (this.arNodes.length>0 || this.IsPairNode()))
return ""+this.text+">";
return "";
}
};
// Some methods of this class is in the editor_php.js/editor_aspx.js
function BXParser(pMainObj)
{
this.pMainObj = pMainObj;
this.arSym = {'bxshy' : ['', '-'], 'bxnbsp' : [' ', ' ']};
this.systemCSS = "img.bxed-anchor{background-image: url(" + global_iconkit_path + ")!important; background-position: -260px 0!important; height: 20px!important; width: 20px!important;}\n" +
"span.bxed-noscript{color: #0000a0!important; padding: 2px!important; font-style:italic!important; font-size: 90%!important;}\n" +
"span.bxed-noindex{color: #004000!important; padding: 2px!important; font-style:italic!important; font-size: 90%!important;}\n" +
"img.bxed-flash{border: 1px solid #B6B6B8!important; background: url(" + image_path + "/flash.gif) #E2DFDA center center no-repeat !important;}\n" +
"img.bxed-hr{padding: 2px!important; width: 100%!important; height: 2px!important;}\n";
}
BXParser.prototype = {
_RecursiveParse: function (oParentNode, oBXNode)
{
switch(oParentNode.nodeType)
{
case 9:
oBXNode.type = 'document';
break;
case 1:
if(oParentNode.__bxID && oParentNode.__bxID == this.__bxID)
return;
oParentNode.__bxID = this.__bxID;
if(oParentNode.tagName.length<=0 || oParentNode.tagName.substring(0, 1)=="/")
return;
oBXNode.type = 'element';
oBXNode.text = oParentNode.tagName.toLowerCase();
var j, attr = oParentNode.attributes, l = attr.length ;
for(j = 0; j < l; j++)
{
if(attr[j].specified || (oBXNode.text == "input" && attr[j].nodeName.toLowerCase()=="value"))
{
var attrName = attr[j].nodeName.toLowerCase();
if(attrName == '__bxid')
continue;
if(attrName=="style")
oBXNode.arAttributes[attrName] = oParentNode.style.cssText;
else if(attrName=="src" || attrName=="href" || attrName=="width" || attrName=="height")
oBXNode.arAttributes[attrName] = oParentNode.getAttribute(attrName, 2);
else
oBXNode.arAttributes[attrName] = attr[j].nodeValue;
}
}
if (oParentNode.style)
oBXNode.arStyle = oParentNode.style;
break;
case 3:
oBXNode.type = 'text';
var res = oParentNode.nodeValue;
if(!(oBXNode.oParent && oBXNode.oParent.text && oBXNode.oParent.text.toLowerCase() == 'pre'))
{
res = res.replace(/\n+/g, ' ');
res = res.replace(/ +/g, ' ');
}
oBXNode.text = res;
break;
}
var arChilds = oParentNode.childNodes;
var oNode, oBXChildNode;
for(var i = 0; i < arChilds.length; i++)
{
oNode = arChilds[i];
oBXChildNode = new BXNode(oBXNode);
oBXChildNode.pParser = this;
this._RecursiveParse(oNode, oBXChildNode);
}
},
Parse: function ()
{
// Limit Component Access: if it's not first parsing and all components was converted to html
if (!this.pMainObj.bDotNet && lca && this.pMainObj.pComponent2Taskbar && _$arComponents !== false && _$LCAContentParser_execed)
{
_$arComponents = {};
_$compLength = 0;
}
this.arNodeParams = {};
this.__bxID = parseInt(Math.random() * 100000) + 1;
this.pNode = new BXNode(null);
this.pNode.pParser = this;
this._RecursiveParse(this.pMainObj.pEditorDocument, this.pNode);
},
GetHTML: function (bFormatted)
{
return this.pNode.GetHTML(bFormatted);
},
SystemParse: function(sContent)
{
var _this = this;
this.strStyleNodes = this.systemCSS;
sContent = this.ClearFromHBF(sContent);
sContent = sContent.replace(/(
]*>)\s*(<\/td>)/ig, "$1 $2");
//TODO: at the beginning of the parsing - replace ?> for something, at the end unparse it back. For easier regexps.
// Image
sContent = sContent.replace(//ig,
function(str, s1)
{
var arParams = _this.GetAttributesList(s1), i , val, res = "", bPhp = false;
if (arParams && arParams.id)
{
var oTag = _this.pMainObj.GetBxTag(arParams.id);
if (oTag.tag)
return str;
}
res = "/i, SITE_TEMPLATE_PATH);
src = src.replace(/<\?\s*echo\s*SITE_TEMPLATE_PATH;?\s*\?>/i, SITE_TEMPLATE_PATH);
}
res += 'src="' + src + '" ';
continue;
}
bPhp = _this.isPhpAttribute(arParams[i]);
if (!bPhp) // No php in attribute
res += i + '="' + BX.util.htmlspecialchars(arParams[i]) + '" ';
}
}
res += " />";
return res;
}
);
// Link
sContent = sContent.replace(/(