Thomas Handorf edited this page Apr 22, 2018 · 6 revisions

In layerJS, the layout of the page is fully controlled by the hierarchy of stages, layers and frames and their attributes. Links control how this layout is dynamically changed upon user interaction.

Using links for triggering the transition has 3 advantages. First, it's easy using a mechanism that is known since the beginning of HTML. Second, every transition creates a new history entry. You can use the browser back and forward buttons to navigate through your application. Third, connecting the UI state with the URL allows you the create deep links into your application.

Hash router

All interactions possible in layerJS can be triggered by regular links. layerJS provides different "router" modules that "run" those interactions. The hashrouter is the simples router and is active by default.

In it's simplest form you just need to mention a frame name after the '#' sign.

<a href="#frame1">Go</a>

Note: frame1 should be a unique name as the link above does not mention any layer. layerJS will search all layers in the site and will do the transition in the layer that contains "frame1".

This can be accompanied by transition paramaters defining the transition type ("p") and the duration ("t")

<a href="#frame1&p=right&t=2s">Go</a>

There exist the special frames !next, !prev and !none that determine the frame to be changed by context. !next and !prev will activate the frame after or the frame before the current frame. !none will show no frame. You need to supply a layer as context.

<a href="#mylayer.!next">Go</a>

You can combine transitions in different layer within one link:

<a href="#menulayer.!none&p=fade;popup&p=fade">Go</a>

The above will fade in a popup frame called "popup" while at the same time fading out the menu.

File router

The file router allows transitions between frames in different HTML files. The is useful if you would like to spread content between different site for load times and SEO reasons. To use first enable the file router:

<body lj-router="filerouter">
...

Then use a link the refers the file with the frame to be loaded

<a href="./otherfile.html">Go</a>

The filerouter will load the other files as an ajax request (Note: it needs to be on the same domain or CORS needs to be active on the server). It will analyze the stage-layer-frame hierarchy of the new file, matches common parts with the current file and adds new frames to the current hierarchy. Then it identifies the frames that should be active in the new file and does the correponsing transitions in the current file.

Important The structures of the files need to be similar. For example

file1.html
<body lj-type="stage" lj-router="filerouter">
  <div lj-type="layer" id="contentlayer">
    <div lj-type="frame" id="frame1">
    </div>
  </div>
</body>
file2.html
<body lj-type="stage" lj-router="filerouter">
  <div lj-type="layer" id="contentlayer">
    <div lj-type="frame" id="frame2">
    </div>
  </div>
</body>

a link <a href="./file2.html"></a> will dynamically add "frame2" to "contentlayer" in the current page and do a transition from frame1 to frame2.

Static router

Note: the static router is currently being revised and not working in the current version

The static router allows you to add absolute urls that are connected to states, a list indicating which frames are active in which stages.

layerJS.router.addStaticRoute("/frame1",["frame1"])

will add a static route that will transition to frame1 if a link to “/frame1” is clicked. More complex scenarios are possible

layerJS.router.addStaticRoute("/awesome",["stage1.layer1.frame2","stage2.layer2.frame6"])

will trigger transitions in layer1 and layer2 if the user goes to /awesome.

Advanced usage

no-url

By adding

lj-no-url="true"

to the layer, the state of that layer is not shown in the url. This is helpful for opening and closing menues, etc. so for state changes that you don't need to save in a deeplink or want to go through in history.

Interstage transitions

Interstage transitions allow sending frames from one stage to another, creating effect like "zooming" a card in a grid to fullscreen while leaving all other cards in the grid.

Interstage transitions work similar as normal transitions. You simply need to specify the target layer in front of the frame. Here is an example with the has router:

<a href="#newlayer.frame1">fullscreen</a>

You can move the frame back with:

<a href="#oldlayer.frame1">fullscreen</a>

Note: both transitions will make frame1 the active frame in the target layer. if that is not desired use '$' at the end of the path :

<a href="#oldlayer.frame1$">fullscreen</a>
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.