var _____WB$wombat$assign$function_____ = function(name) {return (self._wb_wombat && self._wb_wombat.local_init && self._wb_wombat.local_init(name)) || self[name]; };
if (!self.__WB_pmw) { self.__WB_pmw = function(obj) { this.__WB_source = obj; return this; } }
{
let window = _____WB$wombat$assign$function_____("window");
let self = _____WB$wombat$assign$function_____("self");
let document = _____WB$wombat$assign$function_____("document");
let location = _____WB$wombat$assign$function_____("location");
let top = _____WB$wombat$assign$function_____("top");
let parent = _____WB$wombat$assign$function_____("parent");
let frames = _____WB$wombat$assign$function_____("frames");
let opener = _____WB$wombat$assign$function_____("opener");
var ASPxClientCommandConsts = {
BOLD_COMMAND : "bold",
ITALIC_COMMAND: "italic",
UNDERLINE_COMMAND: "underline",
STRIKETHROUGH_COMMAND: "strikethrough",
SUPERSCRIPT_COMMAND: "superscript",
SUBSCRIPT_COMMAND: "subscript",
JUSTIFYCENTER_COMMAND: "justifycenter",
JUSTIFYLEFT_COMMAND: "justifyleft",
INDENT_COMMAND: "indent",
OUTDENT_COMMAND: "outdent",
JUSTIFYRIGHT_COMMAND: "justifyright",
JUSTIFYFULL_COMMAND: "justifyfull",
FONTSIZE_COMMAND : "fontsize",
FONTNAME_COMMAND : "fontname",
FONTCOLOR_COMMAND: "forecolor",
BACKCOLOR_COMMAND: "backcolor",
FORMATBLOCK_COMMAND: "formatblock",
APPLYCSS_COMMAND: "applycss",
REMOVEFORMAT_COMMAND: "removeformat",
UNDO_COMMAND: "undo",
REDO_COMMAND: "redo",
COPY_COMMAND: "copy",
KBCOPY_COMMAND: "kbcopy",
PASTE_COMMAND: "paste",
KBPASTE_COMMAND: "kbpaste",
PASTEFROMWORD_COMMAND: "pastefromword",
PASTEFROMWORDDIALOG_COMMAND: "pastefromworddialog",
CUT_COMMAND: "cut",
KBCUT_COMMAND: "kbcut",
SELECT_ALL: "selectall",
DELETE_COMMAND: "delete",
KBDELETE_COMMAND: "kbdelete",
TEXTTYPE_COMMAND: "texttype",
NEWPARAGRAPHTYPE_COMMAND: "newparagraphtype",
LINEBREAKETYPE_COMMAND: "linebreaktype",
ENTER_COMMAND: "enter",
PASTEHTML_COMMAND: "pastehtml",
RESIZEOBJECT_COMMAND: "resizeobject",
DRAGDROPOBJECT_COMMAND: "dragdropobject",
DROPOBJECTFROMEXTERNAL_COMMAND: "dropobjectfromexternal",
INSERTORDEREDLIST_COMMAND: "insertorderedlist",
INSERTUNORDEREDLIST_COMMAND: "insertunorderedlist",
UNLINK_COMMAND: "unlink",
INSERTLINK_COMMAND: "insertlink",
INSERTIMAGE_COMMAND: "insertimage",
CHANGEIMAGE_COMMAND: "changeimage",
CHECKSPELLING_COMMAND: "checkspelling",
INSERTIMAGE_DIALOG_COMMAND: "insertimagedialog",
CHANGEIMAGE_DIALOG_COMMAND: "changeimagedialog",
INSERTLINK_DIALOG_COMMAND: "insertlinkdialog",
CHANGELINK_DIALOG_COMMAND: "changelinkdialog",
INSERTTABLE_DIALOG_COMMAND: "inserttabledialog",
TABLEPROPERTIES_DIALOG_COMMAND: "tablepropertiesdialog",
TABLECELLPROPERTIES_DIALOG_COMMAND: "tablecellpropertiesdialog",
TABLECOLUMNPROPERTIES_DIALOG_COMMAND: "tablecolumnpropertiesdialog",
TABLEROWPROPERTIES_DIALOG_COMMAND: "tablerowpropertiesdialog",
PRINT_COMMAND: "print",
FULLSCREEN_COMMAND: "fullscreen",
INSERTTABLE_COMMAND: "inserttable",
CHANGETABLE_COMMAND: "changetable",
CHANGETABLECELL_COMMAND: "changetablecell",
CHANGETABLEROW_COMMAND: "changetablerow",
CHANGETABLECOLUMN_COMMAND: "changetablecolumn",
DELETETABLE_COMMAND: "deletetable",
DELETETABLEROW_COMMAND: "deletetablerow",
DELETETABLECOLUMN_COMMAND: "deletetablecolumn",
INSERTTABLECOLUMNTOLEFT_COMMAND: "inserttablecolumntoleft",
INSERTTABLECOLUMNTORIGHT_COMMAND: "inserttablecolumntoright",
INSERTTABLEROWBELOW_COMMAND: "inserttablerowbelow",
INSERTTABLEROWABOVE_COMMAND: "inserttablerowabove",
SPLITTABLECELLHORIZONTALLY_COMMAND: "splittablecellhorizontally",
SPLITTABLECELLVERTICALLY_COMMAND: "splittablecellvertically",
MERGETABLECELLRIGHT_COMMAND: "mergetablecellright",
MERGETABLECELLDOWN_COMMAND: "mergetablecelldown",
CheckSpellingCore_COMMAND: "checkspellingcore",
Start_COMMAND: "start",
CUSTOMDIALOG_COMMAND: "customdialog",
EXPORT_COMMAND: "export",
SAVESTATEUNDOREDOSTACK_COMMAND: "savestateundoredostack"
};
var ASPxHtmlEditorCommands = {
Browser: {}
};
ASPxHtmlEditorCommands.Command = _aspxCreateClass(null, {
constructor: function(cmdID) {
this.commandID = cmdID;
},
Execute: function(cmdValue, editor) {
return true;
},
GetCommandID: function() {
return this.commandID;
},
GetState: function(editor) {
return true;
},
GetValue: function(editor) {
return null;
},
IsDefaultAction: function(editor) {
return false;
},
IsImmediateExecution: function() {
return false;
},
IsHtmlChangeable: function() {
return true;
},
IsLocked: function(editor) {
return false;
},
IsReversable: function() {
return true;
},
IsClientCommand: function() {
return true;
}
});
ASPxHtmlEditorCommands.Browser.Command = _aspxCreateClass(ASPxHtmlEditorCommands.Command, {
Execute: function(cmdValue, editor) {
ASPxHtmlEditorCommands.Command.prototype.Execute.apply(this, arguments);
var contentAreaDoc = editor.GetDesignViewDocument();
if (!this.NeedUseCss())
contentAreaDoc.execCommand(this.GetUseCSSCommandName(), false, false);
if(!editor.isSelectionRestored)
editor.RestoreSelection();
var isSuccessfully = contentAreaDoc.execCommand(this.GetCommandName(), false, this.GetCorrectedValue(cmdValue));
if (!this.NeedUseCss())
contentAreaDoc.execCommand(this.GetUseCSSCommandName(), false, true);
editor.SetFocus();
return isSuccessfully;
},
GetCommandName: function() {
return this.commandID;
},
GetCorrectedValue: function(value) {
return value;
},
GetState: function(editor) {
var ret = true;
if (!this.IsAlwaysEnabledCommand(this.commandID)) {
try {
ret = this.TryGetState(editor);
}
catch(ex) { ret = false; }
}
return ret;
},
GetValue: function(editor) {
var ret = null;
try {
ret = this.TryGetValue(editor);
}
catch(e) {}
return ret;
},
GetUseCSSCommandName: function(doc) {
return __aspxNetscapeFamily ? "styleWithCSS" : "useCSS";
},
IsLocked: function(editor) {
var ret = this.TryGetIsLocked(editor);
if (__aspxOpera && ret) {
try {
ret = !this.TryGetState(editor);
}
catch(ex) { ret = false; }
}
return ret;
},
TryGetState: function(editor) {
return editor.GetDesignViewDocument().queryCommandState(this.GetCommandName());
},
TryGetValue: function(editor) {
return editor.GetDesignViewDocument().queryCommandValue(this.GetCommandName());
},
TryGetIsLocked: function(editor) {
try {
return !editor.GetDesignViewDocument().queryCommandEnabled(this.GetCommandName());
} catch(e) {}
return true;
},
IsAlwaysEnabledCommand: function(commandID) {
return this.commandID == ASPxClientCommandConsts.FONTSIZE_COMMAND || this.commandID == ASPxClientCommandConsts.FONTNAME_COMMAND;
},
NeedUseCss: function() {
return true;
}
});
ASPxHtmlEditorCommands.Browser.FontStyle = _aspxCreateClass(ASPxHtmlEditorCommands.Browser.Command, {
Execute: function(cmdValue, editor) {
if(__aspxFirefox && __aspxBrowserVersion >= 4 && editor.GetSelection().GetHtml() != "") {
var contentAreaDoc = editor.GetDesignViewDocument();
contentAreaDoc.execCommand("useCSS", false, true);
var isSuccessfully = this.ExecuteInternal(cmdValue, editor);
contentAreaDoc.execCommand("useCSS", false, false);
return isSuccessfully;
}
else {
return this.ExecuteInternal(cmdValue, editor);
}
},
ExecuteInternal: function(cmdValue, editor) {
var selection = editor.GetSelection();
var elements = selection.GetElements();
for(var i = 0, el; el = elements[i]; i++) {
if(el.nodeType == 1)
this.ClearStyles(el);
}
return ASPxHtmlEditorCommands.Browser.Command.prototype.Execute.call(this, cmdValue, editor);
},
ClearStyles: function(element) {
var styles = [];
if(this.commandID == ASPxClientCommandConsts.BOLD_COMMAND)
styles = ["fontWeight", "bold", "normal", "light"];
else if(this.commandID == ASPxClientCommandConsts.ITALIC_COMMAND)
styles = ["fontStyle", "italic", "normal"];
else if(this.commandID == ASPxClientCommandConsts.UNDERLINE_COMMAND)
styles = ["textDecoration", "underline", "none"];
else if(this.commandID == ASPxClientCommandConsts.STRIKETHROUGH_COMMAND)
styles = ["textDecoration", "line-through", "none"];
if(styles.length == 0) return;
var styleName = styles[0];
if(element.style[styleName]) {
for(var i = 1; i < styles.length; i++) {
var styleValue = styles[i];
var regEx = new RegExp(styleValue, "gi");
element.style[styleName] = element.style[styleName].replace(regEx, "");
}
}
for(var el = element.firstChild; el; el = el.nextSibling) {
if(el.nodeType == 1)
this.ClearStyles(el);
}
}
});
ASPxHtmlEditorCommands.Browser.Justify = _aspxCreateClass(ASPxHtmlEditorCommands.Browser.Command, {
Execute: function(cmdValue, editor) {
var selection = editor.GetSelection();
var curElement = selection.GetSelectedElement();
var setAlign = this.GetAlignByCommandID();
if(!setAlign)
return false;
if(this.IsImgElement(curElement)) {
ASPxHtmlEditorCommands.Browser.Command.prototype.Execute.apply(this, arguments);
var imageInfo = ASPxHtmlEditorCommands.ChangeImage.GetImageProperties(curElement);
setAlign = setAlign == "justify" ? "left" : setAlign;
curElement = ASPxHtmlEditorCommands.ChangeImage.SetImageProperties(curElement, {
width: null,
height: null,
align: setAlign,
useFloat: imageInfo.useFloat
});
if(_aspxIsExistsElement(curElement))
ASPxClientHtmlEditorSelection.SelectElement(curElement, editor);
return true;
}
else {
var selection = editor.GetSelection();
var elements = selection.GetElements();
if(elements.length == 0)
elements.push(curElement);
for(var i = 0, el; el = elements[i]; i++) {
var par = this.FindAlignParagraph(el);
if(par && !this.IsTextAlignStateConform(par, setAlign)) {
par.align = "";
par.style.textAlign = setAlign;
}
}
if(__aspxIE && (curElement.tagName == "DIV" || this.IsElementContainsDivs(curElement))) {
var divs = [];
if(curElement.tagName == "DIV")
divs.push(curElement);
else {
for(var child = curElement.firstChild; child; child = child.nextSibling) {
if(child.tagName == "DIV")
divs.push(child);
}
}
for(var i = 0, div; div = divs[i]; i++)
_aspxChangeStyleAttribute(div, "display", "inline");
var res = ASPxHtmlEditorCommands.Browser.Command.prototype.Execute.call(this, cmdValue, editor);
for(var i = 0, div; div = divs[i]; i++)
_aspxRestoreStyleAttribute(div, "display");
return res;
}
return ASPxHtmlEditorCommands.Browser.Command.prototype.Execute.call(this, cmdValue, editor);
}
},
FindAlignParagraph: function(element) {
for(var el = element; el && el.tagName != "BODY"; el = el.parentNode) {
if(el.tagName == "P" && ((el.style && el.style.textAlign) || el.align))
return el;
}
return null;
},
TryGetState: function(editor) {
var curElement = ASPxClientHtmlEditorSelection.Create(editor).GetParentElement();
var findAlign = this.GetAlignByCommandID();
if(!findAlign || !curElement)
return false;
var isImgElement = this.IsImgElement(curElement);
if(!isImgElement && !__aspxWebKitFamily)
return ASPxHtmlEditorCommands.Browser.Command.prototype.TryGetState.call(this, editor);
if(isImgElement){
var imageInfo = ASPxHtmlEditorCommands.ChangeImage.GetImageProperties(curElement);
return imageInfo.align == findAlign;
}
if(curElement.nodeType == 1 && this.IsTextAlignStateConform(curElement, findAlign))
return true;
return this.IsTextAlignStateConform(curElement.parentNode, findAlign);
},
IsTextAlignStateConform: function(element, findAlign) {
return _aspxGetAttribute(element, "align") == findAlign || element.style.textAlign == findAlign;
},
IsImgElement: function(element) {
return (element && element.nodeType == 1 && element.tagName.toLowerCase() == "img");
},
IsElementContainsDivs: function(element) {
for(var child = element.firstChild; child; child = child.nextSibling) {
if(child.tagName == "DIV")
return true;
}
return false;
},
GetAlignByCommandID: function() {
switch(this.commandID) {
case "justifyleft":
return "left";
break;
case "justifycenter":
return "center";
break;
case "justifyright":
return "right";
break;
case "justifyfull":
return "justify";
break;
default:
return null;
}
}
});
ASPxHtmlEditorCommands.SelectionManipulationCommand = _aspxCreateClass(ASPxHtmlEditorCommands.Command, {
Execute: function(cmdValue, editor) {
this.newElements = [];
if(__aspxIE && __aspxBrowserMajorVersion > 8)
editor.RestoreSelection();
},
WrapElementInternal: function(target, wrapper) {
var inline = this.IsInlineTextElement(wrapper);
if((inline || this.IsNewElement(target.previousSibling)) && target.previousSibling && this.CanMerge(target.previousSibling, wrapper)) {
target.previousSibling.appendChild(target);
return target.previousSibling;
}
else if ((inline || this.IsNewElement(target.nextSibling)) && target.nextSibling && this.CanMerge(target.nextSibling, wrapper)) {
target.nextSibling.insertBefore(target, target.nextSibling.firstChild);
return target.nextSibling;
}
else {
target.parentNode.insertBefore(wrapper, target);
wrapper.appendChild(target);
this.newElements.push(wrapper);
return wrapper;
}
},
IsNewElement: function(target) {
for(var i = 0, el; el = this.newElements[i]; i++) {
if(target == el)
return true;
}
return false;
},
CanMerge: function(el1, el2) {
return el1.tagName == el2.tagName && el1.className == el2.className;
},
IsInlineTextElement: function(el) {
var expr = /^(SPAN|B|STRONG|I|EM|U|SUP|SUB|FONT)$/i;
return expr.test(typeof(el) == "object" ? el.tagName : el);
},
SeparateParentByPredicate: function(target, predicate) {
while(target && predicate(target) && this.SeparateParent(target, target.parentNode.className, false)) {
target = target.parentNode;
}
return target;
},
SeparateParent: function(target, className, tryMerge) {
var parent = target.parentNode;
if(!parent || parent.tagName == "BODY")
return false;
if(target.previousSibling) {
var prevParent = parent.previousSibling;
if(!prevParent || prevParent.tagName != parent.tagName || prevParent.className != parent.className) {
prevParent = parent.cloneNode(false);
parent.parentNode.insertBefore(prevParent, parent);
}
for(var child = parent.firstChild; child && child != target; child = parent.firstChild) {
prevParent.appendChild(child);
}
}
if(target.nextSibling) {
var nextParent = parent.nextSibling;
if(!nextParent || nextParent.tagName != parent.tagName || nextParent.className != parent.className) {
nextParent = parent.cloneNode(false);
_aspxInsertElementAfter(nextParent, parent);
}
for(var child = parent.lastChild; child && child != target; child = parent.lastChild) {
nextParent.insertBefore(child, nextParent.firstChild);
}
}
this.SetClassName(parent, className);
if(tryMerge && parent.previousSibling && this.CanMerge(parent, parent.previousSibling)) {
parent.previousSibling.appendChild(target);
_aspxRemoveElement(parent);
}
else if(tryMerge && parent.nextSibling && this.CanMerge(parent, parent.nextSibling)) {
parent.nextSibling.insertBefore(target, parent.nextSibling.firstChild);
_aspxRemoveElement(parent);
}
return true;
},
SetClassName: function(target, className) {
if(!className)
_aspxRemoveAttribute(target, !__aspxIE || __aspxBrowserVersion >= 8 ? "class" : "className");
else
target.className = className;
}
});
ASPxHtmlEditorCommands.ApplyCss = _aspxCreateClass(ASPxHtmlEditorCommands.SelectionManipulationCommand, {
Execute: function(cmdValue, editor) {
ASPxHtmlEditorCommands.SelectionManipulationCommand.prototype.Execute.apply(this, arguments);
cmdValue.tagName = _aspxTrim(cmdValue.tagName).toUpperCase();
cmdValue.cssClass = _aspxTrim(cmdValue.cssClass);
if(this.IsExclusionTagName(cmdValue.tagName))
return false;
var selection = editor.GetSelection();
var parentElement = selection.GetSelectedElement();
if(parentElement.nodeType == 3)
parentElement = parentElement.parentNode;
var cleanMode = !cmdValue.cssClass && !cmdValue.tagName;
if(this.IsExclusionTagName(parentElement.tagName)) {
this.SetClassName(parentElement, cmdValue.cssClass);
}
else if(selection.GetHtml()) {
var elements = selection.GetElements();
for(var i = 0, el; el = elements[i]; i++) {
if(cleanMode)
this.CleanFormat(el);
else if(!this.GetEqualParentElement(el.nodeType == 3 ? el.parentNode : el, cmdValue.tagName, cmdValue.cssClass))
this.ApplyFormat(el, cmdValue.cssClass, cmdValue.tagName);
}
}
},
GetValue: function(editor) {
var element = editor.GetSelection().GetSelectedElement();
var tagName = "";
var cssClass = "";
if (element && element.nodeType == 1 && element.tagName != "BODY") {
tagName = element.tagName.toLowerCase();
cssClass = element.className;
}
return { tagName: tagName, cssClass: cssClass };
},
CleanFormat: function(el) {
var parent = el.parentNode;
if(el.nodeType == 3 && parent.className && this.IsInlineTextElement(parent))
this.SeparateParent(el, "", true);
else if(el.nodeType == 1) {
this.CleanFormatInDescendants(el);
var prevSibling = el.previousSibling;
if(el.previousSibling && prevSibling.tagName == el.tagName && !prevSibling.className) {
for(var child = el.firstChild; child; child = el.firstChild) {
el.previousSibling.appendChild(child);
}
_aspxRemoveElement(el);
}
}
},
CleanFormatInDescendants: function(el) {
if(el.nodeType == 1) {
this.SetClassName(el, "");
for(var child = el.firstChild; child; child = child.nextSibling) {
this.CleanFormatInDescendants(child);
}
}
},
ApplyFormat: function(el, className, tagName) {
if(el.nodeType == 1 && (!tagName || el.tagName == tagName))
this.AppendClassName(el, className);
else
this.ApplyWrapperFormat(el, !tagName ? "SPAN" : tagName, className);
},
ApplyWrapperFormat: function(el, tagName, className) {
if(this.FindNotNestedNode(el) && this.IsCantBeNested(tagName)) {
var _this = this;
var predicate = function(target) { return !_this.IsCantBeNested(target); };
var nnElement = this.SeparateParentByPredicate(el, predicate);
var wrapper = this.WrapElement(nnElement, tagName, className);
for(var child = nnElement.firstChild; child; child = nnElement.firstChild) {
nnElement.parentNode.insertBefore(child, nnElement);
}
_aspxRemoveElement(nnElement);
}
else if(this.IsInlineTextElement(el.nodeType == 3 ? el.parentNode : el)) {
var _this = this;
var predicate = function(target) { return !_this.IsInlineTextElement(target.parentNode); };
el = this.IsInlineTextElement(tagName) ? el : this.SeparateParentByPredicate(el, predicate);
this.WrapElement(el, tagName, className);
}
else if(el.nodeType == 3)
this.WrapElement(el, tagName, className);
else
this.ApplyFormatToInlineChilds(el, tagName, className);
},
AppendClassName: function(target, className) {
if(className && target.className.indexOf(className) == -1) {
if(target.className.length > 0)
className = " " + className;
target.className += className;
}
},
WrapElement: function(target, tagName, className) {
var wrapper = target.ownerDocument.createElement(tagName);
this.SetClassName(wrapper, className);
this.WrapElementInternal(target, wrapper);
},
ApplyFormatToInlineChilds: function(el, tagName, className) {
var child = el.firstChild;
while(child) {
var next = child.nextSibling;
if(child.nodeType == 3)
this.WrapElement(child, tagName, className);
else if(child.tagName == tagName && child.className.indexOf(className) < 0)
this.AppendClassName(child, className);
else if(this.IsInlineTextElement(child))
this.WrapElement(child, tagName, className);
else
this.ApplyFormatToInlineChilds(child, tagName, className);
child = next;
}
},
IsCantBeNested: function(el) {
var expr = /^(H[1-6]|P|ADDRESS|BLOCKQUOTE|PRE|A)$/i;
return expr.test(typeof(el) == "object" ? el.tagName : el);
},
IsExclusionTagName: function(tagName) {
tagName = tagName.toUpperCase();
return tagName == "IMG" || tagName == "TABLE" || tagName == "OBJECT" || tagName == "EMBED";
},
GetEqualParentElement: function(elem, tagName, cssClass) {
if (tagName && cssClass)
return _aspxGetParentByTagNameAndAttributeValue(elem, tagName, "class", cssClass);
else if (cssClass)
return _aspxGetParentByPartialClassName(elem, cssClass);
},
FindNotNestedNode: function(el) {
if(!el || el.tagName == "BODY")
return null;
if(el.nodeType == 3)
el = el.parentNode;
if(this.IsCantBeNested(el))
return el;
return this.FindNotNestedNode(el.parentNode);
}
});
ASPxHtmlEditorCommands.Browser.FontColor = _aspxCreateClass(ASPxHtmlEditorCommands.Browser.Command, {
Execute: function(cmdValue, editor) {
if (!cmdValue)
cmdValue = editor.currentFontColor;
else
editor.currentFontColor = cmdValue;
var hyperlinks;
if(__aspxIE || __aspxWebKitFamily)
hyperlinks = this.SaveHyperlinks(editor);
if(__aspxFirefox && __aspxBrowserVersion >= 4) {
var contentAreaDoc = editor.GetDesignViewDocument();
contentAreaDoc.execCommand("useCSS", false, false);
var commandExecResult = ASPxHtmlEditorCommands.Browser.Command.prototype.Execute.call(this, cmdValue, editor);
contentAreaDoc.execCommand("useCSS", false, true);
}
else
var commandExecResult = ASPxHtmlEditorCommands.Browser.Command.prototype.Execute.call(this, cmdValue, editor);
if(hyperlinks)
this.RestoreHyperlinks(hyperlinks);
return commandExecResult;
},
GetValue: function(editor) {
return _aspxColorToHexadecimal(ASPxHtmlEditorCommands.Browser.Command.prototype.GetValue.call(this, editor));
},
NeedUseCss: function() {
return !__aspxNetscapeFamily;
},
TryGetValue: function(editor) {
return editor.currentFontColor;
},
SaveHyperlinks: function(htmlEditor) {
var hyperlinks = [ ];
var selection = ASPxClientHtmlEditorSelection.Create(htmlEditor);
var selectionContainer = selection.GetParentElement();
var anchors = _aspxGetElementsByTagName(selectionContainer, "A");
for(var i = 0; i < anchors.length; i++) {
var anchor = anchors[i];
if(this.IsHyperlink(anchor)) {
hyperlinks.push(
{
element: anchor,
innerHTML: anchor.innerHTML
}
);
}
}
return hyperlinks;
},
RestoreHyperlinks: function(hyperlinks) {
for(var i = 0; i < hyperlinks.length; i++) {
var hyperlink = hyperlinks[i];
hyperlink.element.innerHTML = hyperlink.innerHTML;
}
},
IsHyperlink: function(anchor) {
return typeof(anchor.href) == "string" && anchor.href.length > 0;
}
});
ASPxHtmlEditorCommands.Browser.FontSize = _aspxCreateClass(ASPxHtmlEditorCommands.Browser.Command, {
GetValue: function(editor) {
var value = ASPxHtmlEditorCommands.Browser.Command.prototype.GetValue.call(this, editor);
if(value && typeof(value) == 'string') {
if(value.indexOf("px") > -1) {
var index = _aspxGetDefaultSafariFontSizesInPixelHashTable()[value];
return index > -1 ? index + 1 : null;
}
if(value.indexOf("pt") > -1) {
var index = _aspxGetDefaultSafariFontSizesHashTable()[value];
return index > -1 ? index + 1 : null;
}
}
return value;
}
});
ASPxHtmlEditorCommands.Browser.FontName = _aspxCreateClass(ASPxHtmlEditorCommands.Browser.Command, {
GetValue: function(editor) {
var value = ASPxHtmlEditorCommands.Browser.Command.prototype.GetValue.call(this, editor);
return value ? this.TrimApostrophes(value) : "";
},
TrimApostrophes: function(str) {
if(str.indexOf('\'') == 0)
str = str.substr(1);
if(str.indexOf('\'') == str.length - 1)
str = str.substr(0, str.length - 1);
return str;
},
NeedUseCss: function() {
return !(__aspxFirefox && __aspxBrowserVersion >= 4);
}
});
ASPxHtmlEditorCommands.Browser.BgColor = _aspxCreateClass(ASPxHtmlEditorCommands.Browser.FontColor, {
Execute: function(cmdValue, editor) {
if (!cmdValue)
cmdValue = editor.currentBgColor;
else
editor.currentBgColor = cmdValue;
return ASPxHtmlEditorCommands.Browser.Command.prototype.Execute.call(this, cmdValue, editor);
},
GetCommandName: function() {
return __aspxIE ? ASPxHtmlEditorCommands.Browser.Command.prototype.GetCommandName.call(this) : "HiliteColor";
},
NeedUseCss: function() {
return true;
},
TryGetValue: function(editor) {
return editor.currentBgColor;
}
});
ASPxHtmlEditorCommands.Browser.InsertList = _aspxCreateClass(ASPxHtmlEditorCommands.Browser.Command, {
GetState: function(editor) {
var curSelection = ASPxClientHtmlEditorSelection.Create(editor);
var tagName = "";
switch (this.GetCommandName()) {
case ASPxClientCommandConsts.INSERTORDEREDLIST_COMMAND:
tagName = "OL";break;
case ASPxClientCommandConsts.INSERTUNORDEREDLIST_COMMAND:
tagName = "UL";break;
}
return !!_aspxGetParentByTagName(curSelection.GetParentElement(), tagName);
},
Execute: function(cmdValue, editor) {
if(__aspxIE) {
var doc = editor.GetDesignViewDocument();
var selectedElement = editor.GetSelection().selectedElement;
var clientSelection = editor.GetSelection().clientSelection;
var listItem = _aspxGetParentByTagName(selectedElement, "LI");
var tagName = (this.GetCommandName() == ASPxClientCommandConsts.INSERTORDEREDLIST_COMMAND) ? "OL" : "UL";
var oppositeTagName = (tagName == "OL") ? "UL" : "OL";
if(listItem != null && listItem.tagName == "LI" && listItem.parentNode.tagName == oppositeTagName) {
var bookmark = clientSelection.GetExtendedBookmark();
var curList = listItem.parentNode;
var newList = doc.createElement(tagName);
curList.parentNode.insertBefore(newList, listItem.parentNode);
if(listItem.previousSibling && listItem.previousSibling.tagName == "LI") {
var newPrevList = curList.cloneNode(false);
var curNode = curList.firstChild;
do {
var nextNode = curNode.nextSibling;
newPrevList.appendChild(curNode);
curNode = nextNode;
} while(curNode && nextNode != listItem);
newList.parentNode.insertBefore(newPrevList, newList);
}
newList.appendChild(listItem);
if(curList.childNodes.length == 0)
_aspxRemoveElement(curList);
newList.appendChild(listItem);
selectedElement = _aspxGetElementByIdInDocument(doc, bookmark.endMarkerID);
clientSelection.SelectElement(selectedElement);
clientSelection.RemoveExtendedBookmark(bookmark);
ASPxHtmlEditorCommands.Command.prototype.Execute.apply(this, arguments);
return true;
}
else if(!listItem && selectedElement.tagName != tagName) {
var bookmark = clientSelection.GetExtendedBookmark();
selectedElement = this.GetBlockSelectedElement(selectedElement);
var lineInfos = this.GetLineInfos(selectedElement);
var selectedLineInfos = this.GetSelectedLineInfos(selectedElement, lineInfos, bookmark);
var result = this.CreateBulletList(doc, tagName, lineInfos, selectedLineInfos.startLineIndex, selectedLineInfos.endLineIndex);
if(__aspxBrowserMajorVersion == 9)
editor.RestoreSelection();
selectedElement = _aspxGetElementByIdInDocument(doc, bookmark.endMarkerID);
clientSelection.SelectElement(selectedElement);
clientSelection.RemoveExtendedBookmark(bookmark);
if(result)
return true;
}
}
return ASPxHtmlEditorCommands.Browser.Command.prototype.Execute.call(this, cmdValue, editor);
},
CreateBulletList: function(doc, tagName, lineInfos, startLineIndex, endLineIndex) {
if(startLineIndex == -1 || endLineIndex == -1)
return false;
var lineIndex = startLineIndex;
var lineCount = lineInfos.length;
while(lineIndex <= endLineIndex) {
var line = lineInfos[lineIndex];
var firstLineNode = line[0];
var lastLineNode = line[line.length - 1];
var firstLineElement = this.GetLineSelectedElement(firstLineNode);
var lastLineElement = this.GetLineSelectedElement(lastLineNode);
var firstBlockNode = this.GetBlockSelectedElement(firstLineNode);
var hasBlockSibling = _aspxGetChildNodes(firstBlockNode, function(element) {
return ASPxHtmlEditorCommands.Enter.IsBlockNode(element);
}).length > 0;
var parent = null;
var replacedElement = null;
var isParentBlockLimit = this.IsBlockLimitElement(firstBlockNode);
var isMoveOutTheBlock = !hasBlockSibling && !isParentBlockLimit;
if(lineIndex == startLineIndex) {
var isList = false;
var sBlock = firstBlockNode;
if(sBlock.tagName == "LI") {
sBlock = sBlock.parentNode;
isList = true;
isMoveOutTheBlock = true;
}
for(var i = 0; i < lineIndex; i++) {
var uBlock = this.GetBlockSelectedElement(lineInfos[i][0]);
if(uBlock.tagName == "LI")
uBlock = uBlock.parentNode;
if(uBlock == sBlock && uBlock.tagName != tagName) {
var tFirst = lineInfos[i];
var tLast = lineInfos[lineIndex - 1];
var tFirstLineNode = tFirst[0];
var tLastLineNode = tLast[tLast.length - 1];
var textNodes = ASPxClientHtmlProcessingUtils.SplitNode(uBlock, [tFirstLineNode, tLastLineNode]);
if(isMoveOutTheBlock)
sBlock.parentNode.insertBefore(textNodes[1].cloneNode(true), sBlock);
else {
var childs = textNodes[1].childNodes;
var target = sBlock.firstChild;
for(var j = 0; j < childs.length; j++)
sBlock.insertBefore(childs[j].cloneNode(true), target);
}
this.RemoveLineBreakElement(uBlock, tFirstLineNode, tLastLineNode);
this.RemoveLineElement(uBlock, tFirstLineNode, tLastLineNode);
if(isList) {
while(_aspxGetInnerText(uBlock.firstChild) == "")
uBlock.removeChild(uBlock.firstChild);
}
break;
}
}
}
if(isParentBlockLimit && !this.IsAcceptableElement(firstBlockNode)) {
lineIndex++;
continue;
}
if(firstBlockNode.tagName == "LI") {
var parentLI = _aspxGetParentByTagName(firstLineNode, "LI");
var parentList = parentLI.parentNode;
var prev = parentList.previousSibling;
if(parentList.tagName != tagName) {
if(!prev || prev.nodeType != 1 || prev.tagName != tagName) {
prev = document.createElement(tagName);
parentList.parentNode.insertBefore(prev, parentList);
}
prev.appendChild(parentLI.cloneNode(true));
_aspxRemoveElement(parentLI);
}
else if(prev && prev.nodeType == 1 && prev.tagName == tagName) {
prev.appendChild(parentLI.cloneNode(true));
_aspxRemoveElement(parentLI);
}
if(_aspxGetInnerText(parentList) == "")
parentList.parentNode.removeChild(parentList);
}
else {
var list = doc.createElement(tagName);
var addInBegin = false;
if(isMoveOutTheBlock) {
replacedElement = firstBlockNode;
parent = replacedElement.parentNode;
var node = replacedElement.previousSibling;
if(node && node.nodeType == 1 && node.tagName == tagName)
list = node;
else
parent.insertBefore(list, replacedElement);
parent = replacedElement;
}
else {
parent = firstLineElement.parentNode;
var prevNode = firstLineElement.previousSibling;
var nextNode = lastLineElement.nextSibling;
if(prevNode && prevNode.nodeType == 1 && prevNode.tagName == tagName)
list = prevNode;
else if(nextNode && nextNode.nodeType == 1 && nextNode.tagName == tagName) {
list = nextNode;
addInBegin = true;
}
else {
parent.insertBefore(list, firstLineElement);
if(this.IsBoundaryElement(list.previousSibling))
parent.removeChild(list.previousSibling);
}
}
var li = doc.createElement("LI");
if(addInBegin)
list.insertBefore(li, list.firstChild);
else
list.appendChild(li);
var textNodes = ASPxClientHtmlProcessingUtils.SplitNode(parent, [firstLineNode, lastLineNode]);
if(isMoveOutTheBlock)
this.AppendLineElement(li, replacedElement, textNodes[1].cloneNode(true));
else {
var childs = textNodes[1].childNodes;
for(var j = 0; j < childs.length; j++)
this.AppendLineElement(li, null, childs[j].cloneNode(true));
}
this.RemoveLineBreakElement(parent, firstLineNode, lastLineNode);
this.RemoveLineElement(parent, firstLineNode, lastLineNode);
if(replacedElement && _aspxGetInnerText(replacedElement) == "")
replacedElement.parentNode.removeChild(replacedElement);
}
lineIndex++;
}
return true;
},
AppendLineElement: function(li, lineBlock, node) {
if(lineBlock && {p:1, div:1}[node.tagName.toLowerCase()]) {
_aspxCopyAllAttributes(lineBlock, li);
li.innerHTML = node.innerHTML;
}
else
li.appendChild(node);
},
RemoveLineBreakElement: function(lineBlock, firstLineNode, lastLineNode) {
var isRemoved = false;
var first = firstLineNode;
var last = lastLineNode;
var parent = first.parentNode;
do {
if(last && this.IsBoundaryElement(last.nextSibling)) {
last.parentNode.removeChild(last.nextSibling);
isRemoved = true;
}
else if(first && this.IsBoundaryElement(first.previousSibling)) {
first.parentNode.removeChild(first.previousSibling);
isRemoved = true;
}
else {
first = first ? first.previousSibling : null;
last = last ? last.nextSibling : null;
if(!(first || last)) {
first = parent.previousSibling ? parent.previousSibling : null;
last = parent.nextSibling ? parent.nextSibling : null;
if(parent != lineBlock)
parent = parent.parentNode;
}
}
} while(!isRemoved && parent != lineBlock);
},
RemoveLineElement: function(lineBlock, firstLineNode, lastLineNode) {
if(firstLineNode == lastLineNode) {
firstLineNode.parentNode.removeChild(firstLineNode);
return;
}
var isNeedRemoveElement = (arguments[3] == true);
if(lineBlock.hasChildNodes()) {
var childs = lineBlock.childNodes;
var index = 0;
while(childs[index]) {
if(childs[index].hasChildNodes())
isNeedRemoveElement = this.RemoveLineElement(childs[index], firstLineNode, lastLineNode, isNeedRemoveElement);
if(childs[index] == firstLineNode)
isNeedRemoveElement = true;
if(isNeedRemoveElement) {
if(childs[index] == lastLineNode)
isNeedRemoveElement = false;
lineBlock.removeChild(childs[index]);
}
else
index++;
}
}
return isNeedRemoveElement;
},
GetBlockSelectedElement: function(element) {
while(element && !(this.IsBlockLimitElement(element) || this.IsBlockElement(element)))
element = element.parentNode;
return element;
},
GetLineSelectedElement: function(element) {
var parent = element.parentNode;
while(parent && !this.IsBlockLimitElement(parent) && !this.IsBlockElement(parent)) {
element = parent;
parent = parent.parentNode;
}
return element;
},
GetLineInfos: function(selectedElement) {
var properties = {
lineInfos: [],
lineElements: []
};
properties = this.SearchHtmlLines(selectedElement, properties);
return properties.lineInfos;
},
GetSelectedLineInfos: function(parentElement, lineInfos, bookmark) {
var startLineIndex = -1,
endLineIndex = -1,
i = 0,
lineCount = lineInfos.length;
while(i < lineCount) {
var line = lineInfos[i];
var markers;
if(line.length == 1 && line[0].nodeType == 1)
markers = this.SearchMarkers(line[0], bookmark);
else if(line.length > 1) {
params = [line[0], line[line.length - 1]];
parts = ASPxClientHtmlProcessingUtils.SplitNode(parentElement, params);
var markers = this.SearchMarkers(parts[1], bookmark);
if(startLineIndex == -1 && markers.startMarkerIsFound)
startLineIndex = i;
if(endLineIndex == -1 && markers.endMarkerIsFound)
endLineIndex = i;
}
i++;
}
return {
startLineIndex: startLineIndex,
endLineIndex: endLineIndex
};
},
SearchHtmlLines: function(element, properties) {
var nodes = element.childNodes;
for(var i = 0; i < nodes.length; i++) {
var isLineBreak = this.IsBoundaryElement(nodes[i]) || this.IsBlockElement(nodes[i]) || this.IsBlockLimitElement(nodes[i]);
if( !isLineBreak ) {
if(nodes[i].hasChildNodes())
properties = this.SearchHtmlLines(nodes[i], properties);
else
properties.lineElements.push(nodes[i]);
}
else {
if(properties.lineElements.length > 0) {
properties.lineInfos.push( properties.lineElements );
properties.lineElements = [];
}
if(nodes[i].hasChildNodes())
properties = this.SearchHtmlLines(nodes[i], properties);
}
}
if(this.IsBlockElement(element) || this.IsBlockLimitElement(element)) {
if(properties.lineElements.length > 0) {
properties.lineInfos.push( properties.lineElements );
properties.lineElements = [];
}
}
return properties;
},
SearchMarkers: function(element, bookmark) {
var start = false;
var end = false;
if(element.nodeType == 1) {
if(element.id == bookmark.startMarkerID)
start = true;
if(element.id == bookmark.endMarkerID)
end = true;
if(element.hasChildNodes()) {
var childs = element.childNodes;
for(var i = 0; i < childs.length; i++) {
var markers = this.SearchMarkers(childs[i], bookmark);
start = start || markers.startMarkerIsFound;
end = end || markers.endMarkerIsFound;
}
}
}
return {
startMarkerIsFound: start,
endMarkerIsFound: end
};
},
IsAcceptableElement: function(element) {
var unacceptableElements = {colgroup: 1, table: 1, tbody: 1, thead:1, tfoot:1, tr: 1 };
if(element.nodeType == 1)
return !unacceptableElements[element.tagName.toLowerCase()];
return true;
},
IsBlockElement: function(element) {
return ASPxHtmlEditorCommands.Enter.IsBlockNode(element);
},
IsBlockLimitElement: function(element) {
if(!this.limiters) {
this.limiters = {};
for(var e in __aspxHEPathBlockLimitElements) {
if(!{div:1}[e])
this.limiters[e] = 1;
}
}
return element.nodeType == 1
&& !!this.limiters[element.tagName.toLowerCase()];
},
IsBoundaryElement: function(element) {
return element != null && element.nodeType == 1 && element.tagName.toUpperCase() == "BR";
}
});
ASPxHtmlEditorCommands.Browser.Indent = _aspxCreateClass(ASPxHtmlEditorCommands.Browser.Command, {
Execute: function(cmdValue, editor) {
var curSelection = ASPxClientHtmlEditorSelection.Create(editor);
var selectedList = ASPxHtmlEditorCommands.Browser.Indent.GetMainParentList(curSelection.GetParentElement());
if (selectedList)
this.IndentList(selectedList, curSelection, editor);
else
ASPxHtmlEditorCommands.Browser.Command.prototype.Execute.call(this, cmdValue, editor);
return true;
},
GetState: function(editor) {
return false;
},
IsLocked: function(editor) {
if (__aspxOpera)
return this.TryGetIsLocked(editor);
return ASPxHtmlEditorCommands.Browser.Command.prototype.IsLocked.call(this, editor);
},
TryGetIsLocked: function(editor) {
var isLocked = false;
var curSelection = ASPxClientHtmlEditorSelection.Create(editor);
var selectedList = ASPxHtmlEditorCommands.Browser.Indent.GetParentList(curSelection.GetParentElement());
if (selectedList) {
selectedList = ASPxHtmlEditorCommands.Browser.Indent.GetMainParentList(curSelection.GetParentElement());
isLocked = !this.IsIndentionAllowed(selectedList,
curSelection.GetStartContainer(),
curSelection.GetEndContainer(), editor);
}
else
isLocked = ASPxHtmlEditorCommands.Browser.Command.prototype.TryGetIsLocked.call(this, editor);
return isLocked;
},
IndentList: function(listNode, selection, editor) {
var bookmark = selection.GetExtendedBookmark();
var doc = editor.GetDesignViewDocument();
selection = ASPxClientHtmlEditorSelection.Create(editor);
var newlistNode = ASPxHtmlEditorCommands.Browser.Indent.IndentListCore(listNode, selection.GetStartContainer(),
selection.GetEndContainer(), this.GetIndent());
listNode.parentNode.replaceChild(newlistNode, listNode);
if(__aspxIE && __aspxBrowserMajorVersion > 8 && bookmark.endMarkerID) {
var endBm = doc.getElementById(bookmark.endMarkerID);
if(endBm.parentNode.childNodes.length == 2 && endBm.parentNode.firstChild.id == bookmark.startMarkerID) {
var fakeElement = doc.createTextNode(" ");
endBm.parentNode.insertBefore(fakeElement, endBm.parentNode.firstChild);
}
}
selection.SelectExtendedBookmark(bookmark);
if(fakeElement)
fakeElement.parentNode.removeChild(fakeElement);
if (!__aspxIE || __aspxBrowserMajorVersion > 8)
editor.SetFocus();
},
IsIndentionAllowed: function(listNode, startItemNode, endItemNode, htmlEditor) {
startItemNode = ASPxHtmlEditorCommands.Browser.Indent.EnsureListItemNode(startItemNode);
endItemNode = ASPxHtmlEditorCommands.Browser.Indent.EnsureListItemNode(endItemNode);
var indent = this.GetIndent();
var listItemArray = ASPxHtmlEditorCommands.Browser.Indent.GetListItemArray(listNode, 0, null);
listItemArray = ASPxHtmlEditorCommands.Browser.Indent.IndentListItemsInItemArray(listItemArray, startItemNode, endItemNode, indent);
if (listItemArray == null || listItemArray[0].level != 0)
return false;
for (var i = 1; i < listItemArray.length; i++) {
if (indent > 0) {
if (listItemArray[i].level - listItemArray[i - 1].level > indent)
return false;
}
else if (listItemArray[i].level < 0)
return false;
}
return true;
},
GetIndent: function() {
var indent = 0;
switch (this.GetCommandName()) {
case ASPxClientCommandConsts.INDENT_COMMAND:
indent = 1; break;
case ASPxClientCommandConsts.OUTDENT_COMMAND:
indent = -1; break;
}
return indent;
}
});
ASPxHtmlEditorCommands.Browser.Indent.IndentListCore = function(listNode, startNode, endNode, indent) {
startNode = ASPxHtmlEditorCommands.Browser.Indent.EnsureListItemNode(startNode);
endNode = ASPxHtmlEditorCommands.Browser.Indent.EnsureListItemNode(endNode);
var listItemArray = ASPxHtmlEditorCommands.Browser.Indent.GetListItemArray(listNode, 0, null);
var itemArray = ASPxHtmlEditorCommands.Browser.Indent.IndentListItemsInItemArray(listItemArray, startNode, endNode, indent);
return ASPxHtmlEditorCommands.Browser.Indent.GenerateListByItemArray(itemArray);
};
ASPxHtmlEditorCommands.Browser.Indent.GetListItemArray = function(listNode, currentLevel, itemArray, parentItemIndex) {
if (!itemArray)
itemArray = [ ];
if (!_aspxIsExists(parentItemIndex))
parentItemIndex = -1;
var curListItem = _aspxGetChildByTagName(listNode, "LI" ,0);
while(curListItem) {
itemArray.push({ 'level': currentLevel, 'node' : curListItem, 'parentItemIndex' : parentItemIndex });
var nestedListNode = ASPxHtmlEditorCommands.Browser.Indent.GetChildList(curListItem);
if (nestedListNode)
itemArray = ASPxHtmlEditorCommands.Browser.Indent.GetListItemArray(nestedListNode, currentLevel + 1, itemArray, itemArray.length - 1);
curListItem = ASPxHtmlEditorCommands.Browser.Indent.GetNextListItem(curListItem);
}
return itemArray;
};
ASPxHtmlEditorCommands.Browser.Indent.IndentListItemsInItemArray = function(itemArray, startListItem, endListItem, indent) {
var startItemIndex = -1;
var endItemIndex = -1;
for (var i = 0; i < itemArray.length; i++) {
if (itemArray[i].node == startListItem)
startItemIndex = i;
if (itemArray[i].node == endListItem)
endItemIndex = i;
if (startItemIndex != -1 && endItemIndex != -1)
break;
}
if (startItemIndex == -1 || endItemIndex == -1)
return null;
for (var i = startItemIndex; i <= endItemIndex; i++)
itemArray[i].level += indent;
if (indent < 0) {
for (var i = 0; i < itemArray.length; i++) {
if (itemArray[i].parentItemIndex != -1) {
var parentLevel = itemArray[itemArray[i].parentItemIndex].level;
if (itemArray[i].level - parentLevel > 1)
itemArray[i].level += indent;
}
}
}
return itemArray;
};
ASPxHtmlEditorCommands.Browser.Indent.GenerateListByItemArray = function(itemArray) {
if (itemArray.length <= 0)
return null;
var doc = itemArray[0].node.document || itemArray[0].node.ownerDocument;
var listNodeByLevel = [];
var listItemNodeArray = [];
var curLevel = 0;
for (var i = 0; i < itemArray.length; i++) {
var curItem = itemArray[i];
if (curLevel > curItem.level) {
for (var j = curItem.level + 1; j <= curLevel; j++)
listNodeByLevel[j] = null;
}
if (!listNodeByLevel[curItem.level]) {
var oldListNode = ASPxHtmlEditorCommands.Browser.Indent.GetParentList(curItem.node);
var newListNode = oldListNode.cloneNode(false);
listNodeByLevel[curItem.level] = newListNode;
if (curItem.level - 1 >= 0)
listItemNodeArray[curItem.level - 1].appendChild(newListNode);
}
var clonedListItem = ASPxHtmlEditorCommands.Browser.Indent.CloneListItem(curItem.node, doc);
listItemNodeArray[curItem.level] = clonedListItem;
listNodeByLevel[curItem.level].appendChild(clonedListItem);
curLevel = curItem.level;
}
return listNodeByLevel[0];
};
ASPxHtmlEditorCommands.Browser.Indent.EnsureListItemNode = function(node) {
while (node) {
var tagName = "";
var parentNode = node.parentNode;
if (parentNode && parentNode.nodeType == 1)
tagName = parentNode.tagName.toUpperCase();
if (tagName == "OL" || tagName == "UL")
break;
node = parentNode;
}
return node;
};
ASPxHtmlEditorCommands.Browser.Indent.CloneListItem = function(item, doc) {
var newItem = item.cloneNode(true);
newItem.innerHTML = "";
for (var i = 0 ; i < item.childNodes.length; i++) {
var tagName = item.childNodes[i].tagName;
tagName = tagName ? tagName.toUpperCase() : "";
if ((tagName != "UL") && (tagName != "OL"))
newItem.appendChild(item.childNodes[i].cloneNode(true));
}
return newItem;
};
ASPxHtmlEditorCommands.Browser.Indent.GetChildList = function(elem) {
for (var i = 0 ; i < elem.childNodes.length; i++) {
var tagName = elem.childNodes[i].tagName;
tagName = tagName ? tagName.toUpperCase() : "";
if ((tagName == "UL") || (tagName == "OL"))
return elem.childNodes[i];
}
return null;
};
ASPxHtmlEditorCommands.Browser.Indent.GetNextListItem = function(listItemNode) {
var nextListItemNode = listItemNode.nextSibling;
while (nextListItemNode != null && nextListItemNode.nodeType != 1)
nextListItemNode = nextListItemNode.nextSibling;
return nextListItemNode;
};
ASPxHtmlEditorCommands.Browser.Indent.GetMainParentList = function(elem) {
var lastListNode = null;
while (elem) {
if (elem.nodeType == 1) {
var tagName = elem.tagName.toUpperCase();
if (tagName == "UL" || tagName == "OL")
lastListNode = elem;
}
elem = elem.parentNode;
}
return lastListNode;
};
ASPxHtmlEditorCommands.Browser.Indent.GetParentList = function(elem) {
var selectedList = _aspxGetParentByTagName(elem, "OL");
if (!selectedList)
selectedList = _aspxGetParentByTagName(elem, "UL");
return selectedList;
};
var __aspxEmptyBorderTableClassName = "dxEmptyBorderTable";
var __aspxHESizeTypeRegExp = new RegExp("([0-9]*[,.]?[0-9]*)(px|%)");
var _aspxHETableHelper = {
AppendEmptyBorderClassName: function(elem) {
if (elem.className.indexOf(__aspxEmptyBorderTableClassName) > -1)
return;
elem.className += " " + __aspxEmptyBorderTableClassName;
},
IsEmptyBorder: function(table) {
if (!table)
return false;
return table.border == "0" || !table.border;
},
ReplaceTableStyleBorderByAttribute: function(table) {
var tableStyle = table.style;
if (tableStyle.borderLeftColor &&
(tableStyle.borderLeftColor == tableStyle.borderRightColor) &&
(tableStyle.borderRightColor == tableStyle.borderBottomColor) &&
(tableStyle.borderBottomColor == tableStyle.borderTopColor)) {
this.SetTableBorderColor(table, tableStyle.borderBottomColor);
tableStyle.borderLeftColor = "";
_aspxRemoveStyleAttribute(tableStyle, "borderLeftColor");
tableStyle.borderRightColor = "";
_aspxRemoveStyleAttribute(tableStyle, "borderRightColor");
tableStyle.borderTopColor = "";
_aspxRemoveStyleAttribute(tableStyle, "borderTopColor");
tableStyle.borderBottomColor = "";
_aspxRemoveStyleAttribute(tableStyle, "borderBottomColor");
}
},
RemoveEmptyBorderClassName: function(elem) {
elem.className = elem.className.replace(__aspxEmptyBorderTableClassName, "");
},
GetTable: function(element) {
if(!element) return null;
return element.tagName == "TABLE" ? element : _aspxGetParentByTagName(element, "TABLE");
},
GetTableRow: function(elem) {
if (elem && elem.nodeType == 1 && elem.tagName.toUpperCase() == "TR")
return elem;
var cell = this.GetTableCell(elem);
if (cell)
return cell.parentNode;
return null;
},
GetTableCellBySelection: function(startElem, endElem) {
var cell = _aspxHETableHelper.GetTableCell(startElem);
if (!cell && endElem) {
cell = _aspxHETableHelper.GetTableCell(endElem);
if (__aspxSafari && startElem && startElem.tagName.toUpperCase() == "TR") {
var index = cell.cellIndex - 1;
if (index < 0)
cell = startElem.cells[startElem.cells.length - 1];
else
cell = startElem.cells[index];
}
}
return cell;
},
GetTableCell: function(element) {
if (!element)
return null;
if (element.nodeType == "1" &&
(element.tagName.toUpperCase() == "TD" || element.tagName.toUpperCase() == "TH"))
return element;
var cell = _aspxGetParentByTagName(element, "TD");
if (!cell)
cell = _aspxGetParentByTagName(element, "TH");
return cell;
},
GetTableProperties: function(table) {
var tableInfoObject = {
borderWidth: 0,
borderColor: null,
backgroundColor: null,
width: null,
height: null,
cellPadding: 0,
cellSpacing: 0,
align: null,
accessibility: null
};
if (table.className.indexOf(__aspxEmptyBorderTableClassName) == -1) {
if (_aspxIsExists(table.border))
tableInfoObject.borderWidth = table.border;
var borderColor = this.GetTableBorderColor(table);
if (_aspxIsExists(borderColor))
tableInfoObject.borderColor = borderColor;
}
if (table.style.backgroundColor)
tableInfoObject.backgroundColor = table.style.backgroundColor;
if (table.style.width)
tableInfoObject.width = table.style.width;
if (table.style.height)
tableInfoObject.height = table.style.height;
tableInfoObject.cellPadding = table.cellPadding;
tableInfoObject.cellSpacing = table.cellSpacing;
if (table.align)
tableInfoObject.align = table.align;
var accessibility = { caption: "", summary: "", headers: "" };
accessibility.headers = this.GetAccessibilityHeadersValue(table);
accessibility.caption = this.GetAccessibilityCaption(table);
accessibility.summary = table.summary;
tableInfoObject.accessibility = accessibility;
return tableInfoObject;
},
SetTableProperties: function(table, properties, htmlEditor) {
if (properties) {
if (_aspxIsExists(properties.borderWidth))
this.SetTableBorderWidth(table, properties.borderWidth, htmlEditor);
if (_aspxIsExists(properties.borderColor))
this.SetTableBorderColor(table, properties.borderColor);
this.SetBackgroundColor(table, properties.backgroundColor);
table.cellSpacing = properties.cellSpacing;
table.cellPadding = properties.cellPadding;
if (properties.width)
table.style.width = properties.width;
else if (_aspxIsExists(table.style.width)) {
_aspxRemoveAttribute(table, "width");
_aspxRemoveStyleAttribute(table, "width");
}
if (properties.height)
table.style.height = properties.height;
else if (_aspxIsExists(table.style.height)) {
_aspxRemoveAttribute(table, "height");
table.style.height = "";
_aspxRemoveStyleAttribute(table, "height");
}
if (properties.align)
table.align = properties.align;
else if (_aspxIsExists(table.align)) {
table.align = "";
_aspxRemoveAttribute(table, "align");
}
if (properties.accessibility)
this.SetTableAccessibility(table, properties.accessibility);
}
},
SetTableBorderWidth: function(table, borderWidth, htmlEditor) {
if (__aspxFirefox && table.style.borderCollapse == "collapse") {
var tempTableId = ASPxClientSelection.CreateUniqueID();
_aspxChangeAttribute(table, "id", tempTableId);
table.style.borderCollapse = "separate";
this.currentHtmlEditor = htmlEditor;
_aspxSetTimeout("_aspxHETableHelper.SetTableBorderWidthDelay('" + tempTableId + "'," + borderWidth + ")", 100);
}
else {
_aspxSetAttribute(table, "border", borderWidth);
this.SetEmptyTableBorderClass(table);
}
},
SetTableBorderWidthDelay: function(tableId, borderWidth) {
var table = _aspxGetElementByIdInDocument(this.currentHtmlEditor.GetDesignViewDocument(), tableId);
_aspxSetAttribute(table, "border", borderWidth);
table.style.borderCollapse = "collapse";
_aspxRestoreAttribute(table, "id");
this.SetEmptyTableBorderClass(table);
this.currentHtmlEditor.commandManager.UpdateLastItemInRestoreHtmlArray();
this.currentHtmlEditor = null;
},
SetEmptyTableBorderClass: function(table) {
if (this.IsEmptyBorder(table))
this.AppendEmptyBorderClassName(table);
else
this.RemoveEmptyBorderClassName(table);
},
GetCellProperties: function(cell) {
var cellInfo = {
backgroundColor: null,
align: null,
vAlign: null
};
if (cell.style.textAlign)
cellInfo.align = cell.style.textAlign;
if (cell.style.verticalAlign)
cellInfo.vAlign = cell.style.verticalAlign;
if (cell.style.backgroundColor)
cellInfo.backgroundColor = cell.style.backgroundColor;
return cellInfo;
},
SetCellProperties: function(cell, properties) {
if (properties.vAlign)
cell.style.verticalAlign = properties.vAlign.toLowerCase();
else if (_aspxIsExists(cell.vAlign))
_aspxRemoveStyleAttribute(cell, "verticalAlign");
if (properties.align)
cell.style.textAlign = properties.align.toLowerCase();
else if (_aspxIsExists(cell.align))
_aspxRemoveStyleAttribute(cell, "textAlign");
this.SetBackgroundColor(cell, properties.backgroundColor);
},
SetCellPropertiesForAllCell: function(table, properties) {
for (var i = 0; i < table.rows.length; i++) {
for (var j = 0; j < table.rows[i].cells.length; j++)
this.SetCellProperties(this.GetCell(table, i, j), properties);
}
},
SetColumnProperties: function(cell, properties) {
var table = _aspxGetParentByTagName(cell, "TABLE");
var row = cell.parentNode;
var tableModel = _aspxHETableHelper.CreateTableModel(table);
var columnIndex = this.GetColumnIndexByTableModel(tableModel, row.rowIndex, cell);
var colSpan = this.GetColSpan(cell);
for (var i = 0; i < tableModel.length; i++) {
for (var j = columnIndex; j < columnIndex + colSpan; j++) {
var curCell = tableModel[i][j];
if (this.GetColSpan(curCell) <= colSpan) {
this.SetCellProperties(curCell, properties);
if (properties.width)
curCell.style.width = properties.width;
else if (_aspxIsExists(curCell.style.width)) {
curCell.style.width = "";
_aspxRemoveStyleAttribute(curCell, "width");
}
}
}
}
},
GetColumnProperties: function(cell) {
var columnInfo = {
backgroundColor: null,
width: null,
align: null,
vAlign: null
};
var table = _aspxGetParentByTagName(cell, "TABLE");
var row = cell.parentNode;
var tableModel = _aspxHETableHelper.CreateTableModel(table);
var columnIndex = this.GetColumnIndexByTableModel(tableModel, row.rowIndex, cell);
var colSpan = this.GetColSpan(cell);
var curCellInfo = this.GetCellProperties(cell);
var align = columnInfo.align = curCellInfo.align;
var vAlign = columnInfo.vAlign = curCellInfo.vAlign;
var backgroundColor = columnInfo.backgroundColor = curCellInfo.backgroundColor;
var maxCellWidth = 0;
var isWidthDefined = true;
for (var i = 0; i < tableModel.length; i++) {
for (var j = columnIndex; j < columnIndex + colSpan; j++) {
var curCell = tableModel[i][j];
if (this.GetColSpan(curCell) <= colSpan) {
var curCellInfo = this.GetCellProperties(curCell);
if (curCell.style.width && _aspxGetClearClientWidth(curCell) > maxCellWidth)
maxCellWidth = curCell.style.width;
if (align != curCellInfo.align)
columnInfo.align = null;
if (vAlign != curCellInfo.vAlign)
columnInfo.vAlign = null;
if (backgroundColor != curCellInfo.backgroundColor)
columnInfo.backgroundColor = null;
if (isWidthDefined) {
var curCellColSpan = this.GetColSpan(curCell);
if (curCellColSpan != colSpan)
isWidthDefined = false;
else if (columnIndex != this.GetColumnIndexByTableModel(tableModel, i, curCell))
isWidthDefined = false;
}
}
}
}
if (isWidthDefined && this.ParseSizeString(maxCellWidth).value > 0)
columnInfo.width = maxCellWidth;
return columnInfo;
},
GetRowProperties: function(cell) {
var rowInfo = {
backgroundColor: null,
height: null,
align: null,
vAlign: null
};
var table = _aspxGetParentByTagName(cell, "TABLE");
var row = cell.parentNode;
var tableModel = _aspxHETableHelper.CreateTableModel(table);
var rowSpan = this.GetRowSpan(cell);
var curCellInfo = this.GetCellProperties(cell);
var align = rowInfo.align = curCellInfo.align;
var vAlign = rowInfo.vAlign = curCellInfo.vAlign;
var backgroundColor = rowInfo.backgroundColor = curCellInfo.backgroundColor;
var maxCellHeight = 0;
var isHeightDefined = true;
for (var i = row.rowIndex; i < row.rowIndex + rowSpan; i++) {
for (var j = 0; j < tableModel[i].length; j++) {
var curCell = tableModel[i][j];
if (this.GetRowSpan(curCell) <= rowSpan) {
var curCellInfo = this.GetCellProperties(curCell);
if (curCell.style.height && _aspxGetClearClientHeight(curCell) > maxCellHeight)
maxCellHeight = curCell.style.height;
if (align != curCellInfo.align)
rowInfo.align = null;
if (vAlign != curCellInfo.vAlign)
rowInfo.vAlign = null;
if (backgroundColor != curCellInfo.backgroundColor)
rowInfo.backgroundColor = null;
if (isHeightDefined) {
var curCellRowSpan = this.GetRowSpan(curCell);
if (curCellRowSpan != rowSpan)
isHeightDefined = false;
else if (row.rowIndex != curCell.parentNode.rowIndex)
isHeightDefined = false;
}
}
}
}
if (isHeightDefined && this.ParseSizeString(maxCellHeight).value > 0)
rowInfo.height = maxCellHeight;
return rowInfo;
},
SetRowProperties: function(cell, properties) {
var table = _aspxGetParentByTagName(cell, "TABLE");
var row = cell.parentNode;
var tableModel = _aspxHETableHelper.CreateTableModel(table);
var columnIndex = this.GetColumnIndexByTableModel(tableModel, row.rowIndex, cell);
var rowSpan = this.GetRowSpan(cell);
var rowIndex = row.rowIndex;
for (var i = rowIndex; i < rowIndex + rowSpan; i++) {
for (var j = 0; j < tableModel[i].length; j++) {
if (this.GetRowSpan(tableModel[i][j]) <= rowSpan) {
this.SetCellProperties(tableModel[i][j], properties);
if (properties.height)
tableModel[i][j].style.height = properties.height;
else if (_aspxIsExists(tableModel[i][j].style.width)) {
tableModel[i][j].style.height = "";
_aspxRemoveStyleAttribute(tableModel[i][j], "height");
}
}
}
}
},
SetTableAccessibility: function(table, properties) {
if (properties.caption) {
var caption = table.createCaption();
caption.innerHTML = properties.caption;
}
else
table.deleteCaption();
if (properties.summary)
table.summary = properties.summary;
else
_aspxRemoveAttribute(table, "summary");
var hasColumnHeaders = this.GetHasColumnHeaders(table);
var headers = properties.headers;
this.SetRowAndBothHeaders(table, headers);
this.SetColumnAndBothHeaders(table, headers, hasColumnHeaders);
},
SetColumnAndBothHeaders: function(table, headers, hasColumnHeaders) {
if ((headers == 'column' || headers == 'both') && !this.GetHasColumnHeaders(table)) {
for (var i = 0; i < table.rows.length; i++) {
var newCell = _aspxReplaceTagName(table.rows[i].cells[0], 'TH');
if (newCell != null && !(headers == 'both' && newCell.scope == 'col'))
newCell.scope = 'row';
}
}
if (hasColumnHeaders && headers != 'column' && headers != 'both') {
for (var i = 0; i < table.rows.length; i++) {
var row = table.rows[i];
if (row.parentNode.nodeName.toUpperCase() == 'TBODY') {
var newCell = _aspxReplaceTagName(row.cells[0], 'TD');
if (newCell != null)
newCell.removeAttribute('scope');
}
}
}
},
SetRowAndBothHeaders: function(table, headers) {
var hasRowHeaders = this.GetHasRowHeaders(table);
if (!hasRowHeaders && (headers == 'row' || headers == 'both')) {
var firstRow = table.rows[0];
for (var i = 0; i < firstRow.childNodes.length; i++) {
if (firstRow.childNodes[i].nodeType == 1) {
var th = _aspxReplaceTagName(firstRow.childNodes[i], 'TH');
if (th)
th.scope = 'col';
}
}
var tHead = table.tHead;
if (!tHead)
tHead = table.createTHead();
if (tHead.childNodes.length == 0)
tHead.appendChild(firstRow);
for (var i = table.tBodies.length - 1; i >= 0; i--) {
if (_aspxTrim(table.tBodies[i].innerHTML) == "")
table.removeChild(table.tBodies[i]);
}
}
if (hasRowHeaders && headers != 'row' && headers != 'both') {
var firstRow = table.rows[0];
for (var i = 0; i < firstRow.cells.length; i++) {
var newCell = _aspxReplaceTagName(firstRow.cells[i], "TD");
if (newCell != null)
_aspxRemoveAttribute(newCell, "scope");
}
if (table.tHead && table.tHead.childNodes.length > 0) {
var firstRow = table.tBodies[0].firstChild;
for (var i = table.tHead.childNodes.length - 1; i >= 0; i--) {
if (table.tHead.childNodes[i].nodeType == 1)
firstRow = table.tBodies[0].insertBefore(table.tHead.childNodes[i], firstRow);
}
table.removeChild(table.tHead);
}
}
},
GetAccessibilityHeadersValue: function(table) {
var hasColumnHeaders = this.GetHasColumnHeaders(table);
var hasRowHeaders = this.GetHasRowHeaders(table);
var ret = null;
if (hasColumnHeaders && hasRowHeaders)
ret = "both";
else if (hasColumnHeaders)
ret = "column";
else if (hasRowHeaders)
ret = "row";
return ret;
},
GetAccessibilityCaption: function(table) {
var caption = _aspxGetChildByTagName(table, "CAPTION", 0);
if (caption)
return caption.innerHTML;
return "";
},
GetHasColumnHeaders: function(table) {
for (var i = 0; i < table.rows.length; i++) {
if (table.rows[i].cells[0].nodeName.toUpperCase() != 'TH')
return false;
}
return true;
},
GetHasRowHeaders: function(table) {
if (table.rows.length == 0)
return false;
for (var i = 0; i < table.rows[0].cells.length; i++) {
if (table.rows[0].cells[i].nodeName.toUpperCase() != 'TH')
return false;
}
return true;
},
IsTableColumnEqual: function(table) {
if (table.rows.length < 0)
return false;
var cellWidth = table.rows[0].cells[0].style.width;
if (!cellWidth)
return false;
for (var i = 0; i < table.rows.length; i++) {
var curRow = table.rows[i];
for (var j = 0; j < curRow.cells.length; j++)
if (cellWidth && cellWidth != this.GetCell(table, i, j).style.width)
return false;
}
return true;
},
AdjustColumnWidth: function(table) {
var cellWidth = 100 / table.rows[0].cells.length + "%";
for (var i = 0; i < table.rows.length; i++) {
var curRow = table.rows[i];
for (var j = 0; j < curRow.cells.length; j++) {
_aspxRemoveAttribute(this.GetCell(table, i, j), "width");
this.GetCell(table, i, j).style.width = cellWidth;
}
}
},
InsertColumn: function(cell, shift, htmlEditor) {
if (cell.nodeName.toUpperCase() != "TD" && cell.nodeName.toUpperCase() != "TH")
return "";
var table = this.GetTable(cell);
var tableModel = this.CreateTableModel(table);
var row = cell.parentNode;
var columnIndex = this.GetColumnIndexByTableModel(tableModel, row.rowIndex, cell);
var colSpan = this.GetColSpan(cell);
var nextColumnIndex = -1;
if (shift > 0)
nextColumnIndex = columnIndex + colSpan;
else
nextColumnIndex = columnIndex;
var isTableColumnEqual = this.IsTableColumnEqual(table);
var doc = _aspxGetElementDocument(cell);
for (var r = 0; r < tableModel.length; r++) {
var curCell = shift > 0 ? tableModel[r][nextColumnIndex - 1] : tableModel[r][nextColumnIndex];
if(!curCell) continue;
var curCellColumnIndex = this.GetColumnIndexByTableModel(tableModel, r, curCell);
var curCellColSpan = this.GetColSpan(curCell);
if ((shift > 0 && curCellColumnIndex + curCellColSpan == columnIndex + colSpan) ||
(shift == 0 && curCellColumnIndex == columnIndex)) {
var curCellRowSpan = this.GetRowSpan(curCell);
var newCell = this.CreateNewCellByCell(tableModel[r][columnIndex], true);
for (var j = r; j < r + curCellRowSpan; j++)
_aspxArrayInsert(tableModel[j], newCell, nextColumnIndex);
r = j - 1;
}
else
_aspxArrayInsert(tableModel[r], curCell, nextColumnIndex);
}
var rowIndex = row.rowIndex;
this.GenerateTableFromModel(tableModel, table);
if (isTableColumnEqual)
this.AdjustColumnWidth(table);
if (htmlEditor)
this.SelectCellCore(tableModel[rowIndex][nextColumnIndex], htmlEditor);
},
InsertRow: function(cell, shift, htmlEditor) {
if (cell.nodeName.toUpperCase() != "TD" && cell.nodeName.toUpperCase() != "TH")
return "";
var table = this.GetTable(cell);
var tableModel = this.CreateTableModel(table);
var row = cell.parentNode;
var rowIndex = row.rowIndex;
var columnIndex = this.GetColumnIndexByTableModel(tableModel, rowIndex, cell);
var rowSpan = this.GetRowSpan(cell);
var doc = _aspxGetElementDocument(cell);
var newRowIndex = -1;
var rowIndexInModel = -1;
if (shift > 0) {
rowIndexInModel = rowIndex + rowSpan - 1;
newRowIndex = rowIndex + rowSpan + shift - 1;
}
else {
newRowIndex = rowIndex;
rowIndexInModel = rowIndex;
}
var newRowModel = [ ];
for (var i = 0; i < tableModel[rowIndexInModel].length; i++) {
var curCell = tableModel[rowIndexInModel][i];
var curCellRow = curCell.parentNode;
var curCellRowSpan = this.GetRowSpan(curCell);
if ((shift > 0 && (curCellRow.rowIndex + curCellRowSpan == rowIndex + rowSpan)) ||
(shift == 0 && (curCellRow.rowIndex == rowIndex))) {
var curCellColSpan = this.GetColSpan(curCell);
var newCell = this.CreateNewCellByCell(curCell);
for (var j = i; j < i + curCellColSpan; j++)
newRowModel[j] = newCell;
i = j - 1;
}
else
newRowModel[i] = tableModel[rowIndexInModel][i];
}
_aspxArrayInsert(tableModel, newRowModel, newRowIndex);
var newRow = null;
if (_aspxGetParentByTagName(cell, "THEAD"))
newRow = table.tHead.insertRow(newRowIndex);
else
newRow = table.insertRow(newRowIndex);
_aspxCopyAllAttributes(row, newRow);
_aspxRemoveAttribute(newRow, "id");
this.GenerateTableFromModel(tableModel, table);
if (htmlEditor)
this.SelectCellCore(tableModel[newRowIndex][columnIndex], htmlEditor);
},
RemoveRow: function(cell, htmlEditor) {
var row = _aspxHETableHelper.GetTableRow(cell);
if (row) {
var table = this.GetTable(cell);
var tableModel = this.CreateTableModel(table);
var columnIndex = this.GetColumnIndexByTableModel(tableModel, row.rowIndex, cell);
var rowIndex = row.rowIndex;
var rowSpan = this.GetRowSpan(tableModel[rowIndex][columnIndex]);
for (var r = rowSpan + rowIndex - 1; r >= rowIndex; r--) {
_aspxArrayRemoveAt(tableModel, r);
if (r < table.rows.length)
table.deleteRow(r);
}
if (table.rows.length > 0) {
this.GenerateTableFromModel(tableModel, table);
if (htmlEditor) {
rowIndex = Math.min(rowIndex, table.rows.length - 1);
this.SelectCellCore(tableModel[rowIndex][columnIndex], htmlEditor);
}
}
else
_aspxRemoveElement(table);
return true;
}
return false;
},
RemoveColumn: function(cell, htmlEditor) {
var row = _aspxHETableHelper.GetTableRow(cell);
if (row) {
var table = this.GetTable(cell);
var tableModel = this.CreateTableModel(table);
var columnIndex = this.GetColumnIndexByTableModel(tableModel, row.rowIndex, cell);
var rowIndex = row.rowIndex;
var colSpan = this.GetColSpan(tableModel[rowIndex][columnIndex]);
for (var r = 0; r < tableModel.length; r++) {
for (var c = columnIndex + colSpan - 1; c >= columnIndex; c--) {
_aspxArrayRemoveAt(tableModel[r], c);
}
}
if (tableModel[rowIndex].length > 0) {
this.GenerateTableFromModel(tableModel, table);
if (htmlEditor) {
columnIndex = Math.min(columnIndex, tableModel[rowIndex].length - 1);
this.SelectCellCore(tableModel[rowIndex][columnIndex], htmlEditor);
}
}
else
_aspxRemoveElement(table);
return true;
}
return false;
},
SplitCellHorizontal: function(cell, htmlEditor) {
if (!cell)
return false;
var table = _aspxGetParentByTagName(cell, "TABLE");
var row = cell.parentNode;
var rowIndex = row.rowIndex;
var tableModel = _aspxHETableHelper.CreateTableModel(table);
var columnIndex = this.GetColumnIndexByTableModel(tableModel, row.rowIndex, cell);
var colSpan = isNaN(cell.colSpan) ? 1 : cell.colSpan;
var doc = _aspxGetElementDocument(table);
var newCellWidth = "";
var newCell = doc.createElement(cell.nodeName);
newCell.style.cssText = cell.style.cssText;
this.AddDefaultContentToCell(newCell);
if (colSpan > 1) {
var newColSpan = Math.ceil(colSpan / 2);
var startIdx = columnIndex + newColSpan;
var endIdx = columnIndex + colSpan;
var rowSpan = isNaN(cell.rowSpan) ? 1 : cell.rowSpan;
for (var r = rowIndex; r < rowIndex + rowSpan; r++) {
for (var i = startIdx; i < endIdx; i++)
tableModel[r][i] = newCell;
}
}
else {
var newTableModel = [ ];
var newRowHash = {};
for (var i = 0; i < tableModel.length; i++) {
var newRow = tableModel[i].slice(0, columnIndex);
if (tableModel[i].length <= columnIndex) {
newTableModel.push(newRow);
continue;
}
if (tableModel[i][columnIndex] == cell) {
newRow.push(cell);
newRow.push(newCell);
}
else {
newRow.push(tableModel[i][columnIndex]);
newRow.push(tableModel[i][columnIndex]);
}
for (var j = columnIndex + 1; j < tableModel[i].length; j++)
newRow.push(tableModel[i][j]);
newTableModel.push(newRow);
}
tableModel = newTableModel;
}
var cellWidthInfo = _aspxHETableHelper.ParseSizeString(tableModel[rowIndex][columnIndex].style.width);
if (cellWidthInfo.valueType) {
var newCellWidth = cellWidthInfo.value / 2;
tableModel[rowIndex][columnIndex].style.width = newCellWidth + cellWidthInfo.valueType;
newCell.style.width = newCellWidth + cellWidthInfo.valueType;
}
this.GenerateTableFromModel(tableModel, table);
if (htmlEditor)
this.SelectCellCore(tableModel[rowIndex][columnIndex], htmlEditor);
},
SplitCellVertical: function(cell, htmlEditor) {
if (!cell)
return false;
var table = _aspxGetParentByTagName(cell, "TABLE");
var row = cell.parentNode;
var rowIndex = row.rowIndex;
var tableModel = _aspxHETableHelper.CreateTableModel(table);
var columnIndex = this.GetColumnIndexByTableModel(tableModel, rowIndex, cell);
var rowSpan = this.GetRowSpan(cell);
var doc = _aspxGetElementDocument(table);
if (rowSpan > 1) {
var newRowSpan = Math.ceil(rowSpan / 2);
var newCell = doc.createElement(cell.nodeName);
newCell.style.cssText = cell.style.cssText;
this.AddDefaultContentToCell(newCell);
var startRowIndex = rowIndex + newRowSpan;
var endRowIndex = rowIndex + rowSpan;
var curColumnIndex = columnIndex;
while (tableModel[rowIndex][curColumnIndex] == cell) {
for (var r = startRowIndex; r < endRowIndex && r < tableModel.length; r++) {
if (tableModel[r][curColumnIndex] == cell)
tableModel[r][curColumnIndex] = newCell;
}
curColumnIndex++;
}
}
else {
var newRowHash = {};
var newRowIndex = rowIndex + 1;
var isThead = !!_aspxGetParentByTagName(cell, "THEAD");
var newRow = null;
if (isThead)
newRow = table.tHead.insertRow(newRowIndex);
else
newRow = table.insertRow(newRowIndex);
_aspxCopyAllAttributes(row, newRow);
_aspxRemoveAttribute(newRow, "id");
_aspxArrayInsert(tableModel, [ ], newRowIndex);
for (var i = 0; i < tableModel[rowIndex].length; i++) {
if (tableModel[rowIndex][i] == cell) {
if (!newRowHash[cell]) {
var newCell = doc.createElement(cell.nodeName);
newCell.style.cssText = cell.style.cssText;
newRowHash[cell] = newCell;
this.AddDefaultContentToCell(newRowHash[cell]);
}
tableModel[newRowIndex][i] = newRowHash[cell];
}
else
tableModel[newRowIndex][i] = tableModel[rowIndex][i];
}
}
this.GenerateTableFromModel(tableModel, table);
if (htmlEditor)
this.SelectCellCore(tableModel[rowIndex][columnIndex], htmlEditor);
},
MergeCellHorizontal: function(cell, htmlEditor) {
var table = _aspxGetParentByTagName(cell, "TABLE");
var row = cell.parentNode;
var rowIndex = row.rowIndex;
var tableModel = _aspxHETableHelper.CreateTableModel(table);
var columnIndex = this.GetColumnIndexByTableModel(tableModel, rowIndex, cell);
var nextCellColumnIndex = this.GetNextCellColumnIndexByTableModel(tableModel, rowIndex, columnIndex);
var nextCell = tableModel[rowIndex][nextCellColumnIndex];
var rowSpan = isNaN(cell.rowSpan) ? 1 : cell.rowSpan;
var newCell = this.MergeCell(cell, nextCell);
var cellWidthInfo = _aspxHETableHelper.ParseSizeString(tableModel[rowIndex][columnIndex].style.width);
var mergedCellWidthInfo = _aspxHETableHelper.ParseSizeString(tableModel[rowIndex][nextCellColumnIndex].style.width);
if (cellWidthInfo.valueType && cellWidthInfo.valueType == mergedCellWidthInfo.valueType)
newCell.style.width = cellWidthInfo.value + mergedCellWidthInfo.value + cellWidthInfo.valueType;
for (var i = rowIndex; i < rowIndex + rowSpan; i++) {
var curColumnIndex = columnIndex;
while (tableModel[i] &&
(tableModel[i][curColumnIndex] == cell || tableModel[i][curColumnIndex] == nextCell)) {
tableModel[i][curColumnIndex] = newCell;
curColumnIndex++;
}
}
this.GenerateTableFromModel(tableModel, table);
if (htmlEditor)
this.SelectCellCore(tableModel[rowIndex][columnIndex], htmlEditor);
},
MergeCellVertical: function(cell, htmlEditor) {
var table = _aspxGetParentByTagName(cell, "TABLE");
var row = cell.parentNode;
var rowIndex = row.rowIndex;
var tableModel = _aspxHETableHelper.CreateTableModel(table);
var columnIndex = this.GetColumnIndexByTableModel(tableModel, rowIndex, cell);
var nextCellRowIndex = this.GetNextCellRowIndexByTableModel(tableModel, rowIndex, columnIndex);
var colSpan = this.GetColSpan(cell);
var nextCell = tableModel[nextCellRowIndex][columnIndex];
var newCell = this.MergeCell(cell, nextCell);
for (var i = columnIndex; i < columnIndex + colSpan; i++) {
var curRowIndex = rowIndex;
while (tableModel[curRowIndex] &&
(tableModel[curRowIndex][i] == cell || tableModel[curRowIndex][i] == nextCell)) {
tableModel[curRowIndex][i] = newCell;
curRowIndex++;
}
}
this.GenerateTableFromModel(tableModel, table);
if (htmlEditor)
this.SelectCellCore(tableModel[rowIndex][columnIndex], htmlEditor);
},
IsMergeCellHorizontalAllow: function(cell, htmlEditor) {
var isAllow = false;
var tableModel = _aspxHETableHelper.CreateTableModel(_aspxGetParentByTagName(cell, "TABLE"));
var row = cell.parentNode;
var colIndx = this.GetColumnIndexByTableModel(tableModel, row.rowIndex, cell);
var nextCellColIndx = colIndx + this.GetColSpan(cell);
var nextCell = tableModel[row.rowIndex][nextCellColIndx];
if (nextCell) {
if (this.GetRowSpan(cell) == this.GetRowSpan(nextCell)) {
var realNextCellRow = nextCell.parentNode;
isAllow = realNextCellRow.rowIndex == row.rowIndex;
}
}
return isAllow;
},
IsMergeCellVerticalAllow: function(cell, htmlEditor) {
var isAllow = false;
var table = _aspxGetParentByTagName(cell, "TABLE");
var nextCell = this.GetNextCellVertical(cell);
if (nextCell) {
var colSpan = isNaN(cell.colSpan) ? 1 : cell.colSpan;
var nextCellColSpan = isNaN(nextCell.colSpan) ? 1 : nextCell.colSpan;
isAllow = colSpan == nextCellColSpan;
}
return isAllow;
},
MergeCell: function(firstCell, secondCell) {
var doc = _aspxGetElementDocument(firstCell);
var newCell = doc.createElement(firstCell.nodeName);
newCell.innerHTML = firstCell.innerHTML;
var emptyHtmlRegExp = new RegExp(__aspxHEEmptyHtmlRegExpPattern, "ig");
if (!emptyHtmlRegExp.test(secondCell.innerHTML))
newCell.innerHTML += "
" + secondCell.innerHTML;
_aspxCopyAllAttributes(firstCell, newCell);
return newCell;
},
CreateTableModel: function(table) {
var rows = table.rows;
var rowCount = 0;
var model = [ ];
for (var i = 0; i < rows.length; i++) {
if (!model[rowCount])
model[rowCount] = [ ];
var colCount = 0;
for (var j = 0, cl = rows[i].cells.length; j < cl; j++) {
var curCell = rows[i].cells[j];
while (model[rowCount][colCount])
colCount++;
var colSpan = this.GetColSpan(curCell);
var rowSpan = this.GetRowSpan(curCell);
for (var rs = 0; rs < rowSpan; rs++) {
var rowInd = rowCount + rs;
if (rowInd >= rows.length)
break;
if (!model[rowInd])
model[rowInd] = [ ];
for (var cs = 0; cs < colSpan; cs++)
model[rowInd][colCount + cs] = curCell;
}
colCount += colSpan - 1;
}
rowCount++;
}
return model;
},
GenerateTableFromModel: function(model, sourceTable) {
var rowSpanAttr = __aspxIE ? "_dxrowspan" : "rowSpan";
for (var i = 0; i < model.length; i++) {
for (var j = 0; j < model[i].length; j++) {
if (model[i][j].parentNode)
model[i][j].parentNode.removeChild(model[i][j]);
model[i][j].colSpan = model[i][j][rowSpanAttr] = 1;
model[i][j].rowSpan = 1;
model[i][j].rowIsNotSpanned = false;
model[i][j].colIsNotSpanned = false;
}
}
var maxColumnCount = 0;
for (var i = 0; i < model.length; i++) {
for (var j = 0; j < model[i].length; j++) {
if (model[i][j]) {
var cell = model[i][j];
if (j > maxColumnCount)
maxColumnCount = j;
if (!cell.colIsNotSpanned) {
if (model[i][j - 1] == cell)
cell.colSpan++;
if (model[i][j + 1] != cell)
cell.colIsNotSpanned = true;
}
}
}
}
var sourceRows = new Array();
for (var i = 0; i <= maxColumnCount; i++) {
for (var j = 0; j < model.length; j++) {
if (model[j] && model[j][i] && !model[j][i].rowIsNotSpanned) {
var cell = model[j][i];
if (model[j - 1] && model[j - 1][i] == cell)
cell[rowSpanAttr]++;
if (!model[j + 1] || model[j + 1][i] != cell)
cell.rowIsNotSpanned = true;
}
}
}
var doc = _aspxGetElementDocument(sourceTable);
for (var i = 0; i < model.length; i++) {
var rowObj = doc.createElement(sourceTable.rows[i].tagName);
_aspxCopyAllAttributes(sourceTable.rows[i], rowObj);
for (var j = 0; j < model[i].length; ) {
var cell = model[i][j];
_aspxRemoveAttribute(cell, "rowIsNotSpanned");
_aspxRemoveAttribute(cell, "colIsNotSpanned");
if (model[i - 1] && model[i - 1][j] == cell) {
j += cell.colSpan;
continue;
}
rowObj.appendChild(cell);
var isEmptyRowSpan = cell.rowSpan == 1;
if (rowSpanAttr != 'rowSpan' && _aspxIsExists(cell[rowSpanAttr])) {
if (cell[rowSpanAttr] > 1)
isEmptyRowSpan = false;
cell.rowSpan = cell[rowSpanAttr];
cell.removeAttribute(rowSpanAttr);
}
if (cell.colSpan == 1)
cell.removeAttribute('colspan');
if (isEmptyRowSpan)
cell.removeAttribute('rowspan');
j += cell.colSpan;
}
sourceTable.rows[i].parentNode.replaceChild(rowObj, sourceTable.rows[i]);
}
},
AddDefaultContentToCell: function(cell) {
cell.innerHTML = " ";
},
CreateNewCellByCell: function(cell, resetWidth) {
var newCell = _aspxGetElementDocument(cell).createElement(cell.nodeName);
if (cell.style.cssText !== '') {
newCell.style.cssText = cell.style.cssText;
if (resetWidth && _aspxHETableHelper.ParseSizeString(newCell.style.width).valueType == "%")
newCell.style.width = "";
}
this.AddDefaultContentToCell(newCell);
return newCell;
},
ParseSizeString: function(sizeString) {
var ret = { value: null, valueType: null };
var res = __aspxHESizeTypeRegExp.exec(sizeString);
if (res && res.length > 2) {
ret.value = parseFloat(res[1]);
ret.valueType = res[2];
}
return ret;
},
SetBackgroundColor: function(element, color) {
if (color)
element.style.backgroundColor = color;
else {
element.style.backgroundColor = "";
_aspxRemoveStyleAttribute(element.style, "backgroundColor");
}
},
SetTableBorderColor: function(table, color) {
table.setAttribute(__aspxIE ? "borderColor" : "bordercolor", color);
},
GetTableBorderColor: function(table, color) {
return _aspxGetAttribute(table, __aspxIE ? "borderColor" : "bordercolor");
},
GetRowIndex: function(cell) {
var row = cell.parentNode;
return row.rowIndex;
},
GetCell: function(table, rowIndex, colIndex) {
return table.rows[rowIndex].cells[colIndex];
},
GetNextCellVertical: function(cell) {
var nextCell = null;
var row = cell.parentNode;
var table = _aspxGetParentByTagName(cell, "TABLE");
var rowSpan = this.GetRowSpan(cell);
if (table.rows.length > row.rowIndex + rowSpan) {
var nextRow = table.rows[row.rowIndex + rowSpan];
var prevSumSpan = 0;
for(var i = 0, prevInd = cell.cellIndex; i <= prevInd; i++)
prevSumSpan += this.GetColSpan(row.cells[i]);
var nextSumSpan = 0;
for(var i = 0, rowLen = nextRow.cells.length; i < rowLen; i++) {
var nextSpan = this.GetColSpan(nextRow.cells[i]);
nextSumSpan += nextSpan;
if((this.GetColSpan(cell) == nextSpan) && (nextSumSpan == prevSumSpan)) {
nextCell = nextRow.cells[i];
break;
}
}
}
return nextCell;
},
GetColumnIndexByTableModel: function(model, rowIndex, cell) {
if (model.length < rowIndex + 1)
return -1;
var row = model[rowIndex];
for (var i = 0; i < row.length; i++) {
if (row[i] == cell)
return i;
}
return -1;
},
GetNextCellColumnIndexByTableModel: function(model, rowIndex, columnIndex) {
if (model.length < rowIndex + 1)
return -1;
var cell = model[rowIndex][columnIndex];
for (var i = columnIndex; i < model[rowIndex].length; i++) {
if (model[rowIndex][i] != cell)
return i;
}
return -1;
},
GetNextCellRowIndexByTableModel: function(model, rowIndex, columnIndex) {
if (model.length < rowIndex + 1)
return -1;
var cell = model[rowIndex][columnIndex];
for (var i = rowIndex; i < model.length; i++) {
if (model[i][columnIndex] != cell)
return i;
}
return -1;
},
GetNextRow: function(row) {
var table = _aspxGetParentByTagName(row, "TABLE");
var i = 0;
for (i = 0; i < table.rows.length; i++)
if (table.rows[i] == row)
break;
return i + 1 < table.rows.length ? table.rows[i + 1] : null;
},
GetColSpan: function(cell) {
return isNaN(cell.colSpan) ? 1 : cell.colSpan;
},
GetRowSpan: function(cell) {
return isNaN(cell.rowSpan) ? 1 : cell.rowSpan;
},
SelectCell: function(table, rowIndex, colIndex, htmlEditor) {
var cell = this.GetCell(table, rowIndex, colIndex);
if (cell)
this.SelectCellCore(cell, htmlEditor);
},
SelectCellCore: function(cell, htmlEditor) {
var elem = cell;
if (cell.childNodes.length > 0 && !__aspxIE)
elem = cell.childNodes[0];
if (!__aspxIE)
htmlEditor.SetFocus();
ASPxClientHtmlEditorSelection.SelectElement(elem, htmlEditor, __aspxOpera);
},
DeleteRows: function(table) {
for (var i = 0; i < table.rows.length; i++) {
var rIndex = table.rows[i].sectionRowIndex;
table.deleteRow(rIndex);
}
}
};
ASPxHtmlEditorCommands.Tables = {};
ASPxHtmlEditorCommands.Tables.Table = {
IsSelected: function(htmlEditor) {
var curSelection = ASPxClientHtmlEditorSelection.Create(htmlEditor);
return !!_aspxHETableHelper.GetTable(curSelection.GetParentElement());
},
SetRowAndColumnCount: function(table, rowCount, columnCount, isColumnEqualWidth) {
_aspxHETableHelper.DeleteRows(table);
var cellWidth = 100 / columnCount + "%";
for (var i = 0; i < rowCount; i++) {
var newRow = table.insertRow(i);
for (var j = 0; j < columnCount; j++) {
var cell = newRow.insertCell(j);
if (isColumnEqualWidth)
cell.style.width = cellWidth;
}
}
},
Insert: _aspxCreateClass(ASPxHtmlEditorCommands.Command, {
Execute: function(cmdValue, htmlEditor) {
ASPxHtmlEditorCommands.Command.prototype.Execute.apply(this, arguments);
var doc = htmlEditor.GetDesignViewDocument();
var tableId = ASPxClientSelection.CreateUniqueID();
var emptyTableHtml = "