Use a theme function to handle markup in progress.js

Created on 7 February 2014, about 11 years ago
Updated 22 April 2025, 13 days ago

Problem/Motivation

The markup for the initial state of the progress bar is inside progress-bar.html.twg:

<div id="progress" class="progress">
  {% if label %}
    <div class="progress__label">{{ label }}</div>
  {% endif %}
  <div class="progress__track"><div class="progress__bar" style="width: {{ percent }}%"></div></div>
  <div class="progress__percentage">{{ percent }}%</div>
  <div class="progress__description">{{ message }}</div>
</div>

The markup for each 'update' of the progress bar added as a string inside of progress.js:

this.element = $('<div class="progress" aria-live="polite"></div>').attr('id', id);
    this.element.html('<div class="progress__label">&nbsp;</div>' +
      '<div class="progress__track"><div class="progress__bar"></div></div>' +
      '<div class="progress__percentage"></div>' +
      '<div class="progress__description">&nbsp;</div>');

If a theme wants to change the mark up of the progress bar they must do it in two places, which is not obvious. It's also more complex and potentially dangerous to change the mark up string in the the javascript:

setProgress: function (percentage, message, label) {
      if (percentage >= 0 && percentage <= 100) {
        $(this.element).find('div.progress__bar').css('width', percentage + '%');
        $(this.element).find('div.progress__percentage').html(percentage + '%');
      }
      $('div.progress__description', this.element).html(message);
      $('div.progress__label', this.element).html(label);
      if (this.updateCallback) {
        this.updateCallback(percentage, message, this);
      }
    },

To update the progress bar the javascript looks for specific classes in mark up/

Proposed resolution

This is a fun excuse to experiment with Twig.js. If we loaded progress-bar.html.twig on the front-end we would cut out the maintenance burden of specifying the code in two places as well as making it easy for themes to change the mark up.

We can also use this to make the JS less dependant on these specific progress bar classes but just passing the variables through the template each time instead of search for classes in the mark up.

Remaining tasks

  • Discuss
  • Write a patch

User interface changes

None

API changes

None?

✨ Feature request
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component

javascript

Created by

πŸ‡¬πŸ‡§United Kingdom lewisnyman Nomadic

Live updates comments and jobs are added and updated live.
  • stale-issue-cleanup

    To track issues in the developing policy for closing stale issues, [Policy, no patch] closing older issues

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thank you for sharing your idea for improving Drupal.

    We are working to decide if this proposal meets the Criteria for evaluating proposed changes. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or there is no community support. Your thoughts on this will allow a decision to be made.

    Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

    Thanks!

Production build 0.71.5 2024