Skip to content

Instantly share code, notes, and snippets.

@opi
Last active June 8, 2017 09:52
Show Gist options
  • Save opi/6078227 to your computer and use it in GitHub Desktop.
Save opi/6078227 to your computer and use it in GitHub Desktop.
Simple social links extra_field for drupal.
<?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($){
$( document ).ready(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