Coder Social home page Coder Social logo

sapegin / social-likes Goto Github PK

View Code? Open in Web Editor NEW
1.1K 73.0 245.0 1.64 MB

Beautiful social “like” buttons with counters for jQuery.

Home Page: http://social-likes.js.org/

License: MIT License

CSS 41.61% HTML 25.76% JavaScript 27.94% CoffeeScript 4.68%

social-likes's Introduction

Social Likes

Powered by You Build Status

Try the all new Social Likes Next: no jQuery, no counters, Retina, IE11+, improved skins.

Beautiful share buttons with counters for popular social networks: Facebook, Twitter, Google+, Pinterest, Vkontakte, etc. Uses jQuery.

See demo

Features

  • Easy to install.
  • Beautiful and all in one style (with three different skins).
  • Won’t explode your page’s layout.

Installation and configuration

Use interactive builder to generate the code.

Or install via npm: npm install --save social-likes.

Advanced configuration

Layout

Default

All buttons in a row.

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

Vertical

All buttons in a column.

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

Single button

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

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

Icons only

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

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

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 page’s 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:

<div class="social-likes" data-url="http://landscapists.info/" data-title="Landscapists of Russia"></div>
<div class="social-likes social-likes_single" data-single-title="This is Sharing!"></div>
$('.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 (site’s or your own Twitter) and related (any other Twitter you want to advertise) values for <div class="twitter">:

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

Pinterest

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

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

Manual initialization

Could be useful on dynamic (AJAX) websites.

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

Dynamic URL changing

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

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

Refreshing counters

By default counters for any unique 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) {
	// Request new counters
	$(event.currentTarget).socialLikes({forceUpdate: true});

	// Or just increase the number
	var counter = $(event.currentTarget).find('.social-likes__counter_' + service);
	counter.text(+(counter.text()||0)+1).removeClass('social-likes__counter_empty');
});

Adding your own button

You can find some custom buttons in contrib folder.

Define socialLikesButtons object:

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

Or with a custom click handler:

var socialLikesButtons = {
	livejournal: {
		click: function(e) {
			// this.widget.data('something')
		}
	}
};

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 it like any other button:

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

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

FAQ

Likes or shares?

This plugin allows your users to “share” the content of your website. (Un)fortunately¹ real “likes” are possible only when you use original Facebook, Google+, etc. buttons.

¹ I believe that “shares” are much better and valuable than “likes” because they’re more visible in feed and users could add they’re own comments to links they share. “Like” costs nothing.

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 you’re experiencing any problems with meta data try Open Graph Debugger and Twitter Card Validator.

How to fix Twitter counter

Twitter counter API was disabled by Twitter but you can replace it with OpenShareCount. It’s free but you have to register your site there.

  1. Create account at OpenShareCount.

  2. Add this script before you include social-likes.js:

<script>
var socialLikesButtons = {
  twitter: {
    counterUrl: 'https://opensharecount.com/count.json?url={url}&callback=?',
    convertNumber: function(data) {
      return data.count;
    }
  }
};
</script>

How to use Social Likes with Wordpress, etc.

See wiki.

How to track activity with Google Analytics

You can track how many people click on each social button on your site with Google Analytics (or other analytics service). Note that you can track clicks only, not real shares.

$(document).on('popup_opened.social-likes', function(event, service) {
    ga('send', 'social', service, 'share', location.href);
});

Troubleshooting

The buttons don’t work, displayed without design or don’t displayed at all

First look at your browser’s console. If you see an error “Uncaught ReferenceError: jQuery is not defined”:

Then you need to include jQuery into your page. Make sure you use version at least 1.7 (and lower than 2.0 if you need to support IE8) and you include jQuery before social-likes.js. The easiest way to do it is to use Google CDN:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

If you don’t see any error check the following:

  1. social-likes.js is included after jQuery and the path is correct.

  2. social-likes_flat.css or social-likes_classic.css or social-likes_birman.css is included in of your page and the path is correct.

So you need your page to look like this:

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>Welcome to my site!</title>
	<link href="social-likes_birman.css" rel="stylesheet">
	<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
	<script src="social-likes.js"></script>
	...

Counters don’t work

Twitter counter was disabled in 3.0.15.

In most cases if you don’t see counters it’s because social networks APIs return zeros. You could check API requests results in Network tab in your browser’s 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 you have more than one Social Likes blocks on a page with different URLs, Google+ counter will work only for the first block. Google+ counter also won’t work when you refresh counters with forceUpdate option or change URL dynamically.

If your site have internationalized domain name (e.g. президент.рф) make sure you convert it to Punycode (e.g. xn--d1abbgf6aiiy.xn--p1ai).

