Feather Wiki

A tiny tool for simple, self-contained wikis!

Extension Development / Documentation /

FW.state

Created:

The state object on window.FW holds data in memory that should be retained between DOM renders done by nanochoo along with a few other helpful bits of data that provide context for the app.

The first thing to be aware of is the default collection of values stored in state by Choo, which will not be covered in this documentation:
https://github.com/choojs/choo/blob/master/README.md#state. You should also be aware of what is removed by nanochoo to save space, namely any state values related to components and routing.

The rest of FW.state controls various elements of Feather Wiki that are all defined in initState.js. This page outlines each variable and object in alphabetical order.

c #

String | FW.state.c stores the custom CSS for the current wiki as a string.

changed #

Boolean | FW.state.changed specifies whether the wiki's data has changed since the wiki was loaded or the last time "Save Wiki" was clicked. This value controls when the "Save Wiki" button turns red and is checked by events.CHECK_CHANGED.

edit #

Boolean | FW.state.edit specifies whether the current user-created page should be displayed in edit mode. When true, the page edit interface will be displayed.

edits #

Object / null | FW.state.edits contains the edit state for the page that is being edited. When a page is not being edited, edits is set to null.

edits keys #

name: String
FW.state.edits.name contains the value in the "Page Title" field on the edit display.
slug: String
FW.state.edits.slug contains the value in the "Page Slug" field on the edit display.
content: String
FW.state.edits.content contains the string value of the text area on the edit display where page content is entered.
tags: String
FW.state.edits.tags contains the value in the "Page Tags" field on the edit display.
parent: String
FW.state.edits.parent contains the page id of the page selected in the "Parent" field on the edit display. If "None" is selected, then this is an empty string.

If using a build of Feather Wiki that includes the Markdown editor, FW.state.edits also contains a useMd key, which is a Boolean value that specifies whether the Markdown editor should be displayed for the stored content.

events #

Object | FW.state.events stores the default nanochoo state event constants plus the constants that control Feather Wiki-specific events handled by FW.emitter. This object is mainly just for specify event names as the object keys whose values are short, unique strings for differentiating events.

See FW.emitter for each custom event key and what they do.

j #

String | FW.state.j stores the custom JavaScript for the current wiki as a string.

keep #

Boolean | FW.state.keep is a temporary value used only for preventing navigation while editing if the navigation confirmation is denied by the user.

notis #

Array | FW.state.notis is the array where notifications are stored when created using events.NOTIFY.

now #

String | FW.state.now is the hashed value of current contents of FW.state.p.

p #

Object | FW.state.p is the object that stores all user-created content for the currently loaded Feather Wiki.

p keys #

name: String
The title of your Feather Wiki as set in Wiki Settings.
desc: String
Your Feather Wiki's description as set in Wiki Settings.
pages: Array
The individual page data for your wiki.
img: Object
A key-value set of ids and the full image data of images inserted into your wiki.
published: Boolean
Whether your wiki should show edit buttons as set in Wiki Settings.
home: String
The id of the page set to display when you click the title of your wiki as set in Wiki Settings.
static: Boolean
Whether to include a static HTML copy of your wiki's full content in the output HTML instead of just a table of contents listing the page titles.

pg #

Object | FW.state.pg is the object reference to the current page that is updated using FW.state.help.getPage() every time event.NAVIGATE is run.

If the page is not found, then it will either return 1) an edit page to easily create a new page (if the FW.state.query.page value is 2 characters or longer) or 2) (if the value is 1 character, which is reserved for internal pages) a special object with the value

{
  e: true,
  name: '404',
  content: '<p>Page not found</p>'
}

prev #

String | FW.state.prev is the hashed value of contents of FW.state.p when the Feather Wiki was loaded or last saved.

recent #

Array | FW.state.recent is an array of the most recently visited pages in order starting with the most recently visited page in the format

{
  p: pageId,
  t: timestamp
}

This array is used in the Recent tab in the menu.

root #

String | FW.state.root is the value of window.location.pathname when the Feather Wiki is first loaded. This is assumed to be the path to the Feather Wiki file stored on the server or in your file system.

sb #

Boolean | FW.state.sb is the toggle value that determines whether the menu is displayed on mobile-size screens.

sbTab #

String | FW.state.sbTab is the currently visible tab in the menu. It defaults to "Pages", and other possible values are "Recent" or "Tags".

sbx #

Set | FW.state.sbx is a Set that contains the page ids of the currently expanded menu items. The items in this set are used by FW.state.help.getChildList() to determine what menu items are expanded.

src #

Boolean | FW.state.src is the toggle that determines whether the HTML rich text editor displays the raw HTML.

t #

Array | FW.state.t is a collection of all individual tags currently used by any pages in the wiki.

views #

Object | FW.state.views is the set of internal views used by Feather Wiki. Each key is a single letter and is associated with a particular Choo view that takes the form of a function that returns an HTMLElement produced by window.html.

a
The all pages view: source code
m
The view used to display pages referenced throughout the wiki that do not exist: source code
p
Does not get rendered directly, instead it controls how pages are rendered: source code
s
The Wiki Settings view: source code
t
The view used to display pages with the selected tag clicked from the Tags tab in the menu: source code