Git Product home page Git Product logo

andreasonny83 / angular2-cookie-law Goto Github PK

View Code? Open in Web Editor NEW
37.0 5.0 24.0 1.23 MB

Angular2+ component that provides a banner to inform users about cookie law

Home Page: https://stackblitz.com/edit/angular2-cookie-law

License: MIT License

TypeScript 78.29% JavaScript 10.27% HTML 6.36% CSS 5.09%
angular2 angular4 angular2-cookie banner ng2 ng4 cookies angular-components angular2-components angularjs

angular2-cookie-law's Introduction

Maintainers Wanted

This project was originally intended to be only consumed by my NG applications. I'm now working full-time on React related project only and it's been a while since I did look into Angular related code.

However, since there are now several people relying on this small and simple package, I'm looking for volunteers to actiely look after this project. If anyone is interested, please reply into this ticket.

Build Status npm version npm Coverage Status Commitizen friendly semantic-release

Angular2 Cookie Law

Angular2+ component that provides a banner to inform users about the cookie law now with Angular Universal support

Angular2 Cookie Law is an HTML <cookie-law> tag enhanced with styling and animation.

This documentation is for the latest version of angular2-cookie-law (>=6.x.x).

angular2-cookie-law@7 supports bot Angular v6 and v7

If you're using an older version of Angular (<6), please install angular2-cookie-law in version 1 with npm i --save angular2-cookie-law@1 and check out the documentation available here.

Live DEMO:

Table of contents

Installation

  1. Install the component using npm
  2. angular2-cookie-law depends on the Angular animations module in order to be able to do more advanced transitions. If you want these animations to work in your app, you have to install the @angular/animations module and include the BrowserAnimationsModule in your app.
# To get the latest stable version and update package.json file:
$ npm install angular2-cookie-law@6 @angular/animations --save

or yarn with:

$ yarn add angular2-cookie-law @angular/animations

Setup

angular2-cookie-law class is an Angular module therefore, it needs to be registered in the modules array (encouraged way):

// app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { CookieLawModule } from 'angular2-cookie-law';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [ AppComponent ],
  imports: [
    BrowserModule,
    BrowserAnimationsModule, // BrowserAnimationsModule is required
    CookieLawModule // import Angular's CookieLaw modules
  ],
  bootstrap: [ AppComponent ]
})
export class AppModule { }

Usage

Use the component anywhere around your application:

// app.component.ts
import { Component } from '@angular/core';

@Component({
  selector: 'app',
  template: `
    <cookie-law></cookie-law>
  `
})
export class AppComponent  { }

Example

// app.component.ts
import { Component } from '@angular/core';

@Component({
  selector: 'app',
  template: `
    <h1>
      Hello World!
    </h1>

    <cookie-law></cookie-law>
  `
})
export class AppComponent  { }
Output

cookie-law example

Demo App

Have a look at the demo app available in this repository for a real Angular application using the angular2-Cookie-Law library. Clone this repo on you machine with

$ git clone [email protected]:andreasonny83/angular2-cookie-law.git

Then install all the Node dependencies (Node v8 or later is required).

$ npm install

And run the project with:

$ npm start

Open your browser to http://localhost:4200/ to see the application running.

Options

Attributes

learnMore

Type Default value
string null

If set to a valid absolute or relative URL, it will render an extra 'learn more' link pointing to the link.

Example
<cookie-law learnMore="/learn-more"></cookie-law>

output with link

awsomeCloseIcon

Font Awsome is required in your header for this feature to work.

<script defer src="https://use.fontawesome.com/releases/v5.0.6/js/all.js"></script>
Type Default value
string null

If set to a Font awsome Icon e.g. "fa-window-close" it will replace the standard SVG with the Font awsome Icon.

Example
<cookie-law awsomeCloseIcon="fa-window-close"></cookie-law>

target

Type Default value
string _blank

