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

bs-cookie-notice

v1.1.1

Published

A simple cookie consent notice alert for Bootstrap 4 without require jQuery

Downloads

37

Readme

Bootstrap Cookie Notice

A simple cookie consent notice alert for Bootstrap 4 without require jQuery.

  • Various configuration options
  • Defaults texts in PT, EN and ES
  • Possibility to add extra classes and callbacks
  • Does not require jQuery
  • Compatible with Bootstrap 4.1.x or more recent
  • It's lightweight, only ± 7 kb script

This plugin is a little bit based on Wruczek/Bootstrap-Cookie-Alert.

Installation

First, you will need to install NPM. Then, run the following command:

$ npm install bs-cookie-notice --save

Usage

Basic

Here is a basic example of using the plugin:

<script type="text/javascript">
    var notice = new BsCookieNotice();
</script>

Automatically opens the notice in the browser when loading the page.

Colors

The default color is dark, but you can choose between it and light. Example:

new BsCookieNotice({
    color: 'light'
});

Default texts

You can change the default texts language, just by setting the locale property (English, Portuguese and Spanish). Example:

new BsCookieNotice({
    locale: 'pt'
});

The default language of the plugin is English.

If you want to change the text to a custom one, you can pass an object with properties named message, accept and / or more to the customMessage property. Example:

new BsCookieNotice({
    locale: 'pt',
    customMessage: {
        more: "Quero saber mais...",
        accept: "Aceitar Todos"
    }
});

Note that it's not necessary to pass all properties on the object, you can choose a default language and just change the text of the Accept button for example.

Learn More URL

One of the indispensable things that needs to be configured is the "Learn more" link URL. For this you can pass to the more property an object containing an option named href with the URL value you want. Example:

new BsCookieNotice({
    more: {
        href: "https://github.com/parkejunior",
    }
});

There may also be a need to use the target attribute. To do this, you can pass the attribute value ( _blank, _self, etc.) to the target property in the more object. Example:

new BsCookieNotice({
    more: {
        href: "https://github.com/parkejunior",
        target: "_blank",
    }
});

Classes and HTML

In the same way that it's possible to configure the URL of the "Learn More" link, it's also possible to configure the "Accept" button.

You can add custom classes for these elements by passing an object to the more (for "Learn More") and accept (for the "Accept" button) properties. For example, changing the color of the button using the Bootstrap class:

new BsCookieNotice({
    accept: {
        class: ["btn-danger"],
    }
});

Or add a custom color for the link:

new BsCookieNotice({
    more: {
        href: "https://github.com/parkejunior",
        class: ["text-warning", "another-classes"],
    }
});

Callbacks

It's also possible to add callbacks to the "Accept" button and the "Learn More" link. Example:

new BsCookieNotice({
    accept: {
        callback: function () {
            console.log("User accept cookies");
        }
    },
    more: {
        href: "https://github.com/parkejunior",
        callback: function () {
            console.log("User wants to learn more");
        }
    }
});

Note: You cannot override the default "Accept" button event, just add a callback.

Expire

The default notice hide expiration time is 365 days after acceptance. You can change this by passing the number of days to the expire property. Example:

new BsCookieNotice({
    expire: 30
});

In this example, after 30 days after the user accepts the cookies, the message will be displayed again and the user must accept it again.

Demo

You can test the plugin by opening the index.html file in your browser.

Contribution

If you find any incorrect English grammar or any suggestions on how to improve the plugin, I appreciate it.