NOTE: You don't state which means you are using to build/compile your story HTML file (Twine 1, Twine 2, TweeGo, etc) so the following instructions will assume you are using the Twine 2.x application, if you are using a command line compiler like TweeGo then the following CSS needs to be placed within a stylesheet tagged Passage and the Javascript within a script tagged one.
The following answer is heavily based on the SugarCube 2.x source code originally written by Thomas Michael Edwards (aka TheMadExile), so all credit for it should be given to him, and all blame for any bugs and/or errors that have been introduced in the following examples should be assigned to me.
It shows how to use code found within SugarCube's uiBarInit() and uiBarStart() functions, and its default UIBar related CSS to re-implement the main functionality of story format's Back & Forward buttons,
1. Add the 'history' related HTML elements to the StoryInterface special passage of your project.
(The default Left and Right arrows glyph of the standard UI layout are actually characters stored within SugarCube's special tme-fa-icons font, this is why HTML Character Escaping is used within the button elements.)
<div id="ui-bar-history">
<button id="history-backward" tabindex="0"></button>
<button id="history-forward" tabindex="0"></button>
</div>
<div id="passages"></div>
2. Add the following CSS to your project's Story Stylesheet area.
It allocates the default styling used to show the Left & Right arrows as well as that used to disable them as necessary.
#ui-bar-history [id|=history] {
font-family: tme-fa-icons;
font-style: normal;
font-weight: 400;
font-variant: normal;
text-transform: none;
line-height: 1;
speak: none;
}
#ui-bar-history [id|=history]:disabled {
color: #444;
background-color: transparent;
border-color: #444;
}
3. Add the following Javascript to your project's Story Javascript area.
It uses jQuery to set up the event handlers required to determine when each of the two buttons should be enabled as well as what to do when each button is selected. The code makes use of the State API to determine how many total Moments are currently within the story's History and how many of them are in the past, and it makes use of the Engine API to navigate between the Moments of the story History.
note: The following code listens for a special (undocumented?) :historyupdate event which is sent by the engine whenever the story's History has been updated, this is how we know when to check the enabled/disabled state of the buttons.
/* Set up a handler for the enabling and disabling of the history-backward/-forward buttons. */
jQuery(document)
.on(':historyupdate.ui-bar',
(function ($backward, $forward) {
return function () {
$backward.prop('disabled', State.length < 2);
$forward.prop('disabled', State.length === State.size);
};
})(jQuery('#history-backward'), jQuery('#history-forward'))
);
/* Set up a handler for the selection of the history-backward button. */
jQuery('#history-backward')
.prop('disabled', State.length < 2)
.ariaClick({
label : L10n.get('uiBarBackward')
}, function () {
Engine.backward()
});
/* Set up a handler for the selection of the history-forward button. */
jQuery('#history-forward')
.prop('disabled', State.length === State.size)
.ariaClick({
label : L10n.get('uiBarForward')
}, function () {
Engine.forward()
});
Obviously you will need to alter the above HTML, CSS, and Javascript to suit the needs of your particular project.