Commit d960c5a2 authored by Philippe Mouchel's avatar Philippe Mouchel
Browse files

Store sharers conf only if different from default

and add template and javascript feature

[refs #70720]
parent e81cb95c
/**
* @file sharer-opener.js
* Opening sharer link in new window
*/
(function ($) {
Drupal.behaviors.sharerOpener = {
attach: function (context, settings) {
$('#sharer-toolbar a', context).click(function () {
// Parse URL to get protocol
var parser = document.createElement('a');
parser.href = $(this).attr('href');
// Open popup if protocol is different from «mailto»
if (parser.protocol !== 'mailto:') {
window.open($(this).attr('href'), $(this).attr('title'), "width=640, height=480");
return false;
}
});
}
};
})(jQuery);
<?php
/**
* @file sharer-toolbar.tpl.php
* Template to present sharer toolbar
*/
?>
<ul id="sharer-toolbar">
<?php foreach ($sharers as $sid => $sharer) : ?>
<li class="shareLink__<?php print $sid; ?>">
<a href="<?php print $sharer['url'];?>" title="<?php print t($sharer['label']);?>">
<i class="<?php print $sharer['icon_class'];?>"></i><?php print t($sharer['label']);?>
</a>
</li>
<?php endforeach; ?>
</ul>
......@@ -70,22 +70,34 @@ function sharer_toolbar_config_form($form, &$form_state) {
* Sharer toolbar configuration form submit.
*/
function sharer_toolbar_config_form_submit($form, &$form_state) {
$sharers = $form_state['values']['sharers'];
$sharers_order = array();
$sharers_configuration = array();
// Get available sharers and submitted values to compare them
$available_sharers = _sharer_toolbar_get_available_sharers();
$submitted_sharers = $form_state['values']['sharers'];
// Iterate on orders to store informations
foreach ($sharers as $sid => $sharer_conf) {
foreach ($submitted_sharers as $sid => $submitted_sharer) {
// Store weight
$sharers_order[$sharer_conf['weight']] = $sid;
$sharers_order[$submitted_sharer['weight']] = $sid;
// Store configuration
// Store status
$sharers_configuration[$sid] = array(
'name' => $sharer_conf['name'],
'icon_class' => $sharer_conf['icon_class'],
'status' => $sharer_conf['status'],
'status' => $submitted_sharer['status'],
);
// And store configuration if different from default
if ($submitted_sharer['name'] != $available_sharers[$sid]['name']) {
$sharers_configuration[$sid]['name'] = $submitted_sharer['name'];
}
if ($submitted_sharer['icon_class'] != $available_sharers[$sid]['icon_class']) {
$sharers_configuration[$sid]['icon_class'] = $submitted_sharer['icon_class'];
}
if ($submitted_sharer['label'] != $available_sharers[$sid]['label']) {
$sharers_configuration[$sid]['label'] = $submitted_sharer['label'];
}
}
// Save values
......
......@@ -92,7 +92,7 @@ function sharer_toolbar_sharer_toolbar_available_sharer() {
'name' => 'Google +',
'icon_class' => 'icon-googleplus',
'url' => 'https://plus.google.com/share?url=[:shared_url:]',
'label' => 'Share on Google+',
'label' => 'Share on Google +',
),
// Twitter sharer
......@@ -117,9 +117,9 @@ function sharer_toolbar_sharer_toolbar_available_sharer() {
/**
* Implements hook_preprocess_node().
* Implements hook_process_node().
*/
function sharer_toolbar_preprocess_node(&$variables) {
function sharer_toolbar_process_node(&$variables) {
module_load_include('inc', 'sharer_toolbar');
$sharing_buttons = array();
......@@ -131,20 +131,12 @@ function sharer_toolbar_preprocess_node(&$variables) {
foreach ($active_sharers as $sid => &$sharer) {
if ($sharer['status']) {
// Merge database configuration in file configuration
// Merge file configuration to complete database configuration
$sharer = array_merge($available_sharers[$sid], $sharer);
// Transform URL
_sharer_toolbar_generate_sharer_url($sharer['url'], $variables);
// Generate button
// $ctnt = . t($sharer['label']);
// $sharing_buttons[$sid] = l($ctnt, $sharer['url'], array(
// 'html' => TRUE,
// 'attributes' => array(
// 'title' => $sharer['label'],
// ),
// ));
}
// or unset before sending array to template
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment