This class allows creation of sharing component which can be used to share URL via Facebook, Twitter, Email or "Copy To Clipboard".
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'); } });
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>
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>
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>
setData(url, text, sharingChannels) : void
Set URL and Text strings for sharing. Optional array of sharing channels. Returns nothing
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>
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>
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>