Skip to content

Latest commit

 

History

History
118 lines (96 loc) · 2.78 KB

shareaholicSDK.md

File metadata and controls

118 lines (96 loc) · 2.78 KB

Shareaholic SDK

Sharing public API

Using the sharing service and UI via JavaScript:

Staging (Unstable):

<script>
  window.ShareaholicBookmarklet = window.ShareaholicBookmarklet || [];
  ShareaholicBookmarklet.push([
    'share', {
      service: 'facebook',
      link: 'http://www.example.com',
      title: 'test title',
      summary: 'this is cool'
    }, 
    function (err) {
      console.log('Sharing invoked ');
      console.log(err);
    }])
</script>

<script 
  type="text/javascript" 
  src="//d2062rwknz205x.cloudfront.net/v2/ShareaholicBookmarklet.js"
  data-shr-debug="true"
  data-shr-assetbase="//d2062rwknz205x.cloudfront.net/v2/"
  data-shr-namespace="ShareaholicBookmarklet"
  data-shr-entrypoint="shrMain.js">
</script>

Production:

<script>
  window.ShareaholicBookmarklet = window.ShareaholicBookmarklet || [];
  ShareaholicBookmarklet.push([
    'share', {
      service: 'facebook',
      link: 'http://www.example.com',
      title: 'test title',
      summary: 'this is cool'
    }, 
    function (err) {
      console.log('Sharing invoked ');
      console.log(err);
    }])
</script>

<script 
  type="text/javascript" 
  src="//dsms0mj1bbhn4.cloudfront.net/v2/ShareaholicBookmarklet.js"
  data-shr-assetbase="//dsms0mj1bbhn4.cloudfront.net/v2/"
  data-shr-namespace="ShareaholicBookmarklet"
  data-shr-entrypoint="shrMain.js">
</script>

Invoking a share command

ShareaholicBookmarklet.push([
  'share', {
    service: 'all'
  }, 
  function onInvoked(err) {
    // err is falsy if there was no error
  }
]);
Sharing command object

All of the fields in the command object are optional EXCEPT for service. If you do not specify the any of the other fields the SDK will do it's best to try and scrape the required fields from the page.

  • service - the service name you wish to share via or all
  • title - the title of the item
  • link - link to the item
  • summary - summary text for the item
  • image - image to share
  • images - an array of images to share
  • short_link - shortened link to the item
  • media_link - link to media to share,
  • link_title - title for the link being shared,
  • source - defaults to Shareaholic
Success callback API

The api object returned in the success callback will give you the ability to subscribe to events generated by user interactions with the UI.

// subscribing to events
function onClose() {
  console.log('modal was closed');
}

// subscribe
api.on('modal.close', onClose);

// unsubscribe
api.off('modal.close', onClose);

API methods:

  • on: pass a topic and callback function for notifications on that topic
  • off: pass a topic and the callback function used to subscribe

API topics:

  • modal.close: the modal window has been closed