diff --git a/README.md b/README.md index a5d94a27..c4b62fe7 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/demo/index.html b/demo/index.html index 99816aae..648fdafb 100644 --- a/demo/index.html +++ b/demo/index.html @@ -50,12 +50,13 @@

Lorem ipsum dolor sit amet, consectetuer adipiscing elit

data-orientation:
default
data-services:
default
data-theme:
grey
+
data-twitter-via:
heiseonline
data-url:
http://www.heise.de/ct/

Lorem ipsum dolor sit amet, consectetuer adipiscing elit

-
+

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.

diff --git a/src/js/services/twitter.js b/src/js/services/twitter.js index a3907921..d2b8008b 100644 --- a/src/js/services/twitter.js +++ b/src/js/services/twitter.js @@ -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', @@ -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() }; }; diff --git a/src/js/shariff.js b/src/js/shariff.js index fa2361ac..13f76a09 100644 --- a/src/js/shariff.js +++ b/src/js/shariff.js @@ -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;