1.3.10 • Published 2 years ago

websy-navigator v1.3.10

Weekly downloads
80
License
MIT
Repository
-
Last release
2 years ago

Websy Navigator

The Websy Navigator is a simple JavaScript class that allows developers to build Single-Page-Applications with minimal amounts of JavaScript. It works by allowing the developer to configure 'views', simply by adding the required classes and attributes to their HTML markup. Each item within the navigator effectively consists of 2 HTML elements. The 'trigger' element and the 'view' element. All 'view' elements are hidden by default. When a 'trigger' element is clicked, the corresponding 'view' element is then shown.

Installation

The package can be installed using NPM.

npm install websy-navigator

You should then include both the JS and CSS files in your web application.

<link rel="stylesheet" href="<pathTo>/websy-navigator.min.css">
<script src="<pathTo>/websy-navigator.min.js" charset="utf-8"></script>

Defining Trigger Elements

To define a Trigger Element, you need to add a class of trigger-item and a data-view attribute to the desired element. The value for the data-view attribute should correspond with that of a View Element.

<ul>
  <li class="trigger-item" data-view="home">Home</li>
  <li class="trigger-item" data-view="blog">Blog</li>
</ul>

Defining View Elements

To define a View Element, you need to add a class of view and a data-view attribute to the desired element. The value for the data-view attribute should correspond with that of a Trigger Element.

<div class="view" data-view="home">
  This is the Home page
</div>
<div class="view" data-view="blog">
  This is the Blog page
</div>

Initializing the Navigator

Once included in the page, a global Class called WebsyNavigator will be available. To instantiate a new instance of the class, simply call a new version of the class, passing in any desired options.

const options = {}
let navController = new WebsyNavigator(options)
navController.init()

Options

The following options are available on the WebsyNavigator:

  • triggerClass - Change the class used to specify Trigger Elements.
  • viewClass - Change the class used to specify View Elements.
  • activeClass - Change the class used to specify an active/visible View Elements.
  • viewAttribute - Change the attribute used to specify a view name.
  • groupAttribute - Change the attribute used to specify a group name.
  • defaultView - Set the default view.
  • defaultGroup - Set the default group.

Grouping

To build hierarchical views, an additional attribute of data-group can be provided to the HTML element. Elements without this attribute are implicitly added to a group called main, unless overridden in the options. View Elements that belong to the main group will also cause the Url to update. For any other group, the Url is not updated. To set a default a View Element that belongs to a group other than main, add the relevant active class to it. A data-parent attribute should also be assigned, providing the desired parent view as the value. This will ensure that all views and child views are opened/closed correctly when navigating.

<div class="view" data-view="home">
  This is the Home page
  <button class="trigger-item" data-view="subviewa" data-group="mygroup" data-parent="home">Sub-view A</button>
  <button class="trigger-item" data-view="subviewb" data-group="mygroup" data-parent="home">Sub-view B</button>
  <div class="view" data-view="subviewa">
    This is sub-view A
  </div>
  <div class="view" data-view="subviewb">
    This is sub-view B
  </div>
</div>

Flippable Objects

It's possible to build a flippable element which has a front and back. Clicking on it will cause it to rotate and reveal whatever is on the other side. To configure the HTML structure, you will need an outer element to act as the parent to the front and back faces. As a minimum, this element should be styles with position: relative;. The front and back should then be children of this element and be assigned the classes trigger-item and flippable-item. The designated back element should be assigned the active class. They should also have a unique data-group attribute and each have their own data-view attribute. A corresponding view element is NOT required. Here is a simple example implementation:

<!-- containing element -->
<div style="position: relative; height: 200px; width: 200px;">
	<!-- front -->
	<div class="trigger-item flippable-item" style="background-color: red;" data-view="front" data-group="flippable">
	</div>
	<!-- back -->
	<div class="trigger-item flippable-item active" style="background-color: blue;" data-view="back" data-group="flippable">
	</div>
</div>

Toggle Behaviour

To create views that can be toggled on and off, simply add an the trigger-toggle class to each applicable Trigger Element.

Subscribing

To subscribe to the WebsyNavigator and listen for when the current view has changed you can call the subscribe function passing in either 'show' or 'hide' as the first parameter and a callback for the second. The provided callback function receives up to 2 parameters, the id of the view and any available url parameters.

navController.subscribe('show', (view, params) => {

})
navController.subscribe('hide', view => {

})
1.3.10

2 years ago

1.3.9

3 years ago

1.3.8

3 years ago

1.3.7

3 years ago

1.3.6

3 years ago

1.3.5

3 years ago

1.3.4

3 years ago

1.3.3

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.63

3 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.1.62

4 years ago

1.1.59

4 years ago

1.1.61

4 years ago

1.1.60

4 years ago

1.1.58

4 years ago

1.1.56

4 years ago

1.1.57

4 years ago

1.1.55

4 years ago

1.1.54

4 years ago

1.1.53

4 years ago

1.1.52

4 years ago

1.1.51

4 years ago

1.1.50

4 years ago

1.1.49

4 years ago

1.1.48

4 years ago

1.1.47

4 years ago

1.1.46

4 years ago

1.1.45

5 years ago

1.1.44

5 years ago

1.1.43

5 years ago

1.1.42

5 years ago

1.1.41

5 years ago

1.1.40

5 years ago

1.1.39

5 years ago

1.1.38

5 years ago

1.1.37

5 years ago

1.1.36

5 years ago

1.1.35

5 years ago

1.1.34

5 years ago

1.1.33

5 years ago

1.1.32

5 years ago

1.1.31

5 years ago

1.1.30

5 years ago

1.1.29

5 years ago

1.1.28

5 years ago

1.1.27

5 years ago

1.1.26

5 years ago

1.1.25

5 years ago

1.1.24

5 years ago

1.1.23

5 years ago

1.1.22

5 years ago

1.1.21

5 years ago

1.1.20

5 years ago

1.1.19

5 years ago

1.1.18

5 years ago

1.1.17

5 years ago

1.1.16

6 years ago

1.1.15

6 years ago

1.1.14

6 years ago

1.1.13

6 years ago

1.1.12

6 years ago

1.1.11

6 years ago

1.1.10

6 years ago

1.1.9

6 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

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.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

0.0.1

6 years ago