Set to _self if you want the external link not to be opened in a new tab.

Example
<cookie-law learnMore="/learn-more" target="_self"></cookie-law>

position

Type Default value
string "bottom"

Allows you to decide where in the page, the banner will be rendered. Possible values are: "bottom" and "top".

Example
<cookie-law position="top" learnMore="/learn-more" target="_self"></cookie-law>

name

Type Default value
string "cookieLawSeen"

Allows you to decide which name will be used for storing the cookie in the client's browser.

Example
<cookie-law name="myShinyCookieLaw"></cookie-law>

The previous example will generate a myShinyCookieLaw=true as soon as the user dismiss the banner.

expiration

Type Default value Description
number - Set a the cookie expiration time (in days)
Example
<cookie-law name="myShinyCookieLaw" expiration="7">I'm gonna expire in 1 week!</cookie-law>

Properties

Name Type Description
cookieLawSeen boolean true if the user has already dismissed the banner
Example
@Component({
  selector: 'demo-app',
  template: `
    <h3 *ngIf="cookieLawSeen">Cookie law has been dismissed</h3>

    <cookie-law #cookieLaw></cookie-law>

  `,
})
export class AppComponent implements OnInit {
  @ViewChild('cookieLaw')
  private cookieLawEl: any;

  private cookieLawSeen: boolean;

  ngOnInit() {
    this.cookieLawSeen = this.cookieLawEl.cookieLawSeen;
  }
}

Events

Name Type Description
isSeen boolean Triggered when the user dismiss the banner
Example
@Component({
  selector: 'demo-app',
  template: `
    <h3 *ngIf="cookieLawSeen">Cookie law has been dismissed</h3>

    <cookie-law (isSeen)="seen($event)"></cookie-law>
  `,
})
export class AppComponent {
  private cookieLawSeen: boolean;

  public seen(evt: any) {
    this.cookieLawSeen = evt;
  }
}

Methods

Name Description
dismiss Dismiss a banner
Example
@Component({
  selector: 'demo-app',
  template: `
  <button type="button" (click)="dismiss()">Dismiss Modal</button>
  <cookie-law #cookieLaw></cookie-law>

  `,
})
export class AppComponent implements OnInit {
  @ViewChild('cookieLaw')
  private cookieLawEl: any;

  public dismiss(): void {
    this.cookieLawEl.dismiss();
  }
}

Custom template

It is possible to overwrite our default cookie policy law text with a custom template. Just put your favorite html content between the component like in the following example:

<cookie-law position="top">
  This website contains cookie.
  <a href="#/cookie-policy">Read more</a>
</cookie-law>

Contributing

This package is using the AngularJS commit messages as default way to contribute with Commitizen node package integrated in this repository.

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Add your changes: git add .
  4. Commit your changes: npm run commit
  5. Push to the branch: git push origin my-new-feature
  6. Submit a pull request 😎

Changelog

Changelog available here

License

MIT License Β© Andrea SonnY

angular2-cookie-law's People

Contributors

andreasonny83 avatar belobrad avatar dependabot[bot] avatar exequiel09 avatar neilime avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

angular2-cookie-law's Issues

expiration to 30 days but expired in less days

Hi, i set expiration to 30 days but seems like the cookie bars is shown before.
How can i set the expiration to until cookies are deleted?

<cookie-law *ngIf="GlobalFields.isBrowser" name="cookieLawSeenRoomless" expiration="30"> Questo sito utilizza cookies per migliorare la tua esperienza. Accetta se sei d'accordo con il loro utilizzo. <a [routerLink]="'/privacy-policy'" title="Privacy Policy">Privacy Policy</a> </cookie-law>

Thank you

feature request: list of property-value pairs to be set in the cookie

Hi Andrea,

It is a great module which allows me to implement basic cookie law with only several lines of codes. If I understand correctly, this module store a cookie on the client computer with only one property: name. Does this mean that if two users use the the same computer and the first user accepts the cookie, the second user will not be prompted the banner?

