shareon/README.md

188 lines
5.6 KiB
Markdown
Raw Normal View History

2021-07-29 09:58:17 -04:00
📯 shareon
==========
2020-03-25 11:32:25 -04:00
2021-07-29 09:58:17 -04:00
> Lightweight, stylish and ethical share buttons for popular social networks
2020-03-25 11:32:25 -04:00
2021-07-29 09:58:17 -04:00
<img src="assets/demo@2x.png" height="90" width="395" alt="demo: shareon buttons for various popular social networks">
2020-03-25 11:32:25 -04:00
2021-07-29 09:58:17 -04:00
- **Small.** Dependency-free. CSS+JS bundle is uner 7 KB, minified and gzipped.
- **Stylish.** Uses official colours and vector logos with no visual mess.
2020-06-26 11:32:02 -04:00
- **Ethical.** Embeds no tracking code. JS is required only for the setup.
2020-03-25 11:32:25 -04:00
2021-07-29 09:58:17 -04:00
Observe the live demo at [shareon.js.org](https://shareon.js.org/)!
2020-03-25 19:38:54 -04:00
2021-07-29 09:58:17 -04:00
Install
-------
### Modern browsers
2020-03-25 19:38:54 -04:00
2021-07-29 09:58:17 -04:00
shareon ships as an ES6 module.
[Most modern browsers](https://caniuse.com/es6-module) support this format.
2020-03-25 19:38:54 -04:00
Include the link to shareon's JS and CSS in your website:
```html
2021-07-29 09:58:17 -04:00
<link href="https://cdn.jsdelivr.net/npm/shareon@2/shareon.css" rel="stylesheet">
<script type="module" src="https://cdn.jsdelivr.net/npm/shareon@2"></script>
```
### Older browsers
If for some reason you don't want to use the ESM format, you can include the
Legacy (IIFE) version of the package
```html
<link href="https://cdn.jsdelivr.net/npm/shareon@2/shareon.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/shareon@2/shareon.legacy.js" type="text/javascript"></script>
2020-03-25 19:38:54 -04:00
```
2021-07-29 09:58:17 -04:00
### Node.js
If you build a web app using Node.js, you can install shareon as a package:
2020-03-25 19:38:54 -04:00
```sh
npm install shareon
2021-07-29 09:58:17 -04:00
```
```sh
2020-03-25 19:38:54 -04:00
yarn add shareon
```
2021-07-29 09:58:17 -04:00
Then, import it in your code:
2020-03-25 19:38:54 -04:00
```js
2020-07-26 08:40:37 -04:00
import shareon from 'shareon';
```
2021-07-29 09:58:17 -04:00
> **💡 Tip!** Modern browsers and some bundlers support importing directly from
> URL:
>
> ```js
> import shareon from 'https://cdn.jsdelivr.net/npm/shareon@2';
> ```
CommonJS' `require()` [**is not supported**](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
Initialization
--------------
2020-07-26 08:40:37 -04:00
By default, shareon will initialize every button after page load. It also
exports the `shareon` function, that will let you repopulate your buttons with
updated information (for example, if you changed the page title):
```js
2021-07-29 09:58:17 -04:00
import shareon from 'shareon';
2020-07-26 08:40:37 -04:00
// shareon auto-initializes
window.title = "Cool new window title";
shareon();
```
2021-07-29 09:58:17 -04:00
If you use the IIFE version, `shareon()` is available as a global function:
2020-07-26 08:40:37 -04:00
```html
2021-07-29 09:58:17 -04:00
<script>
window.title = "Cool new window title";
window.shareon();
2020-07-26 08:40:37 -04:00
</script>
```
2021-07-29 09:58:17 -04:00
Usage
-----
2020-03-25 19:44:31 -04:00
2021-07-29 09:58:17 -04:00
> shareon was heavily inspired by
> [Likely](https://ilyabirman.net/projects/likely/),
> and has backwards-compatible networks' names
2020-03-25 19:47:45 -04:00
2020-03-25 19:44:31 -04:00
Create a container with class `shareon` and populate it with elements, whose
classes match the names of social networks:
2020-03-25 11:32:25 -04:00
2020-03-25 19:25:17 -04:00
```html
<div class="shareon">
<a class="facebook"></a>
<a class="linkedin"></a>
<a class="mastodon"></a>
2021-07-29 09:58:17 -04:00
<!-- App ID is required for the Messenger button to function -->
2020-09-28 07:48:10 -04:00
<a class="messenger" data-fb-app-id="0123456789012345"></a>
2021-07-29 09:58:17 -04:00
2020-03-26 17:45:42 -04:00
<a class="odnoklassniki"></a>
2020-03-25 19:44:31 -04:00
<a class="pinterest"></a>
<a class="pocket"></a>
2021-07-29 09:58:17 -04:00
<a class="reddit"></a>
<a class="telegram"></a>
<a class="twitter"></a>
<a class="viber"></a>
<a class="vkontakte"></a>
<a class="whatsapp"></a>
2020-03-25 19:44:31 -04:00
</div>
```
2021-07-29 09:58:17 -04:00
> The elements don't have to be `<a>`s — if you use a different tag (for example,
`<button>`), shareon will use event listeners instead of `href`. Note that this
is not the intended use case and is slower.
2020-03-25 20:43:16 -04:00
2020-06-26 11:32:02 -04:00
By default, the URL and the title of the page will be used in sharing dialogs.
2020-03-25 19:44:31 -04:00
To change this, you can use the `data-url` and `data-title` attributes. Use them
2020-03-25 20:43:16 -04:00
on the whole container or on the specific buttons:
2020-03-25 19:44:31 -04:00
```html
2021-07-29 09:58:17 -04:00
<div class="shareon" data-url="https://custom.url.com">
<a class="facebook" data-title="Custom title for Facebook"></a>
<a class="twitter" data-title="Custom title for Twitter"></a>
2020-03-25 19:44:31 -04:00
</div>
```
2021-07-29 09:58:17 -04:00
Apart from the URL and title, some social networks support extra parameters:
2020-03-25 19:44:31 -04:00
2021-07-29 09:58:17 -04:00
- you **MUST** add `data-fb-app-id` to the FB Messenger button to make
sharing possible
- add `data-media` to an Odnoklassniki, Pinterest, or VK buttons to customize
the pinned picture
- add `data-text` to a WhatsApp, Mastodon, Telegram, or Viber button to add
custom message text
- add `data-via` to a Twitter or Mastodon button to mention a user
2020-03-25 19:44:31 -04:00
Here are all the custom parameters in their glory:
```html
<div class="shareon" data-url="https://example.com/custom-url">
<a class="facebook" data-title="Custom Facebook title"></a>
2020-09-28 07:48:10 -04:00
<a class="messenger" data-fb-app-id="0123456789012345"></a>
2020-03-25 19:25:17 -04:00
<a class="pinterest" data-media="https://picsum.photos/500">Pin</a>
<a class="telegram" data-text="Check this out!"></a>
<a class="twitter" data-via="MyNickname"></a>
2020-09-28 08:01:29 -04:00
<a class="mastodon" data-via="@MyNickname@myserver.social"></a>
2020-09-28 07:48:10 -04:00
<a class="whatsapp" data-url="https://my-cool-website.com">Send</a>
2020-03-25 11:32:25 -04:00
</div>
```
Other versions
--------------
- [**WordPress version**](https://wordpress.org/plugins/shareon/) by [Gareth](https://github.com/gareth-gillman)
2021-07-29 09:58:17 -04:00
Licence
-------
2021-01-16 16:15:19 -05:00
2021-07-29 09:58:17 -04:00
[BSD-3-Clause](https://spdx.org/licenses/BSD-3-Clause.html) © 2020, Nikita Karamov
2021-07-29 09:58:17 -04:00
shareon logo is the
[Postal Horn emoji](https://github.com/googlefonts/noto-emoji/blob/v2020-09-16-unicode13_1/svg/emoji_u1f4ef.svg)
from
[Noto Emoji](https://github.com/googlefonts/noto-emoji/tree/v2020-09-16-unicode13_1),
which is licensed under the
[Apache License v2.0](https://github.com/googlefonts/noto-emoji/blob/v2020-09-16-unicode13_1/LICENSE).
2021-01-16 17:50:16 -05:00
Includes a modified version of the
[Mastodon logo](https://commons.wikimedia.org/wiki/File:Mastodon_Logotype_%28Simple%29.svg),
which is licensed under the
[APGLv3 license](https://www.gnu.org/licenses/agpl.html) or later.
2021-07-29 09:58:17 -04:00
----
The source code is being hosted
on [GitHub](https://github.com/NickKaramoff/shareon) with mirrors
on [GitLab](https://gitlab.com/NickKaramoff/shareon)
and [Codeberg](https://codeberg.org/NickKaramoff/shareon).