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

cookie-popup-gdpr

v1.3.6

Published

Simple lightweight EU, GDPR cookie popup.

Downloads

42

Readme

Install

npm i cookie-popup-gdpr

Or if you want to load it via a CDN, paste this in the head tag of your site.

<script src="https://cdn.jsdelivr.net/npm/cookie-popup-gdpr/dist/popup.min.js"></script>

If you get an error like exports is not defined add this var exports = {}; to your Code. (Example can be found in example.html).

Usage

To configure and show the popup add the code below to your website. You can find more information about the configuration below.

let config = {
  heading: "This site contains cookies",
  //Rest of your configuration
};

window.onload = function () {
  let popup = new CookiePopup(config);
};

An full example can be found on JSFiddle

Configuration

CookiePopupConfig

| name | type | description | | ----------------- | ------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------- | | heading | string | The heading of your cookie popup. | | informationText | string | Will be displayed below your heading and should give the user a short description what cookies are and why they are required. | | checkboxes | Array<CheckboxItem> | Define what cookie categories the user will be able to opt in/out of. More information about the type CheckboxItem below. | | buttons | Array<ButtonItem> | Define what predefined checkbox combinations the user will be able to select. More information about the type ButtonItem below. | | tableHeads | Array<string> | Headings for the columns of the service table. (service table is defined in CheckboxItem) | | callback | (res: Array<ResultObject>) => void | This function will be called after the user made a selection. | | style | string | Provide your own stylesheet. Will default to the "popup.css" file. | | position | string | Defines the position of the popup. Poissble values: top, top-left,top-right,bottom, bottom-left,bottom-right | | savePref | boolean | Defines if the user will be able to save his preferences. | | savePrefDefault | boolean | Defines the default value of the save preferences checkbox. |

CheckboxItem

| name | type | description | | ------------- | ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | title | string | The label for the checkbox. | | required | boolean | If true the checkbox will be disabled and set to true otherwise it will have the value of the checked attribute below. | | checked | boolean | Determines the default value of the checkbox. | | name | string | Choose a descriptive and unique name for this cookie category. | | description | string | A short description of the intended use of these cookies. | | services | Array<Array<string>> | Provide information about the used cookies. NOTE: Length of the inner list must be equal to the length of the attribute tableHead in the config |

ButtonItem

| name | type | description | | --------- | ------------ | ------------------------------------------------------------------------------------------------------------ | | title | string | The text inside the button. | | onclick | () => void | Define the onclick behaviour of the button. Use check and uncheck functions the define checkbox presets. | | green | boolean | If true button will be depicted in green otherwise in default color. |

ResultObject

| name | type | description | | ---------- | ---------------------- | ------------------------------------------------------------- | | name | string | The unqiue name of the category specified in the CheckboxItem | | checked | boolean | Shows whether the user opted in or out of the category. | | services | Array<Array<string>> | A List of all the services in this category. |

Presets

As mentioned in the configuration above you can define checkbox presets, you would usually do this in a ButtonItem with the functions check and uncheck. Both functions take an undefined amount of arguments of type string with names (defined in CheckboxItem) of cookie categories. NOTE: Names must be unique.

let buttonItem = {
  title: "Only necessary",
  onclick: () => {
    check("necessary");
    uncheck("marketing", "location");
  },
};

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Maximilian Mittelhammer - @maxi_maximittel - [email protected]

Project Link: https://github.com/MaxiMittel/cookie-popup-gdpr