Skip to content

Instantly share code, notes, and snippets.

@wplit
Created August 20, 2019 06:58
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wplit/7861b18ef34ffd955b43ddcacc9ef6e8 to your computer and use it in GitHub Desktop.
Save wplit/7861b18ef34ffd955b43ddcacc9ef6e8 to your computer and use it in GitHub Desktop.
remove IDs from repeater component in Oxygen (to remove Lighthouse Error)
jQuery(".oxy-dynamic-list").find("*").removeAttr('id');
@wplit
Copy link
Author

wplit commented Nov 7, 2019

This performs much faster.. Note; this will not remove the first instance of the ID found, only the duplicates of that ID found further down the page. So the first stays in the html the 2nd, 3rd, 4th... just the duplicates are removed. This is because when it finds the first one, it doesn't yet know it has duplicates and it only runs once down the page, when it finds the 2nd one, it removes it and so on... The previous code, above, removes all IDs that have duplicates, even the very first one, but it's slower to run.

(function($){
 
  //abort if we're viewing inside builder
  if ($ ('html'). attr ('ng-app') == 'CTFrontendBuilder') 
     return;

  var ids = {};
  $('.oxygen-body [id]').each(function() {
    if (this.id && ids[this.id]) {
     $(this).removeAttr('id');
    }
    ids[this.id] = 1;
  });
  
})(jQuery);

@wpsumo
Copy link

wpsumo commented Nov 7, 2019

I do hope there is some way Oxygen can build an option to disable all ID's on the front end. Or at least turn them into classes if they need to be there. Would solve all these problems in one go.

Yeah, let's see what they figure out here since we run into the same issue over and over again. Would be great to move over to classes let user utilize ID for other purposes such as jump/anchor links.

Thanks, I'll give it a run later on!

It's not possible to do this in php to not even render specific block ID's in the frontend. Thinking about this being more suitable for performance than manipulate with jQuery. If possible.

Many workarounds in inline js now, think I will be about time to enqueue a static file so be can utilize caching.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment