sapegin's social-likes (old) with removed jquery
 
 
 
 
 
Go to file
Artem Sapegin d729b93832 Tweak license. 2014-04-04 10:20:19 +04:00
contrib Merge master, update deps. 2013-12-23 23:50:29 +04:00
specs popup_opened and popup_closed events. 2014-02-12 16:40:51 +04:00
src Disable Google+ counter on HTTPS pages (close #58). 2014-04-01 13:11:56 +04:00
.gitignore Skin switcher on demo page. 2013-12-24 18:04:38 +04:00
Changelog.md Changelog. 2014-02-12 17:00:14 +04:00
Contributing.md Update Contributing.md 2013-11-12 13:41:26 +03:00
Readme.md Fix license link. 2014-04-04 10:19:30 +04:00
bower.json v3.0.2 2014-02-12 17:00:36 +04:00
license.md Tweak license. 2014-04-04 10:20:19 +04:00
social-likes.jquery.json v3.0.2 2014-02-12 17:00:36 +04:00
social-likes.min.js v3.0.2 2014-02-12 17:00:36 +04:00
social-likes_birman.css v3.0.2 2014-02-12 17:00:36 +04:00
social-likes_classic.css v3.0.2 2014-02-12 17:00:36 +04:00
social-likes_flat.css v3.0.2 2014-02-12 17:00:36 +04:00

Readme.md

Social Likes

Bower version Built with Grunt

Beautiful “like” buttons with counters for popular social networks: Facebook, Twitter, LiveJournal, etc. Uses jQuery.

Features

  • Easy to install.
  • Beautiful and all in one style.
  • Wont explode your pages layout.

Installation and configuration

Use interactive builder to generate the code.

Or install via Bower: $ bower install social-likes.

Advanced configuration

Layout

Default

All buttons in a row.

<ul class="social-likes">
	<li class="facebook" title="Share link on Facebook">Facebook</li>
	...
</ul>

Vertical

All buttons in a column.

<ul class="social-likes social-likes_vertical">
	<li class="facebook" title="Share link on Facebook">Facebook</li>
	...
</ul>

Single button

One button with a counter (summ of all the networks). Opens popup with like buttons in vertical layout. Use data-single-title attribute to change button title.

<ul class="social-likes social-likes_single" data-single-title="Share me!">
	<li class="facebook" title="Share link on Facebook">Facebook</li>
	...
</ul>

Icons only

If you want to remove button titles add social-likes_notext class to make it looks better.

<ul class="social-likes social-likes_notext">
	<li class="facebook" title="Share link on Facebook"></li>
	...
</ul>

Options

Options define via HTML data attributes or JavaScript parameters object.

url

URL of shareable page. Current page by default.

title

Title for Twitter, Vkontakte and LiveJournal. Current pages title by default.

html

HTML code for LiveJournal button. By default tag with link to current page.

counters

Disables “likes” counters when “no”. Default: “yes”.

zeroes

Show counters even when number is 0. Default: “no”.

single-title

Share button title for “single button” mode. Default: “Share”.

Examples:

<ul class="social-likes" data-url="http://landscapists.info/" data-title="Landscapists of Russia"></ul>
<ul class="social-likes social-likes_single" data-single-title="This is Sharing!"></ul>
$('.social-likes').socialLikes({
	url: 'https://github.com/sapegin/social-likes/',
	title: 'Beautiful “like” buttons with counters for popular social networks',
	counters: true,
	singleTitle: 'Share it!'
});

Services specific options

Twitter

You can specify via (sites Twitter) and related (any other Twitter you want to advertise) values for <li class="twitter">:

<li class="twitter" data-via="sapegin" data-related="Landscapists">Twitter</li>

Pinterest

You should specify an image URL via data-media attribute on <li class="pinterest">:

<li class="pinterest" data-media="http://example.com/image/url.jpg">Pinterest</li>

Manual initialization

Could be useful on dynamic (AJAX) websites.

<ul id="share">
	<li class="facebook">Facebook</li>
	...
</ul>
$('#share').socialLikes();

Dynamic URL changing

You can dynamically replace URL, title and Pinterest image without reinitialization.

<ul id="share2" class="social-likes" data-url="http://example.com/" data-title="My example">
	<li class="facebook">Facebook</li>
	...
</ul>
$('#share2').socialLikes({
	url: 'http://github.com/',
	title: 'GitHub',
	data: {
		media: 'http://birdwatcher.ru/i/userpic.jpg'  // Image for Pinterest button
	}
});

Refreshing counters

By default counters for any uniqe URL requested only once. You can force new request with forceUpdate option:

$('#share2').socialLikes({
	forceUpdate: true
});

Events

counter.social-likes

Triggers for every counter.

$('.social-likes').on('counter.social-likes', function(event, service, number) {
	// service: facebook, twitter, etc.
});

ready.social-likes

Triggers after all counters loaded.

$('.social-likes').on('ready.social-likes', function(event, number) {
	// number is total number of shares
});

popup_opened.social-likes

Triggers after popup window opened.

$('.social-likes').on('popup_opened.social-likes', function(event, service, win) {
	// win is popup window handler (window.open())
});

popup_closed.social-likes

Triggers after popup window closed.

$('.social-likes').on('popup_closed.social-likes', function(event, service) {
	$(event.currentTarget).socialLikes({forceUpdate: true});  // Update counters
});

Adding your own button

You can find some custom buttons in contrib folder.

Define socialLikesButtons hash:

var socialLikesButtons = {
	surfingbird: {
		popupUrl: 'http://surfingbird.ru/share?url={url}',
		popupWidth: 650,
		popupHeight: 500
	}
};

If you know the social network search page's url, you can make a link to results of searching in this network. There are search urls for Twitter and VKontakte by default.

var socialLikesButtons = {
	twitter: {
		...
		searchUrl: 'https://twitter.com/search?src=typd&q={url}'
	}
};

Add some CSS:

.social-likes__button_surfingbird {
	background: #f2f3f5;
	color: #596e7e;
	border-color: #ced5e2;
	}
.social-likes__icon_surfingbird {
	background: url(http://surfingbird.ru/img/share-icon.png) no-repeat 2px 3px;
	}

And use in like any other button:

<li class="surfingbird">Surf</li>

See sources (src folder) for available options and class names and contrib folder for custom buttons examples.

How to change title, description and image

You can use Open Graph. It works for Facebook, Twitter, Google+, Pinterest and Vkontakte).

You can add additional Twitter data using Twitter Card. You have to approve every type of Twitter Card.

<meta property="og:type" content="article">
<meta property="og:url" content="{page_url}">
<meta property="og:title" content="{title}">
<meta property="og:description" content="{description}">
<meta property="og:image" content="{image_url}">
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@SiteTwitter">
<meta name="twitter:creator" content="@sapegin">

If youre experincing any problems with meta data try Open Graph Debugger and Twitter Card Validator.

How to use Social Likes with Wordpress, etc.

See wiki.

Troubleshooting

Counters dont work

In most cases if you dont see counters its because social networks APIs return zeroes. You could check API requests results in Network tab in your browsers developer tools:

Double check that you use canonical URLs (without extra parameters such as utm_source). You can change URL via data-url option.

If youre sure that its a bug please file an issue and provide a link to a page with non-working counter.

Release History

The changelog can be found in the Changelog.md file.


License

The MIT License, see the included license.md file.