nanorep.sdk.Sharing

This class allows creation of sharing component which can be used to share URL via Facebook, Twitter, Email or "Copy To Clipboard".

Example usage

1. Add script to your page:

<script src="https://<AccountName>.nanorep.co/web/include.js?sdk=sharing"></script>

2. Create empty <div>:

<div id="sharing-example"></div>

3. Initialize Sharing component:

var sharing = new nanorep.sdk.Sharing({
  url: 'http://example.com/test/page',   // specify any URL here
  text: 'Hey, look what I have:',        // specify any additional text here
}, document.getElementById('sharing-example')).on({
  showPopup: function(){
    alert('popup becomes visible');
  }
});

Options

url

Type: String

Default: location.href

Specify URL which needs to be shared

var sharingInstance = new nanorep.sdk.Sharing({
  url: 'http://my-cool-website.com/test/page',
}, document.getElementById('example-options-url'));
<div id="example-options-url"></div>

text

Type: String

Default: document.title

Specify text which needs to be added in sharing

var sharingInstance = new nanorep.sdk.Sharing({
  text: 'My cool article title',
}, document.getElementById('example-options-text'));
<div id="example-options-text"></div>

sharingChannels

Type: Array

Default: ['clipboard', 'email', 'facebook', 'twitter']

Array of sharing channels that should be visible for user

var sharingInstance = new nanorep.sdk.Sharing({
  sharingChannels: ['clipboard', 'twitter'],
}, document.getElementById('example-options-channels'));
<div id="example-options-channels"></div>

Methods

setData

setData(url, text, sharingChannels) : void

Set URL and Text strings for sharing. Optional array of sharing channels. Returns nothing

Parameters

url: String Same as url option
text: String Same as text option
sharingChannels (optional): Array of strings Same as sharingChannels option
var sharingInstance = new nanorep.sdk.Sharing({}, document.getElementById('example-methods-setData'));
sharingInstance.setData('https://my-cool-web.com', 'And great article!');
<div id="example-methods-setData"></div>

shareVia

shareVia(channelType) : void

Activate sharing of specific type. Returns nothing

Parameters

channelType: String Specific sharing channel. Any from sharingChannels option
var sharingInstance = new nanorep.sdk.Sharing({}, document.getElementById('example-methods-shareVia'));
sharingInstance.shareVia('twitter');
<div id="example-methods-shareVia"></div>

Events

showPopup

sharingInstance.on('showPopup', function() {})

Occurred when sharing popup is opened

var sharingInstance = new nanorep.sdk.Sharing({}, document.getElementById('example-events-showPopup'));
sharingInstance.on('showPopup', function() {
  alert('Sharing popup is opened');
});
<div id="example-events-showPopup"></div>

hidePopup

sharingInstance.on('hidePopup', function() {})

Occurred when sharing popup is closed

var sharingInstance = new nanorep.sdk.Sharing({}, document.getElementById('example-events-hidePopup'));
sharingInstance.on('hidePopup', function() {
  alert('Sharing popup is closed');
});
<div id="example-events-hidePopup"></div>