Global Lua Modules/NavboxBuilder

## NavboxBuilder

**NavboxBuider** is a module that makes creating navboxes a breeze.

## Features

* Unlimited rows and sections.
* Collapsible navbox and sections.
* Possibility to customize/localize parameter names.
* Parameter documentation can be imported from Dev Wiki and it will reflect customized parameter names

## How to install

In order to use it you need to have Scribunto extension enabled on your wiki. If it isn't available for your community, just send a request via Special:Contact.

### Module

First thing is the module itself. You don't need to copy the code. Just create a module titled **Module:NavboxBuilder** (or any other – just remember to adjust `#invoke` calls) and put this in the code

```
return require('Dev:NavboxBuilder')

```

You can also customize parameters and change some additional settings at this point. See their respective sections for more info.

### CSS

There are two things to do here. First is importing the stylesheet that gives structure to the navbox. To do that just add this **at the top** of your Common.css or Wikia.css.

```
@import "http://dev.wikia.com/load.php?mode=articles&articles=Global\_Lua\_Modules/NavboxBuilder/code.css&only=styles";

```

Second is changing how it looks. More info on that can be found in the Design section below.

### Template

The module is designed to be used as a regular template. To do that just create a template (ex: **Template:Navbox**) with following content:

```
<onlyinclude>{{#invoke:NavboxBuilder|create}}</onlyinclude>

== Parameters ==
{{#invoke:NavboxBuilder|documentation}}
```

Now the template you created will accept parameters documented below.

These parameters can also be passed directly to the `#invoke` and will act as defaults. Their values will be overridden by same ones passed to the template.

Styling parameters are an exception. In their case both values will be used together.

The example above also includes the part that will insert parameter documentation on your wiki.

```
{{#invoke:NavboxBuilder|documentation}}
```

It'll display in your wiki's language (if a translation exists) and change to reflect customized parameters.

You can change the language by specifying it in an additional parameter

```
{{#invoke:NavboxBuilder|documentation|<lang code>}}
```

## Parameters

Below is the list of all available parameters. At least one list is required for the navbox to show up. Apart from that, all other parameters are optional.

### Main

* `Title` – main title of the navbox.
* `Links` – links that appear on left side of the title bar.
	+ You can put any wikisyntax here.
	+ `Title` is required for it to work.
* `State` – should the navbox be collapsed or expanded by default
	+ Values: *`collapsed`* or *`expanded`* (case insensitive)
	+ Empty or unrecognized values will disable collapsing.
	+ `Title` is required for it to work
* `Above` and `Below` – fields above and below sections and images.
* `Left image` and `Right image` – fields beside sections, most commonly used to add images.
	+ You can put any content here, not only images.

### Sections

Sections include all lists with the same or higher number up to the next section.

* `Header n` – heading of a section
	+ n – any positive integer
	+ Requires at least one list to be included to show up
* `State n` – should the section be collapsed or expanded by default
	+ n – number of an existing header
	+ Values: *`collapsed`* or *`expanded`* (case insensitive)
	+ Empty or unrecognized values will disable collapsing.
* `%header\_state%` – same as above, but affects all headers
	+ Values: *`collapsed`* or *`expanded`* (case insensitive)
	+ Empty or unrecognized values will disable collapsing.
	+ Can be overridden by `State n`
* `%layout\_n%` – selects layout for that section
	+ n – any positive integer
	+ Can be used without `Header n` to create a separate section without a header
	+ Values: *`%value_table_layout%`* or *`%value_horizontal_layout%`* (case insensitive)
	+ Empty or unrecognized values will use default (*`%value_table_layout%`*).

#### Table layout (*`%value_table_layout%`*)

Standard layout with lists and sublists.

* `Left image n` and `Right image n` – fields beside sections lists in that section, most commonly used to add images.
	+ n – number of an existing header
	+ You can put any content here, not only images.

