Custom background using "Custom Class" + "Custom CSS"?
-
Actually I've made it more generic so I can easily add CSS to multiple categories:
<script> $(window).on('action:ajaxify.contentLoaded', function(){ if (ajaxify.data && ajaxify.data.cid){ $('body').addClass('categoryid_'+ajaxify.data.cid); } }); </script>
Then just edit
.categoryid_16{.....}
in the custom CSS. -
Adding a one on the next start event should work I think.
</script> $(window).on('action:ajaxify.contentLoaded', function(){ if (ajaxify.data && ajaxify.data.cid){ $('body').addClass('categoryid_'+ajaxify.data.cid); $(window).one('action:ajaxify.start', function(){ $('body').removeClass('categoryid-'+ajaxify.data.cid); }); } }); </script>
-
Went with this:
<script> $(window).on('action:ajaxify.contentLoaded', function(){ $("body").removeClass (function (index, css) { return (css.match (/\bcategoryid_\S+/g) || []).join(' '); }); if (ajaxify.data && ajaxify.data.cid){ $('body').addClass('categoryid_'+ajaxify.data.cid); } }); </script>
-
@yariplus said:
Adding a one on the next start event should work I think.
</script> $(window).on('action:ajaxify.contentLoaded', function(){ if (ajaxify.data && ajaxify.data.cid){ $('body').addClass('categoryid_'+ajaxify.data.cid); $(window).one('action:ajaxify.start', function(){ $('body').removeClass('categoryid-'+ajaxify.data.cid); }); } }); </script>
Testing shows that works too - but is there any way the removeClass() could fail to get called even though the body retains the class? (e.g. a refresh doesn't count as not calling it, because the classes would get reset anyway.)
Copyright © 2024 NodeBB | Contributors