DawnWizard
DawnWizard v1.0
Originally made for Dawn's question in StackOverflow
http://stackoverflow.com/questions/6378814/
Made by Kalle H. Väravas
http://stackoverflow.com/users/721553/
No direct copyright or licences.
Use however you want, just give me lots of +1 :)
HTML
<div id="put_wizard_here" />
CSS
body {font-family: Arial, Verdana; font-size: 12px;}
h1 {font-size:18px;}
p {margin: 10px 0px;}
#question {display: block; margin-bottom: 5px;}
#message {display: none; margin: 5px 0px 0px; font-weight: bold;}
#message.error {color: red;}
#message.success {color: green;}
JavaScript
(function ($) {
$.fn.exists = function () {return $(this).length > 0;}
$.fn.DawnWizard = function (input_setup) {
var default_setup = {
title: 'Demo wizard',
description: 'Welcome text..'
};
setup = jQuery.extend(default_setup, input_setup || {});
var wizard_container = $(this);
var questions_count = 0;
jQuery.each(setup['questions'], function () {
questions_count++;
});
load_startup = function () {
results = [];
wizard_container.empty().append(
$('<h1>').html(setup['wizard']['title']),
content_container = $('<div id="content">').append(
$('<p>').html(setup['wizard']['description']),
$('<button id="start_wizard" />').text('Start the Wizard')
)
);
$('#start_wizard').click(function () {
load_question(current_qid = 1);
});
};
load_results = function () {
content_container.empty().append(results_container = $('<p>'));
jQuery.each(setup['questions'], function (i, question) {
results_container.append($('<div>').text(explain_qid(i) + ' - ' + results[i]));
});
content_container.after($('<button id="start_over">').text('Start over'));
current_qid = 1;
$('#start_over').click(function () {
load_startup(current_qid = 1);
});
};
load_question = function (qid) {
if (qid == 0) {
load_startup();
return;
} else if (qid == questions_count + 1) {
load_results();
return;
}
content_container.empty().append(
$('<p>').append(
$('<b id="question">').html(setup['questions'][qid]['question']),
questions =...