4
votes

Question

Is it possible to remember the last item linked and have that one be selected the next time the Insert a Link dialog box is used?

Background

Our Sitecore content editors use the rich text editor (Telerik RadEditor) to edit HTML content on our website. Sometimes they need to create several links on the same page that are in similar areas (e.g. several different related articles). Currently, when they click on the Insert Link button, they are brought to the Insert a Link dialog box with the current item selected in the content tree. They browse to the item they'd like to link and click Link. Then they go to create another link, and it opens the Insert a Link dialog box to the current item again, instead of the item they just linked.

1

1 Answers

2
votes

The solution which I found requires changes in Website\sitecore\shell\Controls\Rich Text Editor\RichText Commands.js file and works as long as you don't reload the page. You may easily extend it to work when some other page is edited by storing the information in a cookie instead of using the variable prevId.

First of all you need to define variable at the beginning of your file:

var prevId = null;

We will assign the last chosen item id to this variable every time we insert Sitecore link.

Second step is to extend scInsertSitecoreLink function to assign the prevId variable after the link is chosen:

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

And the last step is to amend RadEditorCommandList["InsertSitecoreLink"] function that it uses the prevId variable value if it is set before it tries to assign scItemID which holds current item id:

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;
    }