@@ -81,7 +81,54 @@ <h3 id="fides-embed-no-results" class="no-results no-results--is-hidden">
8181 </ h3 >
8282 </ main >
8383 < script >
84+ /**
85+ * Sanitize a string to be a valid CSS class name.
86+ * - Replaces invalid characters with hyphens
87+ * - Collapses multiple hyphens
88+ * - Trims leading/trailing hyphens
89+ * - Prefixes with underscore if starts with digit or hyphen+digit
90+ */
91+ const toValidClassName = ( str ) => {
92+ let result = str
93+ . replace ( / [ ^ A - Z a - z 0 - 9 _ - ] / g, "-" )
94+ . replace ( / - + / g, "-" )
95+ . replace ( / ^ - | - $ / g, "" ) ;
96+ if ( / ^ [ 0 - 9 ] / . test ( result ) || / ^ - [ 0 - 9 ] / . test ( result ) ) {
97+ result = "_" + result ;
98+ }
99+ return result ;
100+ } ;
101+
84102 const onInitialized = ( ) => {
103+ // Add experience config ID and property ID as classes to the body for per-brand CSS styling
104+ const experienceConfigId =
105+ window . Fides ?. experience ?. experience_config ?. id ;
106+ if ( experienceConfigId ) {
107+ try {
108+ window . document . body . classList . add (
109+ toValidClassName ( experienceConfigId ) ,
110+ ) ;
111+ } catch ( e ) {
112+ window . fidesDebugger ?. (
113+ "Failed to add experience config ID as class:" ,
114+ experienceConfigId ,
115+ e ,
116+ ) ;
117+ }
118+ }
119+ const propertyId = window . Fides ?. experience ?. property_id ;
120+ if ( propertyId ) {
121+ try {
122+ window . document . body . classList . add ( toValidClassName ( propertyId ) ) ;
123+ } catch ( e ) {
124+ window . fidesDebugger ?. (
125+ "Failed to add property ID as class:" ,
126+ propertyId ,
127+ e ,
128+ ) ;
129+ }
130+ }
131+
85132 let fidesUIShown = false ;
86133 window . addEventListener ( "FidesUIShown" , ( ) => {
87134 fidesUIShown = true ;
0 commit comments