Skip to content

Commit

Permalink
Feat: add .validConsent() method
Browse files Browse the repository at this point in the history
  • Loading branch information
orestbida committed Aug 6, 2023
1 parent 115f909 commit 7beb89b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
21 changes: 17 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ A __lightweight__ & __gdpr/ccpa compliant__ cookie consent plugin written in pla
5. Now you must configure the scripts and cookies.
* [How to block/manage script tags](#how-to-blockmanage-scripts)
* [How to autoclear cookies](#how-to-clear-cookies)

<br>

## How to block/manage scripts
Expand Down Expand Up @@ -515,7 +515,7 @@ Cookies must be listed manually as the plugin is not aware of them.
[Full example](https://github.com/orestbida/cookieconsent/blob/9ad310e7edcac7bf23600ff0e23d42254d3fced2/demo/demo_iframemanager/cookieconsent-init.js#L139).

<br>

## Layout options & customization
You can choose a few layout options via `gui_options`.

Expand Down Expand Up @@ -544,7 +544,7 @@ cc.run({
You can customize the color scheme using css variables, which you can find at the top of [cookieconsent.css](src/cookieconsent.css) file.

<br>

## API
Once you configure and run the plugin:

Expand Down Expand Up @@ -636,6 +636,19 @@ the following methods are available:
```
</p>
</details>
- <details><summary>cc<code>.validConsent()</code></summary>
<p>
If consent is valid return <code>true</code>, otherwise <code>false</code>.
```javascript
// Example: show modal if consent is not valid
if (!cc.validConsent()) {
cc.show();
}
```
</p>
</details>
- <details><summary>cc<code>.eraseCookies(&lt;cookie_names&gt;, &lt;optional_path&gt;, &lt;optional_domains&gt;)</code> [v2.5.0+]</summary>
<p>
Expand Down Expand Up @@ -1050,7 +1063,7 @@ CookieConsent does not have any built-in functionality to block iframes. You can
}
})
```
</p>
</details>
Expand Down
4 changes: 4 additions & 0 deletions src/cookieconsent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2131,6 +2131,10 @@
return _getCookie(cookie_name, 'one', true) !== "";
}

_cookieconsent.validConsent = function(){
return !invalid_consent;
}

/**
* Function to run when event is fired
* @callback eventFired
Expand Down
1 change: 1 addition & 0 deletions types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ declare global {
show(delay?: number, create_modal?: boolean): void
eraseCookies(_cookies: string | string[], _path?: string, _domain?: string): void
validCookie(cookie_name: string): boolean
validConsent(): boolean
allowedCategory(cookie_category: string): boolean
set(field: string, data: Record<string, any>): boolean
get(field: string, cookie_name?: string): Record<string, any>
Expand Down

0 comments on commit 7beb89b

Please sign in to comment.