@@ -15,5 +15,53 @@ window.highlightCode = (element) => {
1515
1616// Create Capitalize string
1717window . capitalize = ( string ) => string . replace ( / ^ \w / , ( c ) => c . toUpperCase ( ) ) ;
18+
1819// Create a snake case string
1920window . snakeCase = ( string ) => string && string . match ( / [ A - Z ] { 2 , } (? = [ A - Z ] [ a - z ] + [ 0 - 9 ] * | \b ) | [ A - Z ] ? [ a - z ] + [ 0 - 9 ] * | [ A - Z ] | [ 0 - 9 ] + / g) . map ( s => s . toLowerCase ( ) ) . join ( '_' ) ;
21+
22+ // Share a content to social Media
23+ const share = function ( ) {
24+ function popupCenter ( url , title , width , height ) {
25+ let popupWidth = width || 640
26+ let popupHeight = height || 440
27+ let windowLeft = window . screenLeft || window . screenX
28+ let windowTop = window . screenTop || window . screenY
29+ let windowWidth = window . innerWidth || document . documentElement . clientWidth
30+ let windowHeight = window . innerHeight || document . documentElement . clientHeight
31+ let popupLeft = windowLeft + windowWidth / 2 - popupWidth / 2
32+ let popupTop = windowTop + windowHeight / 2 - popupHeight / 2
33+ window . open ( url , title , 'scrollbars=yes, width=' + popupWidth + ', height=' + popupHeight + ', top=' + popupTop + ', left=' + popupLeft )
34+ }
35+
36+ let twitter = document . querySelector ( '.share_twitter' )
37+ if ( twitter ) {
38+ twitter . addEventListener ( 'click' , function ( e ) {
39+ e . preventDefault ( )
40+ let url = this . getAttribute ( 'data-url' )
41+ let shareUrl = 'https://twitter.com/intent/tweet?text=' + encodeURIComponent ( document . title ) + '&via=johns_corp' + '&url=' + encodeURIComponent ( url )
42+ popupCenter ( shareUrl , 'Partager sur Twitter' )
43+ } )
44+ }
45+
46+ let facebook = document . querySelector ( '.share_facebook' )
47+ if ( facebook ) {
48+ facebook . addEventListener ( 'click' , function ( e ) {
49+ e . preventDefault ( )
50+ let url = this . getAttribute ( 'data-url' )
51+ let shareUrl = 'https://facebook.com/sharer/sharer.php?u=' + encodeURIComponent ( url )
52+ popupCenter ( shareUrl , 'Partager sur Facebook' )
53+ } )
54+ }
55+
56+ let linkedin = document . querySelector ( '.share_linkedin' )
57+ if ( linkedin ) {
58+ linkedin . addEventListener ( 'click' , function ( e ) {
59+ e . preventDefault ( )
60+ let url = this . getAttribute ( 'data-url' )
61+ let shareUrl = 'https://www.linkedin.com/shareArticle?url=' + encodeURIComponent ( url )
62+ popupCenter ( shareUrl , 'Partager sur LinkedIn' )
63+ } )
64+ }
65+ }
66+
67+ share ( )
0 commit comments