An awesome, light-weight module which does as expected. Can you please add additional configuration to limit the progress display bar per node or perhaps a content type.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Déjà vu created an issue. See original summary.

basvredeling’s picture

Title: Additional configuraiton » Additional configuration

If the js library is implemented within a block instead of a preprocess_html hook, you get all that stuff out of the box: display for specific users roles, node types or paths.

----

I've tried this approach but it doesn't function properly. So I've ended up hacking something into the theme instead.

/**
 * Implements template_preprocess_HOOK() for html.
 */
function MYTHEME_preprocess_html(&$variables) {
  /** @var \Drupal\Core\Routing\CurrentRouteMatch $current_route */
  $current_route = Drupal::service('current_route_match');
  $route_match = $current_route->getCurrentRouteMatch();

  // Disable the scroll progress bar on all pages except article nodes.
  $node_types = ['article'];
  if (isset($variables['#attached']['library']) && !empty($variables['#attached']['library'])) {
    foreach ($variables['#attached']['library'] as $i => $library) {
      if (substr_count($library, 'scroll_progress')) {
        if ($route_match->getRouteName() !== 'entity.node.canonical' || !in_array($route_match->getParameter('node')->bundle(), $node_types)) {
          unset($variables['#attached']['library'][$i]);
        }
      }
    }
  }
}

flocondetoile’s picture

Status: Active » Needs review
StatusFileSize
new12.14 KB
new81.36 KB

This patch add 2 new settings.

- Enable : this option allows the site builder to enable / disable the scroll progress globally. Without this option if a site builder want to disable the feature he must uninstall the module.
- Visibility conditions on the request path : you can configure the visibility based on the request path as does the condition plugin "request_path" with the possibility to negate the conditions. This settings should cover most needs.

The patch add a service helper which could permit to easily add others conditions in future if needed.

This capture show the new settings added.

new settings added

An update hook set default value to the new settings : TRUE for enable and an empty array for visibility settings, to keep current behavior.

flocondetoile’s picture

Patch #3 applies on 8.x-2.1. Looks like I need to reroll on 1.x-dev as the last commit changes the configuration name of the module settings (scroll_progress_config.settings became scroll_progress.settings). First waiting feedback from the maintainer.

flocondetoile’s picture

Path #3 uses the path_alias manager service introduced in Drupal Core 8.8 (https://www.drupal.org/node/3092086). So it needs to require Drupal Core ^8.8 minimum version. I will update the patch with #4 feedbacks.

flocondetoile’s picture

StatusFileSize
new22.7 KB

Patch #3 rerolled against 2.x-dev branch.

This patch add also another settings "Element" : The element on which we want to attach the scroll progress element. Default to body. This can be useful if for example you have a main navigation sticky and you want append the scroll progress inside this main navigation (and then in your theme you can chnage the css rule position of the scroll progress element).

This patch contains too the fix of the bug mentionned in #3205142: Markup bar-long or scroll-progress-bottom added multiple times.

Also several fix are included about :
- the missing dependency on drupalSettings for each library
- the missing config schema of the module settings
- a missing default config when the module is enabled

As the Service Helper uses the path_alias manager service introduced in Drupal Core 8.8, the minimum requirement for the module is ^8.8. The patch makes also the module compatible with Drupal 9, using core_version_requirement: ^8.8 || ^9.

flocondetoile’s picture

Opened a merge request, to be able to package the module on a Drupal 9 project.

keshavv’s picture

Status: Needs review » Reviewed & tested by the community
keshavv’s picture

Status: Reviewed & tested by the community » Fixed
keshavv’s picture

Status: Fixed » Closed (fixed)