Hey we are having the same problem with inserting links as the following article (http://www.telerik.com/community/forums/thread/b311D-tgtmm.aspx). I'm using version 4.4.1.0. I really need:
<property name="StripAbsoluteAnchorPaths">True</property>
<property name="StripAbsoluteImagesPaths">True</property>
So whenever I add a hyperlink form the Pages gallery I get an error: "You must specify a valid field value."
So I cannot add a link to anything in my pages gallery, but I need to...
When I use the solution provided in the article above, I get a popup message of "The content is invalid. Do you want to auto-correct it?". If I click ok, it deletes the hyperlink. Plus the error above is again stated.
Can you please provide me / us with a solution to this. I am ready to go live with my Web Content Management System (all I need to do is add the links in, and this needs to work for when my users edit their pages) and I really wanted to use your product for my editor... Please help...
10 Answers, 1 is accepted
We developed a new mechanism that preserves the link/image paths the way they are inserted to the RadEditor content area. Please, follow the step-by-step instructions below to enable the path keeper filter in RadEditor for MOSS:
1) Open the \Program Files\Common Files\Microsoft Shared\web server extensions\wpresources\RadEditorSharePoint\4.4.1.0__1f131a624888eeed\RadControls\Editor\ConfigFile.xml file and register the OnClientInit event of RadEditor:
<configuration>
...
<property name="OnClientInit">OnClientInitFilter</property>
</configuration>
You should also set the StripAbsoluteAnchorPaths and StripAbsoluteImagesPaths properties to true, e.g.
<property name="StripAbsoluteAnchorPaths">True</property>
<property name="StripAbsoluteImagesPaths">True</property>
2) Open the page with the <radE:RadHtmlField in Microsoft Office SharePoint Designer and put the following JavaScript inside the PlaceHolderAdditionalPageHead asp:content tag:
<asp:Content ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server">
<script type="text/javascript">
originalOnClientLoadFunctions = new Object();
function OnClientInitFilter(editor)
{
//use the filter only on IE
if (editor.IsIE)
{
//save the original onclientload function reference
if (typeof(editor.OnClientLoad) != "undefined" && editor.OnClientLoad != null)
{
originalOnClientLoadFunctions[editor.Id] = editor.OnClientLoad;
}
editor.OnClientLoad = OnClientLoadFilter;
if (typeof(RadEditorNamespace.OriginalSetElementInnerHTML) == "undefined")
{
RadEditorNamespace.OriginalSetElementInnerHTML = RadEditorNamespace.SetElementInnerHTML;
RadEditorNamespace.SetElementInnerHTML = function (elem, content)
{
content = GetStoredOriginalPathsAndAttributes(content);
RadEditorNamespace.OriginalSetElementInnerHTML(elem,content);
RestoreOriginalPathsAndAttributes(elem);
};
}
editor.OriginalSetContentMethod = editor.SetContent;
editor.SetContent = function(content)
{
if (!editor.InitialSetContentCalled)
{
editor.InitialSetContentCalled = true;
editor.InitialNonModifiedContent = content;
}
//Call the original editor method:
editor.OriginalSetContentMethod(content);
}
editor.OriginalPasteHtml = editor.PasteHtml;
editor.PasteHtml = function(content, sTitle, bSelectText, bFireSelChanged, bAddUndo)
{
content = GetStoredOriginalPathsAndAttributes(content);
editor.OriginalPasteHtml(content, sTitle, bSelectText, bFireSelChanged, bAddUndo);
RestoreOriginalPathsAndAttributes(editor.GetContentArea());
}
}
}
function GetStoredOriginalPathsAndAttributes(content)
{
var pathsRegExp = /((href|src)\s*=\s*('|")?)(.*?)(\3)(\s|(\/)?>)/ig;
content = content.replace(pathsRegExp, "$2=$3$4$3 originalAttribute=\"$2\" originalPath=\"$4\"$6");
return content;
}
function RestoreOriginalPathsAndAttributes(contentArea)
{
var children = contentArea.getElementsByTagName("*");
for(var i=0; i < children.length; i++)
{
var currentChild = children[i];
var originalPath = currentChild.getAttribute("originalPath");
var originalAttribute = currentChild.getAttribute("originalAttribute");
if (originalPath != null && originalAttribute != null)
{
currentChild.removeAttribute("originalPath");
currentChild.removeAttribute("originalAttribute");
if (originalPath.toLowerCase().indexOf("mailto:")==0)
{
//fix the IE bug where a mailto link with a subject will change the anchor text
continue;
}
//fix anchors
originalPath = originalPath.replace(windo w.location.href+"#","#");
//
currentChild.removeAttribute(originalAttribute);
currentChild.setAttribute(originalAttribute, originalPath);
}
}
}
function OnClientLoadFilter(editor)
{
if (editor.InitialSetContentCalled)
{
editor.SetHtml(editor.InitialNonModifiedContent);
}
editor.InitialNonModifiedContent = null;
//call the original OnClientLoad function
if (typeof(originalOnClientLoadFunctions[editor.Id]) != "undefined" && originalOnClientLoadFunctions[editor.Id] != null)
{
originalOnClientLoadFunctions[editor.Id](editor);
}
}
</script>
<style>
...
</style>
3. Save the files and test the editor.
If this does not help you to solve the problem set the StripAbsoluteAnchorPaths and StripAbsoluteImagesPaths properties to false, e.g.
<property name="StripAbsoluteAnchorPaths">False</property>
<property name="StripAbsoluteImagesPaths">False</property>
and test with the same code again.
Best regards,
Rumen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
<property name="StripAbsoluteAnchorPaths">True</property>
<property name="StripAbsoluteImagesPaths">True</property>
I get this error, as well as the problem I was having before.
Exception while executing client event OnClientInitError:'OnClientInitFilter' is undefined.
When I set it to:
<property name="StripAbsoluteAnchorPaths">False</property>
<property name="StripAbsoluteImagesPaths">False</property>
It works fine, but obviously I need to not have the http://servername/ in the path...
Could you please right click on the page on which you receive the js error and choose View Source. After that see that the following js code exists in the source:
<script type="text/javascript"> |
originalOnClientLoadFunctions = new Object(); |
function OnClientInitFilter(editor) |
{ |
//use the filter only on IE |
if (editor.IsIE) |
{ |
//save the original onclientload function reference |
if (typeof(editor.OnClientLoad) != "undefined" && editor.OnClientLoad != null) |
{ |
originalOnClientLoadFunctions[editor.Id] = editor.OnClientLoad; |
} |
editor.OnClientLoad = OnClientLoadFilter; |
if (typeof(RadEditorNamespace.OriginalSetElementInnerHTML) == "undefined") |
{ |
RadEditorNamespaceRadEditorNamespace.OriginalSetElementInnerHTML = RadEditorNamespace.SetElementInnerHTML; |
RadEditorNamespace.SetElementInnerHTML = function (elem, content) |
{ |
content = GetStoredOriginalPathsAndAttributes(content); |
RadEditorNamespace.OriginalSetElementInnerHTML(elem,content); |
RestoreOriginalPathsAndAttributes(elem); |
}; |
} |
editoreditor.OriginalSetContentMethod = editor.SetContent; |
editor.SetContent = function(content) |
{ |
if (!editor.InitialSetContentCalled) |
{ |
editor.InitialSetContentCalled = true; |
editor.InitialNonModifiedContent = content; |
} |
//Call the original editor method: |
editor.OriginalSetContentMethod(content); |
} |
editoreditor.OriginalPasteHtml = editor.PasteHtml; |
editor.PasteHtml = function(content, sTitle, bSelectText, bFireSelChanged, bAddUndo) |
{ |
content = GetStoredOriginalPathsAndAttributes(content); |
editor.OriginalPasteHtml(content, sTitle, bSelectText, bFireSelChanged, bAddUndo); |
RestoreOriginalPathsAndAttributes(editor.GetContentArea()); |
} |
} |
} |
function GetStoredOriginalPathsAndAttributes(content) |
{ |
var pathsRegExp = /((href|src)\s*=\s*('|")?)(.*?)(\3)(\s|(\/)?>)/ig; |
contentcontent = content.replace(pathsRegExp, "$2=$3$4$3 originalAttribute=\"$2\" originalPath=\"$4\"$6"); |
return content; |
} |
function RestoreOriginalPathsAndAttributes(contentArea) |
{ |
var children = contentArea.getElementsByTagName("*"); |
for(var i=0; i < children.length; i++) |
{ |
var currentChild = children[i]; |
var originalPath = currentChild.getAttribute("originalPath"); |
var originalAttribute = currentChild.getAttribute("originalAttribute"); |
if (originalPath != null && originalAttribute != null) |
{ |
currentChild.removeAttribute("originalPath"); |
currentChild.removeAttribute("originalAttribute"); |
if (originalPath.toLowerCase().indexOf("mailto:")==0) |
{ |
//fix the IE bug where a mailto link with a subject will change the anchor text |
continue; |
} |
//fix anchors |
originalPathoriginalPath = originalPath.replace(windo w.location.href+"#","#"); |
// |
currentChild.removeAttribute(originalAttribute); |
currentChild.setAttribute(originalAttribute, originalPath); |
} |
} |
} |
function OnClientLoadFilter(editor) |
{ |
if (editor.InitialSetContentCalled) |
{ |
editor.SetHtml(editor.InitialNonModifiedContent); |
} |
editor.InitialNonModifiedContent = null; |
//call the original OnClientLoad function |
if (typeof(originalOnClientLoadFunctions[editor.Id]) != "undefined" && originalOnClientLoadFunctions[editor.Id] != null) |
{ |
originalOnClientLoadFunctions[editor.Id](editor); |
} |
} |
</script> |
The JavaScript code should be defined above the RadEditor declaration. So you need to put it somewhere on the page above the following tag:
<radE:RadHtmlField id="Content" FieldName="PublishingPageContent" runat="server" AllowSpecialTags="True"/>
Best regards,
Rumen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
<%@ Page language="C#" Inherits="Microsoft.SharePoint.Publishing.PublishingLayoutPage,Microsoft.SharePoint.Publishing,Version=12.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePointWebControls" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="PublishingWebControls" Namespace="Microsoft.SharePoint.Publishing.WebControls" Assembly="Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="PublishingNavigation" Namespace="Microsoft.SharePoint.Publishing.Navigation" Assembly="Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="radEditorSP" Namespace="Telerik.SharePoint.FieldEditor" Assembly="RadEditorSharePoint, Version=4.4.1.0, culture=neutral, PublicKeyToken=1f131a624888eeed" %>
<asp:Content ContentPlaceholderID="PlaceHolderPageTitle" runat="server">
<SharePointWebControls:FieldValue id="PageTitle" FieldName="Title" runat="server"/>
</asp:Content>
<asp:Content ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server">
<script type="text/javascript">
function OnClientLoad(editor)
{
editor.AttachEventHandler ("RADEVENT_SUBMIT", function (e)
{
// the code below will call the Format Stripper tool with the "Span" tags
// the other possible options are All, CSS, WORD_ALL, WORD and SPAN
oTool = new Object();
oTool.GetSelectedValue = function() { return "WORD_ALL"; }
editor.Fire("FormatStripper", oTool);
}
);
}
originalOnClientLoadFunctions = new Object();
function OnClientInitFilter(editor)
{
//use the filter only on IE
if (editor.IsIE)
{
//save the original onclientload function reference
if (typeof(editor.OnClientLoad) != "undefined" && editor.OnClientLoad != null)
{
originalOnClientLoadFunctions[editor.Id] = editor.OnClientLoad;
}
editor.OnClientLoad = OnClientLoadFilter;
if (typeof(RadEditorNamespace.OriginalSetElementInnerHTML) == "undefined")
{
RadEditorNamespace.OriginalSetElementInnerHTML = RadEditorNamespace.SetElementInnerHTML;
RadEditorNamespace.SetElementInnerHTML = function (elem, content)
{
content = GetStoredOriginalPathsAndAttributes(content);
RadEditorNamespace.OriginalSetElementInnerHTML(elem,content);
RestoreOriginalPathsAndAttributes(elem);
};
}
editor.OriginalSetContentMethod = editor.SetContent;
editor.SetContent = function(content)
{
if (!editor.InitialSetContentCalled)
{
editor.InitialSetContentCalled = true;
editor.InitialNonModifiedContent = content;
}
//Call the original editor method:
editor.OriginalSetContentMethod(content);
}
editor.OriginalPasteHtml = editor.PasteHtml;
editor.PasteHtml = function(content, sTitle, bSelectText, bFireSelChanged, bAddUndo)
{
content = GetStoredOriginalPathsAndAttributes(content);
editor.OriginalPasteHtml(content, sTitle, bSelectText, bFireSelChanged, bAddUndo);
RestoreOriginalPathsAndAttributes(editor.GetContentArea());
}
}
}
function GetStoredOriginalPathsAndAttributes(content)
{
var pathsRegExp = /((href|src)\s*=\s*('|")?)(.*?)(\3)(\s|(\/)?>)/ig;
content = content.replace(pathsRegExp, "$2=$3$4$3 originalAttribute=\"$2\" originalPath=\"$4\"$6");
return content;
}
function RestoreOriginalPathsAndAttributes(contentArea)
{
var children = contentArea.getElementsByTagName("*");
for(var i=0; i < children.length; i++)
{
var currentChild = children[i];
var originalPath = currentChild.getAttribute("originalPath");
var originalAttribute = currentChild.getAttribute("originalAttribute");
if (originalPath != null && originalAttribute != null)
{
currentChild.removeAttribute("originalPath");
currentChild.removeAttribute("originalAttribute");
if (originalPath.toLowerCase().indexOf("mailto:")==0)
{
//fix the IE bug where a mailto link with a subject will change the anchor text
continue;
}
//fix anchors
originalPath = originalPath.replace(windo w.location.href+"#","#");
//
currentChild.removeAttribute(originalAttribute);
currentChild.setAttribute(originalAttribute, originalPath);
}
}
}
function OnClientLoadFilter(editor)
{
if (editor.InitialSetContentCalled)
{
editor.SetHtml(editor.InitialNonModifiedContent);
}
editor.InitialNonModifiedContent = null;
//call the original OnClientLoad function
if (typeof(originalOnClientLoadFunctions[editor.Id]) != "undefined" && originalOnClientLoadFunctions[editor.Id] != null)
{
originalOnClientLoadFunctions[editor.Id](editor);
}
}
</script>
</asp:Content>
<asp:Content ContentPlaceholderID="PlaceHolderMain" runat="server">
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td class="swgcTitle">
<SharePointWebControls:textfield FieldName="Site_x0020_Title" runat="server"/>
</td>
</tr>
<tr>
<td class="swgcContent">
<div id="richHtmlDiv">
<radEditorSP:radhtmlfield runat="server" id="Content" FieldName="SiteContent"></radEditorSP:RadHtmlField>
</div>
</td>
</tr>
</table>
</asp:Content>
I noticed a small bug in the code you sent. On the line:
originalPath = originalPath.replace(windo w.location.href+"#","#");
you need to remove the space so windo w reads window. After that the code should execute OK.
It seems that Rumen sent you the code with a typo. I apologize for that.
All the best,
Lini
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
When I set:
<property name="StripAbsoluteAnchorPaths">True</property>
<property name="StripAbsoluteImagesPaths">True</property>
I get a popup: "The content is invalid. Do you want to auto-correct it?". If I click ok, it deletes the hyperlink. Then below the Rad Editor I get "You must specify a valid field value."
When I set:
<property name="StripAbsoluteAnchorPaths">False</property>
<property name="StripAbsoluteImagesPaths">False</property>
It inserts the link and it seems to use the full path....
Ok, so I guess that JS code does work.
So we have to put this into all of our Page Layouts to get the links working?
kind of odd to have to set this value to False and use the JS code...
Steve
Yes, you need this code on each page that has RadEditor. The best place to put it would be the master page, which is used by your layouts.
All the best,
Lini
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
When a new version of RadEditor comes out, will I have to keep this code or not??? Or will this problem be fixed?
Thanks again
Steve
The next release of RadEditor will include this functionality out of the box so you will not need to add it explicitly anymore. The release is scheduled for the second half of December.
Sincerely yours,
Lini
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center