qna.js
Chat like questions and answers
Usage
Editable Example
Api
In the browser, qna
is a global variable. In Node, do:
var qna = ;
var q = new qna(nodeSelection, snippets [, opts]);
This will initialize a qna instance on the documents nodeSelection
and corresponding snippets
with the given options.
nodeSelection
— A DOM Node List or a query selector string (passed intodocument.querySelectorAll()
).snippets
— An ordered Array ofsnippetObjects
.snippetObject
— An Object literal with the following propertiesstr
— A String (required)pauseDelay
— A Number representing the delay before typing in milliseconds (optional, default 750)typeSpeed
— A Number representing the typing speed in milliseconds (optional, default 50)
opts
—
Key | Description | Value |
---|---|---|
responder |
A function for generating responses to form submissions | A function that returns a snippetObject Array |
form |
The form element to listen for a submit event. | A DOM Element or a selector String |
answer |
The answer to the question | An instance on qna |
q.respond([callback, args])
Type the snippets
to the corresponding nodeSelection
list defined at initialization with an optional callback that will be called after all the snippets have been typed to the screen.
If a responder was specified at initialization the additional arguments will be passed through to the responder function. If the responder returns a snippetObject
it will use those snippetObjects
to type to the corresponding nodeSelection
q.bindAnswer(a, [callback])
a
is a instance of qna.
callback
is a function that will be called after the questions form has been submitted.
Assign an answer and optional callback to a question.
The answers a.respond
method will be triggered when the questions form is submitted with that events parameters (formEvent, formEl).
Installation
Install via npm:
$ npm i --save qna
Install via bower:
$ bower i --save alex-ray/qna