#### Horizontal layout (*`%value_horizontal_layout%`*)

Horizontal layout with lists forming columns. Sublists are not supported and will be treated as regular lists.

* `%perrow\_n%` – maximum number of lists per row.
	+ n – number of an existing section.
	+ Value: any number above 1.
	+ Number of columns is still limited by space needed. You can't go higher than flexbox allows.
* `%span\_n%` – how many columns should the list span.
	+ n – number of an existing list.
	+ Value: any number between 0 and corresponding `%perrow\_n%`

### Lists

* `List n` – single row with a list of links
	+ n – any positive integer
* `Group n` – heading of a list
	+ n – number of an existing list or sublist

Sublists will appear as sub entries of the group with same n.

* `List n.m` – single row with a list of links
	+ n and m – any positive integers
* `Group n.m` – heading of a sublist
	+ n and m – numbers of an existing sublist

### Styling

* `Navbox class` and `Navbox style` – applied to the main navbox element
* `Title class` and `Title style` – applied to the title bar
* `Base class` and `Base style` – applied to all groups, subgroups, headers, *above* and *below* fields
* `Above class` and `Above style` – applied to the above field
* `Below class` and `Below style` – applied to the below field
* `Image class` and `Image style` – applied to all image fields
* `Left image class` and `Left image style` – applied to the main left image field
* `Right image class` and `Right image style` – applied to the main right image field
* `Header class` and `Header style` – applied to all headers
* `Header n class` and `Header n style` – applied to the header specified with n
* `Left image n class` and `Left image n style` – applied to the left image field in the section specified with n
* `Right image n class` and `Right image n style` – applied to the right image field in the section specified with n
* `Group class` and `Group style` – applied to all groups
* `Subgroup class` and `Subgroup style` – applied to all subgroups
* `Group n class` and `Group n style` – applied to the group specified with n
* `Group n.m class` and `Group n.m style` – applied to the subgroup specified with n and m
* `List class` and `List style` – applied to all lists
* `List n class` and `List n style` – applied to the list specified with n
* `List n.m class` and `List n.m style` – applied to the list specified with n and m

## Customizing parameters

When importing the module. Copy this and fill in yours

```
return require('Dev:NavboxBuilder').changeParameters{
    -- Settings
    tpllinks = 'Links',
    state = 'State',

    -- Fields
    title = 'Title',
    above = 'Above',
    below = 'Below',
    limage = 'Left image',
    rimage = 'Right image',

    -- Sections
    header\_n = 'Header #',
    limage\_n = 'Left image #',
    rimage\_n = 'Right image #',
    state\_n = 'State #',

    -- Groups
    group\_n = 'Group #',
    group\_n\_m = 'Group #.#',
    list\_n = 'List #',
    list\_n\_m = 'List #.#',

    -- CSS
    navbox\_class = 'Navbox class',
    navbox\_style = 'Navbox style',
    title\_class = 'Title class',
    title\_style = 'Title style',
    base\_class = 'Base class',
    base\_style = 'Base style',
    above\_class = 'Above class',
    above\_style = 'Above style',
    below\_class = 'Below class',
    below\_style = 'Below style',
    image\_class = 'Image class',
    image\_style = 'Image style',
    limage\_class = 'Left image class',
    limage\_style = 'Left image style',
    rimage\_class = 'Right image class',
    rimage\_style = 'Right image style',
    header\_class = 'Header class',
    header\_style = 'Header style',
    header\_n\_class = 'Header # class',
    header\_n\_style = 'Header # style',
    limage\_n\_class = 'Left image # class',
    limage\_n\_style = 'Left image # style',
    rimage\_n\_class = 'Right image # class',
    rimage\_n\_style = 'Right image # style',
    group\_class = 'Group class',
    group\_style = 'Group style',
    group\_n\_class = 'Group # class',
    group\_n\_style = 'Group # style',
    group\_n\_m\_class = 'Group #.# class',
    group\_n\_m\_style = 'Group #.# style',
    list\_class = 'List class',
    list\_style = 'List style',
    list\_n\_class = 'List # class',
    list\_n\_style = 'List # style',
    list\_n\_m\_class = 'List #.# class',
    list\_n\_m\_style = 'List #.# style',

    -- Values
    value\_expanded = 'expanded',
    value\_collapsed = 'collapsed',
}

```

