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

custom-consent-popup

v0.9.2

Published

A customizable modal window for managing user consent, with various configuration options.

Downloads

189

Readme

CustomConsentPopup

Overview

The CustomConsentPopup class is designed for creating and managing a customizable confirmation modal window. This modal window can be used for various purposes, such as user consent for cookies, terms of service, or other custom notifications.

Features

  • Customizable Appearance: The modal window's position and text can be customized.
  • Flexible Consent Management: Offers various ways to manage user consent, including once per session, once per lifetime, or never showing the modal again.
  • Interactive Options: Includes functionalities for positive and negative responses, with customizable callback functions.

Configuration Options

The modal window's behavior and appearance can be configured with the following properties:

  • show: Determines if the modal window is initially visible (true) or hidden (false).
  • backgroundBlock: If true, the modal window overlay is non-interactive; if false, it allows interaction.
  • backgroundBlockColor: Sets the color of the background overlay when backgroundBlock is true.
  • position: A predefined stylesheet value ("center", "bottom", or "top") determining the modal window's position and size.
  • consentExpirationTime: Manages the display of the consent modal based on user interactions.
    • If a number, represents the time in seconds to reappear after consent.
    • If false, shown only once per lifetime.
    • If true, shown once per browser session.
  • modalWindowHeaderHTML: HTML content for the modal window's header.
  • modalWindowBodyHTML: HTML content for the main body of the modal window.
  • positiveButtonText: Text for the positive (confirmation) button.
  • negativeButtonText: Text for the negative (decline) button.
  • hidemodalWindowOnNegativeClick: Whether to hide the modal window on clicking the negative button.
  • localStorageObjectName: Name for the local storage object to store consent date.
  • blockScroll: Blocks page scrolling when the modal window is displayed if set to true.
  • removeAllContentOnNegativeClick: If true, removes all content from the document body on a negative button click.
  • onlyPositiveButtonOnModalWindow: If true, removes negative button from the modal window. False is default.
  • onPositiveButtonClickcallback: Callback function for when the positive button is clicked.
  • onNegativeButtonClickCallback: Callback function for when the negative button is clicked.
  • onPreviousConsentFoundCallback: Callback function for when previous consent is found.
  • onmodalWindowRenderedCallback: Callback function for when the modal window is rendered.

Usage

You can find demonstrational sample in examples/main.js To use CustomConsentPopup, create an instance with your custom settings and initialize it when the DOM is fully loaded. This can be done using the DOMContentLoaded event:

document.addEventListener('DOMContentLoaded', (event) => {
  // Define your custom settings 
  const options = {
    // Your options here
    position: 'center',
    consentExpirationTime: true,
    // ... other options ...
  };

  // Initialize the CustomConsentPopup with your options
  CustomConsentPopup.init(options);
  })

Example

examples/main.js
const options = {
  consentExpirationTime: 5,
  position: 'top',
  backgroundBlock: true,
  backgroundBlockColor:'rgba(125, 125, 125, 0.5)',
  blockScroll: false,
  onPositiveButtonClickCallback: function() {
    console.log('hey-hey');
  }
};

myConsentPopup.init(options);

Installation

Step 1: Install the Package

Open your terminal or command prompt and install CustomConsentPopup by running:

npm install [email protected]

Step 2: Importing in Your Project

Import CustomConsentPopup in your JavaScript or TypeScript project after installation.

JavaScript:

import CustomConsentPopup from 'custom-consent-popup';

Step 3: Implement in HTML

To use ES6 modules like the import statement in a browser, ensure your HTML script tag includes type="module":

<script type="module" src="path/to/your/script.js"></script>