LightSwitch(statesopt, initialopt)

Color scheme switcher.

Constructor

new LightSwitch(statesopt, initialopt)

Parameters:
Name Type Default Description
statesopt string[]

All possible states. Default: ['auto', 'light', 'dark]

initialopt number 0

Initial state index

Author:
Satoshi Soma (amekusa.com)
License:
Apache-2.0
Copyright 2020 Satoshi Soma

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Source:
src/scripts/LightSwitch.js, line 25

Members

readonlyroomState string

The current state of the room.

Source:
src/scripts/LightSwitch.js, line 51

readonlystate string

The current state.

Source:
src/scripts/LightSwitch.js, line 43

Methods

getPreference(updateopt)string

Fetch user's system preference.

Parameters:
Name Type Default Description
updateopt boolean false

Force update

Source:
src/scripts/LightSwitch.js, line 59
Returns:

preferred state

Type:
string

load()

Initializes the state by loading it from the browser storage,
or reading the attribute values of "switch" or "room" element.

Source:
src/scripts/LightSwitch.js, line 160

nextState()

Switches to the next state.

Source:
src/scripts/LightSwitch.js, line 128

prevState()

Switches to the previous state.

Source:
src/scripts/LightSwitch.js, line 122

save()

Saves the current state to the browser storage.

Source:
src/scripts/LightSwitch.js, line 186

setRoom(elem, attr)

Connects a "room" element to sync state.

Parameters:
Name Type Description
elem Element

Element

attr string

Attribute to sync state

Source:
src/scripts/LightSwitch.js, line 105

setState(state)

Sets the current state.

Parameters:
Name Type Description
state
  • number
  • string

State name or index

Source:
src/scripts/LightSwitch.js, line 114
Example
ls.setState('dark');

setStorage(obj, key)

Sets a storage object to store state.

Parameters:
Name Type Description
obj Storage
key string
Source:
src/scripts/LightSwitch.js, line 84
Example
ls.setStorage(localStorage, 'lightSwitch');

setSwitch(elem, attr)

Connects a "switch" element to sync state.

Parameters:
Name Type Description
elem Element

Element

attr string

Attribute to sync state

Source:
src/scripts/LightSwitch.js, line 92

sync()

Syncs the "switch" and the "room" elements with the current state of this LightSwitch.

Source:
src/scripts/LightSwitch.js, line 134

syncRoom()

Syncs the "room" element with the current state of this LightSwitch.

Source:
src/scripts/LightSwitch.js, line 150

syncSwitch()

Syncs the "switch" element with the current state of this LightSwitch.

Source:
src/scripts/LightSwitch.js, line 141

Licensed under the Apache License 2.0

Documentation generated by JSDoc 4.0.2 using Docolatte theme