scroll_to_top.module in scroll to top 8.0
Same filename and directory in other branches
Provide scroll to top link.
File
scroll_to_top.moduleView source
<?php
/**
* @file
* Provide scroll to top link.
*/
/**
* Implementation of hook_preprocess_page().
*/
function scroll_to_top_preprocess_page(&$variables) {
$theme = \Drupal::theme()
->getActiveTheme()
->getName();
$admin_theme = \Drupal::config('system.theme')
->get('admin');
$config = \Drupal::config('scroll_to_top.settings');
if ($config
->get('scroll_to_top_enable_admin_theme') == TRUE || $config
->get('scroll_to_top_enable_admin_theme') == FALSE && $theme != $admin_theme) {
$variables['#attached']['library'][] = 'scroll_to_top/scroll_to_top';
//building the css style
$position = "";
// Button position
if ($config
->get('scroll_to_top_position', 1) == 1) {
$position = "#back-top { right:40px; }";
}
if ($config
->get('scroll_to_top_position') == 3) {
$position = $position = "#back-top { left:50%;margin:0px;}";
}
// Display label
if ($config
->get('scroll_to_top_display_text') == FALSE) {
$display = "span#link {display : none;}";
}
else {
$display = "";
}
// background color on hover
$bgcolor = "#back-top span#button { background-color: " . $config
->get('scroll_to_top_bg_color_out') . ";}";
$bgcolor .= " #back-top span#button:hover {opacity:1;filter:alpha(opacity = 1);background-color: " . $config
->get('scroll_to_top_bg_color_hover') . ";}";
$css = $position;
$css .= $bgcolor;
$css .= $display;
$variables['#attached']['html_head'][] = [
[
'#tag' => 'style',
'#value' => '.' . $css . '',
],
'scroll_to_top_new_css',
];
$variables['#attached']['drupalSettings']['scroll_to_top']['label'] = $config
->get('scroll_to_top_label');
}
// end if
}
// end scroll_to_top_page_build
Functions
Name![]() |
Description |
---|---|
scroll_to_top_preprocess_page | Implementation of hook_preprocess_page(). |