1# QuizLib Plugin
2
3## Content
4The QuizLib Plugin for Dokuwiki embeds the JavaScript library QuizLib (https://alpsquid.github.io/quizlib/) of Andrew Palmer. The library offers functions to parse quizzes written in well-defined HTML syntax and to evaluate the user answers. Furthermore the plugin provide a simple XML-like syntax with a generic CSS styling as a all-round carefree package. Therefore 3 ways to write quizzes exist:
5* XML syntax with generic styling and generic evaluation function (only one quiz per HTML page)
6* HTML syntax with individual styling and generic evaluation function (only one quiz per HTML page)
7* HTML syntax and individual evaluation function for total freedom
8
9## Preconditions
10The plugin is tested with:
11* 2016-06-26a "Elenor of Tsort"
12* 2015-08-10a "Detritus"
13
14## Usage
15There a three kinds of question formats you can use:
16* plain text
17* radio buttons (exactly one correct answer)
18* checkbox (one or more correct answers)
19
20### XML style
21Every quiz starts with the tag "quizlib". This tag contains as attributes the array with the correct answers ("rightanswers") and the string for the submit button ("submit"). Each element of the rightanswers-array is either a string (for the plain text questions) or again an array with the zero-based indexes ('a0', 'a1', …) of the correct answers (for radio and checkbox). Please use double quotes for the rightanswers-array and single quotes inside.
22
23The questions itself are child elements of the quizlib-tag. Each "question" has an attribute "title" with the content of the question and an attribute "type" (text, radio, checkbox). The possible answers are a list separated by a vertical bar. If you want to use characters that are protected in XML you have to work with entity references (http://www.w3schools.com/xml/xml_syntax.asp):
24* `&lt;` for <
25* `&gt;` for >
26* `&amp;` for &
27* `&apos;` for '
28* `&quot;` for "
29
30```xml
31<quizlib id="quiz" rightanswers="['42',['a0'],['a0','a2','a3']]" submit="Check Answers">
32    <question title="1. What is the answer to life, the universe and everything?" type="text"></question>
33    <question title="2. Your enemy's father..." type="radio">is a hamster|smells of elderberries</question>
34    <question title="3. Which factors will contribute to the end of humanity as we know it?" type="checkbox"> Global warming| The release of Linux 4.1.15| Cats| Advancements in artificial intelligence</question>
35</quizlib>
36```
37
38### HTML style
39The syntax is rather self-explanatory, if something is unclear read documentation of the JavaScript library https://alpsquid.github.io/quizlib/
40
41The only difference to the original is the generic evaluation function "quizlibShowResults". It's the callback function for the onlick-event in the submit-button. Its first argument is the id of the quiz, the second is the array with the answers.
42
43```html
44<!-- Quiz Container -->
45<div id="quiz">
46    <!-- Question 1 -->
47    <div class="quizlib-card quizlib-question">
48        <div class="quizlib-question-title">1. What is the answer to life, the universe and everything?</div>
49        <div class="quizlib-question-answers">
50            <input type="text" name="q1">
51        </div>
52    </div>
53    <!-- Question 2 -->
54    <div class="quizlib-card quizlib-question">
55        <div class="quizlib-question-title">2. Your enemy's father...</div>
56        <div class="quizlib-question-answers">
57            <ul>
58                <li><label><input type="radio" name="q2" value="a"> is a hamster</label></li>
59                <li><label><input type="radio" name="q2" value="b"> smells of elderberries</label></li>
60            </ul>
61        </div>
62    </div>
63    <!-- Question 3 -->
64    <div class="quizlib-card quizlib-question">
65        <div class="quizlib-question-title">3. Which factors will contribute to the end of humanity as we know it?</div>
66        <div class="quizlib-question-answers">
67            <ul>
68                <li><label><input type="checkbox" name="q3" value="a"> Global warming</label></li>
69                <li><label><input type="checkbox" name="q3" value="b"> The release of Linux 4.1.15</label></li>
70                <li><label><input type="checkbox" name="q3" value="c"> Cats</label></li>
71                <li><label><input type="checkbox" name="q3" value="d"> Advancements in artificial intelligence</label></li>
72            </ul>
73        </div>
74    </div>
75    <!-- Answer Button -->
76    <button class="quizlib-submit" type="button" onclick="quizlibShowResults('quiz',['42',['a'],['a','c','d']]);">Check Answers</button>
77</div>
78
79<div id="quizlib-result" class="quizlib-card">
80    You Scored <span id="quiz-percent"></span>% - <span id="quiz-score"></span>/<span id="quiz-max-score"></span><br/>
81</div>
82```
83
84### Total freedom style
85Like HTML style but you have to write your own evaluation function.
86
87## Download
88https://gitlab.hrz.tu-chemnitz.de/sse-public/quizlib/repository/archive.zip?ref=master
89
90