function views_flag_refresh_add_js in Views Flag Refresh 6
Same name and namespace in other branches
- 7 views_flag_refresh.module \views_flag_refresh_add_js()
Adds javascript settings for the view, makes sure the core javascript and settings files
Parameters
$view: An object containing the view.
1 call to views_flag_refresh_add_js()
- views_flag_refresh_preprocess_views_view in ./
views_flag_refresh.module - Preprocess the primary theme implementation for a view.
File
- ./
views_flag_refresh.module, line 122 - Views Flag Refresh allows site administrators to configure which views are refreshed automatically via AJAX when certain flags are selected.
Code
function views_flag_refresh_add_js($view) {
static $processed;
// Only adds the core javascript files and settings once. The file isn't a
// problem, but the settings become an array if they are added more than once.
if (NULL === $processed) {
$path = drupal_get_path('module', 'views_flag_refresh');
drupal_add_js($path . '/views_flag_refresh.js');
$settings = array(
'viewsFlagRefresh' => array(
'imagePath' => base_path() . $path . '/images',
),
);
drupal_add_js($settings, 'setting');
$processed = TRUE;
}
// Gets all widget definitions.
$widgets = views_flag_refresh_widgets_get();
// Adds our view specific settings and javascript files.
$settings = array(
'viewsFlagRefresh' => array(),
);
$flags = (array) $view->display_handler
->get_option('use_ajax_flags');
foreach ($flags as $flag_name => $enabled) {
if ($enabled) {
// Gets widget information, adds javascript, CSS files if defined.
if (!($widget = $view->display_handler
->get_option('use_ajax_flags_widget'))) {
$widget = 'default';
}
if (isset($widgets[$widget]['js file'])) {
drupal_add_js($widgets[$widget]['js file']);
}
if (isset($widgets[$widget]['css file'])) {
drupal_add_css($widgets[$widget]['css file']);
}
// Adds widget information to the javascript settings.
$key = $view->name . '-' . $view->current_display;
$settings['viewsFlagRefresh']['flags'][$flag_name][$key] = array(
'themeHook' => isset($widgets[$widget]['theme hook']) ? $widgets[$widget]['theme hook'] : FALSE,
'themeHookPost' => isset($widgets[$widget]['theme hook post']) ? $widgets[$widget]['theme hook post'] : FALSE,
);
}
}
drupal_add_js($settings, 'setting');
}