Was this article helpful?

Share Bar

Introduction

The Share Bar plugin allows you to easily place in your site a bar with different buttons for sharing content to social destinations. The Share Bar plugin is built out of one or more buttons, arranged horizontally in a bar. Each button represents a direct bookmark destination, a general share button, or an email button.

Once a user clicks on a direct bookmark button, the window of the provider will be opened for direct bookmarking. Once a user clicks on the general share button, the Simple Share mode of the Share plugin will popup, enabling your user to share and bookmark content and site activities to selected social destinations. The Share Bar buttons may be displayed with or without counters, representing the number of shares. For more information regarding the counters, refer to the socialize.getProviderShareCounts API method.

You can use the Share Bar Wizard to customize the visual aspects of the Share Bar plugin design, view, and grab the customized code.

ShareBarUI.gif

 

What's in this Guide?

This document is a step-by-step guide for integrating the Share Bar plugin and also provides a reference and guide for the various customization options. For convenience, we have divided this document into levels of complexity:

Quick Start Implementation

Implementation Overview

Adding the Share Bar plugin is simple, and involves only adding a few lines of code:

  • Step 1: Construct a UserAction object, which represents the action taken by a user on your site. The newsfeed that is published to the social networks is constructed from the fields of this object. All the fields of this object are optional.
     
  • Step 2: Define the Share Bar plugin's params object, including a comma-separated list of providers, representing the buttons to display in the share bar.
     

 

Code Example

Add the following code snip to the <body> of your page to activate the Share Bar plugin that is presented in the screenshot above:


<DIV id=divButtons></DIV> <!-- Share Bar Plugin DIV Container -->
<script language="javascript">
    
    // Step 1: Construct a UserAction object and fill it with data
	var ua = new gigya.socialize.UserAction(); 
	ua.setLinkBack("http://www.youtube.com/watch?v=jqxENMKaeCU"); 
	ua.setTitle("HOME");
	
    // Step 2: Define the Share Bar plugin's params object   	
	var params ={ 
		userAction:ua,
		shareButtons:'facebook-like,google-plusone,share,twitter-tweet,email', // list of providers
		containerID: 'divButtons',
        cid:''
	};
	
    // Step 3: Load the Share Bar plugin: 
    gigya.socialize.showShareBarUI(params);
</script>

 

Code Explanation 

Step 1: Construct a UserAction object and fill it with data

The UserAction object represents a User Action. We use the UserAction object constructor for this purpose:

var ua = new gigya.socialize.UserAction();

After you have constructed the object, you can use the various UserAction member methods to set the object's properties. For example:

ua.setTitle("This is my title");
ua.setDescription("This is the textual content of my post");
...

The UserAction's object properties represent the various items of which a User Action may consist: Title, Description etc.

 

Step 2: Define the Share Bar plugin's parameters

var params ={ 
	userAction:ua,
	shareButtons:'facebook-like,google-plusone,share,twitter-tweet,email', // list of providers
	containerID: 'divButtons',
    cid:''
};

The Share Bar plugin has three required parameters:

  • containerID - The identifier of the DIV element, where the Share Bar plugin should be embedded
  • shareButtons- The list of providers
  • userAction - The userAction object that we have created in Step 1

In this example the ShareButtons parameter is comprised of a list of providers. Instead, you may define an array of ShareButton objects:

var params ={ 
	userAction:ua,
	shareButtons:
	[
		{ // General Share Button
			provider:'share',
			tooltip:'General Share Button',
			userMessage:'default user message'
		},
		{ // Google +1 button
			provider:'google-plusone',
			tooltip:'Recommend this on Google',
			userMessage:'default user message'
		},
		{ // Facebook Like button
			provider:'facebook-like',
			tooltip:'Recommend this on Facebook',
			action:'recommend',
			font:'arial'
		},
		{ // Twitter Tweet button
			provider:'twitter-tweet',
			tooltip:'Share on Twitter',
			defaultText:'Twitter message'
		},
		{ // Email button
			provider:'email',
			tooltip:'Email this',
			iconImgUp:'http://mySite.com/images/myEmailIcon.gif',
                        iconImgOver:'http://mySite.com/images/myEmailIconOver.gif'
                 }
	],
	containerID: 'divButtons',
    cid:''
};

The plugin has additional optional parameters you can use. Please refer to the method's parameters table for the entire list of optional parameters.

 

Step 3: Invoke the Share Bar plugin

Call the socialize.showShareBarUI API method:

gigya.socialize.showShareBarUI(params);

Like every Gigya API method, the socialize.showShareBarUI method receives one parameter - the parameters object, which is the object we have defined in Step 2. (Learn more about Gigya's Basics here). 

 

Note: we highly recommend defining Open Graph Tags on pages that use the Share Bar plugin, for better structured newsfeeds on Facebook ('like') and Google (+1).

 

A Working Example

In the Share Bar plugin demo you may find a complete working example of a share bar that is used to publishes user actions. You may view the code, run it and view the outcome.

 

How the URL to be Shared is Determined

The share buttons are used to share content, and more specifically share a URL. The URL to be shared is determined according to a certain logic. The following list shows the order in which Gigya checks whether a URL exists, and if it does, this is the URL used for sharing:

  1. The ShareButton object's 'url' field
  2. The linkback field of the ShareButton object's userAction
  3. The linkback field of the <provider-name>UserAction
  4. The linkback field of the UserAction
  5. The Open Graph URL tag (og:url tag)
  6. The URL of the current page

 

Changing to Multiple Selection Share

When using the general share button in the Share Bar plugin, the default Share dialog that is displayed is the Simple Share dialog. You can change this to the multiple selection share, which is the more elaborate Share Plugin.

Change the simple share to multiple selection share by adding the optional operationMode parameter to the Share Bar parameters, with the value 'multiSelect':

var params ={ 
	userAction:ua,
	shareButtons:'share,facebook,twitter,email', // list of providers
	containerID: 'divButtons',
    operationMode:'multiSelect',
};

The general share button will now trigger the full Share Plugin:

ShareBar_multi.gif

 You can now use the Share Bar plugin with the full Share plugin capabilities. Please refer to the Share Plugin Guide for further reading. 

 

Special Buttons

Adding a Comments Counter

You can add a Comments button to your Share Bar, with a counter indicating the number of comments made in that specific comments stream. The comments stream is identified by its unique categoryID and streamID.

In order to display the Comments button with a counter, define a ShareButton object with 'comments' as the provider, and the categoryID and streamID that identify the comments stream:

shareButtons:
	[
		{ // Comments Button
			provider:'comments',
			categoryID: 20358285,
			streamID: '1'
		},
		{ // General Share Button
			provider:'share',
			tooltip:'General Share Button',
			userMessage:'default user message'
		},
		{ // Facebook Like button
			provider:'facebook-like',
			tooltip:'Recommend this on Facebook',
			action:'recommend'
		},
		{ // Twitter Tweet button
			provider:'twitter-tweet',
			tooltip:'Share on Twitter',
			defaultText:'Twitter message'
		},
		{ // Email button
			provider:'email',
			tooltip:'Email this',
			iconImgUp:'http://mySite.com/images/myEmailIcon.gif',
            iconImgOver:'http://mySite.com/images/myEmailIconOver.gif'
        }
	],

The Share Bar that is displayed for this code is:

share_bar_comments.gif

 

Localization for Facebook Like Button

In order to display the Facebook Like button, define a ShareButton object or string with 'facebook-like' as the provider. If you wish to display the button in a different language, the language needs to be set in the socialize JS URL before the plugin is loaded. Learn about this in Localization Support for 3rd Party Plugins.

 

Twitter Tweet Button

Special Twitter Button Parameters

You can configure the Twitter Tweet button so that:

  • After tweeting, you can suggest to the user to follow related accounts, by using the 'related' parameter.
  • You can assign the screen name of the user to whom to attribute the Tweet, by using the 'via' parameter.

Define a ShareButton object with 'provider', 'related', and 'via' fields:

shareButtons: 
[    
    { // Twitter Tweet button
        provider:'twitter-tweet',
        related: 'betabeat,youtube',
        via:'etayg'
    } 
]

 

The following Twitter window includes the screen name of the user to whom to attribute the Tweet, i.e. @etayg, and two recommended related accounts:

twitter_via_related.gif

The Twitter Tweet button has additional optional parameters you can use. Please refer to the ShareButton object reference socialize.showShareBarUI for the entire list of optional parameters.

  

Google +1 Supported Browsers

In order to display the Google +1 button, define a ShareButton object or string with 'google-plusone' as the provider. There are few browsers in which the Google +1 button is not supported. Please refer to the Supported browsers for the updated list by Google.

 

Provider mixi

Since mixi is a provider that requires an API key in order to work, you must add a parameter called mixiKey with the mixi API key to the showShareBarUI parameters:

var params ={ 
	userAction:ua,
	shareButtons:'share,mixi,facebook,twitter,email', // list of providers
    containerID: 'divButtons',
    mixiKey:'<Insert the mixi API Key here>'           
};

 

Provider Pinterest

When you add Pinterest to your share bar, you must also define a UserAction object, provide a media item and add the media item to your UserAction object:

// Define an image media item:
var image = {
  type: 'image',
  src: 'http://www.infozoom.ru/wp-content/uploads/2009/08/d06_19748631.jpg',
  href: 'http://www.infozoom.ru'
  }
  
// Define a UserAction onject
var ua = new gigya.socialize.UserAction();
ua.addMediaItem(image);

// Define Share Bar plugin's Parameters
var shareBarParams ={
  userAction:ua,
  shareButtons: "share,stumbleupon,pinterest,email,twitter-tweet,google-plusone,facebook-like",
  containerID: 'divButtons' // location of the Share Bar plugin
}

// Load Share Bar plugin
gigya.socialize.showShareBarUI(shareBarParams);

Read more about adding media items to the UserAction object.

 

Share Bar Plugin Customization

The Share Bar design can be customized using:

 

Method Parameters

You can customize the Share Bar plugin using the following socialize.showShareBarUI method parameters:

  • layout - using this parameter you can arrange the buttons in a vertical bar instead of a horizontal bar
  • showCounts - using this parameter you can display the counters above the corresponding buttons instead of on their right, or choose to display the bar with no counters
  • noButtonBorders - using this parameter you can display buttons without borders

Vertical Layout

ShareBar_vertical.gif

To arrange the buttons in a vertical bar instead of a horizontal bar, add the layout parameter to the Share Bar plugin's parameters, with the value 'vertical':

var params ={ 
	userAction:ua,
	shareButtons:'share,facebook,twitter,email', // list of providers
	containerID: 'divButtons',
    layout:'vertical',
};

 

Counters on Top

ShareBar_top.gif

To display the counters above the corresponding buttons instead of on their right, add the showCounts parameter to the Share Bar plugin's parameters, with the value 'top':

var params ={ 
	userAction:ua,
	shareButtons:'share,facebook,twitter,email', // list of providers
	containerID: 'divButtons',
    showCounts:'top',
};

In the same manner you can display the Share Bar without counters, by adding the showCounts parameter to the Share Bar plugin's parameters, with the value 'none'.

 

No Button Borders

ShareBar_button_no_borders.gif

To arrange the buttons without button borders, add the noButtonBorders parameter to the Share Bar plugin's parameters, with the value 'true':

var params ={ 
	userAction:ua,
	shareButtons:'share,facebook,twitter,email', // list of providers
	containerID: 'divButtons',
    noButtonBorders:true,
};

 

Applying a New Button DesignEdit section

If you wish to apply your own design to the share bar buttons, override the default design by using buttonImages parameter of the socialize.showShareBarUI method. The buttonImages parameter expects a JSON object with a set of fields (all optional). Each field defines a button image part. Following are the basic fields:

  • buttonLeftImgUp - An image for the left part of the button
  • buttonCenterBGImgUp - An image for the center part of the button
  • buttonRightImgUp - An image for the right part of the button

To replace the default button images with your alternative images, set these fields with URLs to the corresponding images.

Add the buttonImages parameter to the Share Bar parameters with your own button images:

var params ={ 
	userAction:ua,
	shareButtons:'share,facebook,twitter,email', // list of providers
	containerID: 'divButtons',
    buttonImages:{buttonLeftImgUp:'Button_Left.png',buttonCenterBGImgUp:'Button_Middle.png',buttonRightImgUp:'Button_Right.png'}
    };

You may also define images to the 'Disabled' 'Mouse over' and 'Down' states of the button, using the corresponding fields of the buttonImages parameter:

  • buttonLeftImgDisabled, buttonCenterBGImgDisabled, buttonRightImgDisabled -  Images for Disabled button (left, center and right).
  • buttonLeftImgOver, buttonCenterBGImgOver, buttonRightImgOver - Images for Mouse Over state (left, center and right).
  • buttonLeftImgDown, buttonCenterBGImgDown, buttonRightImgDown - Images for Down state (left, center and right).

For example:

buttonImages:{buttonLeftImgUp:'Button_Left.png',buttonCenterBGImgUp:'Button_Middle.png',buttonRightImgUp:'Button_Right.png', 
      buttonLeftImgDown:'Button_Left_Down.png',buttonCenterBGImgDown:'Button_Middle_Down.png',
      buttonRightImgDown:'Button_Right_Down.png',buttonLeftImgDisabled:'Button_Left_Disabled.png',
      buttonCenterBGImgDisabled:'Button_Middle_Disabled.png',buttonRightImgDisabled:'Button_Right_Disabled.png',
      buttonLeftImgOver:'Button_Left_Over.png',buttonCenterBGImgOver:'Button_Middle_Over.png',
      buttonRightImgOver:'Button_Right_Over.png'
}

 

 

HTML Elements Style (CSS) Classes

Any elements on the plugin that has an ID can be overridden with supported style attributes. You may use Firebug to identify an HTML element on the plugin and assign a new style to it. Please make sure to use the plugin's container <div> ID when assigning style, so it will not affect other elements on the page.
For example:

<style> #divButtons .gig-share-button-container {background-color:yellow;} </style>

There are five classes that you can use to customize your buttons, overriding the default design:

  • gig-share-button-container - overrides the default design of a button and counter
  • gig-share-button - overrides the default design of a single button
  • gig-share-button-text - overrides the default design of a button's label
  • gig-share-counter - overrides the default design of a single counter
  • gig-share-counter-text - overrides the default design of a counter's value

The following examples demonstrate how to change the default background color of each class specified here. You may change the font size, font color, border, etc. In order to more

Button and Counter

ShareBar_button_container.gif

To design a button and counter with a yellow background, add the following to the <head> section of your page:

<style> #divButtons .gig-share-button-container {background-color:yellow;} </style>

 

Button

ShareBar_button.gif

To design a button with a green background, add the following to the <head> section of your page:

<style> #divButtons .gig-share-button {background-color:green;}</style>

In this example, the button is without borders to allow the green background to be more visible.

 

Button Label

ShareBar_button_text.gif

To design a button label with a red background, add the following to the <head> section of your page:

<style>#divButtons .gig-share-button-text {background-color:red;} </style>

 

Counter

ShareBar_counter.gif

To design a button counter with a purple background, add the following to the <head> section of your page:

<style> #divButtons .gig-share-counter {background-color:purple;} </style>

 

Counter Value

ShareBar_counter_text.gif

To design a counter value with a blue background, add the following to the <head> section of your page:

<style> #divButtons .gig-share-counter-text {background-color:blue;} </style>

 

Additional Classes

In addition, you can further customize your share bar buttons using the following classes:

  • gig-button-up
  • gig-button-down
  • gig-button-over
  • gig-button-disabled

For example, add the following to the <head> section of your page to change the button text to yellow when the button is disabled:

 

<style>#divButtons .gig-button-disabled .gig-share-button-text {color:yellow} </style>

 

 

Templates

The 'buttonTemplate' parameter of the socialize.showShareBarUI method is an HTML template representing the design of a single button without a counter, supporting the following placeholders:

  • $iconImg

  • $text
  • $onClick

The 'buttonWithCountTemplate' parameter of the socialize.showShareBarUI method is an HTML template representing the design of a single button with a counter, supporting the following placeholders:

  • $iconImg
  • $text
  • $onClick
  • $count

You may override the default design by placing new values in these placeholders.

Was this article helpful?
Pages that link here
Page statistics
2812 view(s), 6 edit(s) and 33316 character(s)

Tags

This page has no custom tags set.

Comments

You must to post a comment.

Attach file

Attachments

FileVersionSizeModifiedOptions