If share url returned is false or undefined, do nothing#1017
Closed
bbeardsley wants to merge 1 commit intofossar:masterfrom
Closed
If share url returned is false or undefined, do nothing#1017bbeardsley wants to merge 1 commit intofossar:masterfrom
bbeardsley wants to merge 1 commit intofossar:masterfrom
Conversation
Member
|
Could you clarify when would the share url be false or undefined? |
Contributor
Author
|
This would allow me to have a custom function to do my own thing rather than return a url and do the default goto url behavior. For example I want to invoke the android native share api so in my user.js I have: |
Member
|
We could probably get away with something like this: --- a/public/js/selfoss-shares.js
+++ b/public/js/selfoss-shares.js
@@ -1,7 +1,6 @@
selfoss.shares = {
initialized: false,
- urlBuilders: {},
- openInNewWindows: {},
+ sharers: {},
names: {},
enabledShares: '',
@@ -9,42 +8,41 @@
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;
},
@@ -63,12 +61,7 @@
},
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) { |
Contributor
Author
|
Yes, I started down that path but that will break everyone's user.js if they have custom shares registered. |
Member
|
I think it is pretty rare and easy to fix. Listing it in changelog should be enough. |
Member
|
Closed in 0d75b5c. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.