Skip to content

Commit

Permalink
Merge pull request #113 from OndraM/feature/get-config
Browse files Browse the repository at this point in the history
Add method to read configuration values
  • Loading branch information
orestbida authored Nov 22, 2021
2 parents 3837e6f + 61d1be4 commit 45b5595
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
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
}
})();
})();

0 comments on commit 45b5595

Please sign in to comment.