0.4.0 • Published 3 years ago

jquery-social-share v0.4.0

Weekly downloads
3
License
-
Repository
github
Last release
3 years ago

Simple Social Share

Simple Social Share is a simple way of creating social share buttons on your website without loading all the third party scripts from these networks. It is available in plain javascript and as jQuery plugin. It is based on a blog by Jonathan Suh: Responsible Social Share Links.

Version 0.4.0

For changelog see: https://github.com/MightyMedia/Simple-Social-Share/blob/master/CHANGELOG.md

The jQuery plugin requires jQuery 1.7 or newer.

Licensed under: MIT License - https://github.com/MightyMedia/Simple-Social-Share/blob/master/LICENSE

Requirements

  • jQuery 1.7+ (only when using the jQuery plugin)

Installation

To use Simple Social Share make sure you have jQuery 1.7 or newer. Next, just include the plugin file and you are ready to go.

Plain javascript

<script type="text/javascript" src="simpleSocialShare.min.js"></script>

jQuery

<script type="text/javascript" src="jquery.simpleSocialShare.min.js"></script>

Basic usage

Initialize

Plain javascript

// Without any input, every element with the class simpleSocialShare will get the magic.
simpleSocialShare.init();

// With selector, can be #id, .className or tagName
simpleSocialShare.init('.socialShareBtn');

// With elements, can be 1 DOM element, NodeList or HTMLCollection
simpleSocialShare.init(document.getElementsByClassName('socialShareBtn'));

jQuery

$(document).ready(function(){
    $('.socialShareBtn').simpleSocialShare();
});

Now every element with the class socialShareBtn will turn in to a functional share link.

<a href="#" class="socialShareBtn" data-share-url="http://mightymedia.nl" data-share-network="twitter" data-share-text="Share this awesome link on Twitter">Share on Twitter</a>

Initialize with Options

There are several basic options you can pass along during the initialization. They can be overwritten by individual data attributes per network.

Plain javascript

// Initialization with before and after callback
simpleSocialShare.init( '.socialShareBtn', {

	before	: 'callbackFunctionBefore',
	after	: 'callbackFunctionAfter'

} );

Overwrite or set individually by data attribute

<a href="#" class="socialShareBtn" data-share-url="http://mightymedia.nl" data-share-network="twitter" data-share-text="Share this awesome link on Twitter" data-share-before="callbackFunctionBefore" data-share-after="callbackFunctionAfter">Share on Twitter</a>

Initialize Options

The options you can pass along during initialization:

OptionDescriptionNotes
beforeCallback function to call before the popup opensoptional
afterCallback function to call after the popup openedoptional

Destroy

To completely remove all added Simple Social Share functionality:

Plain javascript

// Input can be the same as used for simpleSocialShare.init();
simpleSocialShare.destroy('selector');

jQuery

$(document).ready(function(){
    $('.socialShareBtn').simpleSocialShare('destroy');
});

Data Attributes Options

The options for a share link/button are set via data attributes on the element. Below is a list with the options.

OptionDescriptionNetworkNotes
share-networkThe network to share onall networksrequired
share-urlThe URL to be sharedall networksrequired
share-textThe text to pass along with the URLlinkedin, pinterest, twitteroptional
share-titleThe title to add the the sharelinkedin onlyoptional
share-viaAccount name to mention in the share/tweettwitter onlyoptional
share-tagsTags to include to the sharepinterest, twitteroptional
share-mediaImage to add to the sharepinterest onlyoptional
share-beforeCallback function before the popup opensall networksoptional
share-afterCallback function after the popup openedall networksoptional

Issues

If you have any ideas or bugs, please submit them to the GitHub issue tracker at https://github.com/MightyMedia/Simple-Social-Share/issues.