Guest User

Progress Knight JS (observe current progress bars)

a guest
Jan 3rd, 2021
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* add current progress bar selector to target with CSS */
  2. $(".progress-bar").has("div.current").addClass("current-pb");
  3.  
  4. // mutation observer instance
  5. var target = $("div.progress-fill");
  6. var observer = new MutationObserver(function(mutations) {
  7.     mutations.forEach(function(mutation) {
  8.         if (mutation.attributeName === "class") {
  9.             var attributeValue = $(mutation.target).prop(mutation.attributeName);
  10.             if ($(mutation.target).hasClass("current")) {
  11.                 $(mutation.target).parent().addClass("current-pb");
  12.             } else {
  13.                 $(mutation.target).parent().removeClass("current-pb");
  14.             }
  15.         }
  16.     });
  17. });
  18. // observe all progress bars
  19. var i;
  20. for (i = 0; i < target.length; i++) {
  21.     observer.observe(target[i], { attributes: true });
  22. }
Advertisement
Add Comment
Please, Sign In to add comment