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); 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() { didInsertElement() {
this._super(); this._super();
@ -106,7 +114,15 @@ export default Ember.Component.extend({
const date = $currentTarget.children().data('time'); const date = $currentTarget.children().data('time');
this.setProperties({ postNumber, date, postId }); this.setProperties({ postNumber, date, postId });
// 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); this._showUrl($currentTarget, url);
}
return false; return false;
}); });