Same name and namespace in other branches
  1. 7.x-1.x colorbox.module \_colorbox_doheader() 1 comment

Loads the various js and css files.

1 call to _colorbox_doheader()
colorbox_init in ./colorbox.module
Implements hook_init().

File

./colorbox.module, line 199

Code

function _colorbox_doheader() {
    static $already_added = FALSE;
    if ($already_added) {
        // Don't add the JavaScript and CSS multiple times.
        return;
    }
    // Insert options and translated strings as JavaScript settings.
    if (variable_get('colorbox_custom_settings_activate', 0)) {
        $js_settings = array(
            'transition' => variable_get('colorbox_transition_type', 'elastic'),
            'speed' => variable_get('colorbox_transition_speed', 350),
            'opacity' => variable_get('colorbox_opacity', '0.85'),
            'slideshow' => variable_get('colorbox_slideshow', 0) ? TRUE : FALSE,
            'slideshowAuto' => variable_get('colorbox_slideshowauto', 1) ? TRUE : FALSE,
            'slideshowSpeed' => variable_get('colorbox_slideshowspeed', 2500),
            'slideshowStart' => variable_get('colorbox_text_start', 'start slideshow'),
            'slideshowStop' => variable_get('colorbox_text_stop', 'stop slideshow'),
            'current' => strip_tags(variable_get('colorbox_text_current', '{current} of {total}')),
            'previous' => strip_tags(variable_get('colorbox_text_previous', '« Prev')),
            'next' => strip_tags(variable_get('colorbox_text_next', 'Next »')),
            'close' => strip_tags(variable_get('colorbox_text_close', 'Close')),
            'overlayClose' => variable_get('colorbox_overlayclose', 1) ? TRUE : FALSE,
            'returnFocus' => variable_get('colorbox_returnfocus', 1) ? TRUE : FALSE,
            'maxWidth' => variable_get('colorbox_maxwidth', '98%'),
            'maxHeight' => variable_get('colorbox_maxheight', '98%'),
            'initialWidth' => variable_get('colorbox_initialwidth', '300'),
            'initialHeight' => variable_get('colorbox_initialheight', '250'),
            'fixed' => variable_get('colorbox_fixed', 1) ? TRUE : FALSE,
            'scrolling' => variable_get('colorbox_scrolling', 1) ? TRUE : FALSE,
            'mobiledetect' => variable_get('colorbox_mobile_detect', 1) ? TRUE : FALSE,
            'mobiledevicewidth' => variable_get('colorbox_mobile_device_width', '480px'),
        );
    }
    else {
        $js_settings = array(
            'opacity' => '0.85',
            'current' => t('{current} of {total}'),
            'previous' => t('« Prev'),
            'next' => t('Next »'),
            'close' => t('Close'),
            'maxWidth' => '98%',
            'maxHeight' => '98%',
            'fixed' => TRUE,
            'mobiledetect' => variable_get('colorbox_mobile_detect', 1) ? TRUE : FALSE,
            'mobiledevicewidth' => variable_get('colorbox_mobile_device_width', '480px'),
        );
    }
    // Determine URL path to public files.
    $js_settings['file_public_path'] = base_path() . variable_get('file_public_path', conf_path() . '/files');
    $js_settings['specificPagesDefaultValue'] = "admin*\nimagebrowser*\nimg_assist*\nimce*\nnode/add/*\nnode/*/edit\nprint/*\nprintpdf/*\nsystem/ajax\nsystem/ajax/*";
    $path = drupal_get_path('module', 'colorbox');
    $style = variable_get('colorbox_style', 'default');
    // Give other modules the possibility to override Colorbox settings and style.
    $data =& $js_settings;
    drupal_alter('colorbox_settings', $data, $style);
    drupal_add_js(array(
        'colorbox' => $js_settings,
    ), array(
        'type' => 'setting',
        'scope' => JS_DEFAULT,
    ));
    // Add and initialize the Colorbox and DOMPurify libraries.
    $variant = variable_get('colorbox_compression_type', 'minified');
    if (module_exists('libraries')) {
        $colorbox_library = libraries_detect('colorbox');
        $dompurify_library = libraries_detect('DOMPurify');
        if ($colorbox_library['installed'] && version_compare($colorbox_library['version'], COLORBOX_MIN_PLUGIN_VERSION, '>=')) {
            libraries_load('colorbox', $variant);
        }
        if ($dompurify_library['installed'] && version_compare($dompurify_library['version'], COLORBOX_DOMPURIFY_MIN_PLUGIN_VERSION, '>=')) {
            libraries_load('DOMPurify', 'minified');
        }
    }
    drupal_add_js($path . '/js/colorbox.js');
    // Add JS and CSS based on selected style.
    switch ($style) {
        case 'none':
            break;
        case 'default':
        case 'plain':
        case 'stockholmsyndrome':
            drupal_add_css($path . '/styles/' . $style . '/colorbox_style.css');
            drupal_add_js($path . '/styles/' . $style . '/colorbox_style.js');
            break;
        default:
            drupal_add_css($style . '/colorbox.css');
    }
    if (variable_get('colorbox_load', 0)) {
        drupal_add_js($path . '/js/colorbox_load.js');
    }
    if (variable_get('colorbox_inline', 0)) {
        drupal_add_js($path . '/js/colorbox_inline.js');
    }
    $already_added = TRUE;
}