Skip to content

Commit

Permalink
closes #73, closes #70, closes #50
Browse files Browse the repository at this point in the history
git-svn-id: http://plugins.svn.wordpress.org/slickquiz/trunk@962877 b8457f37-d9ea-0310-8a92-e5e31aec5664
  • Loading branch information
jewlofthelotus committed Aug 9, 2014
1 parent c2952c5 commit cda2ed8
Show file tree
Hide file tree
Showing 13 changed files with 314 additions and 119 deletions.
3 changes: 2 additions & 1 deletion css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@
.slickQuiz .quizFormWrapper .question label {
display: block;
}
.slickQuiz .quizFormWrapper .selectAny label {
.slickQuiz .quizFormWrapper .selectAny label,
.slickQuiz .quizFormWrapper .forceCheckbox label {
display: inline-block;
}

Expand Down
2 changes: 2 additions & 0 deletions css/front.css
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@
display: block;
font-weight: bold;
}

.slickQuizWrapper ul.answers li.correct,
.slickQuizWrapper ul.responses li.correct p span {
color: #6C9F2E;
}
Expand Down
54 changes: 42 additions & 12 deletions js/admin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Mortgage Knowledge Quiz
jQuery(document).ready(function($) {

var adminPath = location.pathname.replace(/wp-admin.*/, 'wp-admin/');
Expand All @@ -23,6 +22,9 @@ jQuery(document).ready(function($) {
// If editing a quiz, quizJSON will exist
var quizValues = (typeof quizJSON != 'undefined' ? quizJSON : null);

// See if we need to hide and unrequire the ranking levels
var rankingDisabled = (typeof disableRanking != 'undefined' ? disableRanking : null);

var defaults = {
quizArea: 'div.quizFormWrapper',
quizForm: 'form.quizForm',
Expand Down Expand Up @@ -127,13 +129,18 @@ jQuery(document).ready(function($) {
addDefaultFields: function(fieldset) {
for (f in defaults.fields) {
// get field info - if quizJSON exists, use quizJSON data
field = defaults.fields[f];
field = defaults.fields[f];
inputName = field.q.replace(/\W/g,'');
required = field.required ? defaults.requiredString : '';
nameAndId = 'name="' + inputName + '" id="' + inputName + '"';
placeholder = field.placeholder ? 'placeholder="' + field.placeholder + '"' : '';
required = field.required ? defaults.requiredString : '';

if (quizValues != null) {
if (rankingDisabled && /^level/.test(field.jsonName)) {
required = '';
field.required = false;
}

if (quizValues != null && quizValues.info[field.jsonName]) {
value = plugin.formHelper.htmlspecialchars(quizValues.info[field.jsonName]);
} else {
value = '';
Expand All @@ -142,7 +149,7 @@ jQuery(document).ready(function($) {
// Setup Field Container
defaultQuestionHTML = $('<div class="question ' + inputName + '"></div>');

// Add Input Group Label (e.g. "Knowledge Levels")
// Add Input Group Label (e.g. "Ranking Levels")
if (field.label) {
defaultQuestionHTML.append('<label class="main">' + field.label + '</label>');
}
Expand All @@ -152,6 +159,10 @@ jQuery(document).ready(function($) {
defaultQuestionHTML.append('<small class="desc">' + field.descGroup + '</small>');
}

if (rankingDisabled && /^level1/.test(field.jsonName)) {
defaultQuestionHTML.append('<p><small class="desc" style="color: goldenrod;">Ranking levels are currently disabled and will not appear in the quiz.</small></p>');
}

// Add Input Label
defaultQuestionHTML.append('<label>' + required + field.q + '</label> ');

Expand Down Expand Up @@ -220,11 +231,14 @@ jQuery(document).ready(function($) {
plugin.formBuilder.addAnswer(newAnswerHTML, fieldGroup.a[f]);
}

plugin.formBuilder.addForceCheckbox(newAnswerHTML, fieldGroup);
plugin.formBuilder.addSelectAny(newAnswerHTML, fieldGroup);

} else { // Add blank answers to NEW quiz form question
plugin.formBuilder.addAnswer(newAnswerHTML.children('a')[0]);
plugin.formBuilder.addAnswer(newAnswerHTML.children('a')[0]);

plugin.formBuilder.addForceCheckbox(newAnswerHTML.children('a')[0]);
plugin.formBuilder.addSelectAny(newAnswerHTML.children('a')[0]);
}

Expand Down Expand Up @@ -252,15 +266,29 @@ jQuery(document).ready(function($) {
addAnswerLink = fieldGroup ? $(element) : $(element).parent();

var anyAnswerHTML = '<div class="question selectAny">'
+ '<input type="checkbox" name="select_any"' + (fieldGroup && fieldGroup.select_any ? ' checked="checked"' : '') + ' /> '
+ '<label>Selecting any <strong>single</strong> correct answer is valid</label><br /> '
+ '<small class="desc">If you have more than one correct answer for this quesiton, by default the user must choose all correct answers to pass.</small><br />'
+ '<label><input type="checkbox" name="select_any"' + (fieldGroup && fieldGroup.select_any ? ' checked="checked"' : '') + ' /> '
+ 'Selecting any <strong>single</strong> correct answer is valid</label><br /> '
+ '<small class="desc">If you have more than one correct answer for this question, by default the user must choose all correct answers to pass.</small><br />'
+ '<small class="desc">Checking this box will change the question so that choosing any single correct answer will result in a correct response.</small> '
+ '</div>';

addAnswerLink.after($(anyAnswerHTML).hide().fadeIn(800));
},

// Adds "force checkbox" answer option to the selected question
addForceCheckbox: function(element, fieldGroup) {
addAnswerLink = fieldGroup ? $(element) : $(element).parent();

var forceCheckboxHTML = '<div class="question forceCheckbox">'
+ '<label><input type="checkbox" name="force_checkbox"' + (fieldGroup && fieldGroup.force_checkbox ? ' checked="checked"' : '') + ' /> '
+ '<strong>Use checkboxes</strong> even if the question only has one correct answer</label><br /> '
+ '<small class="desc">If you only have one correct answer for this quesiton, by default the quiz will display radio buttons (which only allow a single selection).</small><br />'
+ '<small class="desc">Checking this box will force the question to display checkboxes, which obscures the fact that there is a single answer from the user.</small> '
+ '</div>';

addAnswerLink.after($(forceCheckboxHTML).hide().fadeIn(800));
},

// Return toggle elements
addToggles: function(position) {
toggles = '<a href="#toggleQuestionSets" class="toggleQuestionSets expand">'
Expand Down Expand Up @@ -630,6 +658,7 @@ jQuery(document).ready(function($) {
incorrectResponse = $($(questionSet).children('.incorrect').children('textarea')[0]);
answers = $($(questionSet).children('.answer'));
selectAny = $($(questionSet).find('.selectAny input[type="checkbox"]')[0]).attr('checked');
forceCheckbox = $($(questionSet).find('.forceCheckbox input[type="checkbox"]')[0]).attr('checked');
question = {"a": []};
correctAnswers = false;

Expand Down Expand Up @@ -663,10 +692,11 @@ jQuery(document).ready(function($) {
if ($.inArray(false, questionValidations) > -1) {
valid = false;
} else {
question["q"] = questionInput.attr('value');
question["correct"] = correctResponse.attr('value');
question["incorrect"] = incorrectResponse.attr('value');
question["select_any"] = selectAny ? true : false;
question["q"] = questionInput.attr('value');
question["correct"] = correctResponse.attr('value');
question["incorrect"] = incorrectResponse.attr('value');
question["select_any"] = selectAny ? true : false;
question["force_checkbox"] = forceCheckbox ? true : false;
quizJson["questions"].push(question);
}
});
Expand Down
6 changes: 5 additions & 1 deletion php/slickquiz-edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ class SlickQuizEdit extends SlickQuizModel
// Constructor
function __construct()
{
global $quiz;
global $quiz, $pluginOptions;

$this->get_admin_options();

$quiz = $this->get_quiz_by_id( $_GET['id'] );

// Add Form JS
Expand Down Expand Up @@ -109,4 +112,5 @@ function show_alert_messages()

<script type="text/javascript">
var quizJSON = <?php $slickQuizEdit->get_quiz_json(); ?>;
var disableRanking = <?php echo( $slickQuizEdit->get_admin_option( 'disable_ranking' ) == '1' ? 'true' : 'false' ); ?>;
</script>
9 changes: 7 additions & 2 deletions php/slickquiz-front.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,12 @@ function load_quiz_script()
randomSortAnswers: ' . ( $this->get_admin_option( 'random_sort_answers' ) == '1' ? 'true' : 'false' ) . ',
preventUnanswered: ' . ( $this->get_admin_option( 'disable_next' ) == '1' ? 'true' : 'false' ) . ',
perQuestionResponseMessaging: ' . ( $this->get_admin_option( 'perquestion_responses' ) == '1' ? 'true' : 'false' ) . ',
perQuestionResponseAnswers: ' . ( $this->get_admin_option( 'perquestion_response_answers' ) == '1' ? 'true' : 'false' ) . ',
completionResponseMessaging: ' . ( $this->get_admin_option( 'completion_responses' ) == '1' ? 'true' : 'false' ) . ',
displayQuestionCount: ' . ( $this->get_admin_option( 'question_count' ) == '1' ? 'true' : 'false' ) . ',
displayQuestionNumber: ' . ( $this->get_admin_option( 'question_number' ) == '1' ? 'true' : 'false' ) . '
displayQuestionNumber: ' . ( $this->get_admin_option( 'question_number' ) == '1' ? 'true' : 'false' ) . ',
disableScore: ' . ( $this->get_admin_option( 'disable_score' ) == '1' ? 'true' : 'false' ) . ',
disableRanking: ' . ( $this->get_admin_option( 'disable_ranking' ) == '1' ? 'true' : 'false' ) . '
});';

if ( $this->get_admin_option( 'save_scores' ) == '1' ) {
Expand Down Expand Up @@ -119,7 +122,9 @@ function load_quiz_script()
+ "<input type=\"text\" value=\"' . $name . '\" /></div>"
);';

if ( $this->get_admin_option( 'email_label' ) != '' ) {
if ( $name || $this->get_admin_option( 'email_label' ) != '') {
$display = $name ? 'style=\"display: none;\"' : '';

$out .= '
// insert a email field before the button
$("#slickQuiz' . $quiz->id . ' .buttonWrapper").before(
Expand Down
53 changes: 28 additions & 25 deletions php/slickquiz-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,34 @@ class SlickQuizHelper
function get_admin_options()
{
$this->adminOptions = apply_filters( 'slickquiz_admin_options', array(
'disabled_quiz_message' => '<strong>Sorry.</strong> The requested quiz has been disabled.',
'missing_quiz_message' => '<strong>Sorry.</strong> The requested quiz could not be found.',
'start_button_text' => 'Get Started!',
'check_answer_text' => 'Check My Answer!',
'next_question_text' => 'Next &raquo;',
'back_button_text' => '',
'try_again_text' => '',
'your_score_text' => 'Your Score:',
'your_ranking_text' => 'Your Ranking:',
'skip_start_button' => '0',
'number_of_questions' => '',
'random_sort_questions' => '0',
'random_sort_answers' => '0',
'random_sort' => '0',
'disable_next' => '0',
'perquestion_responses' => '1',
'completion_responses' => '0',
'question_count' => '1',
'question_number' => '1',
'save_scores' => '0',
'name_label' => 'Your Name:',
'email_label' => '',
'share_links' => '0',
'share_message' => 'I\'m a [RANK]! I just scored [SCORE] on the [NAME] quiz!',
'twitter_account' => ''
'disabled_quiz_message' => '<strong>Sorry.</strong> The requested quiz has been disabled.',
'missing_quiz_message' => '<strong>Sorry.</strong> The requested quiz could not be found.',
'start_button_text' => 'Get Started!',
'check_answer_text' => 'Check My Answer!',
'next_question_text' => 'Next &raquo;',
'back_button_text' => '',
'try_again_text' => '',
'your_score_text' => 'Your Score:',
'your_ranking_text' => 'Your Ranking:',
'skip_start_button' => '0',
'number_of_questions' => '',
'random_sort_questions' => '0',
'random_sort_answers' => '0',
'random_sort' => '0',
'disable_next' => '0',
'perquestion_responses' => '1',
'perquestion_response_answers' => '0',
'completion_responses' => '0',
'question_count' => '1',
'question_number' => '1',
'disable_score' => '0',
'disable_ranking' => '0',
'save_scores' => '0',
'name_label' => 'Your Name:',
'email_label' => '',
'share_links' => '0',
'share_message' => 'I\'m a [RANK]! I just scored [SCORE] on the [NAME] quiz!',
'twitter_account' => ''
) );

$pluginOptions = get_option( $this->adminOptionsName );
Expand Down
8 changes: 8 additions & 0 deletions php/slickquiz-new.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ class SlickQuizNew extends SlickQuizModel
// Constructor
function __construct()
{
global $pluginOptions;

$this->get_admin_options();

// Add Form JS
// wp_enqueue_script( 'tiny_mce' );
// the_editor('', 'quizContent');
Expand Down Expand Up @@ -58,3 +62,7 @@ function __construct()
<p class="previewNote"><em>Previewing will save changes to a draft version.</em></p>
</div>
</div>

<script type="text/javascript">
var disableRanking = <?php echo( $slickQuizNew->get_admin_option( 'disable_ranking' ) == '1' ? 'true' : 'false' ); ?>;
</script>
Loading

0 comments on commit cda2ed8

Please sign in to comment.