33
44define ( 'share' , [ 'hooks' ] , function ( hooks ) {
55 const module = { } ;
6+ const baseUrl = window . location . protocol + '//' + window . location . host ;
67
78 module . addShareHandlers = function ( name ) {
8- const baseUrl = window . location . protocol + '//' + window . location . host ;
9-
109 function openShare ( url , urlToPost , width , height ) {
11- window . open ( url + encodeURIComponent ( baseUrl + config . relative_path + urlToPost ) , '_blank' , 'width=' + width + ',height=' + height + ',scrollbars=no,status=no' ) ;
10+ window . open ( url , '_blank' , 'width=' + width + ',height=' + height + ',scrollbars=no,status=no' ) ;
1211 hooks . fire ( 'action:share.open' , {
1312 url : url ,
1413 urlToPost : urlToPost ,
@@ -32,11 +31,36 @@ define('share', ['hooks'], function (hooks) {
3231 } ) ;
3332
3433 addHandler ( '[component="share/twitter"]' , function ( ) {
35- return openShare ( 'https://twitter.com/intent/tweet?text=' + encodeURIComponent ( name ) + '&url=' , getPostUrl ( $ ( this ) ) , 550 , 420 ) ;
34+ const postUrl = getPostUrl ( $ ( this ) ) ;
35+ const twitter_url = `https://twitter.com/intent/tweet?text=${ encodeURIComponent ( name ) } &url=${ encodeURIComponent ( postUrl ) } ` ;
36+ return openShare ( twitter_url , postUrl , 550 , 420 ) ;
3637 } ) ;
3738
3839 addHandler ( '[component="share/facebook"]' , function ( ) {
39- return openShare ( 'https://www.facebook.com/sharer/sharer.php?u=' , getPostUrl ( $ ( this ) ) , 626 , 436 ) ;
40+ const postUrl = getPostUrl ( $ ( this ) ) ;
41+ const facebook_url = `https://www.facebook.com/sharer/sharer.php?u=${ encodeURIComponent ( postUrl ) } ` ;
42+ return openShare ( facebook_url , postUrl , 626 , 436 ) ;
43+ } ) ;
44+
45+ addHandler ( '[component="share/whatsapp"]' , function ( ) {
46+ const postUrl = getPostUrl ( $ ( this ) ) ;
47+ const message = encodeURIComponent ( name ) + ' - ' + encodeURIComponent ( postUrl ) ;
48+ const whatsapp_url = config . useragent . isMobile ?
49+ `whatsapp://send?text=${ message } ` :
50+ `https://wa.me/?text=${ message } ` ;
51+ return openShare ( whatsapp_url , postUrl , 626 , 436 ) ;
52+ } ) ;
53+
54+ addHandler ( '[component="share/telegram"]' , function ( ) {
55+ const postUrl = getPostUrl ( $ ( this ) ) ;
56+ const telegram_url = `https://t.me/share/url?text=${ encodeURIComponent ( name ) } &url=${ encodeURIComponent ( postUrl ) } ` ;
57+ return openShare ( telegram_url , postUrl , 626 , 436 ) ;
58+ } ) ;
59+
60+ addHandler ( '[component="share/linkedin"]' , function ( ) {
61+ const postUrl = getPostUrl ( $ ( this ) ) ;
62+ const linkedin_url = `https://www.linkedin.com/sharing/share-offsite/?url=${ encodeURIComponent ( postUrl ) } ` ;
63+ return openShare ( linkedin_url , postUrl , 626 , 436 ) ;
4064 } ) ;
4165
4266 hooks . fire ( 'action:share.addHandlers' , { openShare : openShare } ) ;
@@ -48,7 +72,8 @@ define('share', ['hooks'], function (hooks) {
4872
4973 function getPostUrl ( clickedElement ) {
5074 const pid = parseInt ( clickedElement . parents ( '[data-pid]' ) . attr ( 'data-pid' ) , 10 ) ;
51- return '/post' + ( pid ? '/' + ( pid ) : '' ) ;
75+ const path = '/post' + ( pid ? '/' + ( pid ) : '' ) ;
76+ return baseUrl + config . relative_path + path ;
5277 }
5378
5479 return module ;
0 commit comments