FEATURE: Use new WebShare API on supported platforms

This commit is contained in:
Rafael dos Santos Silva 2017-09-25 19:15:28 -03:00
parent b0eab6756d
commit 796e1d4c17
1 changed files with 17 additions and 1 deletions

View File

@ -81,6 +81,14 @@ export default Ember.Component.extend({
Ember.run.scheduleOnce('afterRender', this, this._focusUrl);
},
_webShare(url) {
// We can pass title and text too, but most share targets do their own oneboxing
navigator.share({
url: url
})
.catch((error) => console.warn('Error sharing', error));
},
didInsertElement() {
this._super();
@ -106,7 +114,15 @@ export default Ember.Component.extend({
const date = $currentTarget.children().data('time');
this.setProperties({ postNumber, date, postId });
this._showUrl($currentTarget, url);
// use native webshare only when the user clicks on the "chain" icon
// navigator.share needs HTTPS, returns undefined on HTTP
if (navigator.share && !$currentTarget.hasClass('post-date')) {
this._webShare(url);
} else {
this._showUrl($currentTarget, url);
}
return false;
});