Custom Buttons for the Toolbar

This tutorial will show you how to add custom buttons to the FCChat Toolbar. With these buttons, you can add a like box, a twitter feed, or a search engine to the toolbar. You may also create buttons that add specialized functionality to your site, like a recent topics button, a website store button, etc.

There are 3 types of buttons that you can add:

1) Buttons that open a dialog box in the toolbar.
2) Buttons that open another page on your site.
3) Buttons that open a popup window.

Each button you add consists of 2 main elements – an icon, and some text. Both the icon and text are optional. You are responsible for providing the content page that the buttons link to.

We will begin by showing you how the “Like button” and the “Search” button that appear on the home page of this site (www.fastcatsoftware.com) were created. Both of these buttons are of the type 1 variety (above). We will then show you how to create type 2 and 3 buttons.

The first step in creating a custom button is to add the button code to the custom_buttons field in the FCChat Configuration. If you are using WordPress or Joomla, you will place your button code in the textarea provided on the configuration page. For all other installations, you will be editing the FCChat/config/config.js file directly. In this case, you will place your code between the braces of the

custom-buttons:{
},

field.

After creating the button code, you will then add the button to the toolbar_items field, also found in the FCChat Configuration. We will cover the syntax required to add the button to the toolbar_items list later, but first, lets take a look at generating the button code.

Google Search Button

Here is the button code for the Google search button that appears on our home page:

googlesearch:{
	menu_item:{
		width:85,
		icon:"http://www.fastcatsoftware.com/FCChat/current_skin/wp_search.png",
		text:"Search"
	},
	dialog_box:{
		width:450,
		height:350,
		title:"Search Fastcatsoftware",
		iframe_src:"http://www.fastcatsoftware.com/search.html"
	}
}


You would place this code in the custom_buttons field mentioned above. The syntax for the button code is Javascript object literal notation. I mention this because the syntax must be correct in order for the button to be displayed properly. Incorrect syntax may generate an error which will prevent the toolbar from showing up. This is especially true with regard to the placement of commas. Notice that each item in a list has a comma after it, except for the last one. Failure to place commas in the appropriate places can cause the toolbar to crash on some browsers. You must take the same care in placing quotation marks around values which require them.

That being said, let’s get back to what the code above does. Notice, first of all, that the code begins with word googlesearch. This is the name of the button, and you can basically name it anything you like. We could have called it goooglebutton or thegooglethingy, etc. (One caveat: letters, numbers, and underscores are allowed in the button name, but no spaces.)

The other fields in the button code define the appearance and behavior of the button. Some of these fields are required and some are optional. Let’s review what each of these fields accomplishes.

The menu_item section

Each button you create must have a menu_item section. The menu_item section provides FCChat with the information it needs to render the button in the toolbar. Within the menu_item section you may have the following fields:

width (required) The width, in pixels, of the button.

icon (optional) An image for your button. Enter the full URL to the button image file. It will be rendered as a 16X16 pixel image by default (this can be changed). This field is optional, and you may remove it from your button code if you wish.

text (optional) The text for your button. This field is optional, and you may remove it from your button code if you wish.

Here are some additional fields which you may want to add to the menu_item section.

icon_css (optional) A list of CSS properties (ie icon_css:”border:1px solid red;top:5px;left:20px;”) that can be used to alter the location, size, and display properties of the icon.

text_css (optional) A list of CSS properties (ie text_css:”font-family:arial;color:blue;”) that can be used to alter the location, size, display properties of the text.

The dialog_box section

Since the googlesearch button is a type 1 button (it opens a toolbar dialog box), it must contain a dialog_box section. You will omit the dialog_box section when coding type 2 and 3 buttons. The dialog_box section contains the following fields:

width (required) The width in pixels of the dialog box.

height (required) The height in pixels of the dialog box.

title (required) The title of the dialog box.

iframe_src (required) The URL of the page that should be rendered inside the dialog box. For our googlesearch button, we have set up an html page on our site with the Google Site Search function embedded in it (http://www.fastcatsoftware.com/search.html). We use the iframe_src parameter to link that page to our button’s dialog box.

Adding the like button

Now that we have seen the code for the Google search button, lets go ahead and add a second button – the like button – to the custom_buttons field.

The custom_buttons field now looks like this:

     googlesearch:{
	menu_item:{
		width:85,
		icon:"http://www.fastcatsoftware.com/FCChat/current_skin/wp_search.png",
		text:"Search"
	},
	dialog_box:{
		width:450,
		height:350,
		title:"Search Fastcatsoftware",
		iframe_src:"http://www.fastcatsoftware.com/search.html"
	}
    },
    like:{
	menu_item:{
		width:65,
		icon:"http://www.fastcatsoftware.com/FCChat/current_skin/facebook.png",
		text:"Like",
	},
	dialog_box:{
		width:320,
		height:330,
		title:"Our Friends on Facebook",
		iframe_src:"http://www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2Ffastcatsolutions&width=300&height=290&colorscheme=light&show_faces=true&border_color&stream=true&header=true&appId=204858386287047"
	}
    }

The like button contains pretty much the same fields as the googlesearch button. Notice that the iframe_src field now points to the URL for like box plugin, and that the width and height have been adjusted to conform to the dimensions of the like box.

Notice also, in the code above, that, at the very end of the googlesearch button code, there is now a comma, but at the end of the like button code (because it is last in the list) there is no comma. Every button you add must end in a comma except for the last one. I cannot stress this enough, because if you don’t put the commas in the right places, you will have major problems.

Adding the buttons to the toolbar

Ok, we are done creating the button code for our two buttons, but they are not going to show up in the toolbar yet. This is because we have not added them to the toolbar_items list. Let’s do that now.

The toolbar_items field is in the FCChat Configuration, right next to the custom_buttons field we have just finished editing. To add the buttons, you will insert custom_buttons:googlesearch and custom_buttons:like into the list, like this:

Before:

[“fullpage:logo”,”friendscenter”,”social_media:social_media”]

After:

[“fullpage:logo”,”custom_buttons:like”,”custom_buttons:googlesearch”,”friendscenter”,”social_media:social_media”]

You can place the buttons anywhere in the list. That is the order they will appear in the toolbar. The syntax for inserting buttons is always custom_buttons: followed by the name of the button, which is set when you create the button code.

Here is what the two buttons now look like when viewing the toolbar:

Custom buttons in toolbar

Each button opens its own dialog box. Here is what you may see after clicking the search button:

Custom search dialog

Creating type 2 and type 3 buttons

Now we will show you how to create buttons that link to another page or open a pop-up window.

Let’s start by creating a Main Page button. Here is the button code:


main:{
	menu_item:{
		width:80,
		text:"Main Page",
		href:"http://www.fastcatsoftware.com",
		newtab:true
	}
}

This button opens the main page of our site (in this case www.fastcatsoftware.com). We have omitted the icon field from this button, so only a text link will be displayed.

newtab (which is an optional field) is set to true, so that when you click on the button, the link will open in a different tab. Without the newtab parameter, the link would open on the same page.

href points to the URL that the button links to.

Let’s say that you want a button that opens up a pop-up window. Maybe a login button, or something.

Here is the code for that:


login:{
	menu_item:{
		width:75,
		text:"Sign in",
		href:"Javascript:void(0)",
		onclick:"window.open ('http:/MYLOGINURL','mywindow','menubar=1,resizable=1,top=300,left=300,width=350,height=250');"
	}
}

The onclick parameter holds the script to be executed when the button is clicked, in this case we are opening a pop-up.

The href parameter is set to Javascript:void(0) to suppress the buttons default behavior when clicked.

{“topic”:”Custom buttons for the toolbar”}

Quickstyling

This is a tutorial on quickstyling, which is a method of customizing the FCChat widget.

First, locate the quickstyling field in your FCChat configuration. It may appear slightly differently depending on whether you are editing the config.js file directly, or using the configuration page in your dashboard; but, at any rate, it should look something like this:

quickstyling:{
	alldomains:{
		widget:{
			background_css:"",
			width_prop_offsets:"0:0:0", //title : buttons : info box
			height_offset:0, 
			text_top_offset:0, 
			height_prop_offsets:"0:0:0", //title : buttons : info box
			width_offset:0, 
			logo_top_offset:0,
			logo_left_offset:0,
			logo_css:"",
			title_css:"",
			full_page_button_css:"",
			off_button_css:"",
			infobox_css:"",
			base_font_css:"",
			title_font_css:"",
			alert_css:"",
			link_css:"",
			link_hover_css:"",
			link_disabled_css:"",
			info_css:""
		},
		toolbar:{
			background_css:"",
			divider_css:"",
			width_prop_offsets:"0:0:0", //info box : buttons : minimized
			text_top_offset:0, 
                        off_button_left_offset:0,
			base_font_css:"",
			alert_css:"",
			link_css:"",
			link_hover_css:"",
			link_disabled_css:"",
			info_css:""
		},
		dialog:{
			border_css:"",
			title_background_css:"",
			title_css:"",
			link_css:""
		},
		application_window:{
			frame_color:"",
			title_css:""
		},
		full_page_css_obj:{
		}
	}		
}

The purpose of the quickstyling section is to allow you to quickly change the appearance and layout of your FCChat widget, without having to edit the style templates, or use the Template overrides API. Of course, quickstyling does not offer the level of control available in the later two methods, but it should be sufficient to meet the customization needs of most sites.

Edting the Fields

All the fields above that end with css take css style properties, for example:

background_css:”background-color:green;border:1px solid gray;”

If you are not familiar with css properties, here’s a good site to get started: www.w3schools.com/cssref/default.asp.

The fields that end with offest take numerical values, for example:

width_offset:20, or width_offset:-20,

Offsets add or subtract quantities from the default values. The second example above would subtract 20 from the default width.

width_proportion_offsets and height_proportion_offsets are special fields. They take three numerical values separated by colons.

Example: width_proportion_offsets:”10:-10:20″

These fields allow you to increase/decrease the dimensions of the embedded widget and toolbar, as the diagrams below illustrate.

For the widget…


And for the toolbar…

Another special field is full_page_css_obj, which takes css properties in json format, as shown below:

full_page_css_obj:{
     "background:color":"green",
     "border":"1px solid gray",
     "font":"12px arial"
}

Examples

Instead of going over what each individual field in the quickstyling section represents, we will provide you with some complete examples of the types of customizations you can make with quickstying, and you can use these as a springboard to create your own customizations.

Toolbar styling

First, we will change the styling of the toolbar by altering the toolbar section of the quickstyling code as follows


toolbar:{
	background_css:"background-color:lightgray;border: 1px solid gray;-webkit-box-shadow:none;box-shadow:none;", 
	divider_css:"background-color:gray;",
	width_prop_offsets:"50:50:50", //info box : buttons : minimized
	text_top_offset:0, 
        off_button_left_offset:0,
	base_font_css:"color:#444444;",
	alert_css:"color:red;",
	link_css:"color:blue;",
	link_hover_css:"color:purple;",
	link_disabled_css:"color:#bbbbbb;",
	info_css:"color:#444444;"
},

And here is the result:

Notes about this example:

All the CSS properties should end in a semicolon.

The background_css field is used to change the toolbar’s color and border. The shadow around the toolbar has been removed using this field.

The color of text has been changed. The default color is now dark gray (#444444). Link color has been changed to blue.

We have only changed the text color in this example, but you may change the size, font, and other properties as well. If you change the font size, you may find that the vertical alignment is a bit off. To correct this, change the value of text_top_offset. In addition, you may need to shift the off button over a bit. To do this, change the value of off_button_left_offset.

width_prop_offsets has been set to “50:50:50″. This inceases the width of the infobox, buttons section, and minimized toolbar by 50 pixels each. Here is a picture of what the toolbar now looks like in the minimized state:

Widget styling

Next, let’s change the styling of the widget by altering the widget section of the quickstyling code as follows


widget:{
	background_css:"background-color:#666666;border:4px solid lightblue;",
	width_prop_offsets:"0:0:0", //title : buttons : info box
	height_offset:0, 
	text_top_offset:0, 
	height_prop_offsets:"50:50:50", //title : buttons : info box
	width_offset:50, 
	logo_top_offset:0,
	logo_left_offset:0,
	logo_css:"display:none;",
	title_css:"left:10px;",
	full_page_button_css:"",
	off_button_css:"",
	infobox_css:"",
	base_font_css:"color:white;",
	title_font_css:"color:white;",
	alert_css:"color:pink;",
	link_css:"color:white;",
	link_hover_css:"color:yellow;",
	link_disabled_css:"color:#dddddd;",
	info_css:"color:lightblue;"
},

The result:

Explanation:

The background_css property is used to change the widget’s color and border.

The widget was widened by setting width_offset:50,

The color of text has been changed. The default color is now white. Text which displays info about the state of the chat is lightblue. We have only changed the color in this example, but you may change the size, font, and other properties of the text as well.

height_prop_offsets has been set to “50:50:50″. This inceases the height of the title, buttons, and infobox section by 50 pixels each. If the widget was configured for a horizontal layout (for instance, when using the template: widget_default_header.js), we would have wanted to change the width_prop_offsets instead.

The image for the logo has been hidden. This was achieved by setting logo_css:”display:none;”,. Also, the title text’s left property has been changed: title_css:”left:10px;”, to compensate for the absence of the logo.

Dialog and application window styling

Next up, we will add a little styling touch to the dialogs and application windows, by editing the dialog/application_window portion of the code. There aren’t a whole lot of options here, so if you need greater control over the styling of these elements, you will have to use one of the other styling methods, mentioned at the beginning of this tutorial. Here’s the code:


dialog:{
        border_css:"border:2px solid purple;",
	title_background_css:"background-color:purple",
	title_css:"color:yellow;",
	link_css:"color:yellow;"
},
application_window:{
	frame_color:"purple",
	title_css:"color:yellow;"
},

The result:

Explanation:

frame_color is a special field, in that it does not take a full CSS property. Instead it takes a single html color or color code.

Styling the full page chat

Finally, you can add some styling touches to the full page chat window by editing the full_page_css_obj field.

full_page_css_obj:{
     "background:color":"green",
     "font":"12px arial"
}

Explanation:

The style properties that you add to full_page_css_obj will be applied to the document body. This basically allows you to change the properties of the page background, and the style of the Welcome/Loading message. Here we are changing the background color of the page to green, and the font to 12px arial.

{“topic”:”Quickstyling”}

Changing the location (URL) of the Full Page Chat

In this tutorial, we show you how to change the url of the Full Page Chat. To use this tutorial, your must have php enabled on your site. This tutorial applies to version 3.0 and later.

The default location of the full page chat is something like

http://yoursite.com/wp-content/plugins/fcchat/html/chat/index.html

(and here we are using a WordPress site as the example).

The problem is that this exposes a long and ugly URL to the user. Wouldn’t it be better if the Full Page Chat URL was something more intuitive, like

http://yoursite.com/chat/

So how do you get from the nasty URL to the nice one? Here are the steps:

1) Create a folder named chat in the root of your site.

2) Copy the file ../fcchat/html/chat/index.php to the newly created chat folder.

3) Open the file you just copied with a text editor. Find the line that says:

$FCCHAT_BASE_URL=”http://YOURDOMAIN.COM/FCChat/”;

Edit this variable so that it contains the full path to the fcchat folder on your site. Given the example above. this would yield:

$FCCHAT_BASE_URL=”http://yoursite.com/wp-content/plugins/fcchat/”;

4) Finally, go to the FCChat configuration, and set the variable full_page_url to point to the location of your chat, in this case: http://www.yoursite.com/chat/

(You may omit index.php from the path as long as your server has been configured to recognize index.php as a default document. If not, you must append the filename to the path, ie. http://www.yoursite.com/chat/index.php)

{“topic”:”Changing the location of the full page url”}