Creating SharePoint 2010 ribbon toggle button

by Kai 24. April 2012 19:28

Hello to all. Recently I was playing with sharepoint toggle button (when answering one of the sharepoint.stackexchange questions). The question is how to react on user actions in the rich text area, when we click or select a text. Toggle button has additional attribute called QueryCommand. If you specify action for this command, this action will be fired every time when you click (or select a text) in the rich text area of wiki page or content editor web part. I’ve created simple page component (using information from this posts - Implementing Page Components in the SharePoint Ribbon and Sample code: Asynchronously checking if a Ribbon command is available). My solution contains two javascript files – one with custom page component and another is a loader. You may know, that almost javascript files in SharePoint 2010 loads dynamically, using on demand framework (I’ve posted about this), so this sample also is an example of using on demand javascripts.

Solution is rather simple, you can find it in downloadable section in the end of the post.When you select word “SharePoint” in the rich text area, button become active. The only trouble that I have is to make custom button smaller. I’ve tried different TemplateAlias (o2, bold, italic as in cmdui.xml), but button appear only if using o1, may be I missed something, but can’t figure out it. Now it looks like this:


Download solution here (10.05 kb) and good luck in spdevelopment.

Tags: , , ,

SharePoint 2010 | Ribbon | JavaScript

Add comment

  • Comment
  • Preview