What I am suggesting to allow taking in a data structure like

{ 
  user: john smith,
  name: cookie-law,
  date: 09/05/2018
}

which could make the module more flexible, e.g. if the terms and conditions changes, the cookie banner could be popped again.

Best regards,
Jun

Angular v6.0.3 problem

ERROR in node_modules/angular2-cookie-law/lib/cookie-law-element.component.d.ts(1,32): error TS2305: Module '".../node_modules/@angular/core/core"' has no exported member 'AnimationTransitionEvent'.

Cookie expiration

Hi @andreasonny83, I'm using your library in my personal project just HTML like that:

  <cookie-law name="cookieName" learnMore="/privacity">
    Some text inside the cookie banner.
    <a [routerLink]="['/privacity']">Learn more</a>
  </cookie-law>

So, the library is fantastic but I cannot set the expiration time of the cookie so when I close the browser, the cookie expires. Is there any posibility of setting cookie's duration for more than the session of the browser? Maybe setting it for a year or something.

I'm really thankful and waiting for your response!

Pablo

bug?: regular expression

The line 35 in src/cookie-law.service.ts reads as
c = ca[i].replace(/^\s+/g, '');

Is it to remove the starting whitespace? If so, then the RE should be ^\s+?

Uncaught TypeError: Cannot read property 'core' of undefined

Hi,

I've been using your module for a weeks, it works very well but I have an error in my console.
I'm using angular cli : "../node_modules/ng2-page-scroll/bundles/ng2-page-scroll.umd.js"

And then the error :

VM61018:1 Uncaught TypeError: Cannot read property 'core' of undefined
    at eval (eval at module.exports (addScript.js:9), <anonymous>:1:464)
    at eval (eval at module.exports (addScript.js:9), <anonymous>:1:508)
    at eval (<anonymous>)
    at module.exports (addScript.js:9)
    at Object.512 (angular2-cookie-law.umd.js?d15c:1)
    at __webpack_require__ (bootstrap ed73b40…:52)
    at Object.1253 (scripts.bundle.js:16)
    at __webpack_require__ (bootstrap ed73b40…:52)
    at webpackJsonpCallback (bootstrap ed73b40…:23)
    at scripts.bundle.js:1

Any idea ?

Add rel="noopener" to target="_blank" to prevent window.opener vulnerability

Hi - thanks for making this module :)

There is a known vulnerability with the target="_blank" attribute on anchor links, and this is now being flagged by Google's Lighthouse, for example.

The solution would be to add an option to include the rel="noopener" & rel="noreferrer" (for Firefox) attributes to the 'read more' anchor link. You could also just add it by default.

More information about this vulnerability can be read here:
https://developers.google.com/web/tools/lighthouse/audits/noopener
https://jakearchibald.com/2016/performance-benefits-of-rel-noopener/
https://www.jitbit.com/alexblog/256-targetblank---the-most-underestimated-vulnerability-ever/

Custom position

Decide where to display the cookie-law message on the page:

  • top
  • bottom

Opt-out option

Dear All,

There is a way to disagree on accepting cookies?
Is it required by GDPR, is it?

Best Regards
Andrea

Button dismiss

Hi,

I have a problem with the dismiss button :

ERROR TypeError: Cannot read property 'dismiss' of undefined

I have this code in my component HTML :
<cookie-law position="bottom">
<div class="container">
<div class="row">
<div class="col l10">
<div class="cookie-title">Nous utilisons des cookies</div>

