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

* FEATURE: Make share button support custom javascript

* clean code

* formatting

* formatting
This commit is contained in:
hawm 2019-09-12 23:19:43 +08:00 committed by Robin Ward
parent 67a98946b8
commit 7129637279
1 changed files with 25 additions and 16 deletions

View File

@ -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");
}
}
},