0.1.7 • Published 4 years ago

@fngr/loady v0.1.7

Weekly downloads
8
License
MIT
Repository
github
Last release
4 years ago

loady

loady is a tiny and lightweight (1.4kb gzipped) library that loads scripts after a selected event was triggered – for example a click on a button. If the consent is already given, the script will be loaded immediately.

npm version dependencies code style: prettier contributions welcome

Installation

Install via npm

$ npm i @fngr/loady

Usage

import loady from '@fngr/loady'

loady({
  triggerElement: document.getElementById('myButton'),
  event: 'click',
  storageItem: 'load-chartjs-consent',
  script: 'https://cdn.jsdelivr.net/npm/chart.js@2.8.0',
  attributes: {
    defer: true,
  },
})

Options

triggerElement: DOM Element, required
The DOM Element where the event listener will be added to.

event: String, required, default: 'click'
String of event type that triggers event listener on triggerElement

storageItem: String, required
Key of the item that will be placed in localStorage to determine consent

script: String, required
The URL of the script to be loaded after consent

attributes: Object, optional
Object of attributes that should be added to script tag. Something like { 'defer': true }

License

MIT

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.0

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago