onbrandutilityfunctions
Advanced tools
Comparing version
{ | ||
"name": "onbrandutilityfunctions", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "A collection of useful reusable functions for working with uberflip hubs, to be included on an as-needed basis.", | ||
@@ -5,0 +5,0 @@ "main": "scripts.js", |
@@ -473,7 +473,25 @@ /** | ||
/** | ||
* Adds helpful body classes based on content type to make styling easier. | ||
*/ | ||
exports.helpfulClasses = function() { | ||
//An array to keep track of what content types are used (ensures we are dynamic, no hardcoded types) | ||
const typeArray = []; | ||
//the function to run on page change/load | ||
/** | ||
* Removes all known type classes from the body, then adds whichever | ||
* is relevent to that page. Checks to see if that class is known, and if | ||
* not, adds it to the array. | ||
*/ | ||
function detectAndAddClass() { | ||
typeArray.forEach(type => $('body').removeClass(type)); | ||
const $class = $('#page-type-identifier').attr('data-item-type'); | ||
if ($class) { | ||
$('body').addClass($class); | ||
if (typeArray.indexOf($class) < 0) { | ||
typeArray.push($class); | ||
} | ||
} | ||
@@ -486,4 +504,5 @@ | ||
//Event listeners | ||
Hubs.Events.on('load', detectAndAddClass); | ||
Hubs.Events.on('pageChange', detectAndAddClass); | ||
}; |
1587558
0.04%2125
0.76%