## Examples

Here are few example to show what the module is capable of and how to achieve that.

***Note:** examples below use {{NavboxBuilder}} for styling.*

### Title and few rows

```
{{Navbox

}}
```

### Collapsible navbox

```
{{Navbox
...
}}

```

### Template links

```
{{Navbox
...
}}

```

### Title and groups aren't required

```
{{Navbox

}}
```

### Above and below

```
{{Navbox
...
...
}}
```

### Sections

```
{{Navbox
...

}}

```

### Collapsible sections

```
{{Navbox
...

}}

```

### Images

```
{{Navbox
...
...
...
...
}}

```

### Subgroups

```
{{Navbox

}}
```

### Styling

```
{{Navbox
...
}}
```

### Bit of everything

```
{{Navbox

}}
```

## Additional settings

These settings require you to alter how the module is imported to:

```
local NBB = require('Dev:NavboxBuilder')

Put your settings here

return NBB

```

### N's and M's

If you want to change how they appear in the documentation, just change it like so:

```
NBB.n = "your N replacement"
NBB.m = "your M replacement"

```

***Note:** Templates, parser functions etc won't be parsed thou. Only basic wikisyntax, like italics and html tags.*

## Design

If you want to customize the look of your navbox, you have few options. One of it is by using parameters, preferably by passing them to #invoke as defaults. There are few classes that adhere to wiki's theme that are perfect for this, like `color1`, `accent`. In the default skin, you can achieve the look like this:

With as little as this in your Navbox template:

```
{{#invoke:NavboxBuilder|create
}}
```

The other way is styling it in your Common.css or Wikia.css. You can find a guide to classes below.

* Main navbox element
	+ `.navbox`
	+ `.mw-collapsible` – when collapsing is enabled
	+ `.mw-collapsed` – when it's collapsed
* Title bar
	+ `.navbox-title`
	+ `.mw-collapsible-toggle` – when the navbox is collapsible
	+ `.mw-collapsible-toggle-expanded` – when the navbox is expanded
	+ `.mw-collapsible-toggle-collapsed` – when the navbox is collapsed
* Above and below
	+ `.navbox-above` and `.navbox-below`
* Left and right images (both main and sections)
	+ `.navbox-image`
* Section header
	+ `.navbox-header`
	+ `.mw-collapsible-toggle` – when the section is collapsible
	+ `.mw-collapsible-toggle-expanded` – when the section is expanded
	+ `.mw-collapsible-toggle-collapsed` – when the section is collapsed
* Rows
	+ `.navbox-odd` – for odd numbered rows
	+ `.navbox-even` – for even numbered rows
* Groups
	+ `.navbox-group`
* Subgroups
	+ `.navbox-subgroup`
* Lists
	+ `.navbox-list`
	+ `.navbox-nogroup` – when there's no group for this row
* Shared classes
	+ `.navbox-padding` – a way to customize padding of cells. Applies to all lists, groups, subgroups and above/below fields. But not to headers and the title.
	+ `.navbox-base` – a way to highlight headings. Applies to all groups, subgroups, header and above/below fields.

### Spacing

If you want to change the size of spaces between cells, here's what you have to change:

```
.navbox-table {
 border-spacing: 3px;
}
.navbox-table-wrapper {
 margin: 0 -3px -3px;
}
.navbox > .navbox-table-wrapper:first-child,
.navbox-section > .navbox-table-wrapper:first-child {
 margin-top: -3px;
}
.navbox-section {
 margin-top: 3px;
}

```