function high_contrast_init in High contrast 7
Same name and namespace in other branches
- 6 high_contrast.module \high_contrast_init()
Implements hook_init().
File
- ./
high_contrast.module, line 22 - High Contrast main module file.
Code
function high_contrast_init() {
$theme_path = drupal_get_path('theme', variable_get('theme_default', NULL));
// @todo: needed?
drupal_add_css(drupal_get_path('module', 'high_contrast') . '/high_contrast.css');
$high_contrast = [
'link' => _high_contrast_link(),
];
if (_high_contrast_css_exists()) {
$high_contrast['cssFilePath'] = '/' . $theme_path . '/' . HIGH_CONTRAST_CSS_PATH;
}
else {
// @todo: should nob be written on every request.
$current_css_path = 'public://high_contrast_current.css';
file_unmanaged_save_data(_high_contrast_get_current_css_styles(), $current_css_path, FILE_EXISTS_REPLACE);
$high_contrast['cssFilePath'] = file_create_url($current_css_path);
}
// Get original logo path so we can find the img element from DOM and start
// switching with high contrast version.
// @todo: should we first try and read theme_get_setting('logo_path')?
$logoPath = theme_get_setting('logo');
if (!empty($logoPath)) {
$high_contrast['logoPath'] = theme_get_setting('logo');
}
// Set high contrast logo path.
if (_high_contrast_variable_get('high_contrast_default_logo') == 0 && _high_contrast_variable_get('high_contrast_logo_path') !== '') {
$high_contrast['highContrastLogoPath'] = file_create_url(_high_contrast_variable_get('high_contrast_logo_path'));
}
elseif (file_exists($theme_path . '/logo-hg.png')) {
$high_contrast['highContrastLogoPath'] = file_create_url($theme_path . '/logo-hg.png');
}
// Load main js as first script and after last css.
// Should be fastest execution time.
$high_contrast_min = file_get_contents(drupal_get_path('module', 'high_contrast') . '/js/high_contrast.min.js');
// Fix 'Uncaught SyntaxError: Unexpected token ILLEGAL' in Chrome.
$high_contrast_min = str_replace('id=\'high-contrast-css-placeholder\'></script>', 'id=\'high-contrast-css-placeholder\'>\\x3C/script>', $high_contrast_min);
drupal_add_js('var highContrast = ' . json_encode($high_contrast) . ';' . $high_contrast_min, [
'type' => 'inline',
'weight' => '-999',
'group' => '-999',
]);
}