diff --git a/back_to_top.module b/back_to_top.module index 2acd362..4b09141 100644 --- a/back_to_top.module +++ b/back_to_top.module @@ -1,5 +1,11 @@ get(); - $button_settings = array( + $button_settings = [ 'back_to_top_prevent_on_mobile' => $settings['back_to_top_prevent_on_mobile'], 'back_to_top_prevent_in_admin' => $settings['back_to_top_prevent_in_admin'], 'back_to_top_button_type' => $settings['back_to_top_button_type'], 'back_to_top_button_text' => $settings['back_to_top_button_text'], - ); + ]; if ($settings['back_to_top_prevent_on_mobile'] && (is_mobile())) { return FALSE; } @@ -20,18 +26,15 @@ function back_to_top_page_attachments(array &$attachments) { return FALSE; } if ($settings['back_to_top_prevent_in_front'] && (\Drupal::service('path.matcher') - ->isFrontPage()) + ->isFrontPage()) ) { return FALSE; } - //$attachments['#attached']['library'][] = 'core/jquery.ui.core'; - //$attachments['#attached']['library'][] = 'core/jquery.ui.effects.core'; - $attachments['#attached']['library'][] = 'back_to_top/back_to_top_js'; $attachments['#attached']['drupalSettings']['back_to_top']['back_to_top_button_trigger'] = $settings['back_to_top_button_trigger']; - // Add stylesheet for image or text/css button + // Add stylesheet for image or text/css button. if (($settings['back_to_top_button_type']) == "text") { $attachments['#attached']['library'][] = 'back_to_top/back_to_top_text'; } @@ -41,7 +44,7 @@ function back_to_top_page_attachments(array &$attachments) { $css = ''; $hover_css = ''; - // Check variables and add placement + // Check variables and add placement. if ($settings['back_to_top_button_place'] == 2) { $css .= "left: 10px;"; } @@ -66,15 +69,15 @@ function back_to_top_page_attachments(array &$attachments) { if ($settings['back_to_top_button_place'] == 9) { $css .= "top: 50%; left: 50%; margin-left: -50px;"; } - // Check variables and add color from settings - this code could be done a bit nicer + // Check variables and add color from settings - this code could be done a bit nicer. if (($settings['back_to_top_button_type'] == "text") && ($settings['back_to_top_bg_color'] !== '#F7F7F7')) { $css .= "background: " . $settings['back_to_top_bg_color'] . ";"; } if (($settings['back_to_top_button_type'] == "text") && ($settings['back_to_top_border_color'] !== '#CCCCCC')) { - $css .= "border-color: " . $settings['back_to_top_bg_color'] . ";"; + $css .= "border-color: " . $settings['back_to_top_border_color'] . ";"; } if (($settings['back_to_top_button_type'] == "text") && ($settings['back_to_top_hover_color'] !== '#EEEEEE')) { - $hover_css .= "#backtotop:hover { background: " . $settings['back_to_top_hover_color'] . "; border-color: " . $settings['back_to_top_hover_color'] . "; }"; + $hover_css .= "#backtotop:hover { background: " . $settings['back_to_top_hover_color'] . "; border-color: " . $settings['back_to_top_border_color'] . "; }"; } if (($settings['back_to_top_button_type'] == "text") && ($settings['back_to_top_text_color'] !== '#333333')) { $css .= "color: " . $settings['back_to_top_text_color'] . ";"; @@ -84,18 +87,20 @@ function back_to_top_page_attachments(array &$attachments) { $attachments['#attached']['html_head'][] = [ [ '#tag' => 'style', - '#value' => '#backtotop {' . $css . '}' . $hover_css, + '#value' => 'body #backtotop {' . $css . '}' . $hover_css, ], - 'css' + 'css', ]; } - // Add settings to js + // Add settings to js. $attachments['#attached']['drupalSettings']['back_to_top'] += $button_settings; } /** - * Check if mobile or touch device with PHP so javascript and css isn't included in that case + * Check if mobile or touch device with PHP. + * + * So javascript and css isn't included in that case. */ function is_mobile() { // Check for mobile device using Browscap module if it is available. @@ -113,7 +118,7 @@ function is_mobile() { return TRUE; } if (isset($_SERVER["HTTP_USER_AGENT"])) { - $user_agents = array( + $user_agents = [ "midp", "j2me", "iphone", @@ -183,8 +188,8 @@ function is_mobile() { "ipad", "android", "ipod", - "webos" - ); + "webos", + ]; foreach ($user_agents as $user_string) { if (preg_match("/" . $user_string . "/i", strtolower($_SERVER["HTTP_USER_AGENT"]))) { @@ -196,7 +201,9 @@ function is_mobile() { } /** - * Check if page viewed is in admin section or a node/edit for possible option to not include javascript and css in that case + * Check if page viewed is in admin section or a node/edit for possible option. + * + * To not include javascript and css in that case. */ function is_adminpage() { $route = \Drupal::routeMatch()->getRouteObject(); @@ -211,11 +218,11 @@ function is_adminpage() { /** * Implements hook_help(). */ -function back_to_top_help($route_name, \Drupal\Core\Routing\RouteMatchInterface $route_match) { +function back_to_top_help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.back_to_top': $text = file_get_contents(dirname(__FILE__) . "/README.txt"); - if (! \Drupal::moduleHandler()->moduleExists('markdown')) { + if (!\Drupal::moduleHandler()->moduleExists('markdown')) { return '
' . $text . '
'; } else {