Skip to content

Commit

Permalink
Docs: Extend configuration example page to showcase onChange event
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraM committed Feb 11, 2022
1 parent a67f0a4 commit e2ba3c1
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions examples/configuration.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ <h2 class="mt-md-3 mb-3">What is shown here</h2>
Overwriting raw configuration of the underlying cookie-consent component (via <code>config</code> option),
to modify some advanced features.
</li>
<li>Clearing localStorage if user gives consent to only necessary data (<code>onFirstAcceptOnlyNecessary</code>)</li>
<li>Clearing localStorage when user gives consent to only necessary data (<code>onFirstAccept</code>)</li>
<li>Clearing localStorage when user updates consent and rejects some consent category (<code>onChange</code>)</li>
<li>Etc.</li>
</ul>

Expand Down Expand Up @@ -144,10 +145,15 @@ <h2 class="mt-md-3 mb-3">Use cookieConsent instance</h2>
},
onAccept: () => document.getElementById('reset').removeAttribute('hidden'), // reveal Reset cookie button
onFirstAccept: (cookieConsent) => { // user just clicked and gave consent to selected or all categories
if (!cookieConsent.isAllowed('functionality')) {
window.localStorage.clear(); // if we use localStorage for some extended "functionality", remove its contents if we don't have consent
if (!cookieConsent.allowedCategory('functionality')) {
window.localStorage.clear(); // if we use localStorage only for some extended "functionality", remove its contents if we don't have consent
}
},
onChange: (cookieConsent, categories) => { // when user changes settings while on page, the now-rejected categories must be respected
if (categories.changed.includes('functionality') && !cookieConsent.allowedCategory('functionality')) {
window.localStorage.clear(); // if we use localStorage only for some extended "functionality", remove its contents if we don't have consent
}
}
}
);
});
Expand Down

0 comments on commit e2ba3c1

Please sign in to comment.