Skip to content

Commit

Permalink
client: make sharers more flexible
Browse files Browse the repository at this point in the history
  • Loading branch information
jtojnar committed Apr 23, 2018
1 parent 6cd9feb commit 0d75b5c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 28 deletions.
16 changes: 16 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@
### API changes
- `tags` attribute is now consistently array of strings, numbers are numbers and booleans are booleans.

### Customization changes
- `selfoss.shares.register` changed its signature: it no longer takes a boolean argument, and the callback is expected to open a window itself, instead of returning a URL. For example, if you previously had
```javascript
selfoss.shares.register('moo', 'm', true, function(url, title) {
return 'http://moo.foobar/share?u=' + encodeURIComponent(url) + '&t=' + encodeURIComponent(title);
});
```

in your `user.js` file, you will need to change it to

```javascript
selfoss.shares.register('moo', 'm', function(url, title) {
window.open('http://moo.foobar/share?u=' + encodeURIComponent(url) + '&t=' + encodeURIComponent(title));
});
```

### Other changes
- Removed broken instapaper scraping from Reddit spout ([#1033](https://github.com/SSilence/selfoss/pull/1033))

Expand Down
49 changes: 21 additions & 28 deletions public/js/selfoss-shares.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,48 @@
selfoss.shares = {
initialized: false,
urlBuilders: {},
openInNewWindows: {},
sharers: {},
names: {},
enabledShares: '',

init: function(enabledShares) {
this.enabledShares = enabledShares;
this.initialized = true;

this.register('delicious', 'd', true, function(url, title) {
return 'https://delicious.com/save?url=' + encodeURIComponent(url) + '&title=' + encodeURIComponent(title);
this.register('delicious', 'd', function(url, title) {
window.open('https://delicious.com/save?url=' + encodeURIComponent(url) + '&title=' + encodeURIComponent(title));
});
this.register('googleplus', 'g', true, function(url) {
return 'https://plus.google.com/share?url=' + encodeURIComponent(url);
this.register('googleplus', 'g', function(url) {
window.open('https://plus.google.com/share?url=' + encodeURIComponent(url));
});
this.register('twitter', 't', true, function(url, title) {
return 'https://twitter.com/intent/tweet?source=webclient&text=' + encodeURIComponent(title) + ' ' + encodeURIComponent(url);
this.register('twitter', 't', function(url, title) {
window.open('https://twitter.com/intent/tweet?source=webclient&text=' + encodeURIComponent(title) + ' ' + encodeURIComponent(url));
});
this.register('facebook', 'f', true, function(url, title) {
return 'https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(url) + '&t=' + encodeURIComponent(title);
this.register('facebook', 'f', function(url, title) {
window.open('https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(url) + '&t=' + encodeURIComponent(title));
});
this.register('pocket', 'p', true, function(url, title) {
return 'https://getpocket.com/save?url=' + encodeURIComponent(url) + '&title=' + encodeURIComponent(title);
this.register('pocket', 'p', function(url, title) {
window.open('https://getpocket.com/save?url=' + encodeURIComponent(url) + '&title=' + encodeURIComponent(title));
});
this.register('wallabag', 'w', true, function(url) {
this.register('wallabag', 'w', function(url) {
if ($('#config').data('wallabag_version') == 2) {
return $('#config').data('wallabag') + '/bookmarklet?url=' + encodeURIComponent(url);
window.open($('#config').data('wallabag') + '/bookmarklet?url=' + encodeURIComponent(url));
} else {
return $('#config').data('wallabag') + '/?action=add&url=' + btoa(url);
window.open($('#config').data('wallabag') + '/?action=add&url=' + btoa(url));
}
});
this.register('wordpress', 's', true, function(url, title) {
return $('#config').data('wordpress') + '/wp-admin/press-this.php?u=' + encodeURIComponent(url) + '&t=' + encodeURIComponent(title);
this.register('wordpress', 's', function(url, title) {
window.open($('#config').data('wordpress') + '/wp-admin/press-this.php?u=' + encodeURIComponent(url) + '&t=' + encodeURIComponent(title));
});
this.register('mail', 'e', false, function(url, title) {
return 'mailto:?body=' + encodeURIComponent(url) + '&subject=' + encodeURIComponent(title);
this.register('mail', 'e', function(url, title) {
document.location.href = 'mailto:?body=' + encodeURIComponent(url) + '&subject=' + encodeURIComponent(title);
});
},

register: function(name, id, openInNewWindow, urlBuilder) {
register: function(name, id, sharer) {
if (!this.initialized) {
return false;
}
this.urlBuilders[name] = urlBuilder;
this.openInNewWindows[name] = openInNewWindow;
this.sharers[name] = sharer;
this.names[id] = name;
return true;
},
Expand All @@ -63,12 +61,7 @@ selfoss.shares = {
},

share: function(name, url, title) {
url = this.urlBuilders[name](url, title);
if (this.openInNewWindows[name]) {
window.open(url);
} else {
document.location.href = url;
}
this.sharers[name](url, title);
},

buildLinks: function(shares, linkBuilder) {
Expand Down

0 comments on commit 0d75b5c

Please sign in to comment.