Skip to content

EngageDC/socialshare.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

socialshare.js

Simple Social Sharing via Facebook and Twitter

Installing

Paste directly after the <body> opening tag.p

<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : '{your-app-id}',
      status     : true,
      xfbml      : true
    });
  };

  (function(d, s, id){
     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement(s); js.id = id;
     js.src = "//connect.facebook.net/en_US/all.js";
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));
</script>
  • Add a reference to this script: <script language="javascript" src="/js/socialshare.js"></script>
  • socialshare.js will automatically hook into buttons that has the facebook-share or twitter-share classes.
  • Share options can be specified with data- attributes

Note: Make sure to add appriopriate Facebook OpenGraph meta tags (And Twitter Cards)

Facebook share button example

<a href="#" class="facebook-share" data-share-link="http://example.com" data-share-caption="Facebook caption goes here">
  <i class="fa fa-facebook"></i>
</a>

Twitter share button example

<a href="#" class="twitter-share" data-share-text="Twitter share text goes here">
  <i class="fa fa-twitter"></i>
</a>

Google+ share button example

<a href="#" class="googleplus-share" data-share-link="http://example.com">
  <i class="fa fa-google-plus"></i>
</a>

Print button example

<a href="#" class="print-share">
  <i class="fa fa-print"></i>
</a>

Share count

socialshare.js also supports displaying share count, just add an element with the count class as the child of your share button and socialshare.js will automatically detect and load share count via AJAX.

<a href="#" class="facebook-share" data-share-link="http://example.com" data-share-caption="Facebook caption goes here">
  <i class="fa fa-facebook"></i>
  <span class="count"></span>
</a>

About

Simple Social Sharing via Facebook and Twitter

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •