social-likes-nojq/Readme.md

313 lines
7.1 KiB
Markdown
Raw Normal View History

2013-12-16 23:49:48 +04:00
# Social Likes
[![Bower version](https://badge.fury.io/bo/social-likes.png)](http://badge.fury.io/bo/social-likes)
[![Built with Grunt](https://cdn.gruntjs.com/builtwith.png)](http://gruntjs.com/)
2013-02-05 13:25:43 +04:00
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](http://sapegin.github.io/social-likes/) to generate the code.
Or install via [Bower](http://bower.io/): `$ bower install social-likes`.
2013-02-05 13:25:43 +04:00
## Advanced configuration
### Layout
2013-08-26 13:15:30 +04:00
#### Default
2013-08-26 13:15:30 +04:00
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>
```
2013-08-26 13:15:30 +04:00
2013-02-05 13:25:43 +04:00
### Options
2013-11-01 19:00:21 +04:00
Options define via HTML data attributes or JavaScript parameters object.
2013-02-05 13:25:43 +04:00
`url`
URL of shareable page. Current page by default.
`title`
Title for Twitter, Vkontakte and LiveJournal. Current pages title by default.
`html`
2013-02-05 16:32:38 +04:00
HTML code for LiveJournal button. By default <A> tag with link to current page.
2013-02-05 13:25:43 +04:00
`counters`
Disables “likes” counters when “no”. Default: “yes”.
2014-02-03 12:09:25 +04:00
`zeroes`
Show counters even when number is `0`. Default: “no”.
2013-02-05 13:25:43 +04:00
`single-title`
Share button title for “single button” mode. Default: “Share”.
Examples:
```html
<ul class="social-likes" data-url="http://landscapists.info/" data-title="Landscapists of Russia">
</ul>
```
```html
<ul class="social-likes social-likes_single" data-single-title="This is Sharing!">
</ul>
```
2013-11-01 19:00:21 +04:00
```js
$('.social-likes').socialLikes({
url: 'https://github.com/sapegin/social-likes/',
title: 'Beautiful “like” buttons with counters for popular social networks',
2014-02-03 12:09:25 +04:00
counters: true,
singleTitle: 'Share it!'
2013-11-01 19:00:21 +04:00
});
```
2013-02-05 13:25:43 +04:00
### Services specific options
#### Twitter
You can specify `via` (sites Twitter) and `related` (any other Twitter you want to advertise) values for `<li class="twitter">`:
```html
<li class="twitter" data-via="sapegin" data-related="Landscapists">Twitter</li>
```
2013-04-23 11:23:27 +04:00
#### Pinterest
2013-02-05 13:25:43 +04:00
2013-02-05 16:26:24 +04:00
You should specify an image URL via data-media attribute on `<li class="pinterest">`:
2013-02-05 13:25:43 +04:00
```html
2013-02-05 16:26:24 +04:00
<li class="pinterest" data-media="http://example.com/image/url.jpg">Pinterest</li>
2013-02-05 13:25:43 +04:00
```
2013-09-12 12:23:57 +04:00
### Manual initialization
2014-02-04 12:50:52 +04:00
Could be useful on dynamic (AJAX) websites.
2013-09-12 12:23:57 +04:00
```html
<ul id="share">
<li class="facebook">Facebook</li>
...
</ul>
```
```javascript
$('#share').socialLikes();
```
2014-02-04 12:50:52 +04:00
### Dynamic URL changing
2014-02-04 13:03:37 +04:00
You can dynamically replace URL, title and Pinterest image without reinitialization.
2014-02-04 12:50:52 +04:00
```html
<ul id="share2" class="social-likes" data-url="http://example.com/" data-title="My example">
<li class="facebook">Facebook</li>
...
</ul>
```
```javascript
$('#share2').socialLikes({
url: 'http://github.com/',
2014-02-04 13:03:37 +04:00
title: 'GitHub',
data: {
media: 'http://birdwatcher.ru/i/userpic.jpg' // Image for Pinterest button
}
2014-02-04 12:50:52 +04:00
});
```
2014-02-12 16:22:04 +04:00
### Refreshing counters
By default counters for any uniqe URL requested only once. You can force new request with `forceUpdate` option:
```javascript
$('#share2').socialLikes({
forceUpdate: true
});
```
2013-09-12 12:23:57 +04:00
2013-08-08 11:00:53 +04:00
### Events
#### `counter.social-likes`
Triggers for every counter.
2013-08-08 11:00:53 +04:00
```javascript
$('.social-likes').on('counter.social-likes', function(event, service, number) {
// service: facebook, twitter, etc.
});
```
2013-02-05 13:25:43 +04:00
#### `ready.social-likes`
Triggers after all counters loaded.
```javascript
$('.social-likes').on('ready.social-likes', function(event, number) {
// number is total number of shares
});
```
2014-02-12 16:40:51 +04:00
#### `popup_opened.social-likes`
Triggers after popup window opened.
```javascript
$('.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.
```javascript
$('.social-likes').on('popup_closed.social-likes', function(event, service) {
$(event.currentTarget).socialLikes({forceUpdate: true}); // Update counters
});
```
2013-02-05 13:25:43 +04:00
### Adding your own button
2013-06-20 14:53:19 +04:00
You can find some custom buttons in `contrib` folder.
2013-02-05 13:25:43 +04:00
Define `socialLikesButtons` hash:
```javascript
var socialLikesButtons = {
surfingbird: {
popupUrl: 'http://surfingbird.ru/share?url={url}',
2014-02-20 15:29:23 +04:00
popupWidth: 650,
2013-02-05 13:25:43 +04:00
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.
```javascript
var socialLikesButtons = {
twitter: {
...
searchUrl: 'https://twitter.com/search?src=typd&q={url}'
}
};
```
2013-02-05 13:25:43 +04:00
Add some CSS:
```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:
```html
<li class="surfingbird">Surf</li>
```
2013-08-08 11:07:09 +04:00
See sources (`src` folder) for available options and class names and `contrib` folder for custom buttons examples.
2013-02-05 13:25:43 +04:00
### How to change title, description and image
2013-02-05 13:25:43 +04:00
You can use [Open Graph](http://ogp.me/). It works for [Facebook](http://davidwalsh.name/facebook-meta-tags), Twitter, [Google+](https://developers.google.com/+/web/snippet/), [Pinterest](http://developers.pinterest.com/rich_pins/) and [Vkontakte](http://vk.com/dev/widget_like)).
2014-02-21 13:16:25 +04:00
You can add additional Twitter data using [Twitter Card](https://dev.twitter.com/docs/cards). You have to [approve](https://dev.twitter.com/docs/cards/validation/validator) every type of Twitter Card.
2013-02-05 13:25:43 +04:00
```html
<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](https://developers.facebook.com/tools/debug/) and [Twitter Card Validator](https://dev.twitter.com/docs/cards/validation/validator).
2013-09-09 12:22:17 +04:00
2013-04-23 11:23:27 +04:00
### How to use Social Likes with Wordpress, etc.
See [wiki](https://github.com/sapegin/social-likes/wiki/How-to-use-Social-Likes-with-Wordpress,-etc.).
2013-02-05 16:49:27 +04:00
## Release History
2013-12-24 00:18:55 +04:00
The changelog can be found in the `Changelog.md` file.
2013-02-05 13:25:43 +04:00
2013-02-05 13:25:43 +04:00
---
## License
The MIT License, see the included `License.md` file.