Selective suppress the SetImageProperties dialog

3 posts, 1 answers
  1. ian webster
    ian webster avatar
    14 posts
    Member since:
    Jan 2006

    Posted 12 Jul 2011 Link to this post

    Hi,

    I'm using the image tag as a place holder for some custom content the up shot is that if an image has certain attributes (some I've made up) I want to suppress the standard image properties editor that the rad editor has built in if the user clicks 'properties' in the context menu.

    I've been able to get the suppress to work correctly, but I have also stopped the image properties editor from working when a normal image is used.

    My rad editor looks like:

    <telerik:RadEditor ID="ucEditor" runat="server" OnClientLoad="OnClientLoad" Width="99%" Height="470px" ToolsFile="~/Resources/Config/RadControls/DefaultToolsFile.xml">
        <CssFiles>
            <telerik:EditorCssFile Value="" />
        </CssFiles>
        <ContextMenus>
            <telerik:EditorContextMenu TagName="IMG" Enabled="true">
                <telerik:EditorTool Name="EditPageControl" Text="Edit Page Control" />
                <telerik:EditorTool Name="SetImageProperties" />
            </telerik:EditorContextMenu>
        </ContextMenus>
    </telerik:RadEditor>
    I've got the following handler for set image properties:

    Telerik.Web.UI.Editor.CommandList["SetImageProperties"] = function (commandName, editor, args) {
     
        var elem = editor.getSelectedElement();
        var typeId;
        var inmemoryId;
        var savedId;
        var pageControlName;
     
        //get the selected tag
        editor.selectElement(elem);
        var selection = editor.getSelection();
        var selectionHTML = selection.getHtml();
        //attempt to retrieve the parameters we need from the tags
        //attributes
        typeId = $telerik.$(selectionHTML).attr("typeId");
        savedId = $telerik.$(selectionHTML).attr("savedId");
        inmemoryId = $telerik.$(selectionHTML).attr("inMemoryId");
        pageControlName = $telerik.$(selectionHTML).attr("pageControlName");
     
        //check if this is a dynamic page control place holder
        if (typeId != null && savedId != null && inmemoryId != null && pageControlName != null) {
            //user has selected an dynamic page control and is trying to edit it using the image manager - must prevent this!
            alert('This is a dynamic page control, please click Edit Page Control to edit it');
            return; //disable the browsers context menu
        }
    }

    I suspect I need an 'else' part to go with the if but I'm not sure how you would manually invoke the image properties editor.

    Thanks,

    Ian.
  2. Answer
    Dobromir
    Admin
    Dobromir avatar
    1633 posts

    Posted 12 Jul 2011 Link to this post

    Hi Ian,

    You can simply store the original command before overwriting it and then use it in the else clause, e.g.:
    //store the original command
    var oldSetImagePropertiesCommand = Telerik.Web.UI.Editor.CommandList["SetImageProperties"];
     
    Telerik.Web.UI.Editor.CommandList["SetImageProperties"] = function (commandName, editor, args)
    {
        var elem = editor.getSelectedElement();
        var typeId;
        var inmemoryId;
        var savedId;
        var pageControlName;
     
        //get the selected tag
        editor.selectElement(elem);
        var selection = editor.getSelection();
        var selectionHTML = selection.getHtml();
        //attempt to retrieve the parameters we need from the tags
        //attributes
        typeId = $telerik.$(selectionHTML).attr("typeId");
        savedId = $telerik.$(selectionHTML).attr("savedId");
        inmemoryId = $telerik.$(selectionHTML).attr("inMemoryId");
        pageControlName = $telerik.$(selectionHTML).attr("pageControlName");
     
        //check if this is a dynamic page control place holder
        if (typeId != null && savedId != null && inmemoryId != null && pageControlName != null)
        {
            //user has selected an dynamic page control and is trying to edit it using the image manager - must prevent this!
            alert('This is a dynamic page control, please click Edit Page Control to edit it');
            return; //disable the browsers context menu
        }
        else
        {
            oldSetImagePropertiesCommand(commandName, editor, args);
        }
    }


    Best wishes,
    Dobromir
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  3. ian webster
    ian webster avatar
    14 posts
    Member since:
    Jan 2006

    Posted 13 Jul 2011 Link to this post

    Hi Dobromir,

    Thank you - that worked perfectly.

    Regards,

    Ian.
Back to Top