是否可以记住链接的最后一项,并在下次使用插入链接对话框时选择该项?
我们的Sitecore内容编辑者使用富文本编辑器(Telerik RadEditor)编辑我们网站上的HTML内容。有时他们需要在同一页面上创建几个类似区域的链接(例如几个不同的相关文章)。目前,当他们单击“插入链接”按钮时,它们将被带到插入链接对话框,其中包含在内容树中选择的当前项目。他们浏览到他们想要链接的项目,然后点击链接。然后他们去创建另一个链接,然后再次打开插入链接对话框到当前项目,而不是他们刚刚链接的项目。
答案 0 :(得分:2)
我发现的解决方案需要更改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"]
函数,它使用prevId
变量值,如果在它尝试分配保存当前项ID的scItemID
之前设置它:
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;
}