1.0.0 • Published 11 years ago
simple-faq v1.0.0
jquerySimpleFAQ
Simple jQuery plugin for creating FAQ interfaces
Features
- Simple to use. Use existing HTML data (ul > li) for source or use a JSON data array
- Lots of options, but none required.
- Fast live searching using Quicksilver, including relevancy sorting (optionally).
- Add tags to FAQs to increase relevancy of searching.
- Events triggered for extra preocess handling if necessary.
Basic Usage
With an HTML data source:
<ul id='faqs'>
<li>
<!-- Note that you MUST have the "question", "answer", and "tags" classes on these nodes -->
<p class='question'>This is a question?</p>
<div class='answer'>This is the answer.</div>
<p class='tags'>tags, help, searching</p>
</li>
...
</ul>$('#faqs').simpleFAQ(); // Most simple form (all default options)When using the 'data' option (JSON) and searching:
<div><input type='text' id='faqSearch' /></div>
<ul id='faqs'></ul>$('#faqs').simpleFAQ({
data: [
{
question: "This is a question?",
answer: "This is the answer.",
tags: "tags, help, searching" // OPTIONAL, useful for search scoring (and displaying if you wish)
},
...
],
allowSearch: true,
searchNode: '#faqSearch'
});See more examples at: http://jordankasper.com/jquery/faq/examples
Events
- init.simpleFAQ: The basic UI container and event handlers have been added to the document (or have been updated). You should only ever receive ONE of these events per page load. (Arguments: event,
$.jk.SimpleFAQobject) - show.simpleFAQ: Fired when an individual FAQ answer is shown. (Note: when searching for results, this will NOT fire when the FAQ is shown, only when the ANSWER is shown.) (Arguments: event,
HTMLElementfaq) - hide.simpleFAQ: Fired when an individual FAQ answer is hidden (either explicitly by the user, or because another FAQ was shown and the
showOnlyOneoption istrue. (Note: when searching for results, this will NOT fire when the FAQ is hidden because it is not in the result set, only when the ANSWER is hidden after being shown.) (Arguments: event,HTMLElementfaq) - searchStart.simpleFAQ: Fires when the user initiates a search. (Arguments: event)
- searchEnd.simpleFAQ: Fired after a search sction is complete (all results will be showing at this point). (Arguments: event, array scores (NOTE: format will be: [ score, faqNode, ...] ))
- sort.simpleFAQ: Fired when the results of a search are sorted. (Arguments: event, array scores (NOTE: format will be: [ score, faqNode, ...] ))
Event Example
$('#faqs').bind('searchEnd.simpleFAQ', function(jQEvent, results) {
if (results.length < 1) {
// do something when there are no results?
}
});Options
- node:
selector | HTMLElement | jQuery objectThe node (or selector) to use for the FAQ UI. If not set, the current node selected by $(...).simpleFAQ(); will be used. (default:null) - data:
arrayThe JSON data to use for the FAQs (will be added to any HTML FAQs). Format:[ { question: "...", answer: "...", tags: "multiple, tags" /* OPTIONAL */ } ](default:null) - ns:
stringUsed before all assigned classes and as an event namespace. (default:"simpleFAQ") - nodeType:
stringThe type of node to look for (or use with JSON data) for FAQs. (default:"li") - questionClass:
stringThe class that all questions will have (either you have to give them this class, or use the plugin to build the list). (default:"question") - answerClass:
stringThe class that all answers will have (either you have to give them this class, or use the plugin to build the list). (default:"answer") - tagClass:
stringThe class for a node in the answer that contains tags specific to each answer. If this exists, it boosts the score for search terms that are in the tags. (default:"tags") - showOnlyOne:
booleanIf true, only one answer will be visible at a time (accordion style). (default:false) - changeHash:
booleanIf true, the URL hash will be changed on each FAQ toggle, thus allowing for linking directly to a specific FAQ. (default:true) - slideSpeed:
number | stringThe speed to open and close FAQ answers. String values must be one of the three predefined speeds: "slow", "normal", or "fast"; numeric values are the number of milliseconds to run the animation (e.g. 1000). (default:500)
Search Options
- allowSearch:
booleanIf true, adds searching ability (must provide searchNode) (default:false) - searchNode:
selector | HTMLElement | jQuery objectOnly required ifallowSearchistrue; it is the element used for search input. NOTE: we use thekeyupevent, so this should be something that will emit that event correctly and can have avalue! (Can be a node, jQuery object, or selector.) (default:null) - minSearchScore:
numberThe minimum score a FAQ must have in order to appear in search results. Depends on what search function youa re using, but quicksilver returns scores between 0 and 1 (although the final score can be more than 1 based on tag scoring). (default:0.5) - sortSearch:
booleanWhether or not to sort search results by score (descending). (default:false) - showAllOnEmpty:
booleanShould the plugin show all FAQs when there is no search input? (default:true) - caseSensitive:
booleanWhether or not the search is case sensitive. (default:false) - keyTimeout:
numberA number of milliseconds to wait after a keyup event before initiating a search. Allows for better efficiency as a person is typing (live search principle). (default:400) - partialTagScore:
numberWhat to increase the match score by when partial tags are matched (such as "sim" -> "simple") (default:0.1) - exactTagScore:
numberWhat to increase the match score by when an exact tag is matched (such as "simple" -> "simple") (default:0.2) - score:
functionA function used to score FAQ question and answer text (not tags). Should accept the full text and a single search token and return the score (generally a decimal number between 0 and 1, but this is up to you). (default:$.score(Quicksilver scoring function))
1.0.0
11 years ago