npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

socialjs

v2.2.0

Published

Customizable share buttons in vanilla js

Downloads

12

Readme

Social JS 2.2.0

Social JS is a Javascript to easily create share buttons for the most common social media sites. It's built in a way that requires almost no knowledge in javascript but depends instead of the use of data attributes.

View Demo

Features

  • Twitter - API for fetching counts is shutdown
  • Facebook
  • LinkedIn
  • Google Plus
  • Reddit
  • Can fetch share count for each social media. Requires server side client to provide a count for Google Plus. A PHP client is provided.

Browser Support

  • Google Chrome
  • Internet Explorer 10+
  • Firefox
  • Safari 8+

Installation

yarn add socialjs

Setup

<!-- and you'll need to include socialjs of course! -->
<script src="socialjs.min.js"></script>

Usage

socialjs.init();

Settings and Defaults

options: {
  container: '.socialjs',
  fetchCounts: true,
  shortCount: true,
  https: true,
  urls: {
    GooglePlus: 'backend/GooglePlusCall.php',
    Facebook: 'http://graph.facebook.com/',
    Linkedin: 'http://www.linkedin.com/countserv/count/share',
    Reddit: 'http://www.reddit.com/api/info.json'
  },
  onInit: function () {},
  OnAttachEvents: function () {},
  onDestroy: function () {},
  onClick: function () {}
};
  • fetchCounts: Default true. If the plugin should fetch share count or not.
  • shortCount: Default true. Show total by k or M when number is to big.
  • https: Defaults false. Set to true to change all requests from HTTP to HTTPS.
  • GooglePlus: Path to server side google plus client.
  • Facebook: URL to REST Service. Don't change unless you know what your doing.
  • Linkedin: URL to REST Service. Don't change unless you know what your doing.
  • Reddit: URL to REST Service. Don't change unless you know what your doing.
  • onInit: Executes when initialized.
  • OnAttachEvents: Executes when finished attaching all events.
  • onClick: Executes when user clicks any share button.
  • onDestroy: Executes when plugin is removed/destroyed.

Required classes, data-attributes and elements.

  • .sharebutton: Required. Class of the <a href> element containing all data-attributes.
  • data-sharetype: Required. To tell the script what social media it is. Supports twitter, facebook, linkedin or googleplus
  • data-basecount: Optional. If you want to cheat or have moved pages or switched domain but want to keep the old count you can add this and specify a number
  • data-text: Optional. If not specified the plugin will take the title of the page as text.
  • data-via: Only for Twitter. Optional. The creator of the content. Usually your twitter name without the @
  • data-related: Only for Twitter. Optional. The creator of the content. Usually your twitter name without the @

If you want a count to be presented you'll need to add a span element inside the <a href>

Public methods

Exposed methods that you can access and use. The count methods is best to use within the onLoad hook since the count will be fetched by and Ajax request.

  • getCount.Total: getTotalCount,
  • getCount.Facebook: getFacebookCount,
  • getCount.GooglePlus: getGooglePlusCount,
  • getCount.Linkedin: getLinkedinCount,
  • getCount.Reddit: getTwitterCount

How to use a public method

In this example we alert the count of all Facebook shares.

socialjs.init();
alert(socialjs.getCount.Facebook());

Typical setup

This could be your typical script setup for a facebook share button.

socialjs.init();
<div class="socialjs">
  <a class="sharebutton facebook" data-basecount="249" data-sharetype="facebook" data-text="The neat page title" title="Share this on Facebook" href="#"><span class="count"></span></a>
</div>

About server side Google Plus clients

Currently I have only written one in PHP but you can write your own in any language really. The only thing you need to know is that the expected return value from the client is a number and nothing else.

If you want to contribute with a C# client or a client in any other language please do! Just fork and pull request.

change log

2.2.0

  • Added repository to Yarn. Will no longer be updated on Bower.io

2.1.1

  • Fixed bug with https not working as intended.

2.1.0

  • CHANGE: Added option to set all requests from HTTP to HTTPS.

2.0.0-beta

  • CHANGE: Rewritten in vanilla Javascript. No dependencies needed.

0.7.0

0.6.0

  • Added support for Reddit
  • Renamed to Social JS since SimpleShareButtons already existed

0.5.0

  • First real public release