Skip to content

Commit

Permalink
Docs: update code samples and fix typos
Browse files Browse the repository at this point in the history
  • Loading branch information
orestbida committed Sep 17, 2023
1 parent 2bc71ec commit 0e9c87b
Show file tree
Hide file tree
Showing 8 changed files with 318 additions and 183 deletions.
12 changes: 6 additions & 6 deletions docs/advanced/callbacks-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This event is triggered only the very first time that the user expresses their c
- **Example** <br>

```javascript
cc.run({
CookieConsent.run({
onFirstConsent: ({cookie}) => {
// do something
}
Expand All @@ -40,7 +40,7 @@ This event is triggered the very first time the user expresses their choice of c
- **Example** <br>

```javascript
cc.run({
CookieConsent.run({
onConsent: ({cookie}) => {
// do something
}
Expand All @@ -62,7 +62,7 @@ This event is triggered when the user modifies their preferences and only if con
- **Example** <br>

```javascript
cc.run({
CookieConsent.run({
onChange: ({cookie, changedCategories, changedServices}) => {
// do something
}
Expand All @@ -88,7 +88,7 @@ This event is triggered when one of the modals is visible.
- **Example** <br>

```javascript
cc.run({
CookieConsent.run({
onModalShow: ({modalName}) => {
// do something
}
Expand All @@ -112,7 +112,7 @@ This event is triggered when one of the modals is hidden.
- **Example** <br>

```javascript
cc.run({
CookieConsent.run({
onModalHide: ({modalName}) => {
// do something
}
Expand All @@ -136,7 +136,7 @@ This event is triggered when a modal is created and appended to the DOM.
- **Example** <br>

```javascript
cc.run({
CookieConsent.run({
onModalReady: ({modalName, modal}) => {
// do something
}
Expand Down
4 changes: 2 additions & 2 deletions docs/advanced/consent-logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ Here is a full example.
function logConsent(){

// Retrieve all the fields
const cookie = cc.getCookie();
const preferences = cc.getUserPreferences();
const cookie = CookieConsent.getCookie();
const preferences = CookieConsent.getUserPreferences();

// In this example we're saving only 4 fields
const userConsent = {
Expand Down
4 changes: 2 additions & 2 deletions docs/advanced/language-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ The cleanest solution is to separate the translations from the plugin's configur
2. Configure the plugin for use with the external `en.json` translation:

```javascript
cc.run({
CookieConsent.run({
language: {
default: 'en',
translations: {
Expand All @@ -99,7 +99,7 @@ You can set up multiple languages by following the same steps!
An inline translation is easier to implement, but might also make the configuration harder to manage — especially if you have a lot of translations.

```javascript
cc.run({
CookieConsent.run({
language: {
default: 'en',
translations: {
Expand Down
16 changes: 8 additions & 8 deletions docs/advanced/manage-scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ There are two ways to manage your scripts:
* `data-category`: name of the category
* `data-service` (optional): if specified, a toggle will be generated in the `preferencesModal`
* `data-type` (optional): custom type (e.g. `"module"`)
* `data-src` (optional): can be used instead of `src` to avooid validation issues
* `data-src` (optional): can be used instead of `src` to avoid validation issues

Example usage:
```html
Expand Down Expand Up @@ -54,7 +54,7 @@ You can also run **scripts when a category is disabled** (if it was previously e
```

::: warning Custom type
You can set a custom script type via the `data-type` atttribute. E.g. to set the `type="module"` attribute you must specify `data-type="module"`.
You can set a custom script type via the `data-type` attribute. E.g. to set the `type="module"` attribute you must specify `data-type="module"`.

```html{6}
<script
Expand Down Expand Up @@ -98,13 +98,13 @@ You can add the `'!'` before the service name to run some clean-up logic when th
## Using callbacks/events
You can adapt the above examples for use inside the `onConsent` callback:
```javascript
cc.run({
CookieConsent.run({
onConsent: function(){
if(cc.acceptedCategory('analytics')){
if(CookieConsent.acceptedCategory('analytics')){
// Analytics category enabled
}

if(cc.acceptedService('Google Analytics', 'analytics')){
if(CookieConsent.acceptedService('Google Analytics', 'analytics')){
// Google Analytics enabled
}
}
Expand All @@ -114,18 +114,18 @@ cc.run({
Another handy callback is the `onChange` callback, fired when the state of the categories or services is changed (assuming that consent was already expressed).

```javascript
cc.run({
CookieConsent.run({
onChange: function({changedCategories, changedServices}){
if(changedCategories.includes('analytics')){

if(cc.acceptedCategory('analytics')){
if(CookieConsent.acceptedCategory('analytics')){
// Analytics category was just enabled
}else{
// Analytics category was just disabled
}

if(changedServices['analytics'].includes('Google Analytics')){
if(cc.acceptedService('Google Analytics', 'analytics')){
if(CookieConsent.acceptedService('Google Analytics', 'analytics')){
// Google Analytics was just enabled
}else{
// Google Analytics was just disabled
Expand Down
4 changes: 2 additions & 2 deletions docs/advanced/revision-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ You can enable the revision management if you need to refresh the consent due to
## Enable revisions
To enable revisions, you just need to specify a valid `revision` number in your configuration:
```javascript
cc.run({
CookieConsent.run({
revision: 1
});
```
Expand All @@ -24,7 +24,7 @@ Optionally, you can also set a revision message to let your users know what has
2. Specify the `{{startBrackets}}revisionMessage{{endBrackets}}` placeholder inside `consentModal.description`

```javascript
cc.run({
CookieConsent.run({
revision: 1,

language: {
Expand Down
Loading

1 comment on commit 0e9c87b

@vercel
Copy link

@vercel vercel bot commented on 0e9c87b Sep 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

cookieconsent-docs – ./

cookieconsent-docs-orest.vercel.app
cookieconsent.orestbida.com
cookieconsent-docs-git-v30-beta-orest.vercel.app

Please sign in to comment.