Pull automatic share link copying

This commit is contained in:
Kane York 2015-07-21 17:35:03 -07:00
parent 90b85e5b23
commit 5408abd427
3 changed files with 3 additions and 13 deletions

View File

@ -1,6 +1,5 @@
{{#if controller.link}}
<h3>{{view.title}}</h3>
<span class="copy-text {{if copied "success"}}">{{i18n 'share.copied'}}</span>
{{#if date}}
<span class="date">{{displayDate}}</span>
@ -19,4 +18,3 @@
<a href {{action "close"}} aria-label='{{i18n 'share.close'}}' title='{{i18n 'share.close'}}'>{{fa-icon "times-circle"}}</a>
</div>
{{/if}}
<span class="hidden" id="copy-target"></span>

View File

@ -1,4 +1,3 @@
import copyText from 'discourse/lib/copy-text';
export default Discourse.View.extend({
templateName: 'share',
@ -36,6 +35,9 @@ export default Discourse.View.extend({
var $linkForTouch = $('#share-link .share-for-touch a');
$linkForTouch.attr('href',self.get('controller.link'));
$linkForTouch.html(self.get('controller.link'));
var range = window.document.createRange();
range.selectNode($linkForTouch[0]);
window.getSelection().addRange(range);
}
});
}
@ -63,7 +65,6 @@ export default Discourse.View.extend({
var $currentTarget = $(e.currentTarget),
$currentTargetOffset = $currentTarget.offset(),
$shareLink = $('#share-link'),
copyElement = document.getElementById('copy-target'),
url = $currentTarget.data('share-url'),
postNumber = $currentTarget.data('post-number'),
date = $currentTarget.children().data('time');
@ -94,18 +95,10 @@ export default Discourse.View.extend({
$shareLink.css({left: "" + x + "px"});
}
self.set('controller.copied', false);
const copySuccess = copyText(url, copyElement);
self.set('controller.link', url);
self.set('controller.postNumber', postNumber);
self.set('controller.date', date);
Ember.run.later(null, function() {
self.set('controller.copied', copySuccess);
}, 50);
return false;
});

View File

@ -114,7 +114,6 @@ en:
topic: 'share a link to this topic'
post: 'post #%{postNumber}'
close: 'close'
copied: 'copied to clipboard'
twitter: 'share this link on Twitter'
facebook: 'share this link on Facebook'
google+: 'share this link on Google+'