Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to read configuration values #113

Merged
merged 1 commit into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,17 @@ Additional methods for an easier management of your scripts and cookie settings
```
</p>
</details>
- <details><summary>cookieconsent<code>.getConfig(&lt;field&gt;)</code> [v2.7.0+]</summary>
<p>

The `.getConfig()` method allows you to read configuration options from the current instance:
```javascript
cookieconsent.getConfig('current_lang'); // get currently used language
cookieconsent.getConfig('cookie_expiration'); // get configured cookie expiration
// ...
```
</p>
</details>


### All available options
Expand Down
16 changes: 12 additions & 4 deletions src/cookieconsent.js
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,7 @@
if(set){
saved_cookie_content['data'] = data;
_setCookie(_config.cookie_name, JSON.stringify(saved_cookie_content));
}
}

return set;
}
Expand Down Expand Up @@ -1441,6 +1441,14 @@
return cookie[field];
}

/**
* Read current configuration value
* @returns {any}
*/
_cookieconsent.getConfig = function(field){
return _config[field];
}

/**
* Function which will run after script load
* @callback scriptLoaded
Expand Down Expand Up @@ -1495,8 +1503,8 @@

/**
* Manage dynamically loaded scripts: https://github.com/orestbida/cookieconsent/issues/101
* If plugin has already run, call this method to enable
* the newly added scripts based on currently selected preferences
* If plugin has already run, call this method to enable
* the newly added scripts based on currently selected preferences
*/
_cookieconsent.updateScripts = function(){
_manageExistingScripts();
Expand Down Expand Up @@ -1849,4 +1857,4 @@
if(typeof window[init] !== 'function'){
window[init] = CookieConsent
}
})();
})();