+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Customization of LinksDialog

Customization of LinksDialog

3 posts, 0 answered
  1. ravi shankar
    ravi shankar avatar
    18 posts
    Registered:
    13 Feb 2010
    16 Apr 2010
    Link to this post
    Hi Sitefinity,

    I want to add Target dropdown similar to the the Document manager in the LinksDialog(Insert Link).So when i set the target then the link should open in new or same browser based on the target value.


    How can i attain this functionality.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    16 Apr 2010
    Link to this post
    Hello ravi shankar,

    You could open Sitefinity\Admin\ControlTemplates\Pages\Dialogs\LinksEditorDialog.ascx and modify the js to add the new attribute. Below is sample code

    <%@ Register Assembly="Telerik.Libraries" Namespace="Telerik.Libraries.WebControls" TagPrefix="sfLib" %>
     
    <script type="text/javascript">
    var currentElement = document.createElement("a");
    var selectedHtml = "";
     
    function getRadWindow() //mandatory for the RadWindow dialogs functionality
    {
       if (window.radWindow)
        {
        return window.radWindow;
        }
        if (window.frameElement && window.frameElement.radWindow)
        {
         return window.frameElement.radWindow;
        }
        return null;
    }
     
    function initDialog() //called when the dialog is initialized
    {
       var clientParameters = getRadWindow().ClientParameters; //return the arguments supplied from the parent page
     
       if (clientParameters.nodeName && typeof(clientParameters.nodeName) != "undefined" && clientParameters.nodeName == "A")
       {
           currentElement = clientParameters;
               
           urlTxt = document.getElementById('<%= urlTextBox.ClientID %>');
           titleTxt = document.getElementById('<%= linkTextBox.ClientID %>');
           titleLi = document.getElementById("linkText");
           tooltipTxt = document.getElementById('<%= tooltipTextBox.ClientID %>');
     
           if (currentElement.attributes["sfref"] != undefined) {
            urlTxt.value = currentElement.attributes["sfref"].value;
           }
           else if (currentElement.href != "") {
            urlTxt.value = currentElement.href;
           }
           if (currentElement.title != "")
           {
                tooltipTxt.value = currentElement.title;
           }
           if (currentElement.innerHTML != "")
           {
               htmlText = currentElement.innerHTML;
               if (currentElement.childNodes.length > 1)
               {
                    titleLi.style.display = "none";
                    selectedHtml = htmlText
               }
               else
               {
                    titleTxt.value = htmlText;
               }
           }
       }
       else
       {
           titleLi = document.getElementById("linkText");
           titleTxt = document.getElementById('<%= linkTextBox.ClientID %>');
            
           //TELERIK
           htmlText = clientParameters.Html;
           if (clientParameters.Html.indexOf("<IMG ") != -1 || clientParameters.Html.indexOf("<img ") != -1)
            selectedHtml = clientParameters.Html;                   
           pureText = clientParameters.Text;
           titleTxt.value = pureText;
            
           document.getElementById('linkURL').getElementsByTagName('input')[0].focus();
       }
       requiredFieldsValidate();
    }
     
    if (window.attachEvent)
    {
       window.attachEvent("onload", initDialog);
    }
    else if (window.addEventListener)
    {
       window.addEventListener("load", initDialog, false);
    }
     
    function insertLink() //fires when the Insert Link button is clicked
    {
       var closeArgument = currentElement;
       urlTxt = document.getElementById('<%= urlTextBox.ClientID %>');
       titleTxt = document.getElementById('<%= linkTextBox.ClientID %>');
       titleLi = document.getElementById("linkText");
       tooltipTxt = document.getElementById('<%= tooltipTextBox.ClientID %>');
       targetLink = document.getElementById('<%= Target.ClientID %>');
     
       if (urlTxt) {
        closeArgument.href = urlTxt.value;
        if (urlTxt.value.indexOf("~/") == 0 || urlTxt.value.indexOf("[") == 0) {
            closeArgument.setAttribute("sfref", urlTxt.value);
            if (targetLink.checked) {
                closeArgument.setAttribute("target", "_blank");
            }
        } else {
            closeArgument.removeAttribute("sfref");
        }
       }
        
       if (selectedHtml != "")
       {
           closeArgument.innerHTML = selectedHtml;
           
       }
       else if (titleTxt && titleLi.style.display != "none")
       {
            closeArgument.innerHTML = titleTxt.value;
       }  
        
       if (tooltipTxt && tooltipTxt.value != "")
            closeArgument.title = tooltipTxt.value;
        
       var radWindow = getRadWindow();
       radWindow.argument = closeArgument;
       radWindow.close(closeArgument); //use the close function of the getRadWindow to close the dialog and pass the arguments from the dialog to the callback function on the main page.
    }
     
    function beforeInsertLink(src, altText, title)
    {
        if (src != '')
        {
            urlTxt = document.getElementById('<%= urlTextBox.ClientID %>');
            titleTxt = document.getElementById('<%= linkTextBox.ClientID %>');
            if (urlTxt && titleTxt)
            {
                urlTxt.value = src;
                if(titleTxt.value == "")
                    titleTxt.value = title;
            }
        }
        requiredFieldsValidate();
    }
    </script>
    <div class="ctrlProps" id="div1">
    <div class="ctrlContent">
    <div class="uploadPane">
    <p class="mand">* Mandatory fields</p>
    hh
    <h2>Insert a link</h2>
     
    <div  class="dialogBox">
     
        <ol> <li id="linkURL">
            
                <asp:Label ID="Label1" runat="server" Text="<%$Resources:Url %>" AssociatedControlID="urlTextBox"></asp:Label>
                <asp:TextBox runat="server" ID="urlTextBox" onkeydown="requiredFieldsValidate();" onkeyup="requiredFieldsValidate(); return false; " onfocus="requiredFieldsValidate(); return false; " onblur="requiredFieldsValidate(); return false; "></asp:TextBox>
                <asp:Label runat="server" Text="<%$Resources:Or %>"></asp:Label>
                <sfLib:ButtonSelector runat="server" ID="selectFromExistingLink" ButtonText="<%$Resources:SelectFromExisting %>" WindowNavigateUrl="~/Sitefinity/UserControls/Dialogs/PagesSelector.aspx" AssociatedControls="urlTextBox" />
                <p class="example"><asp:Literal ID="Label2" runat="server" Text="<%$Resources:UrlExpl %>" ></asp:Literal></p>
       
          </li>
            <li id="linkText">
                <asp:Label runat="server" Text="<%$Resources:Text %>" AssociatedControlID="linkTextBox"></asp:Label>
                <asp:TextBox runat="server" ID="linkTextBox" onkeydown="requiredFieldsValidate();" onkeyup="requiredFieldsValidate(); return false; " onfocus="requiredFieldsValidate(); return false; " onblur="requiredFieldsValidate(); return false; "></asp:TextBox>
                <p class="example"><asp:Literal ID="Literal1" runat="server" Text="<%$Resources:TextExpl %>" ></asp:Literal></p>
            </li>
            <li>
                <asp:Label ID="Label3" runat="server" Text="<%$Resources:Tooltip %>" AssociatedControlID="tooltipTextBox"></asp:Label>
                <asp:TextBox runat="server" ID="tooltipTextBox"></asp:TextBox>         
                <p class="example"><asp:Literal ID="Literal2" runat="server" Text="<%$Resources:TooltipExpl %>" ></asp:Literal></p>
            </li>
             
             <li>
                <asp:Label ID="Label4" runat="server" Text="NewLink" AssociatedControlID="Target"></asp:Label>
                   <p><asp:CheckBox runat="server" ID="Target" Text="Open In new Window" CssClass="check"/></p>       
                <p class="example"><asp:Literal ID="Literal3" runat="server" Text="Open in new Windows" ></asp:Literal></p>
            </li>
        </ol>
     
    <p runat="server" id="actionButtons" class="button_area bottom">
        <span class="CmsButLeft disabled ok" id="submitBtnDisenabled"><strong class="CmsButRight light">Insert</strong></span>
        <a href="#" onclick="insertLink();" style="display: none; " class="CmsButLeft ok" id="submitBtnEnabled"><strong class="CmsButRight light"><asp:Literal runat="server" Text="<%$Resources:Insert %>"></asp:Literal></strong></a>
        <span class="cmsorlbl"> <asp:Literal runat="server" Text="<%$Resources:Or %>"></asp:Literal> </span>
        <a href="#" onclick="getRadWindow().close();" class="cmscclcmd"><asp:Literal runat="server" Text="<%$Resources:Cancel %>"></asp:Literal></a>
    </p>
    <script type="text/javascript">
    var lURL = document.getElementById("linkURL").getElementsByTagName("input")[0];
    var lText = document.getElementById("linkText").getElementsByTagName("input")[0];
    var textLi = document.getElementById("linkText");
    var submitBtnEnabled = document.getElementById("submitBtnEnabled");
    var submitBtnDisenabled = document.getElementById("submitBtnDisenabled");
     
    function requiredFieldsValidate() {
        if(lURL.value == "" || (textLi.style.display != "none" && lText.value == "")) {
            submitBtnEnabled.style.display = "none";
            submitBtnDisenabled.style.display = "block";
        } else {
            submitBtnEnabled.style.display = "block";
            submitBtnDisenabled.style.display = "none";
        }
             
    }
    </script>
    </div>
    </div>
    </div>
    </div>


    Greetings,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. ravi shankar
    ravi shankar avatar
    18 posts
    Registered:
    13 Feb 2010
    16 Apr 2010
    Link to this post
    Hi Ivan Dimitrov,

    Thanks for the reply it worked well.I added DropdownList instead of checkbox.

    Thanks & Regards
      Ravishankar
Register for webinar
3 posts, 0 answered