toolbar_anti_flicker.module in Toolbar Anti-flicker 8.2
File
toolbar_anti_flicker.module
View source
<?php
function toolbar_anti_flicker_page_attachments_alter(array &$page) {
if (!\Drupal::currentUser()
->hasPermission('access toolbar')) {
return;
}
$page['#attached']['library'][] = 'core/jquery.cookie';
}
function toolbar_anti_flicker_preprocess_html(&$variables) {
if (!\Drupal::currentUser()
->hasPermission('access toolbar')) {
return;
}
$orientation = \Drupal::request()->cookies
->get('toolbar');
$variables['attributes']['class'][] = 'toolbar-loading';
$variables['attributes']['class'][] = 'toolbar-fixed';
if ($orientation == 'vertical') {
$variables['attributes']['class'][] = 'toolbar-vertical';
}
else {
$variables['attributes']['class'][] = 'toolbar-horizontal';
}
$activeTab = \Drupal::request()->cookies
->get('toolbarActiveTab');
if (!empty($activeTab)) {
$variables['attributes']['class'][] = 'toolbar-tray-open';
}
}
function toolbar_anti_flicker_toolbar_alter(&$items) {
$wrapper_attributes =& $items['home']['#wrapper_attributes']['class'];
if (($key = array_search('hidden', $wrapper_attributes)) !== false) {
unset($wrapper_attributes[$key]);
}
}
function toolbar_anti_flicker_replace_library(array &$target_library, $key, array $replacement) {
$key_pos = array_search($key, array_keys($target_library));
if ($key_pos !== false) {
$key_pos++;
$second_array = array_splice($target_library, $key_pos);
$target_library = array_merge($target_library, $replacement, $second_array);
unset($target_library[$key]);
}
}
function toolbar_anti_flicker_library_info_alter(array &$libraries, $module) {
if ($module === 'toolbar' && isset($libraries['toolbar'])) {
$module_path = '/' . drupal_get_path('module', 'toolbar_anti_flicker') . '/';
unset($libraries['toolbar']['css']['component']['css/toolbar.module.css']);
unset($libraries['toolbar']['css']['component']['css/toolbar.menu.css']);
unset($libraries['toolbar']['css']['component']['css/toolbar.theme.css']);
$libraries['toolbar']['css']['component'][$module_path . 'css/toolbar/toolbar.module.css'] = [];
$libraries['toolbar']['css']['component'][$module_path . 'css/toolbar/toolbar.menu.css'] = [];
$libraries['toolbar']['css']['component'][$module_path . 'css/toolbar/toolbar.theme.css'] = [];
toolbar_anti_flicker_replace_library($libraries['toolbar']['js'], 'js/toolbar.js', [
$module_path . 'js/toolbar/js/toolbar.js' => [],
]);
toolbar_anti_flicker_replace_library($libraries['toolbar']['js'], 'js/views/BodyVisualView.js', [
$module_path . 'js/toolbar/js/views/BodyVisualView.js' => [],
]);
toolbar_anti_flicker_replace_library($libraries['toolbar']['js'], 'js/views/ToolbarVisualView.js', [
$module_path . 'js/toolbar/js/views/ToolbarVisualView.js' => [],
]);
toolbar_anti_flicker_replace_library($libraries['toolbar.escapeAdmin']['js'], 'js/escapeAdmin.js', [
$module_path . 'js/toolbar/js/escapeAdmin.js' => [],
]);
}
}