function closeblock_ajax_settings in Close Block 7
Same name and namespace in other branches
- 6 includes/closeblock.api.inc \closeblock_ajax_settings()
Write block settings to Drupal.settings.closeblock.
1 call to closeblock_ajax_settings()
- closeblock_block_view_alter in ./
closeblock.module - Implements hook_block_view_alter().
File
- includes/
closeblock.api.inc, line 55 - Module settings functions.
Code
function closeblock_ajax_settings($data, $block) {
if (user_access('closeblock') && !empty($data['content'])) {
$theme_settings = drupal_static('closeblock_theme_settings');
$blocks = drupal_static('closeblock_blocks');
$settings = variable_get('closeblock_settings', array());
$params = (array) $block;
$block_id = theme('closeblock_block_id', $params);
if (empty($settings[$block_id]['closeblock_active'])) {
return;
}
if (!empty($settings[$block_id]['closeblock_custom'])) {
$theme_settings = array_merge($theme_settings, $settings[$block_id], array());
}
$closed = !empty($blocks[$block_id]) && !empty($theme_settings['closeblock_save']);
if (!empty($theme_settings['closeblock_count']) && $theme_settings['closeblock_count'] > 1) {
if (empty($blocks[$block_id]['count']) || $blocks[$block_id]['count'] < $theme_settings['closeblock_count']) {
if (empty($theme_settings['closeblock_frequency'])) {
$closed = 0;
}
else {
$current_time = time();
$time = strtotime($theme_settings['closeblock_frequency']) - $current_time;
if (empty($blocks[$block_id]['timestamp']) || $blocks[$block_id]['timestamp'] + $time < $current_time) {
$closed = 0;
}
}
}
}
$types = array(
1 => '',
2 => 'slideUp',
3 => 'fadeOut',
);
drupal_add_js(array(
'closeblock' => array(
$block_id => array(
'closed' => $closed,
'speed' => $theme_settings['closeblock_speed'],
'save' => $theme_settings['closeblock_save'],
'type' => $types[$theme_settings['closeblock_type']],
'module' => $params['module'],
'delta' => $params['delta'],
),
),
), array(
'type' => 'setting',
'scope' => JS_DEFAULT,
));
$path = drupal_get_path('module', 'closeblock');
drupal_add_js($path . '/theme/js/closeblock.js');
drupal_add_js(array(
'button_text' => t('@button', array(
'@button' => $theme_settings['closeblock_button_text'],
)),
), 'setting');
drupal_add_css($path . '/theme/css/closeblock.css');
}
}