Name: news-vj-sharetools
Owner: BBC
Description: Visual journalism share tools module
Created: 2015-10-22 09:32:30.0
Updated: 2018-04-23 11:57:16.0
Pushed: 2018-04-23 11:57:15.0
Homepage: null
Size: 154
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
This module is used to add share tools to VJ content.
npm install @bbc/news-vj-sharetools
news-vj-sharetools has a template engine dependency. The reason we have kept 'template_engine' OUT of the sharetools.min.js file is to keep the filesize down - you may already have a template engine in your application and it would be a shame to have to download it twice.
You need to make sure template_engine
is defined in your RequireJS/Webpack paths, e.g.:
late_engine: `${__dirname}/node_modules/template_engine/template_engine`,
sharetools = new ShareTools({
holderEl: '.tempShareToolsHolder',
label: 'Share this page',
shareUrl: document.referrer,
messages: {
twitter: 'Twitter message',
facebook: {
title: 'Facebook share message'
},
email: {
subject: 'SUPER IMPORTANT EMAIL',
message: 'BBC News has new bespoke'
},
// you can also specify custom social networks, e.g.
whatsapp123: {
shareEndpoint: 'http://example.com',
popup: true,
properties: {
name: 'WhatsApp',
age: '23',
subject: 'Testing custom networks'
}
}
},
template: '<h1><%=label%></h1>'
Sending custom template
The template
property is a HTML template that will be rendered by the template engine. The renderer will pass the two values:
.share__overlay
and .share__overlay-close
.See the examples in the bin/templates directory. You can consume these as text if you have the RequireJS Text plugin, e.g.
ne(['text!templates/buttons.tmpl'], function (buttonsTemplate) {
…or you can grab use the template.js files directly.
ne(['templates/template'], function (buttonsTemplate) {
etools.setMessages({
twitter: 'Updated message',
facebook: {
title: 'Updated facebook share message'
},
email: {
subject: 'Hello',
message: 'New info'
},
app: {
title: 'New title',
text: 'Hello world'
}
etools.setShareUrl('http://bbc.co.uk/super-cool-new-url');
etools.onShareButtonClick(function (network) {
console.log(network + ' sharetool clicked');