If you’re sure that it’s a bug please file an issue and provide a link to a page with non-working counter.

Release History

The changelog can be found on the Releases page.

Contributing

Everyone is welcome to contribute. Please take a moment to review the contributing guidelines.

Author


License

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

social-likes's People

Contributors

albburtsev avatar apotheosis91 avatar colch avatar fliptheweb avatar gldmtr avatar hudochenkov avatar im-denisenko avatar justdmitry avatar meritt avatar mshevtsov avatar neochief avatar peterdavehello avatar readmecritic avatar richardwestenra avatar runnx avatar sapegin avatar scream4ik avatar tatarinov avatar thenexus00 avatar weltkind-dmitry-savinkov avatar xdimedrolx avatar zipp3r avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

social-likes's Issues

Update vkontakte.ru to vk.com

vkontakte.ru/share.php redirects to vk.com/login which redirects to vk.com/share.php. Both with 301 status (Moved Permanently).

Not Sharing the current page

Hi,

On my site when I click on the facebook or the twitter link, it does not share the current page but shares the address of my home page instead. Any ideas on what could be causing this and how to fix it?

Thanks,

GitHub star button

Just describe it in Readme. It shouldn’t be in core.

  • Add it to gh-pages.

Больше доступных сервисов

Привет!
Было бы здорово увидеть в будущем больше доступных сервисов, например Pocket и Evernote.
Нет таких планов у тебя?

Pinterest: read media URL from meta tags

<meta property="og:image" content="{image_url}">

or

<link rel="image_src" href="{image_url}">

Throw exception when one of meta tags or data-media attribute not specified.

No images

The Download images button on your site has no images contained in the download

Image URL

Сделать возможность указывать урл картинки для анонса.

Иконки в плоском стиле

В FF28+ (а также, возможно, и более старые версии), а также в Opera 12 отсутствуют иконки в плоском стиле.

2014-05-10 22 40 12

Additional params for popup urls

Additional params are already supported (e. g. via for Twitter) but should be defined in an additionalParams array.

  1. Remove additionalParams array.
  2. Add all data-something attributes to popup URL.

проблема с вконтакте

При использовании некоторых функций битрикса для внешней авторизации через аккаунты соц.сетей на одной странице с этим плагином могут возникнуть проблем.
В частности, вот этот код(строки 113-115)

window.VK = {Share: {count: $.proxy(function(idx, count) {
this.updateCount(this._vkontakte[idx], count);
}, this)}};

может выдавать ошибку.

Решается следующим образом:

                        window.VK["Share"] = {
                            count : $.proxy(
                                function(idx, count)
                                {
                                    this.updateCount(this._vkontakte[idx], count);
                                },
                                this
                            )
                        };

Fix margins/paddings

Переделать отступы вокруг кнопок, чтобы они нормально переносились на новую строку.

onComplete

Сделать callback onComplete, через который можно было бы, к примеру, получить полный список данных для каждого сервиса: кол-во лайков, урл, имя сервиса и тд

Counter for LIKES

Сейчас счетчики показывают количество Share и кнопки соответственно работают именно как Share, а как быть именно с Like (к примеру вконтакте и твиттере)?

Bower missmatch problem

mismatch The version specified in the bower.json of package social-likes mismatches the tag (2.0.9 vs 2.0.8)

Cant get Twitter count.

I used social-likes script in php. I can share the link, but i cant get count of twitter.,

Question about shared count

I have index page with posts, if I shared one of them, for example with facebook, i'ts add +1 to facebook count for all my posts, please, can you explain why is this happening? Probably it's counting shares for current page.

Счетчик для Google+

Есть ли возможность показать счетчик для Google+. Для всех остальных лайков это есть, а вот для Google+ не понимаю как отобразить ?

Custom data-media / data-%smth-to-share% for vk.com

Есть такая фича у VK API – шарить кастомную картинку, а не все картинки со страницы и шарить определенный текст с этой же страницы, как это реализовать в рамках social likes? Проект отличный, не хочется с него слезать, а шарить правильно хочется.

Add pressed state

It would be nice to have a style for "pressed" state.

Here's what I came up with:

pressed

CSS:

.social-likes__button:active {
  -webkit-box-shadow: inset 0 0 3px rgba(0, 0, 0, 0.3));
          box-shadow: inset 0 0 3px rgba(0, 0, 0, 0.3));
}

Facebook Like button (not share)

Hi, first of all, great plugin. Really love it.

Now the problem :)
Sorry for the noob question, but I do not understand how to enable the Facebook Like button instead of the share. I had some problems understanding the documentation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.