-
-
Save flocondetoile/8e1d77dbb6d402540bd9 to your computer and use it in GitHub Desktop.
Simple social links extra_field for drupal.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Social share links | |
$links = array(); | |
$share_url = url('node/'.$node->nid, array('absolute' => TRUE)); | |
$links['facebook'] = array( | |
'href' => 'https://www.facebook.com/sharer/sharer.php?u='.$share_url, | |
'title' => t("Facebook"), | |
'attributes' => array( | |
'data-popup-width' => 700, | |
'data-popup-height' => 300, | |
), | |
); | |
$links['twitter'] = array( | |
'href' => 'https://twitter.com/intent/tweet?text='.$share_url, | |
'title' => t("Twitter"), | |
'attributes' => array( | |
'data-popup-width' => 550, | |
'data-popup-height' => 220, | |
), | |
); | |
$links['googleplus'] = array( | |
'href' => 'https://plus.google.com/share?url='.$share_url, | |
'title' => t("Google+"), | |
'attributes' => array( | |
'data-popup-width' => 600, | |
'data-popup-height' => 330, | |
), | |
); | |
$node->content['social_share'] = array( | |
'#prefix' => '<div class="social-share">', | |
'#suffix' => '</div>', | |
'#theme' => 'links', | |
'#links' => $links, | |
'#heading' => array( | |
'text' => t("Partager sur :"), | |
'level' => 'div', | |
'class' => array('social-share-title') | |
), | |
'#attributes' => array( | |
'class' => array('social-share-links') | |
), | |
'#attached' => array( | |
'js' => array( | |
'(function($){ | |
if ($(window).width() > 500) { | |
$(".social-share-links a").click(function(e){ | |
e.preventDefault(); | |
var h = $(this).attr("data-popup-height"), | |
w = $(this).data("popup-width"); | |
window.open( | |
$(this).attr("href"), | |
"share", | |
"top="+((screen.height-h)/2)+",left="+((screen.width-w)/2)+",width="+w+",height="+h | |
); | |
}); | |
} | |
})(jQuery);' => array('type' => 'inline') | |
) | |
) | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment