Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Make share button support custom javascript (#8090)

hawm7129637279ea
diff --git a/app/assets/javascripts/discourse/lib/sharing.js.es6 b/app/assets/javascripts/discourse/lib/sharing.js.es6
index 4e57b9dfa5e..2a3b4d191b5 100644
--- a/app/assets/javascripts/discourse/lib/sharing.js.es6
+++ b/app/assets/javascripts/discourse/lib/sharing.js.es6
@@ -19,6 +19,11 @@
return "http://twitter.com/intent/tweet?url=" + encodeURIComponent(link) + "&text=" + encodeURIComponent(title);
},
+ // If provided, handle by custom javascript rather than default url open
+ clickHandler: function(link, title){
+ alert("Hello!")
+ }
+
// If true, opens in a popup of `popupHeight` size. If false it's opened in a new tab
shouldOpenInPopup: true,
popupHeight: 265
@@ -48,23 +53,27 @@ export default {
},
shareSource(source, data) {
- const url = source.generateUrl(data.url, data.title);
- const options = {
- menubar: "no",
- toolbar: "no",
- resizable: "yes",
- scrollbars: "yes",
- width: 600,
- height: source.popupHeight || 315
- };
- const stringOptions = Object.keys(options)
- .map(k => `${k}=${options[k]}`)
- .join(",");
-
- if (source.shouldOpenInPopup) {
- window.open(url, "", stringOptions);
+ if (source.clickHandler) {
+ source.clickHandler(data.url, data.title);
} else {
- window.open(url, "_blank");
+ const url = source.generateUrl(data.url, data.title);
+ const options = {
+ menubar: "no",
+ toolbar: "no",
+ resizable: "yes",
+ scrollbars: "yes",
+ width: 600,
+ height: source.popupHeight || 315
+ };
+ const stringOptions = Object.keys(options)
+ .map(k => `${k}=${options[k]}`)
+ .join(",");
+
+ if (source.shouldOpenInPopup) {
+ window.open(url, "", stringOptions);
+ } else {
+ window.open(url, "_blank");
+ }
}
},