Skip to content

Commit

Permalink
feat(core): update to cookieconsent v3.1.0 and its features
Browse files Browse the repository at this point in the history
- add `secure` option to NgcCookieOptions
- add `dismissOnWindowClick` and `ignoreClickFrom` options to `NgcCookieConsentConfig`
  • Loading branch information
tinesoft committed Oct 17, 2018
1 parent a0849f2 commit d674b93
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ View the module in action at https://tinesoft.github.io/ngx-cookieconsent

## Dependencies
* [Angular](https://angular.io) (*requires* Angular 6+, [v1.1.0](https://github.com/tinesoft/ngx-cookieconsent/tree/v1.1.0) is the latest version for Angular < 6 )
* [Cookie Consent](https://cookieconsent.insites.com/) (*requires* Cookie Consent 3 or higher, tested with 3.0.6)
* [Cookie Consent](https://cookieconsent.insites.com/) (*requires* Cookie Consent 3 or higher, tested with 3.1.0)


## Installation
Expand All @@ -35,7 +35,7 @@ npm install --save ngx-cookieconsent
##### Angular-CLI
>**Note**: If you are using `angular-cli` to build your app, make sure that `cookieconsent` is properly listed as a [global library](https://github.com/angular/angular-cli/wiki/stories-global-scripts), and as [global style](https://github.com/angular/angular-cli/wiki/stories-global-styles).
To do so, edit your `.angular-cli.json` as such:
To do so, edit your `angular-cli.json` as such:
```
"scripts": [
"../node_modules/cookieconsent/build/cookieconsent.min.js"
Expand Down
2 changes: 1 addition & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@ng-bootstrap/ng-bootstrap": "^2.2.0",
"@ngx-translate/core": "^10.0.2",
"@ngx-translate/http-loader": "3.0.1",
"@stackblitz/sdk":"^1.2.0",
"@stackblitz/sdk": "^1.2.0",
"bootstrap": "^4.0.1",
"cookieconsent": "^3.0.4",
"core-js": "^2.5.4",
Expand Down
4 changes: 2 additions & 2 deletions demo/src/app/getting-started/getting-started.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h1>Getting Started</h1>
<h2>Dependencies</h2>
<ul>
<li><a href="https://angular.io">Angular</a> (<em>requires</em> Angular 6+, <a href="https://github.com/tinesoft/ngx-cookieconsent/tree/v1.1.0">v1.1.0</a> is the latest version for Angular &lt; 6 )</li>
<li><a href="https://cookieconsent.insites.com/">Cookie Consent</a> (<em>requires</em> Cookie Consent 3 or higher, tested with 3.0.6)</li>
<li><a href="https://cookieconsent.insites.com/">Cookie Consent</a> (<em>requires</em> Cookie Consent 3 or higher, tested with 3.1.0)</li>
</ul>
<h2>Installation</h2>
<p>Install above dependencies via <em>npm</em>. In particular for <code>Cookie Consent</code>:</p>
Expand All @@ -21,7 +21,7 @@ <h5>Angular-CLI</h5>
<blockquote>
<p><strong>Note</strong>: If you are using <code>angular-cli</code> to build your app, make sure that <code>cookieconsent</code> is properly listed as a <a href="https://github.com/angular/angular-cli/wiki/stories-global-scripts">global library</a>, and as <a href="https://github.com/angular/angular-cli/wiki/stories-global-styles">global style</a>.</p>
</blockquote>
<p>To do so, edit your <code>.angular-cli.json</code> as such:</p>
<p>To do so, edit your <code>angular-cli.json</code> as such:</p>
<pre class="editor editor-colors"><div class="line"><span class="source js"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="string quoted double js"><span class="punctuation definition string begin js"><span>&quot;</span></span><span>scripts</span><span class="punctuation definition string end js"><span>&quot;</span></span></span><span class="keyword operator assignment js"><span>:</span></span><span>&nbsp;</span><span class="meta brace square js"><span>[</span></span></span></div><div class="line"><span class="source js"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="string quoted double js"><span class="punctuation definition string begin js"><span>&quot;</span></span><span>../node_modules/cookieconsent/build/cookieconsent.min.js</span><span class="punctuation definition string end js"><span>&quot;</span></span></span></span></div><div class="line"><span class="source js"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="meta brace square js"><span>]</span></span><span class="meta delimiter object comma js"><span>,</span></span></span></div><div class="line"><span class="source js"><span>&nbsp;</span></span></div><div class="line"><span class="source js"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="string quoted double js"><span class="punctuation definition string begin js"><span>&quot;</span></span><span>styles</span><span class="punctuation definition string end js"><span>&quot;</span></span></span><span class="keyword operator assignment js"><span>:</span></span><span>&nbsp;</span><span class="meta brace square js"><span>[</span></span></span></div><div class="line"><span class="source js"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="string quoted double js"><span class="punctuation definition string begin js"><span>&quot;</span></span><span>../node_modules/cookieconsent/build/cookieconsent.min.css</span><span class="punctuation definition string end js"><span>&quot;</span></span></span></span></div><div class="line"><span class="source js"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="meta brace square js"><span>]</span></span><span class="meta delimiter object comma js"><span>,</span></span></span></div><div class="line"><span class="source js"><span>&nbsp;</span></span></div></pre>
<h5>SystemJS</h5>
<blockquote>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"dependencies": {
"@angular/core": "6.0.0",
"@angular/common": "6.0.0",
"cookieconsent": "3.0.6"
"cookieconsent": "3.1.0"
},
"devDependencies": {
"@angular/compiler": "6.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/model/content-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class NgcContentOptions {

link? = 'Learn more';

href? = 'http://cookiesandyou.com';
href? = 'https://cookiesandyou.com';

close? = '&#x274c;';

Expand Down
3 changes: 3 additions & 0 deletions src/model/cookie-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ export class NgcCookieOptions {
// The cookies expire date, specified in days (specify -1 for no expiry)
// Default: 365
expiryDays? = 365;

// If true the cookie will be created with the secure flag. Secure cookies will only be transmitted via HTTPS.
secure? = false;
}
3 changes: 2 additions & 1 deletion src/service/cookieconsent-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('cookieconsent-config', () => {
expect(config.content.allow).toEqual('Allow cookies');
expect(config.content.deny).toEqual('Decline');
expect(config.content.link).toEqual('Learn more');
expect(config.content.href).toEqual('http://cookiesandyou.com');
expect(config.content.href).toEqual('https://cookiesandyou.com');
expect(config.content.close).toEqual('&#x274c;');
expect(config.content.policy).toEqual('Cookie Policy');
expect(config.content.target).toEqual('_blank');
Expand All @@ -66,6 +66,7 @@ describe('cookieconsent-config', () => {
expect(config.cookie.path).toEqual('/');
expect(config.cookie.domain).toBeUndefined();
expect(config.cookie.expiryDays).toEqual(365);
expect(config.cookie.secure).toEqual(false);
});

it('should have sensible "elements" default values', () => {
Expand Down
10 changes: 10 additions & 0 deletions src/service/cookieconsent-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,16 @@ export class NgcCookieConsentConfig {
*/
location?: NgcLocationOptions;

/**
* Set value as click anything on the page, excluding the `ignoreClicksFrom` below (if we click on the revoke button etc)
*/
dismissOnWindowClick?: boolean;

/**
* If `dismissOnWindowClick` is true, we can click on 'revoke' and we'll still dismiss the banner, so we need exceptions.
* Should be an array of class names (not CSS selectors).
*/
ignoreClicksFrom?: string[];

// these callback hooks are called at certain points in the program execution
onPopupOpen?: () => void;
Expand Down
11 changes: 8 additions & 3 deletions src/service/cookieconsent.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const myConfig: NgcCookieConsentConfig = {
allow: '[custom]Allow cookies',
deny: '[custom]Decline',
link: '[custom]Learn more',
href: 'http://cookiesandyou.com/[custom]',
href: 'https://cookiesandyou.com/[custom]',
close: '&#x2789;'
},
palette: {
Expand Down Expand Up @@ -80,7 +80,7 @@ describe('Service: NgcCookieConsent', () => {
expect(CookieConsentUi.getCcMessageElement().textContent).toEqual('This website uses cookies to ensure you get the best experience on our website. Learn more');
expect(CookieConsentUi.getCcDismissElement().textContent).toEqual('Got it!');
expect(CookieConsentUi.getCcLinkElement().textContent).toEqual('Learn more');
expect(CookieConsentUi.getCcLinkElement().getAttribute('href')).toEqual('http://cookiesandyou.com');
expect(CookieConsentUi.getCcLinkElement().getAttribute('href')).toEqual('https://cookiesandyou.com');
});

it('should inject a custom NgcCookieConsent UI when injecting the service with custom config', () => {
Expand All @@ -92,7 +92,8 @@ describe('Service: NgcCookieConsent', () => {
expect(CookieConsentUi.getCcElement()).not.toBeNull();

expect(CookieConsentUi.getCcMessageElement().textContent).toEqual(myConfig.content.message + ' ' + myConfig.content.link);
expect(CookieConsentUi.getCcDismissElement().textContent).toEqual(myConfig.content.dismiss);
expect(CookieConsentUi.getCcDenyElement().textContent).toEqual(myConfig.content.deny);
expect(CookieConsentUi.getCcAllowElement().textContent).toEqual(myConfig.content.allow);
expect(CookieConsentUi.getCcLinkElement().textContent).toEqual(myConfig.content.link);
expect(CookieConsentUi.getCcLinkElement().getAttribute('href')).toEqual(myConfig.content.href);
});
Expand Down Expand Up @@ -344,6 +345,10 @@ export class CookieConsentUi {
return document.querySelectorAll('a.cc-btn.cc-deny').item(0) as HTMLElement;
}

public static getCcAllowElement(): HTMLElement {
return document.querySelectorAll('a.cc-btn.cc-allow').item(0) as HTMLElement;
}

public static getCcDismissElement(): HTMLElement {
return document.querySelectorAll('a.cc-btn.cc-dismiss').item(0) as HTMLElement;
}
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2095,10 +2095,10 @@ [email protected]:
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.3.1.tgz#e7e0a1f9ef43b4c8ba925c5c5a96e806d16873bb"
integrity sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s=

cookieconsent@3.0.6:
version "3.0.6"
resolved "https://registry.yarnpkg.com/cookieconsent/-/cookieconsent-3.0.6.tgz#147afa3e594e7b1a7826e49cb322aa0beee7b987"
integrity sha512-itjtWcF5LcVgyBWfHGcmU0n9LfNZ6BzlKwm02lOqMvjacim9+83gNzsuxJc61+8tjvBXM3hfMl4jnquhHJbpxg==
cookieconsent@3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/cookieconsent/-/cookieconsent-3.1.0.tgz#2c718b304d0e71a6e0d159cac8adf4205fdca152"
integrity sha512-FhkOAzZdIVqg7UfPjymgJBA7ZeEjrMgO8RWh+1Z130K7TlJDNnIORMulvqmt66SPyfrUnFB3SYJ55/7EvEcSEA==

copy-concurrently@^1.0.0:
version "1.0.5"
Expand Down

0 comments on commit d674b93

Please sign in to comment.