Type.registerNamespace("Telerik.Web.UI");
Type.registerNamespace("Telerik.Web.UI.Editor");
Telerik.Web.UI.Editor.Utils =
{
getInvisibleParent : function(parent)
{
while(parent != document)
{
if ("none" == TelerikCommonScripts.getCurrentStyle(parent, "display", ""))
{
return parent;
}
parent = parent.parentNode;
}
return null;
},
evalScriptCode : function(scriptCode)
{
var isSafari = Telerik.Web.Browser.isSafari;
if (isSafari)
{
scriptCode = scriptCode.replace(/^\s*<!--((.|\n)*)-->\s*$/mi, "$1");
}
var newScript = document.createElement("script");
newScript.setAttribute("type", "text/javascript");
if (isSafari)
{
newScript.appendChild(document.createTextNode(scriptCode));
}
else
{
newScript.text = scriptCode;
}
var scriptContainer = document.getElementsByTagName("head")[0];
scriptContainer.appendChild(newScript);
if (isSafari)
{
newScript.innerHTML = "";
}
else
{
newScript.parentNode.removeChild(newScript);
}
},
//Function that returns cleaned content according to supplied [editor] settings
cleanPastedContent : function(dirtyText, stripOptions, questionMessage)
{
var cleanedText = dirtyText;
if (stripOptions == Telerik.Web.UI.StripFormattingOptions.None)
{
if ((dirtyText.match(/style="[^"]*?mso[^"]*?"/ig) || dirtyText.match(/class="?[^"]*?mso[^"]*?"?/ig)) && confirm(questionMessage))
{
cleanedText = Telerik.Web.UI.Editor.Utils.stripFormatting(dirtyText , "WORD");
}//else do nothing
}
else if (stripOptions & Telerik.Web.UI.StripFormattingOptions.All)
{
cleanedText = Telerik.Web.UI.Editor.Utils.stripFormatting(dirtyText , "ALL");
}
else
{
if (stripOptions & Telerik.Web.UI.StripFormattingOptions.MSWordRemoveAll)
{
dirtyText = Telerik.Web.UI.Editor.Utils.stripFormatting(dirtyText, "WORD_ALL");
}
if (stripOptions & Telerik.Web.UI.StripFormattingOptions.MSWordNoFonts)
{
dirtyText = Telerik.Web.UI.Editor.Utils.stripFormatting(dirtyText, "WORD_NO_FONTS");
}
if (stripOptions & Telerik.Web.UI.StripFormattingOptions.MSWord)
{
dirtyText = Telerik.Web.UI.Editor.Utils.stripFormatting(dirtyText, "WORD");
}
if (stripOptions & Telerik.Web.UI.StripFormattingOptions.Css)
{
dirtyText = Telerik.Web.UI.Editor.Utils.stripFormatting(dirtyText, "CSS");
}
if (stripOptions & Telerik.Web.UI.StripFormattingOptions.Font)
{
dirtyText = Telerik.Web.UI.Editor.Utils.stripFormatting(dirtyText, "FONT");
}
if (stripOptions & Telerik.Web.UI.StripFormattingOptions.Span)
{
dirtyText = Telerik.Web.UI.Editor.Utils.stripFormatting(dirtyText, "SPAN");
}
cleanedText = dirtyText;
}
return cleanedText;
},
isCursorMovingKey : function(keyCode)
{
if (keyCode >= 33 && keyCode <= 40) return true;//up, down, end, home, left, up, right, down
return false;
},
isSystemKey : function (keyCode)
{
if (keyCode >=112 && keyCode <=123)return true;//F1 - F12
if (keyCode >=8 && keyCode <=27) return true;//BACK (8) -> ESC (27)
if (keyCode >=32 && keyCode <=46) return true;//SPACE (32) -> DELETE (46)
if (keyCode == 93) return true;//Context menu
return false;
},
storeBrowserPosition : function()
{
var oBody = document.body;
var oDoc = document.documentElement;
this._browserTop = oBody.scrollTop > oDoc.scrollTop ? oBody.scrollTop : oDoc.scrollTop;
this._browserLeft = oBody.scrollLeft > oDoc.scrollLeft ? oBody.scrollTop : oDoc.scrollLeft;
},
restoreBrowserPosition : function(left, top)
{
try
{
if (null == left) left = this._browserLeft;
if (null == top) top = this._browserTop;
var oBody = document.body;
var oDoc = document.documentElement;
oBody.scrollTop = top;
oBody.scrollLeft = left;
oDoc.scrollTop = top;
oDoc.scrollLeft = left;
}
catch(ex){};
},
_getPasteIframe : function()
{
if (!this._pasteIframe)
{
this._pasteIframe = document.createElement("IFRAME");
var style = this._pasteIframe.style;
style.width = "1px";
style.height = "1px";
style.border = "0px solid red";
style.overflow = "hidden";
style.position = "absolute";
//It MUST be added to the document immediately, or there are problems
document.body.appendChild(this._pasteIframe);
var doc = this._pasteIframe.contentWindow.document;
//Must use document.open - or else under IE the iframe does not have a body object immediately to access - needs a timeout and this causes many problems.
var oNewDoc = doc.open("text/html", "replace");
var sMarkup = "<html><head><title>New Document</title></head>" +
"<body contentEditable='true' style='overflow:hidden;margin:0px;padding:0px;height:100%'>" +
"</html>";
oNewDoc.write(sMarkup);
oNewDoc.close();
}
return this._pasteIframe;
},
getPasteContainer : function()
{
var area = this._getPasteIframe();
return area.contentWindow.document.body;
},
getClipboardAsHtml : function()
{
var div = this.getPasteContainer();
div.innerHTML = "";
div.setActive();
document.execCommand('Paste', null);//RE5-4357 - Causes the page to scroll down if scrollers exist!
//TEKI: New - keeps the scroll position, but strips automatically some of the Word formatting, e.g. the margin=0 of P tags.
//This is not very good. So, the old approach was restored
//document.selection.createRange().execCommand('Paste', null);
var oPaste = div.innerHTML;
div.innerHTML = "";
return oPaste;
},
//==================== Format stripping and paste modification functions ===========================================//
stripFormatting : function(textHtml, clearValue)
{
switch (clearValue)
{
case "ALL":
textHtml = textHtml.replace(/<\/?[^>]*>/ig, "");
break;
case "WORD":
case "WORD_ALL":
case "WORD_NO_FONTS":
textHtml = this.stripWordFormatting(textHtml, clearValue);
break;
case "CSS":
textHtml = textHtml.replace(new RegExp("(<[^>]+) class=[^ |^>]*([^>]*>)", "ig"), "$1 $2");
textHtml = textHtml.replace(/(<[^>]+) style="[^"]*"([^>]*>)/ig, "$1 $2");
break;
case "FONT":
textHtml = textHtml.replace(/<\/?font[^>]*>/ig, "");
break;
case "SPAN":
textHtml = textHtml.replace(/<\/?span[^>]*>/ig, "");
break;
default://TO DO: Perhaps add an array to allow people to add their own format strippers
break;
}
return textHtml;
},
replaceNewLineWithBr : function(textData)
{
try
{
textData = textData.replace(/\n/g, "<br>");
return textData;
}
catch (exc) {}
},
convertText2Html : function(text)
{
try
{
text = text.replace(/</g, "<");
text = text.replace(/>/g, ">");
text = text.replace(/\n/g, "<br>");
return text;
}
catch (exc) {}
},
clearWordAttributesInElement : function(domObject, clearValue)
{
var allChilds = document.all ? domObject.all : domOb
评论0