Unverified Commit b14859ec authored by Sheetal Umesh Kumar's avatar Sheetal Umesh Kumar Committed by GitHub

Merge pull request #748 from hypothesis/share-links

Convert share dialog links to use bouncer instead of via.
parents 25d7ca13 ab9beb74
'use strict';
var VIA_PREFIX = 'https://via.hypothes.is/';
// @ngInject
function ShareDialogController($scope, $element, analytics, store) {
var self = this;
function updateViaLink(frames) {
function updateSharePageLink(frames) {
if (!frames.length) {
self.viaPageLink = '';
self.sharePageLink = '';
return;
}
// Check to see if we are on a via page. If so, we just return the URI.
if (frames[0].uri.indexOf(VIA_PREFIX) === 0) {
self.viaPageLink = frames[0].uri;
} else {
self.viaPageLink = VIA_PREFIX + frames[0].uri;
}
self.sharePageLink = 'https://hyp.is/go?url=' + encodeURIComponent(frames[0].uri);
}
var viaInput = $element[0].querySelector('.js-via');
viaInput.focus();
viaInput.select();
var shareLinkInput = $element[0].querySelector('.js-share-link');
shareLinkInput.focus();
shareLinkInput.select();
$scope.$watch(function () { return store.frames(); },
updateViaLink);
updateSharePageLink);
$scope.onShareClick = function(target){
if(target){
......
......@@ -23,20 +23,13 @@ describe('shareDialog', function () {
angular.mock.module('h');
});
it('generates new via link', function () {
it('generates new share link', function () {
var element = util.createDirective(document, 'shareDialog', {});
fakeStore.frames.returns([{ uri: 'http://example.com' }]);
var uri = 'http://example.com';
fakeStore.frames.returns([{ uri }]);
element.scope.$digest();
assert.equal(element.ctrl.viaPageLink, 'https://via.hypothes.is/http://example.com');
});
it('does not generate new via link if already on via', function () {
var element = util.createDirective(document, 'shareDialog', {});
fakeStore.frames.returns([{
uri: 'https://via.hypothes.is/http://example.com',
}]);
element.scope.$digest();
assert.equal(element.ctrl.viaPageLink, 'https://via.hypothes.is/http://example.com');
assert.equal(element.ctrl.sharePageLink,
'https://hyp.is/go?url=' + encodeURIComponent(uri));
});
it('tracks the target being shared', function(){
......
......@@ -9,27 +9,27 @@
</ul>
<div class="tab-content">
<p>Share the link below to show anyone these annotations and invite them to contribute their own.</p>
<p><input class="js-via form-input"
<p><input class="js-share-link form-input"
type="text"
ng-value="vm.viaPageLink"
ng-value="vm.sharePageLink"
readonly /></p>
<p class="share-link-icons">
<a href="https://twitter.com/intent/tweet?url={{vm.viaPageLink | urlEncode}}&hashtags=annotated"
<a href="https://twitter.com/intent/tweet?url={{vm.sharePageLink | urlEncode}}&hashtags=annotated"
target="_blank"
title="Tweet link"
class="share-link-icon h-icon-twitter"
ng-click="onShareClick('twitter')"></a>
<a href="https://www.facebook.com/sharer/sharer.php?u={{vm.viaPageLink | urlEncode}}"
<a href="https://www.facebook.com/sharer/sharer.php?u={{vm.sharePageLink | urlEncode}}"
target="_blank"
title="Share on Facebook"
class="share-link-icon h-icon-facebook"
ng-click="onShareClick('facebook')"></a>
<a href="https://plus.google.com/share?url={{vm.viaPageLink | urlEncode}}"
<a href="https://plus.google.com/share?url={{vm.sharePageLink | urlEncode}}"
target="_blank"
title="Post on Google Plus"
class="share-link-icon h-icon-google-plus"
ng-click="onShareClick('googlePlus')"></a>
<a href="mailto:?subject=Let's%20Annotate&amp;body={{vm.viaPageLink}}"
<a href="mailto:?subject=Let's%20Annotate&amp;body={{vm.sharePageLink}}"
target="_blank"
title="Share via email"
class="share-link-icon h-icon-mail"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment