adamshaylor / jquery-age-gate

A jQuery age gate plug-in with optional adapters for both jquery.cookie and Scott Hamper’s Cookies.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

jQuery age gate

jQuery age gate is a flexible plug-in for people who can write their own CSS. It can use an existing dialog element with a CSS selector or retrieve a remote one with an XHR-compatible string. It comes with two lightweight cookie adapters.

Installation

Bower

From the command line:

bower install --save jquery-age-gate

In your HTML:

<script src="bower_components/jquery-age-gate/jquery-age-gate.min.js">

npm

Alternatively, you can install from npm. From the command line:

npm install --save jquery-age-gate

In your HTML:

<script src="node_modules/jquery-age-gate/jquery-age-gate.min.js">

Usage

First, you’ll need to build and style your age gate dialog element. See the example stylesheet.

You can run the age gate with the default options inside a document ready handler like so:

$(function () {

  $.ageGate();
  
});

You can also run it with your own options. Here they are with their default values:

$(function () {

  $.ageGate({
    whitelistSelector: 'meta[name="age-restricted"][content="false"]',
    backdropId: 'age-gate-backdrop',
    activeBackdropClass: 'active',
    dialogSrc: '#age-gate-dialog',
    activeDialogClass: 'active',
    invalidAgeDialogClass: 'invalid',
    minimumAgeSelector: '[name="age-gate-minimum"]',
    parseUserDateFunction: function () { /* ... */ },
    enterButtonSelector: '.age-gate-enter',
    focusSelector: 'input[name="age-gate-month"]',
    expiration: Infinity
  });
  
});

Check out the examples to see how the options can be used.

Deferrals and events

The $.ageGate() function returns a jQuery deferral which is resolved when the user enters a valid age that meets the minimum requirement. You can close the age gate manually like so:

var deferredAgeVerification = $.ageGate();

// ...

deferredAgeVerification.resolve();

There are also custom events, agevalidated and ageinvalidated that are triggered from the dialog element whenever the user’s input is parsed and evaluted.

Philosophy and disclaimer

The goal of this project is to make the installation and adjustment of an age-gate on large existing sites as painless as possible. I make no claim regarding its efficacy, practical or legal.

About

A jQuery age gate plug-in with optional adapters for both jquery.cookie and Scott Hamper’s Cookies.js

License:MIT License


Languages

Language:HTML 62.7%Language:CSS 19.7%Language:JavaScript 17.6%