Home / Community & Support / Knowledge Base / RadControls for ASP.NET and ASP.NET AJAX / MOSS Integration / How to execute custom code called on RadEditor's events

How to execute custom code called on RadEditor's events

Article Info

Rating: Not rated

Article information

Article relates to

RadEditor for MOSS 5+
RadEditor for SharePoint 2010

Created by

 Georgi Popivanov

Last modified

 9/11/2011

Last modified by

 Rumen Zhekov



HOW-TO 
Execute custom code on the desired editor's event.

SOLUTION for RadEditor for MOSS
In some scenarios it is useful to write custom functionality to be executed on the desired editor's event. The code below demonstrates how to check whether the inserted image through the Image manager has an "alt" attribute set and if it doesn't then urge the user to enter an "alt" attribute name:
  1. Open the wpresources\RadEditorSharePoint\5.x.x.x__1f131a624888eeed\Resources\ MOSSEditorTools.js and write your custom code to be executed on the desired event:   
     
    function OnClientPasteHtml(sender, args)    
    {    
        var commandName = args.get_commandName();    
        var value = args.get_value();    
         
        if (commandName == "ImageManager")    
        {    
            //See if an img has an alt tag set     
            var div = document.createElement("DIV");     
         
            //Do not use div.innerHTML as in IE this would cause the image's src or the link's href to be converted to absolute path.    
            //This is a severe IE quirk.    
            Telerik.Web.UI.Editor.Utils.setElementInnerHtml(div,value);    
         
            //Now check if there is alt attribute     
            var img = div.firstChild;     
            if (!img.alt)    
            {     
                var alt = prompt("No alt tag specified. Please specify an alt attribute for the image", "");    
                img.setAttribute("alt", alt);    
         
                //Set new content to be pasted into the editor     
                args.set_value(div.innerHTML);    
            }     
        }    
    }

      
  2. Open the respective ConfigFile (ConfigFile.xml or ListConfigFile.xml) and set your custom function to be executed on the desired event e.g.

    <property name="OnClientPasteHtml">OnClientPasteHtml</property> 
     
  3. Save the files, clear the browser's cache and review the result.


SOLUTION for RadEditor for SharePoint 2010
The code below demonstrates how to check whether the inserted image through the Image manager has an "alt" attribute set and if it doesn't then urge the user to enter an "alt" attribute name:
  1. Open the \Program Files\Common Files\Microsoft Shared\Web Server Extensions\wpresources\RadEditorSharePoint\6.x.x.x__1f131a624888eeed\Resources\SPEditorTools.js file and write at the end of the file your custom code to be executed on the desired event:   
     
    function OnClientPasteHtml(sender, args)    
    {    
        var commandName = args.get_commandName();    
        var value = args.get_value();    
         
        if (commandName == "ImageManager")    
        {    
            //See if an img has an alt tag set     
            var div = document.createElement("DIV");     
         
            //Do not use div.innerHTML as in IE this would cause the image's src or the link's href to be converted to absolute path.    
            //This is a severe IE quirk.    
            Telerik.Web.UI.Editor.Utils.setElementInnerHtml(div,value);    
         
            //Now check if there is alt attribute     
            var img = div.firstChild;     
            if (!img.alt)    
            {     
                var alt = prompt("No alt tag specified. Please specify an alt attribute for the image", "");    
                img.setAttribute("alt", alt);    
         
                //Set new content to be pasted into the editor     
                args.set_value(div.innerHTML);    
            }     
        }    
    }

     
  2. Open the respective ConfigFile (ConfigFile.xml or ListConfigFile.xml) and set your custom function to be executed on the desired event e.g.

    <property name="OnClientPasteHtml">OnClientPasteHtml</property> 
     
  3. Save the files, clear the browser's cache and review the result.

For more information about the different editor's events please review the following help articles:

Comments

There are no comments yet.
If you'd like to comment on this KB article, please, send us a Support Ticket.
Thank you!

Please Sign In to rate this article.