【问题标题】:Can Sitecore's rich text editor's internal link manager remember your last location?Sitecore 的富文本编辑器的内部链接管理器能否记住您最后的位置?
【发布时间】:2013-04-02 20:31:01
【问题描述】:
问题
是否可以记住最后链接的项目并在下次使用 插入链接 对话框时选择该项目?
背景
我们的 Sitecore 内容编辑器使用富文本编辑器 (Telerik RadEditor) 来编辑我们网站上的 HTML 内容。有时他们需要在同一页面上创建多个位于相似区域的链接(例如,几篇不同的相关文章)。目前,当他们单击“插入链接”按钮时,他们会被带到 插入链接 对话框,并在内容树中选择当前项目。他们浏览到他们想要链接的项目并单击链接。然后他们去创建另一个链接,它会再次打开插入链接对话框到当前项目,而不是他们刚刚链接的项目。
【问题讨论】:
标签:
telerik
sitecore
sitecore6
radeditor
【解决方案1】:
我找到的解决方案需要更改Website\sitecore\shell\Controls\Rich Text Editor\RichText Commands.js 文件,并且只要您不重新加载页面就可以工作。您可以通过将信息存储在 cookie 中而不是使用变量 prevId 来轻松扩展它以在编辑其他页面时使用。
首先你需要在文件的开头定义变量:
var prevId = null;
每次插入 Sitecore 链接时,我们都会将最后选择的项目 ID 分配给该变量。
第二步是扩展scInsertSitecoreLink函数,在选择链接后分配prevId变量:
function scInsertSitecoreLink(sender, returnValue) {
if (!returnValue) {
return;
}
prevId = returnValue.url.match(/id\=[a-fA-F0-9]{32}/g);
if (prevId) {
prevId = prevId[0].substr(3);
}
... rest of the scInsertSitecoreLink goes here
最后一步是修改RadEditorCommandList["InsertSitecoreLink"]函数,如果它在尝试分配保存当前项目ID的scItemID之前设置,则它使用prevId变量值:
RadEditorCommandList["InsertSitecoreLink"] = function(commandName, editor, args) {\
... here goes the original code of the function up to
if (!id) {
... and the code in the bracket
}
... and now we try to assign the prevId which was set after the last link was chosen
if(!id && prevId) {
id = prevId;
}
... and here goes the rest of the function
if (!id) {
id = scItemID;
}