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

@dmstr/cookie-consent

v0.4.1

Published

Library to address GDPR (The General Data Protection Regulation)

Downloads

369

Readme

Build Status

COOKIE CONSENT

It allows the user to choose through his active consent if the page can or not use/render/register features that could collect users personal data.

Getting started

Install

<script src="cookie-consent.js"></script>

Javascript

var cc = new CookieConsent();

or

var cc = new CookieConsent({
  name: 'cookie_consent_status',
  path: '/',
  domain: '',
  expiryDays: 365
});

HTML

<!-- popup toggle buttons (for convenience) -->
<button class="cookie-consent-open">open</button>
<button class="cookie-consent-close">close</button>
<button class="cookie-consent-toggle">toggle</button>
<button class="cookie-consent-controls-open">Open controls</button>
<button class="cookie-consent-controls-close">Close controls</button>
<button class="cookie-consent-controls-toggle">Toggle controls</button>
<button class="cookie-consent-details-open">Open Details</button>
<button class="cookie-consent-details-close">Close Details</button>
<button class="cookie-consent-details-toggle">Toggle details</button>

<!-- the popup that will appear if no consent cookie where saved -->
<div class="cookie-consent-popup">
  <div>
    <span class="cookie-consent-message">We are using cookies</span>
    <a class="cookie-consent-link" href="#">Learn more</a>
    <button class="cookie-consent-accept-all">Accept All</button>
    <button class="cookie-consent-deny-all">Deny All</button>
    <button class="cookie-consent-controls-open">Open controls</button>
    <button class="cookie-consent-controls-close">Close controls</button>
  </div>
  <div class="cookie-consent-controls open">
    <label><input type="checkbox" data-cc-consent="statistics">Statistics</label>
    <label><input type="checkbox" data-cc-consent="extern-media">Extern Media</label>
    <button class="cookie-consent-save">SAVE</button>
  </div>
  <div class="cookie-consent-details open">
    <h2>Statistics</h2>
    <table style="width:100%">
      <tr>
        <td>Name</td>
        <td>Statistics</td>
      </tr>
      <tr>
        <td>Goal</td>
        <td>Create statistics data</td>
      </tr>
      <tr>
        <td>Cookie Names</td>
        <td>_ga, _gat, _gid, _gali</td>
      </tr>
    </table>
  </div>
</div>


<script src="../../dist/cookie-consent.js"></script>
<script>
var cc = new CookieConsent()
</script>

CSS

.cookie-consent-popup {
    animation-name: show;
    animation-duration: 1s;
    animation-timing-function: ease;
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 999999;
}

.cookie-consent-popup.open {
    display: block;
    opacity: 1;
    animation-name: show;
    animation-duration: 1s;
    animation-timing-function: ease;
}

.cookie-consent-controls {
    max-height: 0;
    overflow: hidden;
    -webkit-transition: max-height 0.5s ease-out;
    -moz-transition: max-height 0.5s ease-out;
    transition: max-height 0.5s ease-out;
}

.cookie-consent-controls.open {
    max-height: 600px;
}

.cookie-consent-details {
    max-height: 0;
    overflow: hidden;
    -webkit-transition: max-height 0.5s ease-out;
    -moz-transition: max-height 0.5s ease-out;
    transition: max-height 0.5s ease-out;
}

.cookie-consent-details.open {
    max-height: 600px;
}

@keyframes show {
    from {opacity: 0;}
    to {opacity: 1;}
}

@keyframes hide {
    from {opacity: 1;}
    to {opacity: 0;}
}

OPTIONS

HTML

This Cookie Consent library works in a declarative approach. That mean that you just need to put the right classes in your html to get it working.

  • cookie-consent-popup: The popup widget. It will take the class "open" when no consent cookie was saved or when its manually triggered.
  • cookie-consent-controls: container for the consent checkboxes (controls).
  • cookie-consent-save: save the data-cc-consent values of the checkboxes in its same namespace in the consent cookie.
  • cookie-consent-accept-all: check all consents controls and save.
  • cookie-consent-deny-all: uncheck all consents controls and save.
  • cookie-consent-open: opens the popup.
  • cookie-consent-close: closes the popup.
  • cookie-consent-toggle: toggles the popup.
  • cookie-consent-controls-open: opens the controls
  • cookie-consent-controls-close: closes the controls
  • cookie-consent-controls-toggle: toggles the controls
  • cookie-consent-details-open: opens the details
  • cookie-consent-details-close: closes the details
  • cookie-consent-details-toggle: toggles the details
  • data-cc-consent: the consent name/value that will be stored in the consent cookie.
  • data-cc-namespace: used to group checkboxes and save buttons. In that way you can add different groups in different zones of your website without conflicting with other checkboxes or save buttons.

Events

cc.afterSave = function (cc) {
    // clean google analytics cookies if we do not have the "statistics" consent by expiring them. Then reload the page
  cc.clean({
    'statistics': {
      'cookies': [
        {name: '_ga'},
        {name: '_gat', domain: '', path: '/'},
        {name: '_gid', domain: '', path: '/'}
      ]
    }
  })
  window.location.reload()
}