npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

angular-consent

v2.2.0

Published

[![Build Status](https://travis-ci.org/jvandemo/angular-consent.png?branch=master)](https://travis-ci.org/jvandemo/angular-consent)

Downloads

127

Readme

Angular Consent

Build Status

Easily show consent messages that keep appearing until the user clicks them away.

Useful if you need to show legal disclaimers (e.g. to conform to the EU Cookie Consent law).

  • very lightweight (~1KB)
  • use your own markup and CSS to make the messages fit perfectly in your application
  • supports multiple consent messages on the same page

Try online demo.

Requirements:

Screenshot

Quick example

<!-- add consent attribute to any element -->
<!-- to expose $consent controller to children -->
<section consent>

  <!-- then use your own custom markup to create the message -->
  <section ng-if="$consent.hasNotAgreedYet()">
    <p>This web application uses cookies to store private data.</p>
    <button ng-click="$consent.agree();">Agree</button>
  </section>
  
</section>

Usage

First install the module using bower:

$ bower install angular-cookies
$ bower install angular-consent

and add the library to your application:

<script src="angular-cookies.min.js"></script>
<script src="angular-consent.min.js"></script>

Then add the ngCookies and angularConsent modules to the dependencies of your AngularJS application module:

angular.module('yourApp', ['ngCookies', 'angularConsent']);

Now you can use the consent directive anywhere in your markup:

<!-- add consent attribute to any element -->
<!-- to expose $consent controller to children -->
<section consent>

  <!-- then use your own custom markup to create the message -->
  <section ng-if="$consent.hasNotAgreedYet()">
    <p>This web application uses cookies to store private data.</p>
    <button ng-click="$consent.agree();">Agree</button>
  </section>
  
</section>

To create multiple consents in a single application, pass a unique key to the consent attribute:

<!-- consent for cookie disclaimer -->
<section consent="cookie-disclaimer">
  <section ng-if="$consent.hasNotAgreedYet()">
    <p>This website uses cookies.</p>
    <button ng-click="$consent.agree();">Ok, I understand</button>
  </section>
</section>

<!-- consent for privacy disclaimer -->
<section consent="privacy-disclaimer">
  <section ng-if="$consent.hasNotAgreedYet()">
    <p>This website stores private data.</p>
    <button ng-click="$consent.agree();">Ok, I understand</button>
  </section>
</section>

You can also re-use a consent across your page or application:

<!-- display consent message in header -->
<header consent="cookie-disclaimer">
  <section ng-if="$consent.hasNotAgreedYet()">
    <p>This website uses cookies.</p>
  </section>
</header>

<!-- and show the button in the footer -->
<footer consent="cookie-disclaimer">
  <button ng-click="$consent.agree();">Ok, I understand</button>
</footer>

By default cookies are stored for 360 days, but you can customize cookie options on a consent level:

<!-- expirationDate should be string string of form 'Wdy, DD Mon YYYY HH:MM:SS GMT' -->
<header consent="cookie-disclaimer" consent-cookie-options="{ expires: expirationDate }">
  <section ng-if="$consent.hasNotAgreedYet()">
    <p>This website uses cookies. The cookie will be stored until expiration date.</p>
  </section>
</header>

The $consent API

The following methods are available on the $consent object:

$consent.hasAlreadyAgreed()

Whether or not the user has already agreed.

Arguments

None.

Returns

Boolean.

$consent.hasNotAgreedYet()

Whether or not the user still has to agree.

Arguments

None.

Returns

Boolean.

$consent.agree()

Marks the consent as agreed.

Arguments

None.

Returns

Void.

$consent.reset()

Resets a previous agreement.

Arguments

None.

Returns

Void.

Example with all available methods

<section consent>

  <section ng-if="$consent.hasNotAgreedYet()">
    <p>This message will keep appearing until you agree</p>
    <button ng-click="$consent.agree()">Agree</p>
  </section>
  
  <section ng-if="$consent.hasAlreadyAgreed()">
    <p>This message will appear when user has already agreed</p>
    <button ng-click="$consent.reset()">Try again</p>
  </section>
  
</section>

Contribute

To update the build in the dist directory:

$ gulp

To run the unit tests using the src files:

$ gulp test-src

To run the unit tests using the unminified library:

$ gulp test-dist-concatenated

To run the unit tests using the minified library:

$ gulp test-dist-minified

Change log

v2.2.0

  • Added main property to package.json (#5)

v2.1.1

  • Added check to make sure expires is always set correctly to fix #4

v2.1.0

  • Added support for AngularJS versions older than AngularJS 1.4

v2.0.0

  • Cookies are now stored for 360 days by default (instead of session)
  • Added support for cookie options via consent-cookie-options attribute

v1.0.0

  • Added support for multiple consent messages simultaneously
  • Updated documentation
  • Added demo

v0.1.0

  • Added consent directive
  • Added unit tests
  • Added initial documentation