Create fancy, chrome-look-alike settings for your Chrome or Safari extension in minutes!
The goal of this project is to provide a simple way to generate native-chrome-like settings pages for use in projects like chrome extensions. Settings are defined entirely using a javascript object, the "manifest," and event binding can be easily customized via javascript.
Ideally, this framework contains enough variety of setting types that one need only to edit the "Manifest"
(/source/manifest.js
) and the settings initialization script (/source/settings.js
)
to populate the settings page with the right controls.
├── css ─────────────────────────├─( framework css; if you're extending the framework you should add to these )
│ ├── main.css ────────────────├─( main layout )
│ └── setting.css ─────────────├─( styles for each "setting" [ListBox, Button, etc.] )
├── custom.css ──────────────────├─( your css should go here, probably overriding default styles )
├── i18n.js ─────────────────────├─( your internationalization data )
├── icon.png ────────────────────├─( favicon shown on the settings tab in chrome )
├── index.html ──────────────────├─( index page; loads all javascript and establishes main layout )
├── js ──────────────────────────├─( framework javascript; if you're extending the framework you should add to these )
│ ├── classes ─────────────────├─( mootools-backed framework classes )
│ │ ├── fancy-settings.js ├─( main entry point; contains `FancySettings.initWithManifest` function, used to
│ │ │ │ build all settings and add them to the DOM )
│ │ ├── search.js ───────────├─( provides management interface for the search index )
│ │ ├── setting.js ──────────├─( classes for all setting types (e.g. ListBox, Button, etc.) and the Setting class
│ │ │ │ itself; includes DOM creation and event logic )
│ │ └── tab.js ──────────────├─( class for `Tab`; includes DOM creation and tab switching )
│ └── i18n.js ─────────────────├─( internationalization interface; retrieves i18n values registered in `/source/i18n.js` )
├── lib ─────────────────────────├─( dependencies
│ ├── default.css ─────────────├─( base css for elements and utility classes )
│ ├── mootools-core.js ────────├─( mootools )
│ └── store.js ────────────────├─( localStorage interface )
├── manifest.js ─────────────────├─( your settings manifest; see [The "Manifest"](#the--manifest)
└── settings.js ─────────────────└─( your settings pre-initialization; `FancySettings.initWithManifest` is called here
after any prerequisite async event (e.g. domready, retrieving values from
`chrome.storage`, etc.); see [Settings Initialization](#settings-initialization) )
The "Manifest" (/source/manifest.js
) is a simple javascript file which registers a global object: manifest
. This
object contains the following properties:
-
name
: Name of the manifest -
icon
: Filename of the favicon to show for the options tab in chrome -
alignment
(optional): WIP - not sure how to explain this yet -
settings
:An array containing a "flattened" list of settings. Each element in this array describes one setting. All setting objects, regardless of type, have the following properties:
tab
: The name (and text) of the tab where the setting will be shown; settings with the sametab
value will be rendered on the same tabname
: The name of this setting; this name will be used to reference it later via javascript, usually as the key of an objecttype
: The type of setting, see setting types belowlabel
(optional): The text of a<label>
element which will be rendered before the setting elementgroup
(optional): The name (and text) of the group (a section within a tab) where the setting will be shown; settings with the samegroup
value will be rendered in the same group
Type | Description | Additional Properties | Events |
---|---|---|---|
description |
renders a <p> element containing a block of text |
|
|
button |
renders a <button> element |
|
|
text |
renders an <input> element with a type attribute of either text (default) or password |
|
|
textarea |
renders an <input type='textarea'> element |
|
action : fires on textarea change & keyup |
checkbox |
renders an <input type='checkbox'> element |
HINT: use label with this setting type |
|
slider |
renders an <input type='range'> element |
|
|
popupButton |
a bit of a misnomer; render's a <select> element with <option> childred corresponding to the options array |
|
action : fires on select change |
listbox |
renders a <select> element in listBox mode with <option> elements corresponding to the options array |
|
|
radioButtons |
renders a set of <input type='radio'> elements corresponding to the options array |
|
|
modalButton |
renders a button which, when clicked, opens a modal over the current settings tab, containing nested settings |
|
|
fileButton |
WIP |
All values in the settings page are automatically persisted via localStorage
objects with the prefix of
store.settings.
(e.g. store.settings.myButton
). You can retrieve the values via javascript, operate on them
and ultimately store your chrome extension settings via chrome.storage
for use in your extension.
In the sample code of this repo, this logic resides in the settings
file as well but could
just as easily be factored out.
npm i --save or something
...- add things to your build process...
- customize
manifest.js
- customize
settings.js
- ...