Skip to content

Commit

Permalink
add twitter via support
Browse files Browse the repository at this point in the history
  • Loading branch information
pmb0 committed Feb 2, 2015
1 parent 1d48228 commit 7c6ae0f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Make sure you have installed the [Grunt CLI](http://gruntjs.com/getting-started#
| `data-referrer-track` | A string that will be appended to the share url. Can be disabled using `null`. | `null` |
| `data-services` | An entity-encoded JSON string containing an array of service names to be enabled. Example: `data-services="["facebook","googleplus"]"` Available service names: `twitter`, `facebook`, `googleplus`, `mail`, `info` | (all enabled) |
| `data-theme` | We include two color schemes, `standard` or `grey`. | `standard` |
| `data-twitter-via` | Screen name of the user to attribute the Tweet to | `null` |
| `data-url` | The canonical URL of the page to check. | page's canonical URL or `og:url` or current URL |

## Backends
Expand Down
3 changes: 2 additions & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ <h1>Lorem ipsum dolor sit amet, consectetuer adipiscing elit</h1>
<dt>data-orientation:</dt><dd>default</dd>
<dt>data-services:</dt><dd>default</dd>
<dt>data-theme:</dt><dd>grey</dd>
<dt>data-twitter-via:</dt><dd>heiseonline</dd>
<dt>data-url:</dt><dd>http://www.heise.de/ct/</dd>
</dl>
<article class="slim">
<header>
<h1>Lorem ipsum dolor sit amet, consectetuer adipiscing elit</h1>
<div data-backend-url="/shariff/" data-theme="grey" data-lang="en" class="shariff" data-url="http://www.heise.de/ct/" data-info-url="http://example.com"></div>
<div data-backend-url="/shariff/" data-theme="grey" data-lang="en" class="shariff" data-url="http://www.heise.de/ct/" data-info-url="http://example.com" data-twitter-via="heiseonline"></div>
<time datetime="2014-11-13T10:45:00+02:00">13.11.2014 - 12:45 Uhr</time>
</header>
<p class="deck">Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar.</p>
Expand Down
16 changes: 14 additions & 2 deletions src/js/services/twitter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
'use strict';

var url = require('url');

module.exports = function(shariff) {
var url = encodeURIComponent(shariff.getURL());
var shareUrl = url.parse('https://twitter.com/intent/tweet', true);

// TODO FIXME: remove "encodeURIComponent()" from getShareText()
shareUrl.query.text = decodeURIComponent(shariff.getShareText());
shareUrl.query.url = shariff.getURL();
if (typeof shariff.options.twitterVia !== null) {
shareUrl.query.via = shariff.options.twitterVia;
}
delete shareUrl.search;

return {
popup: true,
shareText: 'tweet',
Expand All @@ -12,6 +23,7 @@ module.exports = function(shariff) {
'en': 'Share on Twitter',
'es': 'Compartir en Twitter'
},
shareUrl: 'https://twitter.com/intent/tweet?text='+ shariff.getShareText() + '&url=' + url + shariff.getReferrerTrack()
// shareUrl: 'https://twitter.com/intent/tweet?text='+ shariff.getShareText() + '&url=' + url
shareUrl: url.format(shareUrl) + shariff.getReferrerTrack()
};
};
2 changes: 2 additions & 0 deletions src/js/shariff.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ _Shariff.prototype = {
// services to be enabled in the following order
services : ['twitter', 'facebook', 'googleplus', 'info'],

twitterVia: null,

// build URI from rel="canonical" or document.location
url: function() {
var url = global.document.location.href;
Expand Down

0 comments on commit 7c6ae0f

Please sign in to comment.