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");
ASPxClientHtmlEditorSelection = _aspxCreateClass(null, {
constructor: function(htmlEditor) {
this.htmlEditor = htmlEditor;
this.clientSelection = ASPxClientHtmlEditorSelection.Create(htmlEditor);
this.clientSelection.Save();
this.isControlSelected = this.clientSelection.IsControl();
this.html = this.clientSelection.GetHtmlText();
this.text = this.clientSelection.GetText();
this.selectedElement = this.clientSelection.GetParentElement();
},
Apply: function() {
this.clientSelection.Restore();
},
GetIsControlSelected: function() {
return this.isControlSelected;
},
GetSelectedElement: function() {
return this.selectedElement;
},
GetHtml: function() {
if(!this.htmlEditor.IsDesignView()) return;
return this.html;
},
GetText: function() {
if(!this.htmlEditor.IsDesignView()) return;
return this.text;
},
GetElements: function() {
var selection = this.htmlEditor.GetSelection();
var elements = [];
if(selection.html != "" && selection.selectedElement.tagName == "IMG")
elements.push(selection.selectedElement);
else if(selection.html != "") {
var bm = selection.clientSelection.GetExtendedBookmark();
var startBm = _aspxGetElementByIdInDocument(this.clientSelection.contentDocument, bm.startMarkerID);
var endBm = _aspxGetElementByIdInDocument(this.clientSelection.contentDocument, bm.endMarkerID);
if(!__aspxIE)
this.PrepareBookmarks(startBm, endBm);
elements = this.htmlEditor.selectionHelper.GetSelectedElements(startBm, endBm);
selection.clientSelection.SelectExtendedBookmark(bm);
}
if(elements.length == 1 && elements[0].tagName == "BODY")
elements = _aspxCollectionToArray(elements[0].childNodes);
elements = this.TryUnionElements(elements);
return elements;
},
TryUnionElements: function(elements) {
if(elements.length > 1) {
var firstEl = elements[0];
var lastEl = elements[elements.length-1];
if(firstEl.parentNode == lastEl.parentNode && firstEl.parentNode.tagName != "BODY" && !firstEl.previousSibling && !lastEl.nextSibling)
elements = [firstEl.parentNode];
}
return elements;
},
PrepareBookmarks: function(startBm, endBm) {
if(startBm.previousSibling && startBm.previousSibling.nodeType == 3 && startBm.previousSibling.nodeValue == "")
_aspxRemoveElement(startBm.previousSibling);
if(endBm.nextSibling && endBm.nextSibling.nodeType == 3 && endBm.nextSibling.nodeValue == "")
_aspxRemoveElement(endBm.nextSibling);
},
SetHtml: function(html, addToHistory) {
addToHistory = _aspxIsExists(addToHistory) ? addToHistory : true;
this.htmlEditor.ExecuteCommand(ASPxClientCommandConsts.PASTEHTML_COMMAND, html, addToHistory);
},
SetHtmlInternal: function(html) {
if(!this.htmlEditor.IsDesignView()) return;
html = ASPxClientHtmlEditor.ProtectUrlsInHTML(html);
var processingContainer = document.createElement("DIV");
processingContainer.innerHTML = html;
this.htmlEditor.ProcessInnerHtml(processingContainer);
html = processingContainer.innerHTML;
if(this.selectedElement.tagName == "IMG") {
if(!__aspxWebKitFamily)
this.selectedElement.parentNode.removeChild(this.selectedElement);
this.InsertHtml(html);
this.htmlEditor.SaveSelection();
}
else {
var elements = this.GetElements();
if(__aspxIE && this.selectedElement.tagName == "DIV" && elements.length == 1 && elements[0] == this.selectedElement) {
var doc = this.htmlEditor.GetDesignViewDocument();
this.htmlEditor.RemoveFocus();
var wrapper = doc.createElement("DIV");
wrapper.innerHTML = html;
var selNode = doc.createElement("SPAN");
this.selectedElement.parentNode.insertBefore(selNode, this.selectedElement);
_aspxRemoveElement(this.selectedElement);
for(var child = wrapper.firstChild; child; child = wrapper.firstChild) {
selNode.parentNode.insertBefore(child, selNode);
}
var _this = this;
setTimeout(function() {
_this.clientSelection.SelectElement(selNode, false);
_this.htmlEditor.SaveSelection();
_aspxRemoveElement(selNode);
}, 0);
return;
}
else if(elements.length > 0) {
var replaceElement = elements[0];
for(var i = 1, element = elements[i]; element; element = elements[++i]) {
if(this.IsElementCanDelete(element))
element.parentNode.removeChild(element);
else if(element.nodeType == 3) {
if(this.IsTableCell(element.parentNode) && element.parentNode.childNodes.length == 1)
element.parentNode.innerHTML = " ";
else
element.nodeValue = "";
}
else if(element.nodeType == 1)
element.innerHTML = this.IsTableCell(element) ? " " : "";
}
if(replaceElement.nodeType == 3) {
var selectNode = this.CreateNode("font", " ");
replaceElement.parentNode.replaceChild(selectNode, replaceElement);
}
else {
var nonContentElementExpr = /^(IMG|BR|TABLE)$/i;
var needRemoveFirstChild = !nonContentElementExpr.test(replaceElement.tagName);
selectNode = needRemoveFirstChild ? this.ReplaceNodeContent(replaceElement) : replaceElement;
}
this.clientSelection.SelectElement(selectNode, true);
}
if(__aspxIE)
html += "";
this.InsertHtml(html);
var doc = this.htmlEditor.GetDesignViewDocument();
if(__aspxIE) {
selectNode = doc.getElementById('selectNode');
if(selectNode) {
this.clientSelection.SelectElement(selectNode);
_aspxRemoveElement(selectNode);
}
var fstNode = doc.getElementById('replaceBr');
if(fstNode)
_aspxRemoveElement(fstNode);
}
else {
if(_aspxIsExistsElement(selectNode) && selectNode.childNodes.length > 0)
_aspxRemoveOuterTags(selectNode);
var fstNode = doc.getElementById('replaceBr');
if(fstNode)
_aspxRemoveElement(fstNode);
if(needRemoveFirstChild && replaceElement) {
if(replaceElement.childNodes.length == 0)
_aspxRemoveElement(replaceElement);
}
}
this.htmlEditor.SaveSelection();
}
},
CreateNode: function(tagName, innerHtml) {
if(!__aspxOpera) {
var node = this.htmlEditor.GetDesignViewDocument().createElement(tagName);
node.innerHTML = innerHtml;
}
else
var node = _aspxCreateHtmlElementFromString("<" + tagName + ">" + innerHtml + "" + tagName + ">");
return node;
},
IsElementCanDelete: function(element) {
var nonDeleteElementExpr = /^(TR|TD|TH|THEAD|TBODY|TFOOT)$/i;
return (element.nodeType == 3 && element.parentNode.tagName != "TD") ||
(element.nodeType == 1 && !nonDeleteElementExpr.test(element.tagName));
},
IsTableCell: function(element) {
return element.tagName == "TD" || element.tagName == "TH";
},
ReplaceNodeContent: function(node) {
if(node.nodeType != 1) return;
var nodeContent = __aspxIE ? "
" : "
";
node.innerHTML = nodeContent;
var replaceNode = this.htmlEditor.GetDesignViewDocument().createElement('font');
replaceNode.innerHTML = " ";
node.appendChild(replaceNode);
return replaceNode;
},
InsertHtml: function(html) {
if (__aspxIE)
this.InsertHtmlIE(html);
else if (__aspxWebKitFamily)
this.InsertHtmlWebKit(html);
else
this.InsertHtmlNS(html);
},
InsertHtmlIE: function(html) {
if(__aspxBrowserMajorVersion > 8) {
html = html.replace(/[\s]{2,}/g, " ");
html = html.replace(/\s(<[^>]+>)\s/g, " $1");
}
var doc = this.htmlEditor.GetDesignViewDocument();
if (doc.selection.type.toLowerCase() != "none")
doc.selection.createRange().execCommand("Delete");
if (doc.selection.type.toLowerCase() != "none")
doc.execCommand("Delete");
html = ASPxClientHtmlEditor.ProtectUrlsInHTML(html);
doc.body.setActive();
var selRange = doc.selection.createRange();
if (selRange && selRange.length) {
var elem = selRange.item(0);
if (elem && elem.tagName.toUpperCase() == "BODY") {
var formElement = elem.getElementsByTagName("FORM")[0];
if (formElement)
_aspxSetInnerHtml(formElement, formElement.innerHTML + html);
}
}
else {
var rngStart = selRange.duplicate();
rngStart.collapse(true);
selRange.pasteHTML(html);
rngStart.setEndPoint("StartToEnd", selRange);
rngStart.select();
}
ASPxClientHtmlEditor.RestoreUrlsInDOM(this.htmlEditor.GetDesignViewDocument());
return true;
},
InsertHtmlNS: function(html) {
var doc = this.htmlEditor.GetDesignViewDocument();
var selection = this.htmlEditor.GetDesignViewIFrameWindow().getSelection();
var range = selection.getRangeAt(0);
var tmpNode = doc.createElement("SPAN");
_aspxSetInnerHtml(tmpNode, html);
range.deleteContents();
range.insertNode(tmpNode);
var selectionPointer;
if(tmpNode.childNodes.length > 0) {
selectionPointer = tmpNode.lastChild;
var length = tmpNode.childNodes.length;
for(var i = 0; i < length; i++)
tmpNode.parentNode.insertBefore(tmpNode.childNodes[0], tmpNode);
tmpNode.parentNode.removeChild(tmpNode);
}
else {
selectionPointer = tmpNode;
}
range = doc.createRange();
range.setStartAfter(selectionPointer);
range.setEndAfter(selectionPointer);
range.collapse(true);
selection.removeAllRanges();
selection.addRange(range);
this.htmlEditor.Focus();
return true;
},
InsertHtmlWebKit: function(html) {
var doc = this.htmlEditor.GetDesignViewDocument();
if(this.selectedElement.tagName == "TD") {
var anchorNode = doc.createElement("SPAN");
anchorNode.innerHTML = " ";
this.selectedElement.appendChild(anchorNode);
}
doc.execCommand("InsertHTML", false, html);
if(anchorNode)
this.selectedElement.removeChild(anchorNode);
this.htmlEditor.Focus();
return true;
},
SetFocusToDocumentStart: function() {
var doc = this.htmlEditor.GetDesignViewDocument();
var sbm = document.createElement("SPAN");
var ebm = document.createElement("SPAN");
sbm.id = "sbm";
ebm.id = "ebm";
doc.body.insertBefore(sbm, doc.body.firstChild)
doc.body.insertBefore(ebm, sbm)
var bookmark = { "startMarkerID": "sbm", "endMarkerID": "ebm" };
this.htmlEditor.GetSelection().clientSelection.SelectExtendedBookmark(bookmark);
}
});
ASPxClientHtmlEditorSelection.ElementsSelectionHelper = _aspxCreateClass(null, {
constructor: function(htmlEditor) {
this.htmlEditor = htmlEditor;
},
GetSelectedElements: function(startBm, endBm) {
var elements = [];
var doc = this.htmlEditor.GetDesignViewDocument();
var chain1 = this.GetAncestorsChain(startBm);
var chain2 = this.GetAncestorsChain(endBm);
var commonAncestor = this.FindCommonAncestor(chain1, chain2);
if(this.IsNeedExchangeBmPlace(chain1, chain2)) {
var tmp = chain1;
chain1 = chain2;
chain2 = tmp;
tmp = startBm;
startBm = endBm;
endBm = tmp;
}
var curAncestor = startBm.parentNode;
var curElement = startBm;
while(curAncestor != commonAncestor) {
while(curElement.nextSibling) {
elements.push(curElement.nextSibling);
curElement = curElement.nextSibling;
}
curElement = curAncestor;
curAncestor = curAncestor.parentNode;
}
var rightLeftTreeNode = chain2[_aspxArrayIndexOf(chain2, commonAncestor) + 1];
rightLeftTreeNode = rightLeftTreeNode ? rightLeftTreeNode : endBm;
while(this.GetNextSibling(curElement) != rightLeftTreeNode) {
elements.push(this.GetNextSibling(curElement));
curElement = this.GetNextSibling(curElement);
}
curAncestor = endBm.parentNode;
curElement = endBm;
var rightElements = [];
var saveAllRightTree = true;
while(curAncestor != commonAncestor) {
if(saveAllRightTree && this.GetNextSibling(curElement) == null) {
if(curAncestor.parentNode == commonAncestor || this.GetNextSibling(curElement) != null) {
rightElements.push(curAncestor);
}
}
else {
saveAllRightTree = false;
while(curElement.previousSibling) {
rightElements.push(curElement.previousSibling);
curElement = curElement.previousSibling;
}
}
curElement = curAncestor;
curAncestor = curAncestor.parentNode;
}
elements = elements.concat(rightElements.reverse());
if(elements.length > 0)
elements[0] = this.PrepareOuterSelectNode(elements[0], startBm, endBm);
if(elements.length > 1)
elements[elements.length - 1] = this.PrepareOuterSelectNode(elements[elements.length - 1], endBm, startBm);
elements = this.MergeTextNodes(elements);
if(elements.length == 1 && elements[0].tagName == "BODY")
elements = _aspxCollectionToArray(elements[0].childNodes);
return elements;
},
MergeTextNodes: function(elements) {
for(var i = 0; el = elements[i]; i++) {
var nextEl = elements[i+1];
if(el.nodeType == 3 && nextEl && nextEl.nodeType == 3 && nextEl.parentNode == el.parentNode) {
el.nodeValue += nextEl.nodeValue;
elements.splice(i + 1, 1);
_aspxRemoveElement(nextEl);
elements[i] = this.FindParentNode(el);
i++;
}
}
return elements;
},
FindParentNode: function(el) {
if(el.parentNode.childNodes.length == 1 && el.parentNode.tagName != "BODY")
return this.FindParentNode(el.parentNode);
return el;
},
FindCommonAncestor: function(chain1, chain2) {
for(var i = 0; i < Math.max(chain1.length, chain2.length); i++) {
if(chain1[i] != chain2[i])
return chain1[i-1];
}
return chain1[chain1.length-1];
},
GetAncestorsChain: function(element) {
var parent = element.parentNode;
var chain = [];
while(parent.tagName != "BODY") {
chain.push(parent);
parent = parent.parentNode;
}
chain.push(parent);
var result = chain.reverse();
result.push(element);
return result;
},
PrepareOuterSelectNode: function(node, bmElement1, bmElement2) {
var parent = node.parentNode;
var parentChildCount = parent.childNodes.length;
if(parent.tagName != "BODY") {
var canMoveToParent =
parentChildCount == 1 ||
(parentChildCount == 2 && (bmElement1.parentNode == parent || bmElement2.parentNode == parent)) ||
(parentChildCount == 3 && bmElement1.parentNode == parent && bmElement2.parentNode == parent);
if(canMoveToParent)
return this.PrepareOuterSelectNode(parent, bmElement1, bmElement2);
}
return node;
},
IsNeedExchangeBmPlace: function(chain1, chain2) {
var chainLength = Math.max(chain1.length, chain2.length);
for(var i = 0; i < chainLength; i++) {
if(i > 0 && chain1[i] != chain2[i])
return _aspxArrayIndexOf(chain1[i - 1].childNodes, chain1[i]) > _aspxArrayIndexOf(chain1[i - 1].childNodes, chain2[i]);
}
return false;
},
GetNextSibling: function(node) {
if(!__aspxIE || node.nextSibling)
return node.nextSibling;
var parent = node.parentNode;
if(parent) {
var index = _aspxArrayIndexOf(parent.childNodes, node);
if(index < parent.childNodes.length - 1)
return parent.childNodes[index + 1];
}
return null;
}
});
ASPxClientHtmlEditorSelection.Create = function(htmlEditor) {
var contentWindow = htmlEditor.GetDesignViewIFrameWindow();
return ASPxClientSelection.Create(contentWindow);
}
ASPxClientHtmlEditorSelection.SelectElement = function(element, htmlEditor, selectAllContent) {
if (!_aspxIsExists(selectAllContent))
selectAllContent = true;
var iframeWindow = htmlEditor.GetDesignViewIFrameWindow();
return __aspxIE ? ASPxClientSelectionIE.SelectElementInDocument(element, iframeWindow.document, selectAllContent) :
ASPxClientSelectionNSOpera.SelectElementInDocument(element, iframeWindow.document, iframeWindow, selectAllContent);
}
ASPxClientSelection = _aspxCreateClass(null, {
constructor: function(contentWindow) {
this.contentWindow = contentWindow;
this.contentDocument = contentWindow.document;
this.startContainer = null;
this.endContainer = null;
this.startOffset = 0;
this.endOffset = 0;
},
GetHtmlText: function() {
},
Save: function() {
},
Restore: function() {
},
GetText: function() {
},
GetHtmlText: function() {
},
GetStartContainer: function() {
this.FindStartEndContainerInternal();
return this.startContainer;
},
GetEndContainer: function() {
this.FindStartEndContainerInternal();
return this.endContainer;
},
GetStartOffset: function() {
this.FindStartEndContainerInternal();
return this.startOffset;
},
GetEndOffset: function() {
this.FindStartEndContainerInternal();
return this.endOffset;
},
IsControl: function() {
return false;
},
IsTextOnly: function() {
return false;
},
GetRange: function() {
},
GetExtendedBookmark: function() {
return null;
},
GetSelectionMarkerElement: function(isStart) {
return null;
},
SelectExtendedBookmark: function(bookmark) {
},
RemoveExtendedBookmark: function(bookmark) {
if (bookmark) {
_aspxRemoveElement(_aspxGetElementByIdInDocument(this.contentDocument, bookmark.startMarkerID));
_aspxRemoveElement(_aspxGetElementByIdInDocument(this.contentDocument, bookmark.endMarkerID));
}
return null;
},
FindStartEndContainer: function() {
},
FindStartEndContainerInternal: function() {
if (this.startContainer || this.endContainer)
return;
this.FindStartEndContainer();
}
});
ASPxClientSelection.IsHtml = function(text) {
if (!text || !text.match) return text;
return text.match(/);
}
ASPxClientSelection.Create = function(contentWindow) {
return __aspxIE ? new ASPxClientSelectionIE(contentWindow) : new ASPxClientSelectionNSOpera(contentWindow);
}
ASPxClientSelection.CreateUniqueID = function() {
return 'dx_temp_' + (new Date()).valueOf() + '_' + Math.floor(Math.random()*1000);
}
ASPxClientSelection.IsControlElement = function(element) {
if (element.nodeType == 1) {
var tagName = element.tagName.toUpperCase();
return tagName == "TABLE" || tagName == "IMG";
}
return false;
};
ASPxClientSelection.InsertNodeAtPosition = function(containerNode, insertNode, containeNodeOffset, doc) {
var newTextNode = null;
if ((containerNode.nodeType == 3) && (insertNode.nodeType == 3))
containerNode.insertData(containeNodeOffset, insertNode.nodeValue);
else {
var afterNode;
if (containerNode.nodeType == 3) {
var textNode = containerNode;
containerNode = textNode.parentNode;
var nodeText = textNode.nodeValue;
var textBefore = nodeText.substr(0, containeNodeOffset);
var textAfter = nodeText.substr(containeNodeOffset);
var beforeNode = doc.createTextNode(textBefore);
afterNode = doc.createTextNode(textAfter);
containerNode.insertBefore(afterNode, textNode);
containerNode.insertBefore(insertNode, afterNode);
newTextNode = beforeNode;
try {
containerNode.insertBefore(beforeNode, insertNode);
}
catch (exc) {}
containerNode.removeChild(textNode);
}
else {
if(containerNode.childNodes.length > 0) {
afterNode = containerNode.childNodes[containeNodeOffset];
containerNode.insertBefore(insertNode, afterNode);
}
else {
if (containerNode.tagName != "BODY")
containerNode = containerNode.parentNode;
containerNode.appendChild(insertNode);
}
}
return newTextNode;
}
}
ASPxClientSelectionIE = _aspxCreateClass(ASPxClientSelection, {
constructor: function(contentWindow) {
this.constructor.prototype.constructor.call(this, contentWindow);
},
Save: function() {
if(!this.IsControl() && !_aspxGetParentByTagName(this.GetParentElement(), "DIV"))
this.contentWindow.focus();
var curSelection = this.contentDocument.selection;
var selRange = curSelection.createRange();
if (selRange.length)
this.sourceIndex = selRange.item(0).sourceIndex;
else {
this.startBookmark = this.GetBookmark(selRange);
this.selectedRange = selRange;
this.isCollapsed = selRange.boundingWidth == 0;
}
},
Restore: function() {
var useBookmark = false;
var selRange;
if(this.selectedRange)
useBookmark = this.GetHtmlText() != this.selectedRange.htmlText;
if (_aspxIsExists(this.sourceIndex)) {
selRange = this.contentDocument.body.createControlRange();
selRange.addElement(this.contentDocument.all(this.sourceIndex));
selRange.select();
}
else if (_aspxIsExists(this.selectedRange)) {
if(useBookmark) {
selRange = this.contentDocument.body.createTextRange();
selRange.moveToBookmark(this.startBookmark);
selRange.select();
selRange.collapse();
} else {
try {
if(this.isCollapsed)
this.selectedRange.collapse();
this.selectedRange.select();
}
catch(e) {}
}
}
this.contentWindow.focus();
},
GetBookmark: function(range) {
return range.getBookmark();
},
GetSelectionMarkerElement: function(isStart) {
var rng = this.GetRange();
var markerID = ASPxClientSelection.CreateUniqueID();
var makerElem = null;
if (this.IsControl()) {
makerElem = this.contentDocument.createElement("span");
makerElem.id = markerID;
var controlElem = rng.item(0);
if (isStart)
controlElem.parentNode.insertBefore(makerElem, controlElem);
else
controlElem.parentNode.insertBefore(makerElem, controlElem.nextSibling);
}
else {
if(rng.parentElement) {
var document = rng.parentElement().document || rng.parentElement().ownerDocument;
if(document != this.contentDocument)
return null;
}
if (rng.collapse)
rng.collapse(isStart);
try {
rng.pasteHTML('');
makerElem = _aspxGetElementByIdInDocument(this.contentDocument, markerID);
} catch (e) { };
}
return makerElem;
},
GetExtendedBookmark: function() {
var controlElementID = null;
var bookmark = null;
if (this.IsControl()) {
var selRange = this.contentDocument.selection.createRange();
controlElementID = ASPxClientSelection.CreateUniqueID();
_aspxChangeAttribute(selRange.item(0), "id", controlElementID);
bookmark = { "controlElementID": controlElementID };
}
else {
var startMarker = this.GetSelectionMarkerElement(true);
var endMarker = this.GetSelectionMarkerElement(false);
if (startMarker != null && endMarker != null)
bookmark = { "startMarkerID": startMarker.id, "endMarkerID": endMarker.id };
}
return bookmark;
},
SelectExtendedBookmark: function(bookmark) {
var rng1 = null;
if (bookmark.controlElementID) {
rng1 = this.contentDocument.body.createControlRange();
var controlElement = _aspxGetElementByIdInDocument(this.contentDocument, bookmark.controlElementID);
_aspxRestoreAttribute(controlElement, "id");
rng1.addElement(controlElement);
}
else {
var startMarker = _aspxGetElementByIdInDocument(this.contentDocument, bookmark.startMarkerID);
var endMarker = _aspxGetElementByIdInDocument(this.contentDocument, bookmark.endMarkerID);
rng1 = this.contentDocument.body.createTextRange();
if (_aspxIsExists(startMarker))
rng1.moveToElementText(startMarker);
rng1.moveStart('character', 0);
var rng2 = this.contentDocument.body.createTextRange();
if (_aspxIsExists(endMarker))
rng2.moveToElementText(endMarker);
rng1.setEndPoint('EndToEnd', rng2);
rng1.moveEnd('character', 0);
_aspxRemoveElement(startMarker);
_aspxRemoveElement(endMarker);
}
rng1.select();
},
SelectElement: function(elem, selectAllContent) {
ASPxClientSelectionIE.SelectElementInDocument(elem, this.contentDocument, selectAllContent);
},
GetRange: function() {
return this.contentDocument.selection.createRange();
},
GetParentElement: function() {
var ret = null;
var rng = this.GetRange();
if (!rng) return ret;
if (rng.length)
ret = rng.item(0);
else if (rng.parentElement)
ret = rng.parentElement();
return ret;
},
GetText: function() {
var ret = "";
var rng = this.contentDocument.selection.createRange();
if (_aspxIsExists(rng.text))
ret = rng.text;
return ret;
},
GetHtmlText: function() {
var ret = "";
var rng = this.GetRange();
if (rng.length)
ret = rng.item(0).outerHTML;
else if (rng.htmlText)
ret = rng.htmlText;
return ret;
},
IsControl: function() {
return this.contentDocument.selection.type == 'Control';
},
IsTextOnly: function() {
var rng = this.contentDocument.selection.createRange();
if (_aspxIsExists(rng.text) && _aspxIsExists(rng.htmlText))
return (rng.text == rng.htmlText);
return false;
},
FindStartEndContainer: function() {
var startMarker = this.GetSelectionMarkerElement(true);
var endMarker = this.GetSelectionMarkerElement(false);
if (!startMarker && !endMarker) {
this.startContainer = this.contentDocument.body;
return;
}
this.startContainer = startMarker.parentNode;
this.startOffset = _aspxArrayIndexOf(this.startContainer.childNodes, startMarker);
_aspxRemoveElement(startMarker);
this.endContainer = endMarker.parentNode;
this.endOffset = _aspxArrayIndexOf(this.endContainer.childNodes, endMarker);
_aspxRemoveElement(endMarker);
if (this.startContainer != this.endContainer) {
if (this.endOffset == 0) {
while (this.endContainer && !this.endContainer.previousSibling)
this.endContainer = this.endContainer.parentNode;
if (this.endContainer)
this.endContainer = this.endContainer.previousSibling;
}
else if (this.endContainer.nodeType == 1)
this.endContainer = this.endContainer.childNodes[this.endOffset - 1];
}
}
});
ASPxClientSelectionIE.SelectElementInDocument = function(elem, docObj, selectAllContent) {
if (!_aspxIsExists(selectAllContent))
selectAllContent = true;
var rng;
if (ASPxClientSelection.IsControlElement(elem)) {
rng = docObj.body.createControlRange();
rng.addElement(elem);
}
else {
try {
rng = docObj.selection.createRange();
}
catch(e) {
window.focus();
docObj.parentWindow.focus();
rng = docObj.selection.createRange();
}
try {
rng.moveToElementText(elem);
}
catch (e) { }
}
if (!selectAllContent) {
try {
rng.collapse(false);
}
catch (e) { }
}
rng.select();
};
ASPxClientDialogSelectionIE = _aspxCreateClass(ASPxClientSelectionIE, {
Save: function() {
if(!this.IsControl())
this.contentWindow.focus();
var curSelection = this.contentDocument.selection;
if (curSelection) {
this.selectionRange = curSelection.createRange();
if (curSelection.type.toLowerCase() == "control")
this.sourceIndex = this.selectionRange.item(0).sourceIndex;
}
},
Restore: function () {
try {
if(_aspxIsExists(this.sourceIndex)) {
var selRange = this.contentDocument.body.createControlRange();
selRange.addElement(this.contentDocument.all(this.sourceIndex));
selRange.select();
}
else if(this.selectionRange)
this.selectionRange.select();
if(!this.IsControl())
this.contentWindow.focus();
} catch (e) { }
}
});
ASPxClientSelectionNSOpera = _aspxCreateClass(ASPxClientSelection, {
constructor: function(contentWindow) {
this.constructor.prototype.constructor.call(this, contentWindow);
},
Save: function() {
var curSelection = this.contentWindow.getSelection();
if (curSelection) {
this.isCollapsedSelection = curSelection.isCollapsed;
this.startNodePath = this.GetNodePath(this.contentDocument.documentElement, curSelection.anchorNode);
this.startNodeOffset = curSelection.anchorOffset;
this.endNodePath = this.GetNodePath(this.contentDocument.documentElement, curSelection.focusNode);
this.endNodeOffset = curSelection.focusOffset;
if (__aspxOpera && this.NeedExchangeStartAndEndNode(this.startNodePath, this.endNodePath, this.startNodeOffset, this.endNodeOffset)) {
var tmp = this.startNodePath;
this.startNodePath = this.endNodePath;
this.endNodePath = tmp;
tmp = this.startNodeOffset;
this.startNodeOffset = this.endNodeOffset;
this.endNodeOffset = tmp;
}
}
else {
this.isCollapsedSelection = null;
this.startNodePath = null;
this.startNodeOffset = null;
this.endNodePath = null;
this.endNodeOffset = null;
}
},
Restore: function() {
try {
var curSelection = this.contentWindow.getSelection();
var startNode = this.GetNodeByPath(this.contentDocument.documentElement, this.startNodePath, true);
var endNode = this.GetNodeByPath(this.contentDocument.documentElement, this.endNodePath, false);
var isSelectionEqual = (curSelection.anchorNode == startNode) && (curSelection.focusNode == endNode) &&
(curSelection.anchorOffset == this.startNodeOffset) && (curSelection.focusOffset == this.endNodeOffset) &&
(curSelection.isCollapsed == this.isCollapsedSelection);
if (!isSelectionEqual) {
ASPxClientSelectionNSOpera.RestoreByStartAndEndNodeCore(startNode, endNode, this.startNodeOffset,
this.endNodeOffset,
this.isCollapsedSelection,
this.contentDocument,
this.contentWindow);
}
} catch (e) { }
},
GetParentElement: function() {
var ret = null;
var rng = this.GetRange();
if (!rng) return ret;
var selection = this.contentWindow.getSelection();
var startContainer = this.GetStartContainer(rng, selection);
var endContainer = this.GetEndContainer(rng, selection);
var startOffset = this.GetStartOffset(rng, selection);
var endOffset = this.GetEndOffset(rng, selection);
if (startContainer == endContainer && (endOffset - startOffset) == 1 &&
(selection.anchorNode.childNodes.length > 0))
ret = selection.anchorNode.childNodes[selection.anchorOffset];
else {
if (!rng.commonAncestorContainer.tagName) {
if (this.contentWindow.document == rng.commonAncestorContainer &&
selection.baseNode)
ret = selection.baseNode.parentNode;
else
ret = rng.commonAncestorContainer.parentNode;
}
else
ret = rng.commonAncestorContainer;
}
return ret;
},
GetRange: function() {
var selection = this.contentWindow.getSelection();
if (!selection || selection.rangeCount < 1)
return null;
return selection.getRangeAt ? selection.getRangeAt(0) : this.contentWindow.createRange();
},
GetText : function() {
var ret = "";
if (this.contentWindow.getSelection)
ret = this.contentWindow.getSelection().toString();
return ret;
},
GetHtmlText: function() {
var ret = "";
var selection = this.contentWindow.getSelection();
var rng = null;
if (selection.getRangeAt && selection.rangeCount > 0) {
rng = selection.getRangeAt(0);
var tempDiv = this.contentWindow.document.createElement("div");
var clonedFragment = rng.cloneContents();
if (_aspxIsExists(clonedFragment)) {
tempDiv.appendChild(clonedFragment);
ret = tempDiv.innerHTML;
}
}
return ret;
},
GetExtendedBookmark : function() {
var startSpan = this.contentDocument.createElement("span");
startSpan.id = ASPxClientSelection.CreateUniqueID();
var endSpan = this.contentDocument.createElement("span");
endSpan.id = ASPxClientSelection.CreateUniqueID();
var isDirectOrder = !this.NeedExchangeStartAndEndNode(this.startNodePath, this.endNodePath, this.startNodeOffset, this.endNodeOffset);
var isEmptyTextSelected = false;
if (this.startContainer == this.endContainer) {
isEmptyTextSelected = this.endOffset == this.startOffset;
if(this.endContainer.tagName == "BR") {
if(!isDirectOrder)
_aspxInsertElementAfter(endSpan, this.endContainer);
else
this.endContainer.parentNode.insertBefore(endSpan, this.endContainer);
}
else {
var newContainer = ASPxClientSelection.InsertNodeAtPosition(this.endContainer, endSpan, this.endOffset, this.contentDocument);
if (_aspxIsExists(newContainer))
this.startContainer = newContainer;
}
if(this.startContainer.tagName == "BR") {
if(!isDirectOrder)
this.startContainer.parentNode.insertBefore(startSpan, this.startContainer);
else
_aspxInsertElementAfter(startSpan, this.startContainer);
}
else
ASPxClientSelection.InsertNodeAtPosition(this.startContainer, startSpan, this.startOffset, this.contentDocument);
}
else {
if(this.endContainer.tagName == "BR") {
if(!isDirectOrder)
_aspxInsertElementAfter(endSpan, this.endContainer);
else
this.endContainer.parentNode.insertBefore(endSpan, this.endContainer);
}
else
ASPxClientSelection.InsertNodeAtPosition(this.endContainer, endSpan, this.endOffset, this.contentDocument);
if(this.startContainer.tagName == "BR"){
if(!isDirectOrder)
this.startContainer.parentNode.insertBefore(startSpan, this.startContainer);
else
_aspxInsertElementAfter(startSpan, this.startContainer);
}
else
ASPxClientSelection.InsertNodeAtPosition(this.startContainer, startSpan, this.startOffset, this.contentDocument);
}
var bookmark = { "startMarkerID": startSpan.id, "endMarkerID": endSpan.id, "isEmptyTextSelected": isEmptyTextSelected, "isDirectOrder": isDirectOrder };
this.SelectExtendedBookmark(bookmark, false);
return bookmark;
},
SelectExtendedBookmark: function(bookmark, withDeleteMarker) {
if (!_aspxIsExists(withDeleteMarker))
withDeleteMarker = true;
var startMarker = _aspxGetElementByIdInDocument(this.contentDocument, bookmark.startMarkerID);
var endMarker = _aspxGetElementByIdInDocument(this.contentDocument, bookmark.endMarkerID);
var rng1 = this.contentDocument.createRange();
rng1.setStart(startMarker.nextSibling ? startMarker.nextSibling : startMarker, 0);
if (startMarker.nextSibling != endMarker) {
var nextSibling = endMarker.nextSibling ? endMarker.nextSibling : endMarker;
rng1.setEnd(nextSibling, 0);
}
var sel = this.contentWindow.getSelection();
sel.removeAllRanges();
sel.addRange(rng1);
if(!bookmark.isDirectOrder) {
sel.collapseToEnd();
sel.extend(startMarker, 0);
}
if (bookmark.isEmptyTextSelected) {
var index = _aspxArrayIndexOf(endMarker.parentNode.childNodes, startMarker);
sel.collapse(endMarker.parentNode, index);
}
if (withDeleteMarker) {
_aspxRemoveElement(startMarker);
_aspxRemoveElement(endMarker);
}
},
FindStartEndContainer: function() {
var rng = this.GetRange();
if(!rng)
rng = { };
var selection = this.contentWindow.getSelection();
if(!selection)
selection = { };
this.startContainer = rng.startContainer ? rng.startContainer : selection.baseNode;
this.endContainer = rng.endContainer ? rng.endContainer : selection.extentNode;
this.startOffset = rng.startOffset != null ? rng.startOffset : selection.baseOffset;
this.endOffset = rng.endOffset != null ? rng.endOffset : selection.extentOffset;
},
IsControl : function () {
var selection = this.contentWindow.getSelection();
if(selection.toString() != "" || !selection.focusNode)
return false;
var focusNode = selection.focusNode;
if(focusNode.nodeType == 1) {
var rng = this.GetRange();
var startContainer = this.GetStartContainer();
var endContainer = this.GetEndContainer();
var startOffset = this.GetStartOffset();
var endOffset = this.GetEndOffset();
if (startContainer == endContainer && (endOffset - startOffset) == 1 &&
(selection.anchorNode.childNodes.length > 0))
focusNode = selection.anchorNode.childNodes[selection.anchorOffset];
}
return (focusNode.tagName == 'IMG');
},
IsTextOnly: function() {
var selection = this.contentWindow.getSelection();
return selection.focusNode && selection.anchorNode &&
((selection.focusNode == selection.anchorNode) ||
((selection.focusNode.nodeType == 3) && (selection.anchorNode.nodeType == 3)));
},
SelectElement: function(elem, selectAllContent) {
if (!_aspxIsExists(selectAllContent))
selectAllContent = true;
ASPxClientSelectionNSOpera.SelectElementInDocument(elem, this.contentDocument, this.contentWindow, selectAllContent);
},
NeedExchangeStartAndEndNode: function(startNodePath, endNodePath, startNodeOffset, endNodeOffset) {
if (startNodePath != endNodePath) {
var startNodePathArray = startNodePath.split("-");
var endNodePathArray = endNodePath.split("-");
var length = Math.min(startNodePathArray.length, endNodePathArray.length);
for (var i = 0; i < length; i++) {
var i1 = parseInt(startNodePathArray[i], 10);
var i2 = parseInt(endNodePathArray[i], 10);
if (i1 > i2)
return true;
}
}
return startNodeOffset > endNodeOffset;
},
GetNodePath: function(rootNode, node) {
var path = "";
var curParentNode = node;
var curNode = node;
if (curParentNode){
while (rootNode != curParentNode) {
curParentNode = curParentNode.parentNode;
if (curParentNode.childNodes) {
var index = _aspxArrayIndexOf(curParentNode.childNodes, curNode);
path = index.toString() + "-" + path;
}
curNode = curParentNode;
}
}
return path.substr(0, path.length - 1);
},
GetNodeByPath: function(rootNode, path, isFirstNode) {
if (path != "") {
var pathNodeArray = path.split("-");
var curNode = rootNode;
for(var i = 0; i < pathNodeArray.length; i++) {
var index = parseInt(pathNodeArray[i], 10);
if(index >= curNode.childNodes.length) {
if(isFirstNode)
this.startNodeOffset = 0;
else
this.endNodeOffset = 0;
return curNode;
}
curNode = curNode.childNodes[index];
}
return curNode;
}
else
return null;
}
});
ASPxClientSelectionNSOpera.RestoreByStartAndEndNodeCore = function(startNode,
endNode,
startNodeOffset,
endNodeOffset, isCollapsed,
docObj, windowObj) {
var curSelection = windowObj.getSelection();
ASPxClientSelectionNSOpera.SelectElementInDocument(startNode, docObj, windowObj);
ASPxClientSelectionNSOpera.SelectElementInDocument(endNode, docObj, windowObj);
if (startNode) {
if(startNode.nodeType == 1 && startNodeOffset > startNode.childNodes.length)
startNodeOffset = startNode.childNodes.length > 0 ? startNode.childNodes.length - 1 : 0;
curSelection.collapse(startNode, startNodeOffset);
}
if (endNode && !isCollapsed) {
if(endNode.nodeType == 1 && endNodeOffset > endNode.childNodes.length)
endNodeOffset = endNode.childNodes.length > 0 ? endNode.childNodes.length - 1 : 0;
if (__aspxWebKitFamily)
curSelection.setBaseAndExtent(startNode, startNodeOffset, endNode, endNodeOffset);
else
curSelection.extend(endNode, endNodeOffset);
}
}
ASPxClientSelectionNSOpera.SelectElementInDocument = function(elem, docObj, windowObj, selectAllContent) {
if (elem) {
if (!_aspxIsExists(selectAllContent))
selectAllContent = true;
var range = docObj.createRange();
range.selectNode(elem);
if (__aspxOpera)
range.selectNodeContents(elem);
if (!selectAllContent)
range.collapse(false);
var selection = windowObj.getSelection();
if (__aspxWebKitFamily)
selection.setBaseAndExtent(range.startContainer, range.startOffset, range.endContainer, range.endOffset);
else {
selection.removeAllRanges();
selection.addRange(range);
}
}
}
ASPxCachedElementsManager = _aspxCreateClass(null, {
constructor: function(htmlEditor) {
this.htmlEditor = htmlEditor;
this.selectedElements = { table: null, tableRow: null, tableCell: null };
this.needGetElementFromSelection = { table: true, tableRow: true, tableCell: true };
},
ClearSeletedElements: function() {
for (var key in this.selectedElements) {
this.selectedElements[key] = null;
this.needGetElementFromSelection[key] = true;
}
},
GetSeletedElement: function(name) {
return this.selectedElements[name];
},
SetSelectedElement: function(name, element) {
this.selectedElements[name] = element;
this.needGetElementFromSelection[name] = false;
},
NeedGetElementFromSelection: function(name) {
return this.needGetElementFromSelection[name] && !_aspxIsExists(this.selectedElements[name]);
}
});
}
/*
playback timings (ms):
exclusion.robots: 0.392
load_resource: 75.973
PetaboxLoader3.resolve: 130.955 (3)
LoadShardBlock: 145.914 (3)
PetaboxLoader3.datanode: 78.98 (4)
exclusion.robots.policy: 0.364
esindex: 0.022
RedisCDXSource: 1.142
captures_list: 184.153
CDXLines.iter: 19.523 (3)
*/