mirror of
https://github.com/discourse/discourse.git
synced 2025-02-05 02:00:45 +08:00
46 lines
1.3 KiB
JavaScript
46 lines
1.3 KiB
JavaScript
/**
|
|
If you want to add a new sharing source to Discourse, you can do so like this:
|
|
|
|
```javascript
|
|
import Sharing from 'discourse/lib/sharing';
|
|
|
|
Sharing.addSource({
|
|
|
|
// This id must be present in the `share_links` site setting too
|
|
id: 'twitter',
|
|
|
|
// The icon that will be displayed, choose between icon name `icon` and custom HTML `htmlIcon`.
|
|
// When both provided, prefer `icon`
|
|
icon: 'twitter-square'
|
|
htmlIcon: '<img src="example.com/example.jpg">',
|
|
|
|
// A callback for generating the remote link from the `link` and `title`
|
|
generateUrl: function(link, title) {
|
|
return "http://twitter.com/intent/tweet?url=" + encodeURIComponent(link) + "&text=" + encodeURIComponent(title);
|
|
},
|
|
|
|
// If true, opens in a popup of `popupHeight` size. If false it's opened in a new tab
|
|
shouldOpenInPopup: true,
|
|
popupHeight: 265
|
|
});
|
|
```
|
|
**/
|
|
|
|
var _sources = {};
|
|
|
|
export default {
|
|
addSource(source) {
|
|
// backwards compatibility for plugins
|
|
if (source.faIcon) {
|
|
source.icon = source.faIcon.replace('fa-', '');
|
|
delete source.faIcon;
|
|
}
|
|
|
|
_sources[source.id] = source;
|
|
},
|
|
|
|
activeSources(linksSetting) {
|
|
return linksSetting.split('|').map(s => _sources[s]).compact();
|
|
}
|
|
};
|