1.2.0 • Published 5 years ago
night.js v1.2.0
night.js
How to Install
At the beginning install the library in your project via npm or Yarn:
$ npm install night.js
$ yarn add night.js
Getting Started
Connect using script tag in HTML:
<script src="/directory/to/library/folder/night.js"></script>
Or CommonJS/ES6 import:
const Night = require('night.js'); // CommonJS
import Night from 'night.js'; // ES6
Next use library with:
• Vanilla JavaScript e.g:
const night = new Night({
// options...
});
Functions
• Switch between light and dark mode:
night.toggle();
• Switch mode automatically (based on time, location and sun position):
night.auto();
• Reset localStorage data:
night.reset();
Options
Name | Type | Default | Description | Available options |
---|---|---|---|---|
lightClass | string |
| Class added to body when light mode is active | Name of the class |
darkClass | string | dark | Class added to body when dark mode is active | Name of the class |
cache | boolean | true | Cache location coordinates in local storage for one day | true (enable), false (disable) |
cacheClear | boolean | true | Clear location coordinates in local storage everyday at midnight | true (enable), false (disable) |
auto | boolean | true | Enable smart switch on script init | true (enable), false (disable) |
onAuto | function | null | Callback on smart switch | () => { // code } |
onLight | function | null | Callback when dark mode is disabled | () => { // code } |
onDark | function | null | Callback when dark mode is enabled | () => { // code } |
onToggle | function | null | Callback on dark/light mode toggle | () => { // code } |
onDenied | function | null | Callback on geolocation permission denied | () => { // code } |
onCacheClear | function | null | Callback when location coordinates and midnight time in local storage cleared | () => { // code } |
onReset | function | null | Callback on localStorage reset | () => { // code } |
Events
smartDark
event will output sun position times and user geolocation latitude & longitude
smartDarkError
event will output message when permission to geolocation is denied
License
This project is licensed under the MIT License © 2018-present Jakub Biesiada
1.2.0
5 years ago
1.2.0-beta.2
5 years ago
1.2.0-beta.1
5 years ago
1.1.8
5 years ago
1.1.7
5 years ago
1.1.6
5 years ago
1.1.5
5 years ago
1.1.4
5 years ago
1.1.4-beta.1
5 years ago
1.1.4-beta.0
6 years ago
1.1.3
6 years ago
1.1.2
6 years ago
1.1.1
6 years ago
1.1.0
6 years ago
1.1.0-beta.1
6 years ago