Adding function buttons to the Madcap Flare WebHelp toolbar
January 12th, 2010 4 Comments
Madcap have, very sensibly, made it easy for you to add your own buttons to the toolbar of Flare’s WebHelp. You can use these custom buttons to … well, to do pretty much whatever you need them to do, within the power of JavaScript.
In this example, all the new button does is change the h1 heading style, giving it an orange background, but you could have buttons to completely change the whole look and feel of your WebHelp – to give readers some variety – or you could add a button that darkens the window and display a lightbox-style popup containing a video of you juggling cats. You might have more useful applications for this functionality, but you get the picture: the functionality is there for you to use however you want. The trick is how you add a button and then how you make that button call a JavaScript function. After that the rest is down to your own JavaScript/jQuery skills. 
So, the following assumes that each topic page in your WebHelp calls a JavaScript file where you keep all the cool, dynamic stuff you want to do when a reader clicks around in your help files. For example, I have a JavaScript file called MyWebHelp.js that uses a lot of jQuery to do stuff, so the head element of each HTML page in my help projects contains the following:
<script type="text/javascript" src="Resources/JavaScript/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="Resources/JavaScript/MyWebHelp.js"></script>
To add a function button to the WebHelp toolbar
- Create an image to serve as the toolbar button and save it as a .gif file.
If you want the button to change on hover, or when clicked, then you can create 2 additional images for these states.
These are the 3 images I used in this example:
- In your JavaScript file add a function that you want to call when the toolbar button is clicked. For example, this function (using jQuery) adds an orange background to the h1 heading on the page (pretty useless, I know, but it illustrates the point):
function makeHeadingOrange() {
$('h1').css('background-color','orange');
} - From the Project Organizer in Flare, open the skin you want to modify.
- Click the Styles tab.
- Select Toolbar Item.
- Right-click Toolbar Item and choose Add Class.
- In the New Style dialog box, enter a name for your button class (for example, makeHeadingOrange).
- Click OK.
- Expand the Toolbar Item list and select your new class.
- In the Basic properties for the class, click in the value column for Icon (this will currently be displaying “not set” as its value).
- Click [Browse for image…] and find the button image you created.
Notes:
- When you specify an image it becomes part of the binary project data. The image file itself is not saved as a resource, like your screenshots, so you can only choose one of the existing images that have been absorbed into the project file, or incorporate a new image by browsing for it.
- The images in this list are not sorted into alphabetical order. New images are simply added to the bottom of the list.
- Choose images for the PressedIcon and HoverIcon properties (you can use the same image for all three states if you want).
- Add a tooltip – for example, Make main heading orange.
- In the Type properties for this class set ControlType to Button.
- Set Onclick to the name of the function you want to call – in my example it’s makeHeadingOrange().
- Click the WebHelp Toolbar tab.
Your new button class is now shown in the Available list. - Move the button class into the Selected list and position as required using the up/down arrows.
- In the section “Custom Javascript to include in Toolbar page”, click Edit.
- Paste the following into the Toolbar JavaScript dialog box:
function makeHeadingOrange() {
parent.frames['body'].makeHeadingOrange();
}
This creates a function called makeHeadingOrange which, when called, in turn calls another function called makeHeadingOrange. This second function is the one you added to your main JavaScript file in step 2 of this process. You could call them by different names if you wanted – but I think it’s clearer to call them the same thing. This second function is in a JavaScript file that’s referenced in your topic files and it isn’t directly accessible from the toolbar frame, so the first function (the one you added in Flare) is used to call it from within the context of the frame named “body”. The “body” frame in Flare WebHelp is the main frame within which the help topics are displayed. You could locate the code for the second JavaScript function within the topic HTML itself, but it’s going to be far easier if this function resides in a JavaScript file that you reference in the head of your topic pages.
You can include as many custom Javascript functions as you want, listed one after the other in this dialog box. When the project is compiled, the text in this box becomes a file called Toolbar.js in the Data/<skin name>/ directory of your WebHelp output.
So, if you want to, you can have lots of buttons, each calling a different function in your main JavaScript file (via the functions in the Toolbar.js file). - Click OK to close the Toolbar JavaScript dialog box.
- Save your changes.
- Build the WebHelp target output and test the results.
Hovering over the button:
Clicking the button:
If you're not a Flare user already you must be interested to have read this far! If you want to find out more about Flare head over to http://www.madcapsoftware.com/products/flare.
Potentially similar posts
- Overcoming hard-coded styles in Madcap Flare – December 2009
- Madcap Flare: Mother knows best! – March 2009
- Viewing dynamically generated HTML in a help topic – January 2009
- Test a help topic without recompiling – December 2008
- Fixing Search in Flare HTML Help – July 2008
January 26th, 2010 at 3:18 am (#)
Alistair, thanks for posting such detailed notes for adding functions to the toolbar. These notes will be helpful when I start digging into this. This post is pretty important. I'm curious to know what other functions you have integrated or plan to integrate into your webhelp.
January 26th, 2010 at 4:00 pm (#)
Yeh, I've added a few little nice things (slide-down panels, draggable glossary popups, "back to top" arrows that only appear if you scroll down a page).
I'm hoping to find some time this weekend to put them into a Flare project and release it here, along with some screencasts to show what they do and how to add them to your own project. I think other Flare users (or anyone creating WebHelp) might find them useful.
I'm really pleased Madcap (whether by design or by default) left it open for people to add these kind of things. Too many software companies take a "my way or the high way" approach.
January 26th, 2010 at 4:00 pm (#)
Yeh, I've added a few little nice things (slide-down panels, draggable glossary popups, "back to top" arrows that only appear if you scroll down a page).
I'm hoping to find some time this weekend to put them into a Flare project and release it here, along with some screencasts to show what they do and how to add them to your own project. I think other Flare users (or anyone creating WebHelp) might find them useful.
I'm really pleased Madcap (whether by design or by default) left it open for people to add these kind of things. Too many software companies take a "my way or the high way" approach.
January 28th, 2010 at 10:08 am (#)
Interesting post. I am in lookout of ideas to improve the WebHelp outputs I am working on. The idea of slide-down panels and draggable glossary popups as mentioned by Alistair sounds too good. Waiting for your next post on this! Cheers!