// Editor class
function SpawEditor(name)
{
this.name = name;
this.toolbar_items = new Array();
this.pages = new Array();
this.tabs = new Array();
this.controlled_editors = new Array();
//this.event_handlers = new Array();
this.config = new Array();
}
SpawEditor.prototype.name;
// secure config id
SpawEditor.prototype.scid;
// stylesheet
SpawEditor.prototype.stylesheet;
// config
SpawEditor.prototype.config;
SpawEditor.prototype.getConfigValue = function(name)
{
return this.config[name];
}
SpawEditor.prototype.setConfigValue = function(name, value)
{
this.config[name] = value;
}
SpawEditor.prototype.getRequestUriConfigValue = function()
{
return this.getConfigValue("__request_uri");
}
// returns true if all pages are initialized
SpawEditor.prototype.isInitialized = function()
{
var result = true;
for (var i=0; i)|(
]*)>)','gi');
htmlValue = htmlValue.replace(hrRgx, '').replace("//>","/>");
}
// workaround for chewed up script, style and other tags under IE when content starts with them
if (document.attachEvent) // ie
{
htmlValue = '.' + htmlValue;
}
// assign value
pdoc.body.innerHTML = htmlValue;
// hr workaround for IE (HR sometimes causes unpredictable behavior in IE)
// replace SPAW:HRs back to HR
if (document.attachEvent) // ie
{
var HRs = pdoc.getElementsByTagName('hr');
if (HRs && HRs.length > 0)
{
for (var i = (HRs.length - 1); i>=0; i--)
{
var realHR = pdoc.createElement('hr');
realHR.mergeAttributes(HRs[i]);
HRs[i].replaceNode(realHR);
}
}
}
// workaround for chewed up script, style and other tags under IE when content starts with them
if (document.attachEvent) // ie
{
var tmpSpan = pdoc.getElementById("spaw2_script_workaround");
tmpSpan.parentNode.removeChild(tmpSpan);
}
this.flash2img();
}
// returns html of the current page
SpawEditor.prototype.getPageHtml = function(page)
{
// raise get html event
SpawEngine.handleEvent("spawgethtml", null, "page_doc", this.name);
var pdoc = this.getPageDoc(page.name);
var pta = this.getPageInput(page.name);
var result;
if (page.editing_mode == "html")
{
// html mode
result = pta.value;
}
else if(page.editing_mode == "design")
{
// remove glyphs
this.removeGlyphs(pdoc.body);
// replace flash placeholders
this.img2flash();
// strip absolute urls
this.stripAbsoluteUrls();
// wysiwyg mode
if (this.getConfigValue("rendering_mode") == "builtin")
{
// let browser handle html rendering
result = pdoc.body.innerHTML;
}
else
{
// call custom html renderer
result = this.dom2xml(pdoc.body, '');
// workaround for broken DOM tree
pta.value = result;
this.updatePageDoc(page);
}
}
if (this.getConfigValue('convert_html_entities'))
result = this.convertToEntities(result);
return result;
}
SpawEditor.updateFields = function(editor, event)
{
editor.updateFields();
}
SpawEditor.prototype.updateFields = function()
{
for(var i=0; i 0)
xbuf += SpawUtils.trimLineBreaks(SpawUtils.htmlEncode(chnode.nodeValue));
else if (chnode.nodeValue.length > 0)
xbuf += " "; // add single space
}
else if (chnode.nodeType == 8) // comment node
{
xbuf += "";
}
else if (chnode.nodeType == 1) // html element
{
if (chnode.getAttribute("__spawprocessed") == null) // workaround to prevent elements from doubling
{
chnode.setAttribute("__spawprocessed",true);
// form attributes string
var attr_str = '';
for(var j=0; j0)
{
var innercode = this.dom2xml(chnode, indent + ((f_indent!="tmp")?" ":""), pInParagraph);
if (SpawUtils.trim(innercode) == '')
innercode = ' ';
// workaround for invalid HTML in IE
var closingTag = "" + tag_name + ">";
if (document.attachEvent) // ie
{
if (tag_name == 'p' && innercode.indexOf("
") != -1)
closingTag = "";
}
xbuf += closingP + f_crlf + f_indent + "<" + SpawUtils.trim(tag_name + attr_str) + ">" + innercode + e_crlf + e_indent + closingTag;
}
else if (chnode.tagName.indexOf("/") == -1)// empty tag (sometimes ending tag is passed as a separate node)
{
if (tag_name == "img"
|| tag_name == "br"
|| tag_name == "wbr"
|| tag_name == "hr"
|| tag_name == "input")
{
xbuf += f_crlf + f_indent + "<" + SpawUtils.trim(tag_name + attr_str) + " />" + e_crlf + e_indent;
}
else
{
// don't generate empty useless tags
if (tag_name != "b"
&& tag_name != "i"
&& tag_name != "u"
&& tag_name != "strike"
&& tag_name != "strong"
&& tag_name != "em"
&& tag_name != "i"
&& tag_name != "span"
)
{
var innercode = '';
if (tag_name == 'p')
innercode = ' ';
xbuf += f_crlf + f_indent + "<" + SpawUtils.trim(tag_name + attr_str) + ">" + innercode + "" + tag_name + ">";
}
}
}
}
else // script & style
{
xbuf += f_crlf + f_indent + "<" + SpawUtils.trim(chnode.tagName.toLowerCase() + attr_str) + ">" + SpawUtils.trim(chnode.innerHTML) + e_crlf + e_indent + "" + chnode.tagName.toLowerCase() + ">";
}
}
}
}
return xbuf;
}
// cleans up code
SpawEditor.prototype.getCleanCode = function(node, clean_type) // clean_type reserved for future use
{
var xbuf = '';
for (var i=0; i 0)
xbuf += chnode.nodeValue.replace(/\u00A0/g, " ");
}
else if (chnode.nodeType == 8) // comment node
{
xbuf += "";
}
else if (chnode.nodeType == 1) // html element
{
if (chnode.getAttribute("__spawprocessed") == null) // workaround to prevent elements from doubling
{
chnode.setAttribute("__spawprocessed",true);
// form attributes string
var attr_str = '';
for(var j=0; j0)
{
if (chnode.tagName.indexOf(":") == -1 && chnode.tagName.toLowerCase() != 'font' && chnode.tagName.toLowerCase() != 'div' && chnode.tagName.toLowerCase() != 'span')
xbuf += "<" + SpawUtils.trim(chnode.tagName.toLowerCase() + attr_str) + ">" + this.getCleanCode(chnode, clean_type) + "" + chnode.tagName.toLowerCase() + ">";
else
xbuf += this.getCleanCode(chnode, clean_type);
}
else if (chnode.tagName.indexOf("/") == -1)// empty tag (sometimes ending tag is passed as a separate node)
{
if (chnode.tagName.indexOf(":") == -1 && chnode.tagName.toLowerCase() != 'font' && chnode.tagName.toLowerCase() != 'div' && chnode.tagName.toLowerCase() != 'span')
{
if (chnode.tagName.toLowerCase() == "img"
|| chnode.tagName.toLowerCase() == "br"
|| chnode.tagName.toLowerCase() == "wbr"
|| chnode.tagName.toLowerCase() == "hr"
|| chnode.tagName.toLowerCase() == "input")
{
xbuf += "<" + SpawUtils.trim(chnode.tagName.toLowerCase() + attr_str) + " />";
}
else
{
xbuf += "<" + SpawUtils.trim(chnode.tagName.toLowerCase() + attr_str) + ">" + chnode.tagName.toLowerCase() + ">";
}
}
}
}
else // script
{
xbuf += "<" + SpawUtils.trim(chnode.tagName.toLowerCase() + attr_str) + ">" + chnode.innerHTML + "" + chnode.tagName.toLowerCase() + ">";
}
}
}
}
return xbuf;
}
// cleans current page code
SpawEditor.prototype.cleanPageCode = function(clean_type) // clean_type reserved for future use
{
var pname = this.getActivePage().name;
var pdoc = this.getActivePageDoc();
var pta = this.getPageInput(pname);
pta.value = this.getCleanCode(pdoc.body, clean_type);
this.updatePageDoc(this.getActivePage());
}
// status bar
SpawEditor.prototype.showStatus = function(message)
{
var sb = this.document.getElementById(this.name + '_status');
if (sb && !document.attachEvent) // disable status bar in IE cause it breaks undo/redo
{
sb.innerHTML = message;
}
}
// right click
SpawEditor.rightClick = function(editor, event)
{
editor.rightClick(editor, event);
}
SpawEditor.prototype.rightClick = function(editor, event)
{
if (SpawEngine.active_context_menu != null)
SpawEngine.active_context_menu.hide();
var cm = new SpawContextMenu(this);
if (cm.show(event))
{
SpawEngine.active_context_menu = cm;
if (event.preventDefault)
event.preventDefault();
else
event.returnValue = false;
}
}
// hide context menu
SpawEditor.hideContextMenu = function(editor, event)
{
editor.hideContextMenu(editor, event);
}
SpawEditor.prototype.hideContextMenu = function(editor, event)
{
if (SpawEngine.active_context_menu)
{
SpawEngine.active_context_menu.hide();
SpawEngine.active_context_menu = null;
}
}
// returns specified element surrounding current selection, returns null if selection is not inside such element
SpawEditor.prototype.getSelectedElementByTagName = function(tagName)
{
var result = null;
var elm = this.getSelectionParent();
while (elm && elm.tagName && elm.tagName.toLowerCase() != tagName.toLowerCase() && elm.tagName.toLowerCase() != 'body')
elm = elm.parentNode;
if (elm && elm.tagName && elm.tagName.toLowerCase() != 'body')
result = elm;
return result;
}
// returns all anchors on the active page
SpawEditor.prototype.getAnchors = function()
{
var anchors = new Array();
var pdoc = this.getActivePageDoc();
var links = pdoc.getElementsByTagName("a");
for (var i=0; ix
Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586