New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

goodshare.js

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

goodshare.js

Useful modern JavaScript solution for share a link from your website to social networks or mobile messengers.

  • 6.0.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
242
decreased by-49.37%
Maintainers
1
Weekly downloads
 
Created
Source

goodshare-js-logo-github

goodshare.js

npm version jsDelivr download js es6 code style: prettier license

Useful jQuery plugin modern JavaScript solution for share a link from your website to social networks or mobile messengers. Easy to install and configuring on any of your website!

Features

Simple install, extensive documentation, developer support, SEO friendly, small bundle size (gzipped size: 3.6 Kb), many options for customization of appearance, clean code without scripts tracking user activity on the page, high speed.

Full Documentation & Demos

Production-ready components

Installation

Install via npm:

$ npm install goodshare.js --save

Or include from jsDelivr CDN:

<script src="https://cdn.jsdelivr.net/npm/goodshare.js@6/goodshare.min.js"></script>

Usage

Script works with any HTML tags: <a> or <div> or <button> or other.

So you can choose any and add required attributes data-social.

For example:

<!-- Create button with share to Twitter -->
<button data-social="twitter">Share this to Twitter</button>

<!-- Create link with share to Facebook -->
<a href="#" data-social="facebook">Share this to Facebook</a>

<!-- Create div container with share to LinkedIn -->
<div data-social="linkedin">Share this to LinkedIn</div>

<!-- Create icon from Fontello.com with share to Google+ -->
<i class="icon-google-plus" data-social="googleplus"></i>

By default, goodshare.js search this tags for get title, description and image (for some social networks):

<head>
  <title>Current page title</title>
  <meta name="description" content="Current page description.">
  <link rel="apple-touch-icon" href="http://example.com/path/to/image.png">
  ...
</head>
Change URL, title or else

If you want to add different url, title, description and image to share element — use special data-* attributes:

  • data-url redefines document.location.href
  • data-title redefines document.title
  • data-description redefines meta[name="description"]
  • data-image redefines link[rel="apple-touch-icon"]

Note: Please keep in mind, not all social networks support all of them data attributes!

Dynamically update

If you want to dynamically update the data that will be used for share. You can call a method Goodshare.reNewAllInstance() that will update data in goodshare providers instance and update EventListeners.

Note: For example, you have a widget to share content that generates images for sharing based on selected items or other user actions.

// Update all data
// Goodshare instance expose in window._goodshare by default
window._goodshare.reNewAllInstance();
Display share count

To display share count, just add data-counter attribute to HTML element that will contain numbers. For example:

<!-- Create link with share to Facebook and counter -->
<a href="#" data-social="facebook">
  Share this to Facebook
  <span data-counter="facebook"></span>
</a>

You also may put this attribute to any element.

Detect share success

Simply calls the handler when the hooking window is closed. Look more at Issue #57

window._goodshare.setShareCallback(function() {
  console.log(arguments);
  // some logic for handling share events
});

Notes

  • No more depending on jQuery! Since 4.x, no longer support the old goodshare.js version (3.2.9 and lower). Thank you jQuery, but ES6 is better and cleaner.
  • Browser support. Since 4.x, goodshare.js do not support Microsoft Internet Explorer 8 and older.
  • Bundle. Since 5.2.0, goodshare.js drop support Webpack 3 and now bundled with Rollup.js. It saved over ~55 Kb of bundle size! Wow!
  • Polyfills. Since 6.0.0, goodshare.js have two versions: with (./goodshare.polyfill.min.js) and without (./goodshare.min.js) Array Polyfill.
  • No need to separated polyfills. Since 6.0.2, goodshare.js drop ./goodshare.polyfill.min.js and separated Array Polyfill from ./src/polyfills.
  • Browser support (2019). Since 6.0.3, goodshare.js only support: MSIE 11+, Edge 13+, Google Chrome 59+ and FireFox 50+.

Author & maintainers

Development and maintenance engaged by Vic Shóstak (aka Koddr). If you want to say «thank you» and/or ask me about goodshare.jscreate new issue.


Your assistance will help make project even better!

Thanks for supporting!

License

The MIT License (MIT)

Keywords

FAQs

Package last updated on 18 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc