Giter Club home page Giter Club logo

social-network-sharing's Introduction

social-network-sharing

sharing-is-caring

Sharing to social networks should be straight forward - Use this library for Huffpost Labs Projects

Use this Library

  • Download social-network-sharing.js
  • If you want specialized Facebook sharing, edit it with the instructions below
  • Publicly host social-network-sharing.js and include a reference to it before calling any of its functions
  • You're good to go!

Sharing to Twitter

In your code, call HuffpostLabsShareTwitter(text, url, callback) where:

  • text is the content of the tweet
  • url is the url of the link back
    • if no url or null is provided, url will default to the page where shared from, ie window.location.href
  • callback (optional) is the function that will be fired upon tweeting

All shares will include via @HuffpostLabs

Example

<img src="/twitter-icon.png" onclick="twitterShare()">
<script>
	function twitterShare() {
		var successCallback = function() {
			console.log('YAY SOMEONE SHARED');
		}
		HuffpostLabsShareTwitter("I just found the coolest widget #ILoveHuffpostLabs", null, successCallback);
	}
</script>

Sharing to Facebook

This will share to someone's 'feed'

In your code, call HuffpostLabsShareFB(shareData, onSuccess, onError), where

  • onSuccess callback that will be fired upon successful share
  • onError (optional) callback that will be fired upon error
  • shareData - a dictionary with the following fields:
    • name (required) - the main header text that is also a link
    • picture (optional) - absolute URL of the picture that will be shared on the left side with the text
    • link (optional) - link back that user will go to when clicking on the name in the share.
      • Defaults to wherever shared from, ie, window.location.href
    • caption (reuired) - sub header shown in facebook post under name
    • description (optional) - sub sub heading shown under caption.
      • If not provided, Facebook will try to be smart and pull content from the page

Example

<img class=".fb-share-btn" src="/fb-button-icon.png" onclick="fbShare()">
<script>
	function fbShare() {
		var successCallback = function() {
			console.log('YAY SOMEONE SHARED');
		}
		var errorCallback = function() {
			console.log('uh oh.... but at least someone tried to share...')
		}
		var shareData = {
			'name': 'Awesome Widget',
			'picture': 'http://www.huffingtonpost.com/contributors/brandon-diamond/headshot.jpg',
			'link': 'http://LINK-TO-MY-AWESOME-STUFF.com',
			'caption': 'This is so cool',
			'description': 'Let me tell you more: blah blah blah...'
		}
		HuffpostLabsShareFB(shareData, successCallback, errorCallback);
	}
</script>

Sharing to Facebook from other domains

Facebook is very picky about where users can share from. Users can only share with our facebook app from our registered domains/subdomains:

if there is a Huffpost subdomain that isn't supported above:

  • get added as an 'administrator' or 'developer' to the HuffpostLabs FB app
  • Add the subdomain
  • Edit this README - add the subdomain above
  • Edit social-network-sharing.js:
    • "http://NEW-SUBDOMAIN.huffingtonpost.com": '1427100424195799',
  • PLEASE make pull request so that everyone else can use it too

  • If you want your facebook share button to hide when domain not supported, put a .fb-share-btn class or a #fb-share-btn id on it
    • If style still overridden, edit the disableFBsharing function

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.