koco dialoger
koco dialoger is a knockout component used to display full screen dialogs. It is an opinionated component based on the Koco generator.
Table of contents
Installation
bower install koco-dialoger
Usage
In your startup file, we need to do a number of things in order to fully initialize the dialoger:
startup.js
;
index.html
Test
Registering a dialog
To register a dialog, you have to use the registerDialog
function:
dialoger
name
parameter
The name of the knockout component being added. -dialog
will be appended automatically at the end.
options
parameter
The options to be used when creating the dialog.
title: string // defines the title of the dialog when displaying. isBower: boolean // defines if the component comes from bower, a default bower path will be used. basePath: string // the base path to be use to find the component. It has to be the root of the default files (see below). htmlOnly: boolean // when creating a dialog, it is possible that there would be no JavaScript linked to this dialog, it will assume so and load the html file using the naming convention (see below).
Creating a dialog component
The creation of a dialog is based on the knockout component system.
JavaScript UI handler
By convention, the name of the file has to be [name]-dialog-ui.js
, [name]
being the name of your new dialog. This file has to return a Knockout component structure.
;
HTML presentation
When using a JavaScript UI handler, the name of this file has to be defined by you. However, if using the htmlOnly option, the component will be loading [name]-dialog.html by convention.
This is a test dialog. Close
Using a dialog
Now that you created a dialog, you may want to display it and get data from it.
Displaying a dialog
To show a dialog, you have to use the show()
function.
dialoger
This function returns a jQuery promise
and will resolve itself when the dialog is closed.
Closing and returning data from a dialog
Upon displaying a dialog, it will present itself in fullscreen and blocking interface. The close button and any data to be transfered to the caller have to be handled by the callee.
Returing data
The JavaScript UI handler will receive a close
function in its params
parameter.
;
The data
parameter is an object and will be passed as-is to the caller.
Since show
returns a promise, you have to use the then
function to claim the returned data.
dialoger;
Closing
To close a dialog, simply call close()
without any parameter.
Using the dialog binding handler
A binding handler
comes with dialoger
to help you display dialogs efficiently.
The binding handler
will handle clicks and set the focus back on the button once it is closed. There are several parameters that can be used:
name: 'name' // name of the dialog to be shown params: {} // parameters to be passed to the dialog. , // callback when the dialog is closed failed: function(err), // callback when the dialog has failed. Note that this is called when there is an actual error, not when the user click cancel.}
Dialog inception
Dialoger is able to stack multiple instances of the same dialog or different ones. The close
function will fall back to the most recently opened dialog.