GithubHelp home page GithubHelp logo

canonical / cookie-policy Goto Github PK

View Code? Open in Web Editor NEW
7.0 12.0 14.0 1.1 MB

A script and stylesheet that displays the Canonical cookie policy

JavaScript 72.97% HTML 23.41% SCSS 3.62%
package npm npm-package web-and-design

cookie-policy's Introduction

Canonical cookie policy component

This project contains the scripts and styles to display a cookie policy notification on a web page.

You can use it to display a custom cookies message of your choosing on your own web page.

Usage

This project can be installed via an NPM package.

yarn add @canonical/cookie-policy

...or...

npm install @canonical/cookie-policy

You can then install the library either by directly linking to it or via an ES6 import.

  1. Via direct link

To consume the library directly, add a link to the JS file containing an IIFE and call the lib:

<script src="[ INSERT YOUR LOCAL PATH ]/js/cookie-policy.js"></script>
<script>
  cpNs.cookiePolicy();
</script>
  1. Via ES6 import
import { cookiePolicy } from '@canonical/cookie-policy';

Revoking the cookie policy

If you would like users to change their preferences you can add js-revoke-cookie-manager class to any element that is present in the document to recall the policy manager.

<button class="js-revoke-cookie-manager">Revoke cookie manager</button>

or

<a href="" class="js-revoke-cookie-manager"Revoke cookie manager</a>

Visiting a page with tracker disabled

If you add the query ?cp=hide to any URL the cookie policy will not be rendered. The main use case is to visit the policy page without the modal blocking the content.

Callback hook

You can set up the cookie policy with a callback when a preference is selected.

function callbackFunction() {
  alert('Calling back');
}
cpNs.cookiePolicy(callbackFunction);

Full example via ES6 import

import { cookiePolicy } from '@canonical/cookie-policy';

cookiePolicy();

Cookie groups

Essential cookies are always allowed, unless the user turns them off in their browser. Otherwise, there will be a series of values the _cookies_accepted cookie can contain :

Cookie value Description Note
all All cookies accepted by the user. Currently used by the existing widget Previous value was true. Using the same cookie.
essential Essential cookies accepted. This is used to hide the notification instead of not setting the cookie
performance Performance cookies accepted. -
functionality Functionality cookies accepted. -

Contributing

If you would like to help improve this project, here is a list of commands to help you get started.

Building the cookie policy

Install the requisite dependencies;

npm install

To build the JS and CSS into the build folder, run:

npm run build

You can view the build files in action by running:

npm run serve

And, visiting http://0.0.0.0:8301/

Hacking

When developing this project you can run the following command to listen to changes in the src/js/*js and src/sass/*scss folders and build them into the /build folder.

npm run watch

Before submitting your pull request, run the linters, which checks both the JS and Sass for errors.

npm run test

Code licensed LGPLv3 by Canonical Ltd.

With ♥ from Canonical

cookie-policy's People

Contributors

anthonydillon avatar barrymcgee avatar bartaz avatar bethcollins92 avatar carkod avatar clementchaumel avatar deadlight avatar dependabot[bot] avatar jkfran avatar minkyngkm avatar nottrobin avatar petesfrench avatar pmahnke avatar renovate-bot avatar renovate[bot] avatar solazio avatar sowasred2012 avatar steverydz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cookie-policy's Issues

Dialog not spanning full fixed width, leaving slivers of arbitrary content visible

Maybe there's a reason, if so please ignore this, but...

image

Wouldn't it be better to make the dialog cover the content underneath? As it stand it leaves a couple of characters visible on one side (in this particular example) and looks strange. Also the hr extends further to the right so the dialog feels off center (due to differences in padding on the sidenav and main content I assume).

Unnecessary grid CSS in built file

There is quite a lot of unnecessary grid related CSS in built file (like: [grid-demo] [class*="col-"]{background:#cdcdcd;margin-bottom:1rem} ...) leaking from Vanilla.

It was already fixed in Vanilla itself, so quite likely rebuilding with newer version should fix that.

Add affordance for old cookies

In version 2.x we set the cookie to the value of "true" when accepting the cookie policy. With the new regulations, we need to force users to re-review the new options. Therefore simply checking the existence of the cookie does not suffice.

Cookies with the value of "true" should also invoke the cookie policy notification.

Update Vanilla Framework to 1.8.0

There were significant changes to patterns used in the cookie policy in V1.8.0 of Vanilla Framework. The dependency should be updated to reduce problems when using the plugin on sites with newer versions of VF.

Styling issues when Vanilla versions are misaligned

cookie-policy includes it's own version of Vanilla and builds its own separate stylesheet with it.
When used in a project that also has Vanilla this means there are 2 Vanilla stylesheets on one website. This can cause issues when these versions don't match.

This happened recently with (fairly unnoticable) issue with modal spacing:

Screenshot 2021-11-04 at 09 32 08

Caused by the fact that cookie-policy is using older version of Vanilla than the websites.
The issue above will be fixed by merging renovate PR #127, but renovate only updates cookie-policy once a month, so this leaves quite a large window of possibly broken experience.

Ideally cookie-policy should not include its own version of Vanilla and rely on version in the project.

We could also update renovate config here to make sure Vanilla is updated immediately when released.

Do not load all the base styles from Vanilla

This module loads the entire base styles from vanilla (vf-base) which includes the embed of a number of fonts. This is bloating sites and should not include fonts but us the parent sites font.

It's not possible to set cookie tracking preferences on iPhone

Summary

The cookie UI isn't very usable on iOS Safari

Current and expected result

When the user scrolls down and attempts to tap the 'save preferences' button, the app thinks the user is trying to use the bottom bar of Safari and blocks the tap.

Screenshot

ezgif-5-ea931d50d51e

Browser details

iOS (latest stable) Safari (latest stable).

Dependency Dashboard

This issue provides visibility into Renovate updates and their statuses. Learn more

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

  • chore(deps): update all dependencies (@babel/core, @babel/preset-env, circleci/node, eslint, rollup, sass, stylelint, stylelint-config-standard, stylelint-order, vanilla-framework)

  • Check this box to trigger a request for Renovate to run again on this repository

Cookie banner causing JS error in Safari v9

Summary

  • Fire up Safari on El Capitan (or Browserstack) and open site on Safari v9
  • Reduce screen resolution to small screen
  • Refresh screen
  • Cookie banner function is breaking global nav
  • See (3rd error in console):

screen shot 2017-06-14 at 16 57 22

Scrolling on the background is not blocked properly

The background scroll lock is not always working and I believe the following steps should fix it:

  1. The scroll-lock class should set the height and width of the body to the height and width of the viewport
  2. The default dialog style should be overwritten. Currently it is not and it appends a square to the end of the page
    image

Modal not focused by default

When you visit a site that has the cookie policy modal displayed you should be able to tab to the buttons and action them with your keyboard. Currently you have to tab through the whole document behind the modal before the focus eventually gets to the modal buttons.

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: Cannot find preset's package (github>whitesource/merge-confidence:beta)

Provide an example flask project

It'd be nice to create an example flask project, similar to the ones we usually have, to test that this package works.

This way, we could also include github actions to test dependency updates

Make the cookie policy a web component

The current cookie policy would be improved by making it a web component, removing problems of local styles on the site effecting the display of the cookie policy.

This would also mitigate the problem of mismatched Vanilla Framework versions - for example in #14

Please convert this project to a Web component project. Using Shadow Dom to encapsulate the markup and scoped styles and is. Create a custom element taking some customising attr.

Update the usage documentation.

Bump a major version.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.