Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added functionality to use url after being updated via hash or pushstate #186

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README-de.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ Für den Aufruf von `grunt demo` muss [Grunt CLI](http://gruntjs.com/getting-sta
| `data-title` | Titel der zu teilenden Seite. | Entweder `DC.title`/`DC.creator` oder `<title>` |
| `data-twitter-via` | User von dem der Tweet ursprünglich stammt. | `null` |
| `data-url` | URL, die geteilt werden soll. | Wenn `data-url` nicht gesetzt ist, wird `link[rel="canonical"]`, `meta[property="og:url"]` oder `location.href` verwendet. |
| `data-use-updated-url` | Gibt an, ob veränderte Url (Hash, history.pushState, etc) genommen werden soll | Ist `data-use-updated-url` nicht gesetzt, wird `link[rel="canonical"]`, `meta[property="og:url"]` oder ursprünglicher `location.href` verwendet. |


## Unterstützte Browser
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ Make sure you have installed the [Grunt CLI](http://gruntjs.com/getting-started#
| `data-title` | Title to be used as share text in Twitter/Whatsapp | page's `DC.title`/`DC.creator` or `<title>` |
| `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 |
| `data-use-updated-url` | Tells if updated url (Hash, history.pushState, etc) should be used | If `data-use-updated-url` is not set, `link[rel="canonical"]`, `meta[property="og:url"]` or original `location.href` will be used. |


## Supported browsers
Expand Down
4 changes: 4 additions & 0 deletions build/shariff.complete.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 32 additions & 33 deletions build/shariff.complete.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/shariff.min.css

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions build/shariff.min.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ <h1>Lorem ipsum dolor sit amet, consectetuer adipiscing elit</h1>
<dt>data-media-url:</dt><dd>http://www.heise.de/imgs/18/1/4/8/0/5/6/9/wa-encryption-d1999f774c5b5757.png</dd>
<dt>data-flattr-user:</dt><dd>example</dd>
<dt>data-services:</dt><dd>[&amp;quot;addthis&amp;quot;,whatsapp&amp;quot;,&amp;quot;facebook&amp;quot;,&amp;quot;xing&amp;quot;,&amp;quot;pinterest&amp;quot;,&amp;quot;linkedin&amp;quot;,&amp;quot;tumblr&amp;quot;,&amp;quot;flattr&amp;quot;,&amp;quot;diaspora&amp;quot;,&amp;quot;reddit&amp;quot;,&amp;quot;stumbleupon&amp;quot;,&amp;quot;threema&amp;quot;,&amp;quot;weibo&amp;quot;,&amp;quot;tencent-weibo&amp;quot;,&amp;quot;qzone&amp;quot;]</dd>
<dt>data-use-updated-url:</dt><dd>true</dd>
</dl>
<article class="slim">
<header>
<h1>Lorem ipsum dolor sit amet, consectetuer adipiscing elit</h1>
<div data-backend-url="/shariff/" data-flattr-user="example" class="shariff" data-services="[&quot;addthis&quot;,&quot;whatsapp&quot;,&quot;facebook&quot;,&quot;xing&quot;,&quot;pinterest&quot;,&quot;linkedin&quot;,&quot;tumblr&quot;,&quot;flattr&quot;,&quot;diaspora&quot;,&quot;reddit&quot;,&quot;stumbleupon&quot;,&quot;threema&quot;,&quot;weibo&quot;,&quot;tencent-weibo&quot;,&quot;qzone&quot;]" data-media-url="http://www.heise.de/imgs/18/1/4/8/0/5/6/9/wa-encryption-d1999f774c5b5757.png"></div>
<div data-backend-url="/shariff/" data-flattr-user="example" data-use-updated-url="true" class="shariff" data-services="[&quot;addthis&quot;,&quot;whatsapp&quot;,&quot;facebook&quot;,&quot;xing&quot;,&quot;pinterest&quot;,&quot;linkedin&quot;,&quot;tumblr&quot;,&quot;flattr&quot;,&quot;diaspora&quot;,&quot;reddit&quot;,&quot;stumbleupon&quot;,&quot;threema&quot;,&quot;weibo&quot;,&quot;tencent-weibo&quot;,&quot;qzone&quot;]" data-media-url="http://www.heise.de/imgs/18/1/4/8/0/5/6/9/wa-encryption-d1999f774c5b5757.png"></div>
<time datetime="2014-11-13T10:45:00+02:00">13.11.2014 - 12:45 Uhr</time>
</header>
<p class="deck">A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth.</p>
Expand All @@ -46,7 +47,7 @@ <h1>Lorem ipsum dolor sit amet, consectetuer adipiscing elit</h1>
<article class="slim">
<header>
<h1>Lorem ipsum dolor sit amet, consectetuer adipiscing elit</h1>
<div data-backend-url="/shariff/" class="shariff" data-services="[&quot;whatsapp&quot;,&quot;facebook&quot;,&quot;twitter&quot;,&quot;googleplus&quot;,&quot;mail&quot;,&quot;info&quot;]" data-mail-url="mailto:[email protected]" data-lang="en" data-title="Lorem ipsum"></div>
<div data-backend-url="/shariff/" class="shariff" data-use-updated-url="true" data-services="[&quot;whatsapp&quot;,&quot;facebook&quot;,&quot;twitter&quot;,&quot;googleplus&quot;,&quot;mail&quot;,&quot;info&quot;]" data-mail-url="mailto:[email protected]" data-lang="en" data-title="Lorem ipsum"></div>
<time datetime="2014-11-13T10:45:00+02:00">13.11.2014 - 12:45 Uhr</time>
</header>
<p class="deck">A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth.</p>
Expand Down
6 changes: 4 additions & 2 deletions src/js/services/addthis.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ module.exports = function(shariff) {
'tr': 'AddThis\'ta paylaş',
'zh': '在AddThis上分享'
},
shareUrl: 'http://api.addthis.com/oexchange/0.8/offer?url=' + url + shariff.getReferrerTrack()
shareUrl: 'http://api.addthis.com/oexchange/0.8/offer?url=' + url + shariff.getReferrerTrack(),
updateUrl: function(){
return 'http://api.addthis.com/oexchange/0.8/offer?url=' + shariff.getUpdatedUrl() + shariff.getReferrerTrack();
}
};
};

6 changes: 5 additions & 1 deletion src/js/services/diaspora.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ module.exports = function(shariff) {
'en': 'Share on Diaspora',
'zh': '分享至Diaspora'
},
shareUrl: url.format(shareUrl) + shariff.getReferrerTrack()
shareUrl: url.format(shareUrl) + shariff.getReferrerTrack(),
updateUrl: function(){
shareUrl.query.url = shariff.getUpdatedUrl();
return url.format(shareUrl) + shariff.getReferrerTrack();
}
};
};
5 changes: 4 additions & 1 deletion src/js/services/facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ module.exports = function(shariff) {
'tr': 'Facebook\'ta paylaş',
'zh': '在Facebook上分享',
},
shareUrl: 'https://www.facebook.com/sharer/sharer.php?u=' + url + shariff.getReferrerTrack()
shareUrl: 'https://www.facebook.com/sharer/sharer.php?u=' + url + shariff.getReferrerTrack(),
updateUrl: function(){
return 'https://www.facebook.com/sharer/sharer.php?u=' + shariff.getUpdatedUrl() + shariff.getReferrerTrack();
}
};
};
5 changes: 4 additions & 1 deletion src/js/services/flattr.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ module.exports = function(shariff) {
'de': 'Artikel flattrn',
'en': 'Flattr this'
},
shareUrl: 'https://flattr.com/submit/auto?title=' + encodeURIComponent(title) + '&description=' + encodeURIComponent(description) + '&category=' + encodeURIComponent(shariff.options.flattrCategory || 'text') + '&user_id=' + encodeURIComponent(shariff.options.flattrUser) + '&url=' + url + shariff.getReferrerTrack()
shareUrl: 'https://flattr.com/submit/auto?title=' + encodeURIComponent(title) + '&description=' + encodeURIComponent(description) + '&category=' + encodeURIComponent(shariff.options.flattrCategory || 'text') + '&user_id=' + encodeURIComponent(shariff.options.flattrUser) + '&url=' + url + shariff.getReferrerTrack(),
updateUrl: function() {
return 'https://flattr.com/submit/auto?title=' + encodeURIComponent(title) + '&description=' + encodeURIComponent(description) + '&category=' + encodeURIComponent(shariff.options.flattrCategory || 'text') + '&user_id=' + encodeURIComponent(shariff.options.flattrUser) + '&url=' + shariff.getUpdatedUrl() + shariff.getReferrerTrack();
}
};
};
6 changes: 4 additions & 2 deletions src/js/services/googleplus.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ module.exports = function(shariff) {
'tr': 'Google+\'da paylaş',
'zh': '在Google+上分享'
},
shareUrl: 'https://plus.google.com/share?url=' + url + shariff.getReferrerTrack()
shareUrl: 'https://plus.google.com/share?url=' + url + shariff.getReferrerTrack(),
updateUrl: function(){
return 'https://plus.google.com/share?url=' + shariff.getUpdatedUrl() + shariff.getReferrerTrack();
}
};
};

7 changes: 7 additions & 0 deletions src/js/services/linkedin.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ module.exports = function(shariff) {
'tr': 'LinkedIn\'ta paylaş',
'zh': '在LinkedIn上分享'
},
<<<<<<< master
shareUrl: 'https://www.linkedin.com/cws/share?url=' + url + shariff.getReferrerTrack(),
updateUrl: function() {
return 'https://www.linkedin.com/cws/share?url=' + shariff.getUpdatedUrl() + shariff.getReferrerTrack();
}
=======
shareUrl: 'https://www.linkedin.com/shareArticle?mini=true&summary=' + descr + '&title=' + title + '&url=' + url
>>>>>>> master
};
};
6 changes: 5 additions & 1 deletion src/js/services/pinterest.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ module.exports = function(shariff) {
'nl': 'Delen op Pinterest',
'zh': '分享至Pinterest'
},
shareUrl: url.format(shareUrl) + shariff.getReferrerTrack()
shareUrl: url.format(shareUrl) + shariff.getReferrerTrack(),
updateUrl: function(){
shareUrl.query.url = shariff.getUpdatedUrl();
return url.format(shareUrl) + shariff.getReferrerTrack();
}
};
};
5 changes: 4 additions & 1 deletion src/js/services/qzone.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ module.exports = function(shariff) {
'en': 'Share on Qzone',
'zh': '分享至QQ空间'
},
shareUrl: 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=' + url + '&title=' + title + shariff.getReferrerTrack()
shareUrl: 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=' + url + '&title=' + title + shariff.getReferrerTrack(),
updateUrl: function(){
return 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=' + shariff.getUpdatedUrl() + '&title=' + title + shariff.getReferrerTrack();
}
};
};
9 changes: 6 additions & 3 deletions src/js/services/reddit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
module.exports = function(shariff) {
var url = encodeURIComponent(shariff.getURL()),
title = encodeURIComponent(shariff.getTitle());

if ( title !== '' ) {
title = '&title=' + title;
}

return {
popup: true,
shareText: {
Expand All @@ -22,6 +22,9 @@ module.exports = function(shariff) {
'en': 'Share on Reddit',
'zh': '分享至Reddit'
},
shareUrl: 'https://reddit.com/submit?url=' + url + title + shariff.getReferrerTrack()
shareUrl: 'https://reddit.com/submit?url=' + url + title + shariff.getReferrerTrack(),
updateUrl: function(){
return 'https://reddit.com/submit?url=' + shariff.getUpdatedUrl() + title + shariff.getReferrerTrack();
}
};
};
9 changes: 6 additions & 3 deletions src/js/services/stumbleupon.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
module.exports = function(shariff) {
var url = encodeURIComponent(shariff.getURL()),
title = encodeURIComponent(shariff.getTitle());

if ( title !== '' ) {
title = '&title=' + title;
}

return {
popup: true,
shareText: {
Expand All @@ -22,6 +22,9 @@ module.exports = function(shariff) {
'en': 'Share on Stumbleupon',
'zh': '分享至Stumbleupon'
},
shareUrl: 'https://www.stumbleupon.com/submit?url=' + url + title + shariff.getReferrerTrack()
shareUrl: 'https://www.stumbleupon.com/submit?url=' + url + title + shariff.getReferrerTrack(),
updateUrl: function(){
return 'https://www.stumbleupon.com/submit?url=' + shariff.getUpdatedUrl() + title + shariff.getReferrerTrack();
}
};
};
5 changes: 4 additions & 1 deletion src/js/services/tencent-weibo.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ module.exports = function(shariff) {
'en': 'Share on tencent weibo',
'zh': '分享至腾讯微博'
},
shareUrl: 'http://v.t.qq.com/share/share.php?url=' + url + '&title=' + title + shariff.getReferrerTrack()
shareUrl: 'http://v.t.qq.com/share/share.php?url=' + url + '&title=' + title + shariff.getReferrerTrack(),
updateUrl: function(){
return 'http://v.t.qq.com/share/share.php?url=' + shariff.getUpdatedUrl() + '&title=' + title + shariff.getReferrerTrack();
}
};
};
5 changes: 4 additions & 1 deletion src/js/services/threema.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ module.exports = function(shariff) {
'tr': 'Threema\'ta paylaş',
'zh': '在Threema上分享'
},
shareUrl: 'threema://compose?text=' + encodeURIComponent(title) + '%20' + url + shariff.getReferrerTrack()
shareUrl: 'threema://compose?text=' + encodeURIComponent(title) + '%20' + url + shariff.getReferrerTrack(),
updateUrl: function(){
return 'threema://compose?text=' + encodeURIComponent(title) + '%20' + shariff.getUpdatedUrl() + shariff.getReferrerTrack();
}
};
};
6 changes: 4 additions & 2 deletions src/js/services/tumblr.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ module.exports = function(shariff) {
'tr': 'tumblr\'ta paylaş',
'zh': '在tumblr上分享'
},
shareUrl: 'http://tumblr.com/widgets/share/tool?canonicalUrl=' + url + shariff.getReferrerTrack()
shareUrl: 'http://tumblr.com/widgets/share/tool?canonicalUrl=' + url + shariff.getReferrerTrack(),
updateUrl: function(){
return 'http://tumblr.com/widgets/share/tool?canonicalUrl=' + shariff.getUpdatedUrl() + shariff.getReferrerTrack();
}
};
};

6 changes: 5 additions & 1 deletion src/js/services/twitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ module.exports = function(shariff) {
'zh': '在Twitter上分享'
},
// shareUrl: 'https://twitter.com/intent/tweet?text='+ shariff.getShareText() + '&url=' + url
shareUrl: url.format(shareUrl) + shariff.getReferrerTrack()
shareUrl: url.format(shareUrl) + shariff.getReferrerTrack(),
updateUrl: function(){
shareUrl.query.url = shariff.getUpdatedUrl();
return url.format(shareUrl) + shariff.getReferrerTrack();
}
};
};
5 changes: 4 additions & 1 deletion src/js/services/weibo.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ module.exports = function(shariff) {
'en': 'Share on weibo',
'zh': '分享至新浪微博'
},
shareUrl: 'http://service.weibo.com/share/share.php?url=' + url + '&title=' + title + shariff.getReferrerTrack()
shareUrl: 'http://service.weibo.com/share/share.php?url=' + url + '&title=' + title + shariff.getReferrerTrack(),
updateUrl: function(){
return 'http://service.weibo.com/share/share.php?url=' + shariff.getUpdatedUrl() + '&title=' + title + shariff.getReferrerTrack();
}
};
};
5 changes: 4 additions & 1 deletion src/js/services/whatsapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ module.exports = function(shariff) {
'tr': 'Whatsapp\'ta paylaş',
'zh': '在Whatsapp上分享'
},
shareUrl: 'whatsapp://send?text=' + encodeURIComponent(title) + '%20' + url + shariff.getReferrerTrack()
shareUrl: 'whatsapp://send?text=' + encodeURIComponent(title) + '%20' + url + shariff.getReferrerTrack(),
updateUrl: function(){
return 'whatsapp://send?text=' + encodeURIComponent(title) + '%20' + shariff.getUpdatedUrl() + shariff.getReferrerTrack();
}
};
};
5 changes: 4 additions & 1 deletion src/js/services/xing.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ module.exports = function(shariff) {
'nl': 'Delen op XING',
'zh': '分享至XING'
},
shareUrl: 'https://www.xing.com/social_plugins/share?url=' + url + shariff.getReferrerTrack()
shareUrl: 'https://www.xing.com/social_plugins/share?url=' + url + shariff.getReferrerTrack(),
updateUrl: function(){
return 'https://www.xing.com/social_plugins/share?url=' + shariff.getUpdatedUrl() + shariff.getReferrerTrack();
}
};
};
21 changes: 20 additions & 1 deletion src/js/shariff.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ var $ = require('jquery');
var url = require('url');

var Shariff = function(element, options) {

var self = this;

// the DOM element that will contain the buttons
this.element = element;

this.getUpdatedUrl = function(){
return global.document.location.href;
};

// Ensure elemnt is empty
$(element).empty();

Expand Down Expand Up @@ -114,6 +119,8 @@ Shariff.prototype = {

flattrCategory: null,

useUpdatedUrl: false,

// build URI from rel="canonical" or document.location
url: function() {
var url = global.document.location.href;
Expand Down Expand Up @@ -212,6 +219,7 @@ Shariff.prototype = {

var $shareLink = $('<a>')
.attr('href', service.shareUrl)
.data('name', service.name)
.append($shareText);

if (typeof service.faName !== 'undefined') {
Expand All @@ -237,8 +245,19 @@ Shariff.prototype = {
// event delegation
$buttonList.on('click', '[data-rel="popup"]', function(e) {
e.preventDefault();

var url = $(this).attr('href');

// check if changed link should be used
if (Boolean(self.options.useUpdatedUrl) === true) {
self.services.forEach(function(service) {
// find button click related service
if (service.name === $(this).data('name') && typeof service.updateUrl !== 'undefined') {
// update url of service with (p.e. via history.pushState or location.hash) updated url
url = service.updateUrl();
}
}.bind(this));
}

var windowName = '_blank';
var windowSizeX = '600';
var windowSizeY = '460';
Expand Down