En poursuivant la navigation, vous acceptez l'installation et l'utilisation des cookies sur votre ordinateur.
<button class="white-text amber darken-1 waves-effect waves-light btn depo cookie-btn" (click)="dismiss()">J'accepte
`

And in my component TS :
@ViewChild('cookieLaw') cookieLawEl: any; ... public dismiss(): void { this.cookieLawEl.dismiss(); }

Can you help me please ?

Thx

throwing errors when using Server Side Rendering (angular 6 universal)

ERROR ReferenceError: document is not defined
at Angular2CookieLawService.seen (/Users/Desktop/stack-website/development/src/frontend/node_modules/angular2-cookie-law/bundles/angular2-cookie-law.umd.js:26:48)
at CookieLawContainerComponent.ngOnInit (/Users/Desktop/stack-website/development/src/frontend/node_modules/angular2-cookie-law/bundles/angular2-cookie-law.umd.js:284:51)
....

Issue when upgrading from Angular 9 to 10

Should I remove this dependency from my project ? When I am trying to upgrade from Angular 9 to 10, I have this message:

 Package "angular2-cookie-law" has an incompatible peer dependency to "@angular/common" (requires "^6.0.0-rc.0 || ^6.0.0 || 7.0.0-rc.0 || ^7.0.0" (extended), would install "10.2.5").
 Package "angular2-cookie-law" has an incompatible peer dependency to "@angular/core" (requires "^6.0.0-rc.0 || ^6.0.0 || 7.0.0-rc.0 || ^7.0.0" (extended), would install "10.2.5").

cookieLawSeen attribute

When included in a page, I want to see a isSeen attribute to the HTML tag.
I want also to have an event triggered when the user dismiss the banner.

@Component({
  selector: 'app',
  template: `
  <div *ngIf="cookieLawSeen">
    This will be rendered only when the cookie banner is dismissed.
  </div>

  <cookie-law (isSeen)="cookieLawSeen"></cookie-law>
  `
})
export class AppComponent {
  private cookieLawSeen: boolean;
}

Support for Angular 7

I just upgraded my project from Angular 6 to 7 today, and it seems to work fine :-)
[email protected]
But I show some warnings:

npm WARN [email protected] requires a peer of @angular/common@^6.0.0-rc.0 || ^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of @angular/core@^6.0.0-rc.0 || ^6.0.0 but none is installed. You must install peer dependencies yourself.

Please update the package.json file to remove the dependency warnings.
Thanks.

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two-Factor Authentication, make configure the auth-only level is supported. semantic-release cannot publish with the default auth-and-writes level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

Custom Template

It is possible to overwrite our default cookie policy law text with a custom template. Just put your favorite html content between the component like in the following example:

<cookie-law position="top"> This website contains cookie. <a href="#/cookie-policy">Read more</a> </cookie-law>

For me this one don't work!!!
I add to axactly the same code and when i change the text it return always "By continuing to browse the site, you're agreeing to our use of cookies.".
How can i resolve ?

App compiles with errors

Following the documentation I get following errors:

ERROR in ../../../../node_modules/angular2-cookie-law/lib/angular2-cookie-law-container.component.d.ts(8,38): error TS2307: Cannot find module '@angular/core'.
../../../../node_modules/angular2-cookie-law/lib/angular2-cookie-law.component.d.ts(8,38): error TS2307: Cannot find module '@angular/core'.
../../../../node_modules/angular2-cookie-law/lib/angular2-cookie-law.component.d.ts(9,40): error TS2307: Cannot find module '@angular/platform-browser'.

The modules are all present and imported in 'app.module.ts'
Running Angular/cli 8.3.2

Refused to to apply inline style

My server add a Content-Security-Policy and since then I have this alerts and problems with angular2-cookie-law component:

Refused to apply inline style because it violates the following Content Security Policy directive: "default-src 'self'".

Versions of Angular
Angular: 8

angular2-cookie-law: "7.0.1"

Bootstrap: 4

Uncaught TypeError: Object(...) is not a function

angular2-cookie-law.js:77 Uncaught TypeError: Object(...) is not a function
at angular2-cookie-law.js:77
at Object. (angular2-cookie-law.js:79)
at webpack_require (bootstrap a3035af3e3185551034c:54)
at Object.655 (main.ts:5)
at webpack_require (bootstrap a3035af3e3185551034c:54)
at Object.533 (Utility.ts:39)
at webpack_require (bootstrap a3035af3e3185551034c:54)
at webpackJsonpCallback (bootstrap a3035af3e3185551034c:25)

I am getting this error when i am trying to run my application. I am using ionic 3 and angular 5. I have installed rxjs-compat as well but this error still shows up.

Looking For Maintainers

Please, comment to this issue if you're interested in becoming a maintainer for this project

Not able to use custom content after upgrade to ver 6

"@angular/core": "6.0.4",
"angular2-cookie-law": "^6.0.2",

When I use

<cookie-law position="bottom" expiration="30">
 Lalala
</cookie-law>

It still shows the default text: By continuing to browse the site ...

Expected behaviour:
Would like to see Lalala text instead of the default one.

custom styling

Would be nice if we could apply custom styles. I can add a PR soon when i have some time

Add Support for Angular 16

I know. The creator of this Package is not maintaining this package anymore. He/She is happy to accept pull-requests. I just wanted to make sure the issue entry for missing Angular 16 support is not missing in the list ツ ✌

Support for Angular 8

I've upgraded my application to Angular 8 and I'm getting some warnings on this package.
Could you update your package.json file to also allow angular 8, so I can get rid of these warnings.

warning " > [email protected]" has incorrect peer dependency "@angular/common@^6.0.0-rc.0 || ^6.0.0 || 7.0.0-rc.0 || ^7.0.0".
warning " > [email protected]" has incorrect peer dependency "@angular/core@^6.0.0-rc.0 || ^6.0.0 || 7.0.0-rc.0 || ^7.0.0".

changing text

Hey there,
Thanks a lot for your great work!
Do you think you could make the text configurable for the next release?
It will help a lot for multilingual sites.
If you don't have time right now I will make a pull request in few days.

Thanks !

popup appear for one sec after every reloading

Hello. I am facing a issue regarding cookie law. It is showing the pop-up for every page reload but just for one second. It should not do that. After showing the pop-up to a user who visit a site for the very first time, it should not show the pop-up. But, for me it is showing it for one second and then disappears.
What I am doing wrong? Any help will be appreciated.
Thanks.

Angular version: 6
I am using server side rendering.

Version 6.0.2 not customizable in Angular 6.0.x

Hi,

It is not possible to customize the directive, like this:

<cookie-law>Hallo Chris Cookie</cookie-law>

Effect you can see under your own demo page as well (using Chrome or Firefox)
https://stackblitz.com/edit/angular2-cookie-law

Can reproduce it with fresh Angular Cli 6.0.8 project:

brings the same result like demo Page.

package.json in my demo project:

{
"name": "testcookie",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^6.0.4",
"@angular/common": "^6.0.3",
"@angular/compiler": "^6.0.3",
"@angular/core": "^6.0.3",
"@angular/forms": "^6.0.3",
"@angular/http": "^6.0.3",
"@angular/platform-browser": "^6.0.3",
"@angular/platform-browser-dynamic": "^6.0.3",
"@angular/router": "^6.0.3",
"angular2-cookie-law": "^6.0.2",
"core-js": "^2.5.4",
"rxjs": "^6.0.0",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular/compiler-cli": "^6.0.3",
"@angular-devkit/build-angular": "~0.6.8",
"typescript": "~2.7.2",
"@angular/cli": "~6.0.8",
"@angular/language-service": "^6.0.3",
"@types/jasmine": "~2.8.6",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.2.1",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~1.7.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.0",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.3.0",
"ts-node": "~5.0.1",
"tslint": "~5.9.1"
}
}

link css has no class

Hello,

Just a minor issue to report, when cookie-law is inserted in the page, the css for 'a' tags overrides page css. It should had a class or an id.

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.