2 * Provides buttons to share a page through multiple social community sites.
5 * @copyright 2001-2018 WoltLab GmbH
6 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
7 * @module WoltLabSuite/Core/Ui/Message/Share
9 define(['EventHandler'], function(EventHandler
) {
13 * @exports WoltLabSuite/Core/Ui/Message/Share
20 var title
= elBySel('meta[property="og:title"]');
21 if (title
!== null) this._pageDescription
= encodeURIComponent(title
.content
);
22 var url
= elBySel('meta[property="og:url"]');
23 if (url
!== null) this._pageUrl
= encodeURIComponent(url
.content
);
25 elBySelAll('.jsMessageShareButtons', null, (function(container
) {
26 container
.classList
.remove('jsMessageShareButtons');
30 link
: elBySel('.jsShareFacebook', container
),
31 share
: (function() { this._share('facebook', 'https://www.facebook.com/sharer.php?u={pageURL}&t={text}', true); }).bind(this)
34 link
: elBySel('.jsShareGoogle', container
),
35 share
: (function() { this._share('google', 'https://plus.google.com/share?url={pageURL}', false); }).bind(this)
38 link
: elBySel('.jsShareReddit', container
),
39 share
: (function() { this._share('reddit', 'https://ssl.reddit.com/submit?url={pageURL}', false); }).bind(this)
42 link
: elBySel('.jsShareTwitter', container
),
43 share
: (function() { this._share('twitter', 'https://twitter.com/share?url={pageURL}&text={text}', false); }).bind(this)
46 link
: elBySel('.jsShareLinkedIn', container
),
47 share
: (function() { this._share('linkedIn', 'https://www.linkedin.com/cws/share?url={pageURL}', false); }).bind(this)
50 link
: elBySel('.jsSharePinterest', container
),
51 share
: (function() { this._share('pinterest', 'https://www.pinterest.com/pin/create/link/?url={pageURL}&description={text}', false); }).bind(this)
54 link
: elBySel('.jsShareXing', container
),
55 share
: (function() { this._share('xing', 'https://www.xing.com/social_plugins/share?url={pageURL}', false); }).bind(this)
58 link
: elBySel('.jsShareWhatsApp', container
),
60 window
.location
.href
= 'https://api.whatsapp.com/send?text=' + this._pageDescription
+ '%20' + this._pageUrl
;
65 EventHandler
.fire('com.woltlab.wcf.message.share', 'shareProvider', {
68 pageDescription
: this._pageDescription
,
69 pageUrl
: this._pageUrl
72 for (var provider
in providers
) {
73 if (providers
.hasOwnProperty(provider
)) {
74 if (providers
[provider
].link
!== null) {
75 providers
[provider
].link
.addEventListener(WCF_CLICK_EVENT
, providers
[provider
].share
);
82 _share: function(objectName
, url
, appendURL
) {
83 window
.open(url
.replace(/\{pageURL}/, this._pageUrl
).replace(/\{text}/, this._pageDescription
+ (appendURL
? "%20" + this._pageUrl
: "")), objectName
, 'height=600,width=600');