'); htm.push ( T ('Note: this quiz has not been assigned as work you need to do.')); //DKTMP '); htm.push ( T ('Your work will be recorded, but it may not count for your class.')); htm.push ( '
'); htm.push ( '');
htm.push ( T ('You can send a request message to your teacher asking them to include this quiz in your class.'));
htm.push ( '
');
htm.push ( '
');
htm.push ( '');
htm.push ( '
'); htm.push ( ''); htm.push ( '
'); htm.push (''); return htm.join ('\n'); } this.process_reg_code = function (reg_code) { if (debug[0]) { console.log ('[process_reg_code] reg_code:', reg_code); } if (reg_code != '') { var data = {reg_code: reg_code}; qqc.jjax (qname, 0, 0, 'reg_code_add_to_class', data); } } this.hide_reg_code_error = function () { $ ('div.qwiz_reg_code_errmsg').html ('').hide (); } this.init_preview = function (i_qwiz) { const $qwizq = $ ('#qwiz' + i_qwiz + ' div.qwizq'); if (preview_min_height) { $qwizq.css ({'min-height': preview_min_height}); } $qwizq.addClass ('qwizq_preview') .on ('mouseenter', q.set_i_qwiz_i_question) .show (); $ ('#qwiz' + i_qwiz).css ({border: 'none'}); if (! q.no_intro_b[i_qwiz] && ! qwizdata[i_qwiz].use_dataset) { $ ('div.intro-qwiz' + i_qwiz).addClass ('qwiz qwizq_preview').show (); } q.display_summary_and_exit (i_qwiz); $ ('#summary-qwiz' + i_qwiz).addClass ('qwiz qwizq_preview').show (); $ ('#next_button-qwiz' + i_qwiz).remove (); var n_questions = qwizdata[i_qwiz].n_questions; for (var i_question=0; i_question<\/code>q)([^\]]*)\]/gm);
var n_questions = m ? m.length : 0;
if (! use_dataset && ! q.qwizard_b && n_questions == 0) {
errmsgs.push (T ('Did not find question tags ("[q]")') + '. qwiz: ' + (i_qwiz + 1));
header_html = '';
} else {
htm = qqc.process_inline_textentry_terms (htm, 'terms', qwizdata, i_qwiz);
errmsgs = errmsgs.concat (qwizdata.additional_errmsgs);
htm = qqc.process_inline_textentry_terms (htm, 'add_terms', qwizdata, i_qwiz);
errmsgs = errmsgs.concat (qwizdata.additional_errmsgs);
var whitespace = qqc.parse_html_block (htm.substr (0, 2000), ['^'], ['[h]', '[i]', '[q]', '[q '], '[
q', 'return whitespace');
if (whitespace) {
htm = htm.replace (whitespace, '');
}
htm = process_header (htm, i_qwiz, 0, true);
if (set_qwizard_data_b && header_html != 'NA') {
qw.set_qwizard_data ('header_text', header_html);
}
var intro_html = qqc.parse_html_block (htm.substr (0, 5000), ['[i]'], ['[q]', '[q ', '[
q', ']*>/g, '');
intro_htmlx = qqc.trim (intro_htmlx).substr (0, 5);
if (htmx != intro_htmlx) {
errmsgs.push (T ('Text before intro') + ' [i]. qwiz: ' + (i_qwiz + 1));
}
intro_html = intro_html.replace ('[i]', '');
intro_html = qqc.balance_closing_tag (intro_html);
}
if (q.qwizard_b) {
intro_html = qqc.shortcodes_to_video_elements (intro_html);
}
if (! no_intro_i_b || q.qwizard_b || qwizdata[i_qwiz].question_time_limit) {
if (debug[0]) {
console.log ('[process_qwiz_pair] intro_html:', intro_html);
}
new_htm += ''
+ qqc.decode_image_tags (intro_html)
+ '\n';
}
if (set_qwizard_data_b) {
intro_hmtl = qqc.remove_empty_opening_tags (intro_html);
qw.set_qwizard_data ('intro_text', intro_html);
}
var exit_html = qqc.parse_html_block (htm, ['[x]'], []);
if (exit_html != 'NA') {
exit_html = exit_html.replace (/\[x\]/, '');
if (exit_html.search (/\[q[ \]]| ';
} else {
qwizdata[i_qwiz].n_questions = n_questions;
const questions_to_show = qwizdata[i_qwiz].questions_to_show;
if (questions_to_show && questions_to_show < n_questions) {
qwizdata[i_qwiz].n_questions_for_done = questions_to_show;
qwizdata[i_qwiz].random_b = true;
} else {
qwizdata[i_qwiz].n_questions_for_done = n_questions;
}
new_htm = q.process_questions (htm, new_htm, i_qwiz, undefined,
undefined, qwizard_process_dataset_questions_f);
}
} else {
if (qwizard_process_dataset_questions_f) {
qwizard.questions_cards_dataset_b = false;
}
new_htm += ''
+ '';
}
}
q.no_intro_b[i_qwiz] = no_intro_i_b && ! qwizdata[i_qwiz].question_time_limit;
new_htm = create_qwiz_divs (i_qwiz, qwiz_tag, new_htm, exit_html);
if (typeof q.qwizard_b != 'undefined') {
if (typeof qwizard != 'undefined') {
qwizard.errmsgs = errmsgs;
}
}
return new_htm;
}
this.process_questions = function (htm, new_htm, i_qwiz, i_qwizard_question,
set_qwizard_f,
qwizard_process_dataset_questions_f) {
if (set_qwizard_f) {
qw = qwizard;
n_qwizzes = 1;
set_qwizard_data_b = true;
q.qwizard_b = true;
}
if (typeof (i_qwizard_question) != 'undefined') {
number_first_question = i_qwizard_question;
} else {
number_first_question = 0;
}
if (! set_qwizard_data_b) {
if (htm.indexOf ('[!') != -1) {
htm = htm.replace (/\[!+\][^]*?\[\/!+\]/gm, '');
}
}
var question_html = htm.match (/(\[q [^\]]*\]| \n'; // This qwiz closing div.
return htm;
}
function create_icon_qwiz_div (i_qwiz) {
const icon_swhs = qwizdata[i_qwiz].icon_swhs;
var htm = [];
htm.push ('');
var icon_qwiz = qqc.get_qwiz_param ('icon_qwiz');
if (icon_qwiz != 'Not displayed') {
const qwizcards_swhs = icon_swhs ? 'swinginghotspot' : 'qwizcards';
if (icon_qwiz != 'Icon only') {
htm.push ('');
}
const title = T ('Questions, comments, suggestions?') + ' support@' + qwizcards_swhs + '.com';
var icon_b64;
if (icon_swhs) {
icon_b64 = 'iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAIAAAAC64paAAAACXBIWXMAABnWAAAZ1gEY0crtAAABiElEQVQ4jZWSv0sCYRyHnzvvinCIhBwEoyFBcJB0CKSmBJejIWhqbAuhv8DFCAdndRehqVDIKdokWlsEI1qiqesMkQNf77yGC/qh1t0zfvg8vO/3fb/gnUiE8/PvgexDLhQIh330v0ilEILNze+Z8qMRCLC7y+oqqoosI8s4DrZNr0e5jK6jafR6mOYs+fSUoyOenrBtAElClllYYGMDReHiguNj3t6oVmfdrVik2yUU+hFms+g6Z2fkcoxGbG3NGUxVabfpdFha+kySSSwLIahUeH/n5OTPhwkGubuj1UJRANJphMCycBxqtT9Nl3CYx8evwba3MQxublBVDzIQi/H6Sj4P0Gjw8MDKijfTZW8Pw2B/n8GAeNyPCSwv4zjU6zSb8yrz19OyAIJBhkP/8mQCIEmMx/5lF3c9fcvuPwvB4uI/B/xmfZ12m+dnNA3TpFQiEPAs399zfc3aGsDODobB4aFn+fIS2+bqioMD+n1Mk0xmuiXNliWJRIJolJcXolFub+n3p1sfn3l/Jjmrf3gAAAAASUVORK5CYII=';
} else {
icon_b64 = 'iVBORw0KGgoAAAANSUhEUgAAABAAAAAUCAIAAAALACogAAAABnRSTlMA/wD/AP83WBt9AAAACXBIWXMAAA7EAAAOxAGVKw4bAAABP0lEQVR4nGP8//8/AymAiSTV5GhgwSZ4rcRrxRooW3futlBnJDlGND/cXzXVccFLVP0oepiwqtZJyH2wrenBtogQBgYGhsv9q15j9cO1qTDVW8JEGRgYGBi0PJ0YGBgYrjzCpuH+qv1rGBgYGHQLoaoZGBgYlOTEGRgYGB68uY+h4fXuQy8ZGBgYnLSRvXjv0UsGBgYGBRFFdA1Prm+6x8DAwBBio4XsyO37GBgYGHTkEHaixYO4mszrWTl1CjmH7iMcKe5nhdAAi4cnL6/A3HbrHgMDw56pJ0QYIOHr5JgmgzASZoOFdggDAwPDy03HRCEhs6YJEne6c0uQHYkUcXt76pL3oTqQQbxqVjay8Sh+cC5pmuuEpkFMWQZNBCNpwMDrWTmT2+5hCCu54EqtomkVLjqYwgoiuGzACWifgQDhK2rq5bcX2gAAAABJRU5ErkJggg==';
}
htm.push ('');
if (icon_qwiz != 'Icon only') {
htm.push ('');
}
}
return htm.join ('');
}
function create_summary_report_div (i_qwiz, exit_html) {
var bottom_html = [];
bottom_html.push ('\n');
bottom_html.push ( '');
bottom_html.push ( '\n');
bottom_html.push ( '');
bottom_html.push ( '\n');
bottom_html.push ( '');
bottom_html.push ( exit_html);
bottom_html.push ( '\n');
bottom_html.push ( '\n');
bottom_html.push ('\n');
return bottom_html.join ('');
}
function get_login_html (i_qwiz, add_team_member_f, msg, proceed_to_pay) {
add_team_member_f = add_team_member_f ? 1 : 0;
proceed_to_pay = proceed_to_pay ? 1 : 0;
var onfocus = 'onfocus="jQuery (\'#qwiz_login-qwiz' + i_qwiz + ' p.login_error\').hide ()"';
var login_div_html = '';
if (msg) {
login_div_html += '' + msg + '';
} else if (add_team_member_f) {
login_div_html += '' + T ('Add team member') + '';
} else {
login_div_html += '' + T ('Record score/credit?') + '';
}
login_div_html += '
';
login_div_html +=
''
+ ''
+ T ('Login incorrect. Please try again')
+ '
\n';
return login_div_html;
}
this.qwiz_password_focus = function (el, i_qwiz) {
el.qwiz_pw = '';
el.value = '';
$ ('#qwiz_login-qwiz' + i_qwiz + ' p.login_error').hide ();
}
function create_restart_button (i_qwiz, htm, feedback_f) {
var restart = htm.match (/\[restart[^\]]*\]/);
if (restart) {
var label;
if (feedback_f || qwizdata[i_qwiz].n_questions == 1) {
label = T ('Do this question again');
} else {
if (qwizdata[i_qwiz].use_dataset && qwizdata[i_qwiz].dataset_intro_f) {
label = T ('Practice more questions');
} else {
label = T ('Take this quiz again');
}
}
var attr = qqc.replace_smart_quotes (restart[0]);
var custom_label = get_attr (attr, 'label');
if (custom_label) {
label = custom_label;
}
var restart_redo = feedback_f ? 'redo_question' : 'restart_quiz' ;
var restart_button_html =
'';
htm = htm.replace (restart, restart_button_html);
}
return htm;
}
function create_bg_img_style (i_qwiz, i_question) {
var style = '';
var bg_img = qwizdata[i_qwiz].bg_img[i_question];
if (bg_img) {
var top = bg_img.top ? bg_img.top + 'px' : '0';
var left = bg_img.left ? bg_img.left + 'px' : '0';
var width = bg_img.width ? bg_img.width + 'px' : 'auto';
var height = bg_img.height ? bg_img.height + 'px' : 'auto';
var style = ' style="background: no-repeat ' + left + ' ' + top
+ ' / ' + width + ' ' + height
+ ' url(' + bg_img.src + ')"';
if (debug[0]) {
console.log ('[create_bg_img_style] style:', style);
}
}
return style;
}
function process_question_attributes (i_qwiz, i_question, question_shortcode, i_qwizard_question) {
if (set_qwizard_data_b) {
if (typeof (i_qwizard_question) == 'undefined') {
i_qwizard_question = i_question;
}
qw.questions_cards[i_qwizard_question] = {};
}
qwizdata[i_qwiz].dataset_id[i_question] = i_question;
qwizdata[i_qwiz].unit[i_question] = qwizdata[i_qwiz].default_unit;
var m = question_shortcode.match (/\[(<\/code>)*q\s*([^\]]*)\]/m);
var attributes = m[2];
if (attributes) {
attributes = qqc.replace_smart_quotes (attributes);
if (set_qwizard_data_b) {
qw.questions_cards[i_qwizard_question].question_attributes = attributes;
}
if (q.qwizard_b) {
qwizdata[i_qwiz].qwizard_multiple_choice_b[i_question] = get_attr (attributes, 'multiple_choice') == 'true';
}
var question_topics = get_attr (attributes, 'topic', true);
if (! question_topics) {
question_topics = get_attr (attributes, 'unit', true);
}
if (question_topics) {
if (debug[4]) {
console.log ('[process_question_attributes] question_topics: ', question_topics);
}
if (set_qwizard_data_b) {
qw.questions_cards[i_qwizard_question].topic = question_topics;
}
question_topics = question_topics.split (/; */);
for (var i=0; i 1 || q.qwizard_b) {
var i_user_question = -1;
if (! q.no_intro_b[i_qwiz] || qwizdata[i_qwiz].use_dataset_questions_htm) {
start_quiz_b = true;
if (! no_login_b && ! q.qwizard_b) {
if (qwizdata[i_qwiz].qrecord_id) {
const user_logged_in_b
= typeof (document_qwiz_user_logged_in_b) != 'undefined'
&& document_qwiz_user_logged_in_b
&& typeof (document_qwiz_username) != 'undefined';
if ( user_logged_in_b
|| ( typeof (document_qwiz_declined_login_b) != 'undefined'
&& document_qwiz_declined_login_b)) {
if (user_logged_in_b & ! document_qwiz_wp_user_session_id) {
var check_team_b = true;
if (! $.cookie ('qwiz_current_login_lt_nmin_ago')) {
check_team_b = false;
var a_team = '';
if (document_qwiz_team_b) {
a_team = ' ' + T ('a team') + ':';
}
if (confirm (T ('You are logged in as') + a_team + ' ' + document_qwiz_username + '.\n' + T ('Do you want to continue? (Click "Cancel" to sign out)'))) {
var login_timeout_min = qqc.get_qwiz_param ('login_timeout_min', 40);
var options = {path: '/',
expires: login_timeout_min/(24.0*60.0)};
$.cookie ('qwiz_current_login_lt_nmin_ago', 1, options);
} else {
qqc.sign_out ();
document_qwiz_user_logged_in_b = false;
}
}
if (check_team_b && document_qwiz_team_b) {
if (! confirm (T ('You are logged in as team') + ': ' + document_qwiz_username + '.\n' + T ('Do you want to continue as this team?'))) {
document_qwiz_session_id = document_qwiz_session_id.split (';')[0];
document_qwiz_username = document_qwiz_username.split ('; ')[0];
document_qwiz_team_b = false;
qqc.set_user_menus_and_icons ();
var msg = T ('OK. Only %s is logged in now');
msg = msg.replace ('%s', document_qwiz_username);
alert (msg);
}
}
qwizdata[i_qwiz].record_start_b = false;
if (document_qwiz_user_logged_in_b) {
var data = {qrecord_id_ok: qwizdata[i_qwiz].qrecord_id_ok, type: 'start', confirm: 'js'};
record_response (i_qwiz, qwizdata[i_qwiz].qrecord_id, data, true);
}
}
} else {
q.display_login (i_qwiz);
return false;
}
}
}
if (qwizdata[i_qwiz].use_dataset || qwizdata[i_qwiz].use_dataset_questions_htm) {
var dataset_intro_f = qwizdata[i_qwiz].dataset_intro_f;
if (dataset_intro_f && dataset_intro_f != 'topics_only') {
q.display_login (i_qwiz, false, 'use_dataset_options');
} else {
$ ('.intro-qwiz' + i_qwiz).hide ();
qqc.get_dataset_questions (qwizdata[i_qwiz].use_dataset, qname,
i_qwiz, qwizdata[i_qwiz].qrecord_id,
[], [], 10000,
qwizdata[i_qwiz].dataset_questions_to_do,
false, // random_b
qwizdata[i_qwiz].use_dataset_questions_htm);
i_user_question = 0;
}
}
} else {
if (q.no_intro_b[i_qwiz]) {
if (qwizdata[i_qwiz].qwiz_timer) {
start_timers (i_qwiz);
}
}
}
if (! qwizdata[i_qwiz].use_dataset && ! qwizdata[i_qwiz].use_dataset_questions_htm) {
q.next_question_from_intro (i_qwiz, i_user_question);
}
} else {
$ ('#mode-' + qwiz_id).css ('visibility', 'hidden');
/* DKTMP
if (q.qwizard_b && ! q.no_intro_b[i_qwiz]) {
$ ('#intro-' + qwiz_id).hide ();
}
*/
}
} else {
var qwizq_id = qwiz_id + '-q' + i_question;
$ ('#' + qwizq_id).hide ();
if (document_qwiz_mobile) {
$ ('#mobile_' + qwizq_id).hide ();
}
if (qwizdata[i_qwiz].pay_quiz_deck_id
&& ( qwizdata[i_qwiz].pay_quiz_ok == 'preview_questions'
|| qwizdata[i_qwiz].pay_quiz_ok == 'preview_period_expired'
|| qwizdata[i_qwiz].pay_quiz_ok == 'no_free_trial')) {
if (qqc.preview_limit ('qwiz', qwizdata, i_qwiz)) {
return;
}
}
}
if (n_questions == 0) {
if (debug[0]) {
console.log ('[next_question] n_questions:', n_questions);
}
return;
}
if (! next_button_active_b) {
$ ('#next_button-' + qwiz_id).hide ();
qwizdata[i_qwiz].next_button_show_b = false;
}
if (i_question != -1 || simple_go_f) {
const hotspot_user_interaction = qwizdata[i_qwiz].hotspot_user_interaction[i_question];
const hotspot_info_only = hotspot_user_interaction && hotspot_user_interaction == 'info_only';
if (qwizdata[i_qwiz].information_question_b[i_question]
|| hotspot_info_only) {
$ ('#next_button_text-qwiz' + i_qwiz).html (T ('Next question'));
if (! q.qwizard_b) {
qwizdata[i_qwiz].answered_correctly[i_question] = 1;
qwizdata[i_qwiz].n_correct++;
if (qwizdata[i_qwiz].n_qs_done) {
qwizdata[i_qwiz].n_qs_done.add (qwizdata[i_qwiz].dataset_id[i_question]);
}
q.display_progress (i_qwiz);
if ( qwizdata[i_qwiz].user_question_number == 1
&& ( q.no_intro_b[i_qwiz]
|| qwizdata[i_qwiz].n_questions == 1)) {
$ ('div#icon_qwiz' + i_qwiz).hide ();
alert_not_logged_in (i_qwiz);
if (qwizdata[i_qwiz].qwiz_timer) {
start_timers (i_qwiz);
}
}
const type = hotspot_info_only ? 'hotspot_diagram' : 'information_only';
if (qwizdata[i_qwiz].qrecord_id && document_qwiz_user_logged_in_b) {
var data = {q_and_a_text: btoa (encodeURIComponent (qwizdata[i_qwiz].q_and_a_text[i_question])),
q_and_a_crc32: qwizdata[i_qwiz].q_and_a_crc32[i_question],
i_question: qwizdata[i_qwiz].dataset_id[i_question],
unit: qwizdata[i_qwiz].unit[i_question],
type: 'information_only',
response: 'continue',
correct_b: 1,
confirm: 'js'};
record_response (i_qwiz, qwizdata[i_qwiz].qrecord_id, data);
}
}
}
}
if (next_button_active_b) {
if (qwizdata[i_qwiz].user_question_number == n_questions) {
q.display_summary_and_exit (i_qwiz);
return;
}
}
if (! (qwizdata[i_qwiz].use_dataset && i_question == -1)
|| (simple_go_f && ! q.qwizard_b)) {
var n_done = qwizdata[i_qwiz].n_correct;
if (! qwizdata[i_qwiz].repeat_incorrect_b) {
n_done += qwizdata[i_qwiz].n_incorrect;
}
var n_questions_for_done = qwizdata[i_qwiz].n_questions_for_done;
if (debug[0]) {
console.log ('[next_question] n_done:', n_done, ', n_questions:', n_questions, ', n_questions_for_done:', n_questions_for_done);
}
if (n_done >= n_questions_for_done) {
if (qwizdata[i_qwiz].i_user_question == -1) {
qwizdata[i_qwiz].i_question = 0;
qwizdata[i_qwiz].i_user_question = 0;
}
var i_user_question = qwizdata[i_qwiz].i_user_question;
qwizdata[i_qwiz].questions[n_questions] = {i_user_prev_question: i_user_question, user_question_number: '--'};
qwizdata[i_qwiz].questions[i_user_question].i_user_next_question = n_questions;
qwizdata[i_qwiz].i_user_question = n_questions;
qwizdata[i_qwiz].saved_i_question = n_questions;
$ ('span.question-number-qwiz' + i_qwiz).html ('--');
if (qwizdata[i_qwiz].qwiz_timer) {
if (qwizdata[i_qwiz].n_qs) {
if (qwizdata[i_qwiz].n_qs_done.size == qwizdata[i_qwiz].n_qs) {
stop_timer (i_qwiz);
qwizdata[i_qwiz].n_qs_done = new Set ();
}
} else {
stop_timer (i_qwiz);
}
}
stop_timer (i_qwiz, true, true);
if (qwizdata[i_qwiz].$question_timer) {
qwizdata[i_qwiz].$question_timer.hide ();
}
q.display_summary_and_exit (i_qwiz);
} else {
if (q.qwizard_b) {
qwizdata[i_qwiz].i_question++;
i_question = qwizdata[i_qwiz].i_question;
} else {
var ii_question;
const reshow_after = qwizdata[i_qwiz].reshow_after;
while (true) {
ii_question = qwizdata[i_qwiz].ii_question;
if (ii_question >= qwizdata[i_qwiz].n_questions_for_done) {
ii_question = 0;
qwizdata[i_qwiz].ii_question = 0;
}
i_question = qwizdata[i_qwiz].question_order[ii_question];
if (qwizdata[i_qwiz].repeat_incorrect_b) {
if (qwizdata[i_qwiz].answered_correctly[i_question] != 1) {
var reshowing = false;
if (reshow_after) {
const i_questions_done = qwizdata[i_qwiz].i_questions_done;
const i_back = i_questions_done.length - reshow_after;
if (i_back >= 0) {
const i_question_back = i_questions_done[i_back];
if (qwizdata[i_qwiz].answered_correctly[i_question_back] != 1) {
reshowing = true;
i_question = i_question_back;
}
}
}
qwizdata[i_qwiz].i_questions_done.push (i_question);
if (! reshowing) {
qwizdata[i_qwiz].ii_question++;
}
break;
}
} else {
if (typeof qwizdata[i_qwiz].answered_correctly[i_question]
== 'undefined'
|| qwizdata[i_qwiz].answered_correctly[i_question] == 0) {
qwizdata[i_qwiz].ii_question++;
break;
}
}
qwizdata[i_qwiz].ii_question++;
}
}
var i_prev_question = qwizdata[i_qwiz].i_user_question;
qwizdata[i_qwiz].i_question = i_question;
if (typeof (qwizdata[i_qwiz].questions[i_question]) == 'undefined') {
qwizdata[i_qwiz].questions[i_question] = {};
}
var question = qwizdata[i_qwiz].questions[i_question];
if (i_prev_question != question.i_user_prev_question) {
question.i_user_prev_question = i_prev_question;
}
if (i_prev_question == -1) {
qwizdata[i_qwiz].i_first_user_question = i_question;
if (debug[0]) {
console.log ('[next_question] i_first_user_question:', i_question);
}
} else {
var prev_question = qwizdata[i_qwiz].questions[i_prev_question];
if (prev_question) {
prev_question.i_user_next_question = i_question;
} else {
console.log ('[next_question] prev_question for i_prev_question', i_prev_question, 'does not exist');
}
if (! q.qwizard_b) {
$ ('.bck-question-qwiz' + i_qwiz).css ({opacity: 0.5}).addClass ('hover');
}
}
qwizdata[i_qwiz].i_user_question = i_question;
if (typeof question.user_question_number == 'undefined') {
qwizdata[i_qwiz].user_question_number++;
question.user_question_number = qwizdata[i_qwiz].user_question_number;
}
if (! q.qwizard_b) {
$ ('span.question-number-qwiz' + i_qwiz).html (question.user_question_number);
}
q.display_question (i_qwiz, i_question, start_quiz_b);
if (q.qwizard_b && n_questions) {
qwizard.set_qwizard_data ('i_question', i_question);
qwizard.go_to_question2 ();
if (qw.questions_cards[i_question].type != 'hotspot_diagram') {
q.display_progress (i_qwiz);
}
}
}
}
};
this.next_question_from_intro = function (i_qwiz, i_user_question) {
if (! qwizdata[i_qwiz].n_questions) {
return;
}
$ ('.intro-qwiz' + i_qwiz).hide ();
if (! q.no_intro_b[i_qwiz]) {
$ ('#icon_qwiz' + i_qwiz).hide ();
if (qwizdata[i_qwiz].qwiz_timer) {
if (qwizdata[i_qwiz].n_qs) {
if (! qwizdata[i_qwiz].n_qs_done) {
qwizdata[i_qwiz].n_qs_done = new Set ();
}
}
start_timers (i_qwiz);
}
}
$ ('.bbfe-qwiz' + i_qwiz).css ({visibility: 'visible', opacity: 0.2}).removeClass ('hover');
$ ('span.question-number-qwiz' + i_qwiz).html (1);
$ ('#next_button-qwiz' + i_qwiz).css ('text-align', 'left');
if (! (qwizdata[i_qwiz].use_dataset || qwizdata[i_qwiz].use_dataset_questions_htm)) {
q.display_progress (i_qwiz, true);
}
$ ('#next_button_text-qwiz' + i_qwiz).html (T ('Next question'));
}
this.bck_question = function (i_qwiz, go_to_beg_f) {
if (! $ ('.bck-question-qwiz' + i_qwiz).hasClass ('hover')) {
return;
}
qwizdata[i_qwiz].bck_f = true;
var i_user_question = qwizdata[i_qwiz].i_user_question;
var i_current_user_question = i_user_question;
if (go_to_beg_f) {
if (qwizdata[i_qwiz].use_dataset && qwizdata[i_qwiz].dataset_intro_f) {
qwizdata[i_qwiz].saved_i_question = qwizdata[i_qwiz].i_question;
$ ('.bck-question-qwiz' + i_qwiz).css ({opacity: 0.2}).removeClass ('hover');
$ ('.fwd-question-qwiz' + i_qwiz).css ({opacity: 0.5}).addClass ('hover');
$ ('span.question-number-qwiz' + i_qwiz).html ('--');
hide_current_question (i_qwiz, i_current_user_question);
if (i_user_question == qwizdata[i_qwiz].n_questions) {
$ ('div#summary-qwiz' + i_qwiz).hide ();
}
qwizdata[i_qwiz].i_question = -1;
q.display_login (i_qwiz, false, 'use_dataset_options');
return;
} else {
i_user_question = qwizdata[i_qwiz].i_first_user_question;
}
} else {
i_user_question = qwizdata[i_qwiz].questions[i_user_question].i_user_prev_question;
if (i_user_question == -1) {
return;
}
}
hide_current_question (i_qwiz, i_current_user_question);
$ ('div#summary-qwiz' + i_qwiz).hide ();
qwizdata[i_qwiz].i_user_question = i_user_question;
var question = qwizdata[i_qwiz].questions[i_user_question];
if (go_to_beg_f || question.i_user_prev_question == -1) {
var $bck = $ ('.bck-question-qwiz' + i_qwiz);
if (qwizdata[i_qwiz].use_dataset && qwizdata[i_qwiz].dataset_intro_f) {
$bck = $bck.last ();
}
$bck.css ({opacity: 0.2}).removeClass ('hover');
}
var user_question_number = question.user_question_number;
$ ('span.question-number-qwiz' + i_qwiz).html (user_question_number);
$ ('.fwd-question-qwiz' + i_qwiz).css ({opacity: 0.5}).addClass ('hover');
qwizq_id = 'qwiz' + i_qwiz + '-q' + i_user_question;
$ ('#' + qwizq_id).show ();
$ ('#next_button-qwiz' + i_qwiz).hide ();
if (document_qwiz_mobile) {
$ ('#mobile_' + qwizq_id).show ();
}
}
this.fwd_question = function (i_qwiz, go_to_end_f) {
if (! $ ('.fwd-question-qwiz' + i_qwiz).hasClass ('hover')) {
return;
}
if (qwizdata[i_qwiz].i_question == -1) {
$ ('#qwiz_login-qwiz' + i_qwiz).hide ();
} else {
var i_user_question = qwizdata[i_qwiz].i_user_question;
var qwizq_id = 'qwiz' + i_qwiz + '-q' + i_user_question;
$ ('#' + qwizq_id).hide ();
if (document_qwiz_mobile) {
$ ('#mobile_' + qwizq_id).hide ();
}
}
if (go_to_end_f) {
if (qwizdata[i_qwiz].i_question == -1) {
qwizdata[i_qwiz].i_question = qwizdata[i_qwiz].saved_i_question;
}
i_user_question = qwizdata[i_qwiz].i_question;
} else {
if (qwizdata[i_qwiz].i_question == -1) {
i_user_question = qwizdata[i_qwiz].i_first_user_question;
qwizdata[i_qwiz].i_question = qwizdata[i_qwiz].saved_i_question;
} else {
i_user_question = qwizdata[i_qwiz].questions[i_user_question].i_user_next_question;
}
}
qwizdata[i_qwiz].i_user_question = i_user_question;
var question = qwizdata[i_qwiz].questions[i_user_question];
if (i_user_question == qwizdata[i_qwiz].i_question) {
qwizdata[i_qwiz].bck_f = false;
$ ('.fwd-question-qwiz' + i_qwiz).css ({opacity: 0.2}).removeClass ('hover');
if (qwizdata[i_qwiz].next_button_show_b) {
$ ('#next_button-qwiz' + i_qwiz).show ();
}
}
var user_question_number = question.user_question_number;
$ ('span.question-number-qwiz' + i_qwiz).html (user_question_number);
if (i_user_question == qwizdata[i_qwiz].n_questions) {
$ ('div#summary-qwiz' + i_qwiz).show ();
} else {
qwizq_id = 'qwiz' + i_qwiz + '-q' + i_user_question;
$ ('#' + qwizq_id).show ();
if (document_qwiz_mobile) {
$ ('#mobile_' + qwizq_id).show ();
}
if (! qwizdata[i_qwiz].summary_b) {
if (user_question_number == qwizdata[i_qwiz].n_questions) {
$ ('div#summary-qwiz' + i_qwiz).show ();
}
}
}
var $bck = $ ('.bck-question-qwiz' + i_qwiz);
if (question.i_user_prev_question == -1) {
$bck = $bck.first ();
}
$bck.css ({opacity: 0.5}).addClass ('hover');
}
this.init_question_order = function (i_qwiz) {
var n_questions = qwizdata[i_qwiz].n_questions;
qwizdata[i_qwiz].question_order = new Array (n_questions);
for (var i=0; i delay_init_drag_and_drop] i_qwiz:', i_qwiz, ', i_question:', i_question);
}
q.init_drag_and_drop ($qwizq[0]);
};
if (! q.qwizard_b) {
setTimeout (delay_init_drag_and_drop, 100);
}
var delay_place_labels = function () {
place_labels (i_qwiz, i_question, qwizq_id);
};
setTimeout (delay_place_labels, 200);
}
var n_label_targets = 0;
var target_count = {};
$qwizq.find ('span.qwizzled_target').not ('.decoy').each (function () {
var classes = $ (this).attr ('class');
var m = classes.match (/qtarget_sib-[0-9]*/);
if (m) {
var qwizzled_target_assoc_id = m[0];
target_count[qwizzled_target_assoc_id] = 1;
} else {
m = classes.match (/qwizzled_target-[0-9]*/);
if (m) {
var qwizzled_target_assoc_id = m[0];
target_count[qwizzled_target_assoc_id] = 1;
} else {
n_label_targets++;
}
}
});
n_label_targets += $qwizq.find ('div.qwizzled_target').not ('.decoy').length;
qwizdata[i_qwiz].n_label_targets = n_label_targets + Object.keys (target_count).length;
q.display_diagram_progress (i_qwiz);
} else if ($qwizq.hasClass ('hotspot_diagram')) {
const $hotspot_image_stack = $qwizq.find ('div.hotspot_image_stack')
qwizdata[i_qwiz].$hotspot_image_stack[i_question] = $hotspot_image_stack;
const $canvas = $hotspot_image_stack.find ('canvas.layer0_edited');
if (q.qwizard_b) {
$hotspot_image_stack.find ('img.layer0_edited, img.qwiz_style_layer').addClass ('qwizard_display_block_important');
$hotspot_image_stack.find ('div.qwiz_hotspot_label').removeClass ('qwizard_display_none_important');
$ ('#icon_qwiz' + i_qwiz).hide ();
} else {
qwizdata[i_qwiz].n_labels_correct = 0;
qwizdata[i_qwiz].n_label_attempts = 0;
const show_hotspots = qwizdata[i_qwiz].show_hotspots[i_question];
const find_the_dot = qwizdata[i_qwiz].find_the_dot[i_question];
if (find_the_dot) {
const find_the_dot_htm = create_find_the_dot_html (i_qwiz, qwizdata[i_qwiz].find_the_dot[i_question]);
$hotspot_image_stack.before (find_the_dot_htm);
$hotspot_image_stack.find ('img.qwiz_layer0, img.qwiz_style_layer').hide ();
$qwizq.find ('input.find_the_dot_dot_color')
.simpleColor ({boxWidth: '25px',
boxHeight: '17px',
onSelect: find_the_dot_color_selected});
$qwizq.find ('input.find_the_dot_background_color')
.simpleColor ({boxWidth: '25px',
boxHeight: '17px',
onSelect: find_the_dot_color_selected});
q.update_find_the_dot (i_qwiz, false, true);
$hotspot_image_stack.find ('canvas.layer0_edited').css ({outline: '1px dotted gray'}).show ();
} else {
qwizdata[i_qwiz].spotmap_width[i_question] = $canvas.data ('qwiz_spotmap_width');
qwizdata[i_qwiz].spotmap_height[i_question] = $canvas.data ('qwiz_spotmap_height');
const sparsemap = $canvas.data ('qwiz_sparsemap');
qwizdata[i_qwiz].sparsemap[i_question] = sparsemap;
const spotmap_data = $canvas.data ('qwiz_spotmap');
if (sparsemap) {
qwizdata[i_qwiz].spotmap[i_question] = JSON.parse (spotmap_data.replace (/(\d+):/g, '"$1":'));
} else {
qwizdata[i_qwiz].spotmap[i_question] = new Uint8ClampedArray (base64js.toByteArray (spotmap_data));
}
qwizdata[i_qwiz].hotspot_image_width[i_question] = $canvas.attr ('width');
qwizdata[i_qwiz].hotspot_image_height[i_question] = $canvas.attr ('height');
$hotspot_image_stack.find ('img.hotspot_only_image').hide ();
if (show_hotspots && show_hotspots.indexOf ('always') != -1) {
$hotspot_image_stack.find ('img.qwiz_style_layer').show ();
}
}
const hotspot_user_interaction = qwizdata[i_qwiz].hotspot_user_interaction[i_question];
if (! hotspot_user_interaction || hotspot_user_interaction == 'label_prompt') {
var n_hotspots;
if (qwizdata[i_qwiz].answered_correctly[i_question] == -1) {
var n_hotspots_to_do = 0;
n_hotspots = qwizdata[i_qwiz].n_hotspots[i_question];
for (var i=0; iClick on:'); // DKTMP
const current_query_hotspot_no = pick_random_hotspot (i_qwiz, i_question);
qwizdata[i_qwiz].current_query_hotspot_no[i_question] = current_query_hotspot_no;
set_hotspot_label_query (i_qwiz, i_question, $qwizq);
}
$hotspot_image_stack.off ('click.hotspot_diagram_click');
if (hotspot_user_interaction && hotspot_user_interaction == 'info_only') {
if (qwizdata[i_qwiz].n_questions > 1 || qwizdata[i_qwiz].use_dataset) {
$ ('#next_button_text-qwiz' + i_qwiz).html (T ('Continue'));
q.position_show_next_button (i_qwiz);
qwizdata[i_qwiz].next_button_show_b = true;
}
if (qwizdata[i_qwiz].user_question_number == 1) {
alert_not_logged_in (i_qwiz);
}
} else {
$hotspot_image_stack.on ('click.hotspot_diagram_click', qwiz_.hotspot_diagram_click);
}
if ( (show_hotspots && show_hotspots.indexOf ('hover_show') != -1)
|| (hotspot_labels_stick && hotspot_labels_stick.indexOf ('hover_show') != -1)) {
$hotspot_image_stack.off ('mousemove click.mobile_hover_eq');
$hotspot_image_stack.on ('mousemove click.mobile_hover_eq', show_hotspot_on_hover);
if (show_hotspots && show_hotspots.indexOf ('keep') == -1) {
$hotspot_image_stack.off ('mouseleave');
$hotspot_image_stack.on ('mouseleave', hide_hotspots);
}
qwizdata[i_qwiz].current_xy_hotspot_no = -1;
}
if (qwizdata[i_qwiz].icon_swhs && ! qwizdata[i_qwiz].hide_qwizcards_icon_b) {
$hotspot_image_stack.append (create_icon_qwiz_div (i_qwiz));
}
var found_clicked_visited = S ('Correctly clicked');
if (hotspot_user_interaction) {
if (hotspot_user_interaction == 'find_hotspots') {
found_clicked_visited = S ('Found');
} else if (hotspot_user_interaction == 'info_only') {
found_clicked_visited = S ('Visited');
}
}
q.display_diagram_progress (i_qwiz, found_clicked_visited);
}
}
if (start_quiz_b && qqc.is_mobile (qwizdata[i_qwiz].mobile_enabled)) {
q.go_mobile (i_qwiz);
} else if (document_qwiz_mobile) {
var $mobile_qwizq = $ ('#mobile_qwiz' + i_qwiz + '-q' + i_question);
if ($mobile_qwizq.length) {
$mobile_qwizq.show ();
} else {
$qwizq.show ();
}
window.scrollTo (0, 1);
} else {
if (debug[0]) {
console.log ('[display_question] $qwizq:', $qwizq);
}
$qwizq.css ('display', 'block');
if (q.qwizard_b) {
var init_b = false;
if (qwizdata[i_qwiz].use_dataset_question_ids[i_question]) {
var $qwiz_editable = $qwizq.find ('.qwiz_editable');
if ($qwiz_editable.length) {
$qwiz_editable.removeClass ('qwiz_editable');
init_b = true;
}
} else {
var hangman_labeled_diagram_f = $qwizq.find ('div.hangman_image').length;
qwizard.init_tinymce ('div#' + qwizq_id + ' .qwiz_editable', false,
hangman_labeled_diagram_f);
init_b = true;
}
if (init_b) {
var reset_i_question = i_question;
if (debug[0]) {
console.log ('[display_question] reset_i_question:', reset_i_question);
}
var delay_reset = function () {
qwizard.reset_show_me_button_text (reset_i_question);
if (typeof qwizdata[i_qwiz].parts_htm[reset_i_question] != 'undefined') {
var parts = qwizdata[i_qwiz].parts_htm[reset_i_question];
var n_parts = parts.length;
for (var i_part=1; i_part <= n_parts; i_part++) {
var part_htm = parts[i_part];
$ ('#qwiz' + i_qwiz + '-q' + reset_i_question + ' div.qwiz-part' + i_part).html (part_htm);
if (debug[12]) {
console.log ('part_htm:', part_htm);
}
}
}
q.init_textentry_autocomplete ($qwizq);
}
setTimeout (delay_reset, 300);
}
}
}
var selector = '#qwiz' + i_qwiz;
if (q.preview) {
selector += '-q' + i_question + '.qwizq_preview';
}
var $qwiz = $ (selector);
if (! document_qwiz_mobile && ! document_qwiz_force_mobile_f) {
if (qwizzled_b) {
var table_width = 10 + $qwizq.find ('table.qwizzled_table').outerWidth ();
if (debug[0]) {
console.log ('[display_question] table_width:', table_width, ', initial_width:', qwizdata[i_qwiz].initial_width);
}
if (table_width > qwizdata[i_qwiz].initial_width) {
$qwiz.css ({width: table_width + 'px', 'max-width': 'none'});
qwizdata[i_qwiz].width_reset = true;
}
if (q.qwizard_b) {
var $labels = $qwizq.find ('.qwizzled_highlight_label');
/* DKTMP DEDRAG
qwizard.create_label_tooltips ($labels);
qwizard.disable_browser_context_menu ($labels);
*/
$labels.addClass ('no_move');
}
} else {
var $img = $qwizq.find ('img');
if ($img.length) {
var img_width = 10 + $img.outerWidth ();
if (q.qwizard_b) {
set_initial_width (i_qwiz);
}
if (debug[0]) {
console.log ('[display_question] img_width:', img_width, ', initial_width:', qwizdata[i_qwiz].initial_width);
}
if (img_width > qwizdata[i_qwiz].initial_width) {
$qwiz.css ({width: img_width + 'px', 'max-width': 'none'});
qwizdata[i_qwiz].width_reset = true;
}
}
}
}
if ($qwiz.length) {
if (! $qwiz.is (':visible')) {
const observer = new IntersectionObserver (scale_quiz_to_container_when_visible, {threshold: 1});
observer.observe ($qwiz[0]);
} else {
scale_quiz_to_container ($qwiz);
}
}
if (! qwizzled_b) {
if (qwizdata[i_qwiz].textentry && qwizdata[i_qwiz].textentry[i_question]) {
var $textentry = $ ('#textentry-qwiz' + i_qwiz + '-q' + i_question);
if (! qwizdata[i_qwiz].textentry[i_question].textentry_suggest_b) {
var $check_answer = $ ('#textentry_check_answer_div-qwiz' + i_qwiz + '-q' + i_question);
$check_answer.find ('button.textentry_check_answer').removeClass ('qwiz_button_disabled');
qwizdata[i_qwiz].check_answer_disabled_b = false;
$check_answer.css ({display: 'inline-block'});
} else if (! qwizdata[i_qwiz].textentry[i_question].single_char_b) {
if (qwizdata[i_qwiz].terms) {
if (! qwizdata[i_qwiz].textentry_terms_metaphones) {
qwizdata[i_qwiz].textentry_terms_metaphones = qqc.process_textentry_terms (qwizdata[i_qwiz].terms);
}
} else {
if (! default_textentry_terms_metaphones) {
var plugin_url = qqc.get_qwiz_param ('url', './');
var terms_data = '';
if (content == 'body' && plugin_url == './') {
if (typeof (document_qwiz_terms) != 'undefined') {
terms_data = document_qwiz_terms;
}
} else {
terms_data = qqc.get_textentry_terms (plugin_url + 'terms.txt', qwizdata);
}
default_textentry_terms_metaphones = qqc.process_textentry_terms (terms_data);
}
}
if (qwizdata[i_qwiz].add_terms) {
if (! qwizdata[i_qwiz].add_textentry_terms_metaphones) {
qwizdata[i_qwiz].add_textentry_terms_metaphones = qqc.process_textentry_terms (qwizdata[i_qwiz].add_terms);
}
}
qwizdata[i_qwiz].check_answer_disabled_b = true;
qwizdata[i_qwiz].textentry_n_hints = 0;
textentry_answers[i_qwiz] = qwizdata[i_qwiz].textentry[i_question].answers;
textentry_answer_metaphones[i_qwiz]
= textentry_answers[i_qwiz].map (function (answer) {
answer = answer.replace (/\s*(\S+)\s.*/, '\$1');
return qqc.metaphone (answer);
});
if (qwizdata[i_qwiz].textentry[i_question].use_terms_b) {
var singular_plural;
if (qwizdata[i_qwiz].textentry[i_question].textentry_plural_b) {
singular_plural = 'plural';
} else {
singular_plural = 'singular';
}
if (qwizdata[i_qwiz].terms) {
current_question_textentry_terms_metaphones[i_qwiz]
= qwizdata[i_qwiz].textentry_terms_metaphones[singular_plural];
} else {
current_question_textentry_terms_metaphones[i_qwiz]
= default_textentry_terms_metaphones[singular_plural];
}
if (qwizdata[i_qwiz].add_terms) {
current_question_textentry_terms_metaphones[i_qwiz]
= current_question_textentry_terms_metaphones[i_qwiz]
.concat (qwizdata[i_qwiz].add_textentry_terms_metaphones[singular_plural]);
}
} else {
current_question_textentry_terms_metaphones[i_qwiz] = [];
}
var textentry_answers_metaphones
= textentry_answers[i_qwiz].map (function (answer) {
return [answer, qqc.metaphone (answer)];
});
if (debug[6]) {
console.log ('[display_question] textentry_answers_metaphones: ', textentry_answers_metaphones);
}
current_question_textentry_terms_metaphones[i_qwiz]
= current_question_textentry_terms_metaphones[i_qwiz]
.concat (textentry_answers_metaphones);
current_question_textentry_terms_metaphones[i_qwiz]
= qqc.sort_dedupe_terms_metaphones (current_question_textentry_terms_metaphones[i_qwiz]);
if (debug[6]) {
console.log ('[display_question] current_question_textentry_terms_metaphones[i_qwiz].length: ', current_question_textentry_terms_metaphones[i_qwiz].length);
console.log ('[display_question] current_question_textentry_terms_metaphones[i_qwiz].slice (0, 10): ', current_question_textentry_terms_metaphones[i_qwiz].slice (0, 10));
var i_start = current_question_textentry_terms_metaphones[i_qwiz].length - 10;
if (i_start > 0) {
console.log ('[display_question] current_question_textentry_terms_metaphones[i_qwiz].slice (' + i_start + '): ', current_question_textentry_terms_metaphones[i_qwiz].slice (i_start));
}
}
var question = qwizdata[i_qwiz].textentry[i_question];
var minlength = question.textentry_minlength;
var correct_answer_length = question.first_correct_answer.length;
if (correct_answer_length < minlength) {
minlength = correct_answer_length;
}
if (! $textentry.autocomplete ('instance')) {
q.init_textentry_autocomplete ($qwizq);
}
$textentry.autocomplete ('option', 'minLength', minlength);
var placeholder;
var check_answer;
if (minlength <= 1) {
placeholder = T ('Type a letter/number');
check_answer = T ('Type a letter');
} else {
minlength = Math.max (minlength, 3);
placeholder = T ('Type %s+ letters/numbers, then select');
placeholder = placeholder.replace ('%s', minlength);
check_answer = T ('Type %s+ letters');
check_answer = check_answer.replace ('%s', minlength);
}
$textentry.attr ('placeholder', placeholder);
$ ('#textentry_check_answer_div-qwiz' + i_qwiz + '-q' + i_question + ' button.textentry_check_answer').html (check_answer);
qwizdata[i_qwiz].check_answer = check_answer;
question.textentry_minlength = minlength;
var $check_answer = $ ('#textentry_check_answer_div-qwiz' + i_qwiz + '-q' + i_question);
$check_answer.find ('button.textentry_check_answer').addClass ('qwiz_button_disabled');
qwizdata[i_qwiz].check_answer_disabled_b = true;
$check_answer.css ({display: 'inline-block'});
if (i_question == 0 && (q.no_intro_b[i_qwiz]
|| qwizdata[i_qwiz].n_questions == 1)) {
$ ('div#qwiz' + i_qwiz).attr ('onmouseenter', qname + '.start_hint_timeout (' + i_qwiz + ')');
} else {
q.start_hint_timeout (i_qwiz);
}
}
if ($textentry.length) {
$textentry.val ('').removeAttr ('disabled');
if ((qwizdata[i_qwiz].n_correct + qwizdata[i_qwiz].n_incorrect) != 0
|| ! q.no_intro_b[i_qwiz]) {
panel_exit_mobile_just_closed_b = true;
if (! q.preview) {
$textentry.focus ();
}
}
}
} else {
if (qwizdata[i_qwiz].information_question_b[i_question]) {
if (qwizdata[i_qwiz].n_questions > 1) {
$ ('#next_button_text-qwiz' + i_qwiz).html (T ('Continue'));
q.position_show_next_button (i_qwiz);
qwizdata[i_qwiz].next_button_show_b = true;
}
} else if (typeof qwizdata[i_qwiz].hangman[i_question] != 'undefined') {
var hangman = qwizdata[i_qwiz].hangman[i_question];
var n_hangman = hangman.n_hangman;
hangman.n_hangman_done = 0;
hangman.n_hangman_correct = 0;
var first_f = true;
var hangman_final_entry;
for (var i_choice=0; i_choice 1
&& hangman.hangman_incorrect_chars[i_choice].length <= 3
&& hangman.hangman_n_hints[i_choice] == 0) {
$hangman.find ('span.hangman_current_entry').html (hangman_final_entry);
hangman.n_hangman_done++;
hangman.n_hangman_correct++;
continue;
}
}
var hangman_current_entry = hangman_final_entry.replace (/>[a-z0-9] <');
hangman.hangman_current_entry[i_choice]
= hangman_current_entry.replace (/u> \t<');
$hangman.find ('span.hangman_current_entry').html (hangman_current_entry);
if (! q.qwizard_b || hangman.hangman_answer[i_choice] != 'placeholder') {
$hangman.find ('input').off ('mousedown');
$ ('#hangman_hint-qwiz' + i_qwiz + '-q' + i_question + '-c' + i_choice)
.removeAttr ('disabled')
.removeClass ('qwiz_button_disabled')
}
hangman.hangman_incorrect_chars[i_choice] = '';
hangman.hangman_incorrect_chars_before_hint[i_choice] = 6;
hangman.hangman_n_hints[i_choice] = 0;
$hangman[0].done_f = false;
$hangman.find ('span.hangman_status').html ('');
var msg;
var hangman_answer = hangman.hangman_answer[i_choice];
if (hangman_answer.search (/[a-z]/i) != -1) {
msg = T ('Type letters in the box');
} else {
msg = T ('Type numbers in the box');
}
$hangman.find ('span.hangman_type_letters').html ('' + msg + '').show ();
$qwizq.find ('div.qwiz_hangman_msg').hide ();
if ( ( qwizdata[i_qwiz].user_question_number > 1
|| ! q.no_intro_b[i_qwiz]
|| qwizdata[i_qwiz].answered_correctly[i_question] == -1
)
&& first_f && ! q.preview) {
first_f = false;
panel_exit_mobile_just_closed_b = true;
var $hangman_input = $qwizq.find ('span.qwiz_hangman.qwiz_hangman_c' + i_choice + ' input');
suppress_hangman_hint_b = true;
if (! q.qwizard_b) {
$hangman_input[0].focus ();
}
}
}
} else {
$ ('input[name=' + qwizq_id + ']').removeAttr ('disabled').prop ('checked', false);
$ ('#mobile_' + qwizq_id + ' li.mobile_choice').show ();
$qwizq.find ('button.show_the_answer').removeAttr ('disabled').show ();
if (! q.qwizard_b) {
/*
$ ('.choices-' + qwizq_id).on ('mouseover', function () {
$ (this).css ({'cursor': 'pointer', 'color': '#045FB4'})
}).on ('mouseout', function () {;
$ (this).css ({'cursor': 'text', 'color': 'black'})
});
*/
$qwizq.find (`.choices-${qwizq_id}, .choices-${qwizq_id} .qwiz-choice`)
.css ({'cursor': '', 'color': ''});
$qwizq.find ('.qwiz_correct_choice').removeClass ('qwiz_correct_choice');
$qwizq.find ('.qwiz_incorrect_choice').removeClass ('qwiz_incorrect_choice');
}
}
}
}
}
function scale_quiz_to_container_when_visible (entries, observer) {
if (debug[0]) {
console.log ('[scale_quiz_to_container_when_visible] entries:', entries);
console.log ('[scale_quiz_to_container_when_visible] observer:', observer);
}
const $qwiz = $ (entries[0].target);
if ($qwiz.is (':visible')) {
scale_quiz_to_container ($qwiz);
observer.unobserve (entries[0].target);
}
}
function scale_quiz_to_container ($qwiz) {
var qwiz_width = $qwiz.outerWidth ();
var $container = $qwiz.parent ();
if ($container.length) {
var container_width = $container.width ();
if (container_width > 0) {
if (qwiz_width > container_width) {
const scale_fac = container_width / qwiz_width;
const trans_pct = Math.round ((1.0 - scale_fac) * 50.0)
const rtl_fac = getComputedStyle ($container[0]).direction == 'rtl' ? 1 : -1;
$qwiz.css ({transform: 'translate(' + rtl_fac*trans_pct + '%, -' + trans_pct + '%) scale(' + scale_fac.toFixed (3) + ')'});
qqc.offset_height_rescale ($qwiz, scale_fac);
const id = $qwiz[0].id;
const m = id.match (/qwiz(\d+)/);
if (m) {
const i_qwiz = m[1];
if (debug[0]) {
console.log ('[scale_quiz_to_container] $qwiz:', $qwiz);
console.log ('[scale_quiz_to_container] i_qwiz:', i_qwiz);
}
qwizdata[i_qwiz].width_reset = true;
}
$qwiz[0].qscale_fac = scale_fac;
}
}
}
}
function record_response (i_qwiz, qrecord_id, data, no_spin_f) {
if (! q.preview && ! q.qwizard_b && ! no_spin_f) {
const hhmmss = DateFormat.format.date (new Date ().getTime (), 'h:mm:ss');
$ ('span.response_recorded_wrapper-qwiz' + i_qwiz)
.css ({display: 'inline-block'})
.attr ('title', T ('Recording your response at') + ' ' + hhmmss + ' - ' + T ('not complete'));
const $response_recording = $ (`span.response_recorded-qwiz${i_qwiz} img.response_recording`);
$response_recording.addClass ('response_recording_spin').removeAttr ('title');
}
qqc.qjax (qname, i_qwiz, qrecord_id, 'record_response_v3', data);
}
this.show_response_recorded = function (i_qwiz) {
if (! q.preview) {
var hhmmss = DateFormat.format.date (new Date ().getTime (), 'h:mm:ss');
const $response_recording = $ (`span.response_recorded-qwiz${i_qwiz} img.response_recording`);
$response_recording.removeClass ('response_recording_spin')
.attr ('title', T ('Response to question') + ' ' + qwizdata[i_qwiz].user_question_number + ' ' + T ('recorded') + ' ' + hhmmss)
}
}
this.pay_lock_settings = function (do_i_qwiz_deck, i_login_qwiz, escaped_session_id,
remember_f, msg) {
qqc.pay_lock_settings (qname, qwizdata, n_qwizzes, i_login_qwiz,
escaped_session_id, remember_f, do_i_qwiz_deck, msg);
}
this.go_mobile = function (i_qwiz) {
non_mobile_scrollLeft = window.scrollX;
non_mobile_scrollTop = window.scrollY;
var $qwiz = $ ('#qwiz' + i_qwiz);
qwizdata[i_qwiz].qwiz_style = $qwiz.attr ('style');
$qwiz.removeAttr ('style').removeClass ('qwiz').addClass ('qwiz-mobile qwizard_qwiz_deck_div');
$qwiz.after ('');
$qwiz.appendTo ('body');
window.scrollTo (0, 0);
$ ('body').css ({overflow: 'hidden'});
$ ('#icon_qwiz' + i_qwiz).hide ();
if (qqc.is_mobile (qwizdata[i_qwiz].mobile_enabled) || ! document_qwiz_force_mobile_f) {
$qwiz.find ('.qwizzled_label_head_standard').hide ();
$qwiz.find ('.qwizzled_label_head_mobile').show ();
var i_question = qwizdata[i_qwiz].i_question;
if (i_question < qwizdata[i_qwiz].n_questions && ! qwizdata[i_qwiz].login_show_b) {
var qwizq_id = 'qwiz' + i_qwiz + '-q' + i_question;
var $qwizq = $ ('#' + qwizq_id);
var $mobile_qwizq = $ ('#mobile_qwiz' + i_qwiz + '-q' + i_question);
if ($mobile_qwizq.length) {
$mobile_qwizq.show ();
$qwizq.hide ();
} else {
$qwizq.show ();
}
}
if (qwizdata[i_qwiz].$qwizzled && qwizdata[i_qwiz].$qwizzled[qwizq_id]) {
reset_label_positions ($qwizq);
$qwiz.css ('width', '');
}
$ ('.go-mobile-qwiz' + i_qwiz).hide ();
if (! document_qwiz_force_mobile_f) {
$ ('.exit-mobile-qwiz' + i_qwiz).show ();
$ ('#mode-qwiz' + i_qwiz).hide ();
$ ('#icon-exit-mobile-qwiz' + i_qwiz).show ();
$ ('#summary-qwiz' + i_qwiz).find ('button.summary_exit_mobile_qwiz').show ();
}
document_qwiz_mobile = 'mobile_';
scale_quiz_to_container ($qwiz);
}
}
this.open_panel_exit_mobile = function (i_qwiz) {
$ ('#overlay-exit-mobile-qwiz' + i_qwiz)
.show ()
.animate ({top: '0px'}, 500);
panel_exit_mobile_open_b = true;
$ ('#icon-exit-mobile-qwiz' + i_qwiz).hide ();
}
this.close_panel_exit_mobile = function (overlay_el) {
$ (overlay_el).animate ({top: '-100px'}, 500,
function () {
$ (this).hide ();
$ ('div.icon-exit-mobile-qwiz').show ();
});
window.scrollTo ($ (window).scrollLeft (), 1);
panel_exit_mobile_open_b = false;
panel_exit_mobile_just_closed_b = true;
return false;
}
this.exit_mobile = function (i_qwiz) {
var $qwiz = $ ('#qwiz' + i_qwiz);
$qwiz.attr ('style', qwizdata[i_qwiz].qwiz_style)
.removeClass ('qwiz-mobile qwizard_qwiz_deck_div')
.addClass ('qwiz');
if ($ ('#xqwiz' + i_qwiz).length) {
$ ('#qwiz' + i_qwiz).css ('width', qwizdata[i_qwiz].initial_width + 'px');
}
$ ('#qwiz_div_placeholder').replaceWith ($qwiz);
$ ('body').css ({overflow: ''});
window.scrollTo (non_mobile_scrollLeft, non_mobile_scrollTop);
$ ('#overlay-exit-mobile-qwiz' + i_qwiz).css ({top: '-100px', display: 'none'});
$ (window).off ('scroll');
$qwiz.find ('.qwizzled_label_head_standard').show ();
$qwiz.find ('.qwizzled_label_head_mobile').hide ();
var i_question = qwizdata[i_qwiz].i_question;
var qwizq_id = 'qwiz' + i_qwiz + '-q' + i_question;
var $qwizq = $ ('#' + qwizq_id);
if (i_question >= 0 && i_question < qwizdata[i_qwiz].n_questions
&& ! qwizdata[i_qwiz].login_show_b) {
var $mobile_qwizq = $ ('#mobile_qwiz' + i_qwiz + '-q' + i_question);
$mobile_qwizq.hide ();
$qwizq.show ();
}
var $table_img;
if (qwizdata[i_qwiz].$qwizzled && qwizdata[i_qwiz].$qwizzled[qwizq_id]) {
$table_img = $qwizq.find ('table.qwizzled_table');
} else {
$table_img = $qwizq.find ('img');
}
if ($table_img.length) {
var table_img_width = 10 + $table_img.outerWidth ();
if (table_img_width > qwizdata[i_qwiz].initial_width) {
var selector = '#qwiz' + i_qwiz;
if (q.preview) {
selector += '-q' + i_question + '.qwizq_preview';
}
$ (selector).css ({width: table_img_width + 'px', 'max-width': 'none'});
qwizdata[i_qwiz].width_reset = true;
}
if (qwizdata[i_qwiz].$qwizzled && qwizdata[i_qwiz].$qwizzled[qwizq_id]) {
reset_label_positions ($qwizq);
}
}
$ ('div.icon-exit-mobile-qwiz, div.icon-panel-exit-mobile-qwiz').hide ();
$ ('.exit-mobile-qwiz').hide ();
$ ('button.summary_exit_mobile_qwiz').hide ();
const mobile_enabled = qwizdata[i_qwiz].mobile_enabled;
if (mobile_enabled == 'Always'
|| (mobile_enabled == 'Small screens only'
&& qqc.is_mobile (mobile_enabled))) {
$ ('.go-mobile-qwiz' + i_qwiz).show ();
}
document_qwiz_mobile = '';
panel_exit_mobile_just_closed_b = false;
}
function reset_label_positions ($qwizq) {
if (debug[8]) {
console.log ('[reset_label_positions] $qwizq:', $qwizq);
}
$qwizq.find ('td.qwizzled_labels div.qwizzled_label').each (function () {
var label_offset = $ (this).parents ('li').offset ();
if (debug[8]) {
console.log ('[reset_label_positions] label_offset:', label_offset);
}
$ (this).data ('label_x', label_offset.left).data ('label_y', label_offset.top);
});
}
this.start_hint_timeout = function (i_qwiz) {
$ ('div#qwiz' + i_qwiz).removeAttr ('onmouseenter');
var i_question = qwizdata[i_qwiz].i_question;
var $check_answer = $ ('#textentry_check_answer_div-qwiz' + i_qwiz + '-q' + i_question);
if (debug[0]) {
console.log ('[start_hint_timeout] $check_answer.length:', $check_answer.length);
}
var show_hint_button = function () {
$check_answer.find ('button.qwiz_textentry_hint')
.removeAttr ('disabled')
.html ('Hint').css ({display: 'inline-block'});
}
$check_answer.find ('button.qwiz_textentry_hint').html ('Hint').hide ();
if (hint_timeout_sec >= 0) {
show_hint_timeout[i_qwiz] = setTimeout (show_hint_button, hint_timeout_sec*1000);
}
}
function process_multiple_choice (i_qwiz, i_question, htm, opening_tags) {
var desktop_htm;
var remaining_htm;
var choices_html = '';
var span_pos = qqc.opening_tag_shortcode_pos ('([c]|[c*])', htm);
if (span_pos == htm.length) {
errmsgs.push (T ('Did not find choices ("[c]")') + '. qwiz: ' + (i_qwiz + 1) + ', ' + T ('question') + ' ' + (i_question + 1));
desktop_htm = '';
remaining_htm = '';
} else {
var question_htm = htm.substr (0, span_pos);
if (debug[0]) {
console.log ('[process_multiple_choice] span_pos: ', span_pos);
console.log ('[process_multiple_choice] question_htm: ', question_htm);
}
if (qwizdata[i_qwiz].qrecord_id) {
var q_and_a_text;
if (qqc.isInteger (qwizdata[i_qwiz].dataset_id[i_question])) {
q_and_a_text = qqc.remove_tags_eols (question_htm);
qwizdata[i_qwiz].q_and_a_text[i_question] = qqc.q_and_a_hash (q_and_a_text);
qwizdata[i_qwiz].q_and_a_crc32[i_question] = qwiz_crc32 (htm);
} else {
qwizdata[i_qwiz].q_and_a_text[i_question] = qwizdata[i_qwiz].dataset_id[i_question];
qwizdata[i_qwiz].q_and_a_crc32[i_question] = 'dataset';
}
}
if (set_qwizard_data_b) {
qw.questions_cards[i_question].type = 'multiple_choice';
question_htm = qqc.shortcodes_to_video_elements (question_htm);
qw.questions_cards[i_question].question_text = opening_tags + question_htm;
}
var bg_img_style = create_bg_img_style (i_qwiz, i_question);
desktop_htm = '\n'
+ ''
+ opening_tags + question_htm
+ '';
if (debug[1]) {
console.log ('[process_multiple_choice] desktop_htm: ', desktop_htm);
}
remaining_htm = htm.substr (span_pos);
choices_html = '';
}
var choice_tags = htm.match (/\[c\*{0,1}\]/gm);
var n_choices = 0;
if (choice_tags) {
n_choices = choice_tags.length;
}
if (debug[0]) {
console.log ('[process_multiple_choice] n_choices: ', n_choices);
}
if (set_qwizard_data_b) {
qw.questions_cards[i_question].n_choices = n_choices;
qw.questions_cards[i_question].choices = [];
qw.questions_cards[i_question].feedbacks = [];
}
var n_correct = 0;
var choice_start_tags = ['[c]', '[c*]'];
var choice_next_tags = ['[c]', '[c*]', '[x]'];
var got_feedback_b = false;
var i_fx = -1;
var feedback_divs = []; // Feedback div for desktop.
var feedback_items = []; // Plain html for mobile.
var choice_items = []; // "
var i_choice_correct = -1;
for (var i_choice=0; i_choice]*>/, '$&' + c);
} else {
choice_html = c + without_c;
}
if (q.qwizard_b) {
choice_html = choice_html.replace (/ /g, '');
} else {
var m = choice_html.match (/<\/p>\s*$/);
if (! m) {
m = choice_html.match (/ \s*$/);
if (! m) {
choice_html += ' ';
}
}
}
if (n_choices > 1
|| (q.qwizard_b
&& qwizdata[i_qwiz].qwizard_multiple_choice_b[i_question])) {
var r = create_radio_button_html (i_qwiz, i_question, i_choice,
choice_tags[i_choice]);
if (r.correct) {
n_correct++;
i_choice_correct = i_choice;
}
var qwiz_question = 'qwiz' + i_qwiz + '-q' + i_question;
var qwiz_question_choice = qwiz_question + '-a' + i_choice;
var style = '';
if (q.qwizard_b) {
style = ' style="cursor: text;"';
}
choice_html = choice_html.replace (/\[c\*{0,1}\]/m, r.htm + '');
if (/^\s*<[ph]/.test (choice_html)) {
choice_html = choice_html.trimEnd ();
var len = choice_html.length;
if (choice_html.substr (len - 4, 3) != '');
if (end_opening_tag_pos != -1) {
choices_html += choice_html.substr (0, end_opening_tag_pos + 1);
choice_html = choice_html.substr (end_opening_tag_pos + 1);
}
choice_html += '';
} else {
choice_html = choice_html.replace (/<\/(p|h[1-6])>$/, '$&');
}
} else {
choice_html += '';
}
if (set_qwizard_data_b) {
var m = choice_html.match (/]+>([^]*?)<\/span>/);
var choice = qqc.shortcodes_to_video_elements (m[1])
qw.questions_cards[i_question].choices[i_choice] = choice;
}
const onclick = 'onclick="' + qname + '.process_choice (event, \'' + qwiz_question_choice + '\')"';
var mc_style_alt = '';
if (qwizdata[i_qwiz].mc_style && qwizdata[i_qwiz].mc_style != 'radio' ) {
mc_style_alt = '-' + qwizdata[i_qwiz].mc_style;
}
if (debug[2]) {
console.log ('[process_multiple_choice] choices_html:', choices_html);
console.log ('[process_multiple_choice] choice_html:', choice_html);
}
var close_span = '';
if (i_choice == n_choices - 1 && ! mc_style_alt) {
const m = choices_html.match (/]*>\s*$/);
if (m) {
i_pos = m.index;
choices_html = choices_html.substr (0, i_pos) + '' + choices_html.substr (i_pos);
close_span = '';
}
}
choices_html += `\n
${choice_html}
` + close_span;
} else {
choice_html = choice_html.replace (/\[c\*{0,1}\]/m, '');
i_choice_correct = 0;
n_correct = 1;
var onclick;
if (qwizdata[i_qwiz].n_questions == 1) {
onclick = qname + '.process_choice (event, \'qwiz' + i_qwiz + '-q' + i_question + '-a0\', true)';
} else {
onclick = qname + '.show_answer_got_it_or_not (' + i_qwiz + ', ' + i_question + ', this)';
}
var button_label = choice_html;
if (button_label.indexOf ('[show_me_placeholder]') != -1) {
button_label = 'Show me the answer';
}
choices_html += '\n';
if (set_qwizard_data_b) {
qw.questions_cards[i_question].type = 'show_me';
choice_html = qqc.shortcodes_to_video_elements (choice_html);
qw.questions_cards[i_question].choices[i_choice] = choice_html;
}
if (! feedback_divs[0]) {
errmsgs.push (T ('Feedback [f] is required for a one-choice question') + '. qwiz: ' + (1 + i_qwiz) + ', ' + T ('question') + ' ' + (1 + i_question));
}
}
}
if (set_qwizard_data_b && qw.questions_cards[i_question].type != 'show_me') {
if (debug[12]) {
console.log ('[process_multiple_choice] choices_html:', choices_html);
}
var pos_sub_span1 = choices_html.substr (31).indexOf ('
\n';
if (debug[1]) {
console.log ('[process_multiple_choice] desktop_htm: ', desktop_htm);
}
if (n_correct == 0) {
if (! q.qwizard_b) {
if (! qwizdata[i_qwiz].use_dataset
&& ! qwizdata[i_qwiz].use_dataset_question_ids[i_question]) {
errmsgs.push (T ('No choice was marked correct') + '. qwiz: ' + (1 + i_qwiz) + ', ' + T ('question') + ' ' + (1 + i_question));
}
}
} else if (n_correct > 1) {
errmsgs.push (T ('More than one choice was marked correct') + '. qwiz: ' + (1 + i_qwiz) + ', ' + T ('question') + ' ' + (1 + i_question));
} else {
if (set_qwizard_data_b) {
qw.questions_cards[i_question].correct_choice = i_choice_correct;
}
}
for (var i_choice=0; i_choice 1 || qwizdata[i_qwiz].use_dataset)) {
desktop_htm += create_got_it_or_not ('', i_qwiz, i_question);
}
if (debug[2]) {
console.log ('[process_multiple_choice] desktop_htm: ', desktop_htm);
}
desktop_htm += '
\n';
var qwiz_question = 'mobile_qwiz' + i_qwiz + '-q' + i_question;
var mobile_htm = [];
mobile_htm.push ('\n');
mobile_htm.push ( opening_tags + question_htm);
mobile_htm.push ( '');
for (var i_choice=0; i_choice 1 || qwizdata[i_qwiz].n_questions == 1) {
onclick = qname + '.process_choice (event, \'' + qwiz_question_choice + '\')';
} else {
onclick = qname + '.show_answer_got_it_or_not (' + i_qwiz + ', ' + i_question + ', this)';
if (choice_items[0].indexOf ('[show_me_placeholder]') != -1) {
choice_items[0] = 'Show me the answer';
}
}
mobile_htm.push ( '- ');
mobile_htm.push ( '');
mobile_htm.push ( choice_items[i_choice]);
mobile_htm.push ( '');
mobile_htm.push ( '
');
}
mobile_htm.push ( '
');
mobile_htm.push ( '');
mobile_htm.push (feedback_divs.replace (/id="qwiz/gm, 'id="mobile_qwiz'));
mobile_htm.push ('');
if (n_choices == 1 && (qwizdata[i_qwiz].n_questions > 1 || qwizdata[i_qwiz].use_dataset)) {
mobile_htm.push (create_got_it_or_not ('mobile_', i_qwiz, i_question));
}
mobile_htm = mobile_htm.join ('\n');
return desktop_htm + '\n' + mobile_htm;
}
function process_textentry (i_qwiz, i_question, htm, opening_tags) {
if (! qwizdata[i_qwiz].textentry) {
qwizdata[i_qwiz].textentry = {};
textentry_b = true;
}
var question_text = htm;
var c_pos = qqc.opening_tag_shortcode_pos ('([c*]|[c])', htm);
if (c_pos < htm.length) {
question_text = htm.substr (0, c_pos);
} else {
errmsgs.push (T ('No answer-word given') + '. qwiz: ' + (1 + i_qwiz) + ', ' + T ('question') + ' ' + (1 + i_question));
}
if (qwizdata[i_qwiz].qrecord_id) {
if (qqc.isInteger (qwizdata[i_qwiz].dataset_id[i_question])) {
var q_and_a_text = qqc.remove_tags_eols (question_text);
q_and_a_text = q_and_a_text.replace (/\[textentry[^\]]*\]/, '_________');
qwizdata[i_qwiz].q_and_a_text[i_question] = qqc.q_and_a_hash (qqc.remove_tags_eols (q_and_a_text));
qwizdata[i_qwiz].q_and_a_crc32[i_question] = qwiz_crc32 (htm);
} else {
qwizdata[i_qwiz].q_and_a_text[i_question] = qwizdata[i_qwiz].dataset_id[i_question];
qwizdata[i_qwiz].q_and_a_crc32[i_question] = 'dataset';
}
}
if (set_qwizard_data_b) {
qw.questions_cards[i_question].type = 'textentry';
question_text = qqc.shortcodes_to_video_elements (question_text);
qw.questions_cards[i_question].question_text = opening_tags + question_text;
qw.questions_cards[i_question].choices = [];
qw.questions_cards[i_question].correct_choice_fs = [];
qw.questions_cards[i_question].feedbacks = [];
}
var textentry_plural_b = false;
var textentry_suggest_b = true;
var textentry_minlength = 3;
var use_dict_b = default_use_dict == 'true';
var use_terms_b = default_use_terms == 'true';
var single_char_b = false;
var m = htm.match (/\[textentry([^\]]*)\]/m);
var attributes = '';
if (m) {
attributes = m[1];
if (attributes) {
attributes = qqc.replace_smart_quotes (attributes);
textentry_plural_b = get_attr (attributes, 'plural') == 'true';
textentry_suggest_b = get_attr (attributes, 'suggest') != 'false';
var attr_val = get_attr (attributes, 'minlength');
if (attr_val != '') {
textentry_minlength = attr_val;
}
var use_terms = get_attr (attributes, 'use_terms');
if (use_terms) {
use_terms_b = use_terms != 'false';
}
var use_dict = get_attr (attributes, 'use_dict');
if (use_dict) {
use_dict_b = use_dict != 'false';
}
single_char_b = get_attr (attributes, 'single_char') == 'true';
}
}
if (set_qwizard_data_b) {
qw.questions_cards[i_question].type = single_char_b ? 'one_letter_answer' : 'textentry';
qw.questions_cards[i_question].textentry_attributes = attributes;
qw.questions_cards[i_question].textentry_plural_b = textentry_plural_b;
}
var remaining_htm = htm.substr (c_pos);
htm = htm.substr (0, c_pos);
var classname;
var style;
if (single_char_b) {
classname = 'qwiz_single_char_entry';
style = 'style="width: 2rem; padding: 2px;" ';
} else if (textentry_suggest_b) {
classname = 'qwiz_textentry';
style = 'style="width: 18em; padding: 2px;" ';
} else {
classname = 'qwiz_textentry_no_suggest';
style = 'style="width: 18em; padding: 2px;" ';
}
var input = '';
var new_htm;
var re = new RegExp ('\\[textentry[^\\]]*\\]');
if (q.qwizard_b) {
new_htm = create_hangman_textentry_editable_divs (i_qwiz, i_question,
opening_tags, [input],
'textentry', re, htm);
} else {
new_htm = '\n'
+ opening_tags + htm.replace (re, input);
}
new_htm += '
'
+ '\n'
+ '\n'
+ ' \n'
+ '\n'
+ '\n';
var n_correct = 0;
var choice_start_tags = ['[c]', '[c*]'];
var choice_next_tags = ['[c]', '[c*]', '[x]'];
var got_feedback_b = false;
var feedback_divs = [];
qwizdata[i_qwiz].textentry[i_question] = {};
qwizdata[i_qwiz].textentry[i_question].choices = [];
qwizdata[i_qwiz].textentry[i_question].textentry_plural_b = textentry_plural_b;
qwizdata[i_qwiz].textentry[i_question].textentry_suggest_b = textentry_suggest_b;
qwizdata[i_qwiz].textentry[i_question].textentry_minlength = textentry_minlength;
qwizdata[i_qwiz].textentry[i_question].use_terms_b = use_terms_b;
qwizdata[i_qwiz].textentry[i_question].use_dict_b = use_dict_b;
qwizdata[i_qwiz].textentry[i_question].single_char_b = single_char_b;
qwizdata[i_qwiz].textentry[i_question].choices_correct = [];
qwizdata[i_qwiz].textentry[i_question].answers = [];
qwizdata[i_qwiz].textentry[i_question].first_correct_answer = '';
qwizdata[i_qwiz].check_answer_disabled_b = true;
var i_choice = 0;
var default_choice_given_b = false;
while (true) {
var choice_html = qqc.parse_html_block (remaining_htm, choice_start_tags,
choice_next_tags);
if (choice_html == 'NA') {
break;
}
remaining_htm = remaining_htm.substr (choice_html.length);
if (q.wordpress_page_f) {
choice_html = cvt_feedback (choice_html);
}
var r = process_feedback_item (choice_html, i_qwiz, i_question, i_choice);
choice_html = r.choice_html;
var feedback_item_html = '';
if (r.feedback_div) {
got_feedback_b = true;
feedback_divs.push (r.feedback_div);
feedback_item_html = r.feedback_item_html;
var r = process_feedback_item (choice_html, i_qwiz, i_question,
i_choice);
if (r.feedback_div) {
errmsgs.push (T ('More than one feedback shortcode [f] given with choice') + '. qwiz: ' + (1 + i_qwiz) + ', ' + T ('question') + ' ' + (1 + i_question) + ', ' + T ('choice') + ' ' + (1 + i_choice));
}
} else {
feedback_divs.push ('');
}
if (set_qwizard_data_b) {
qw.questions_cards[i_question].feedbacks[i_choice]
= qqc.shortcodes_to_video_elements (feedback_item_html);
}
var correct_b = choice_html.search (/\[c\*\]/) != -1;
if (correct_b) {
n_correct++;
}
choice_html = choice_html.replace (/[^]*\[c\*{0,1}\]/, '');
if (! (q.qwizard_b && choice_html.indexOf ('placeholder') != -1)) {
choice_html = choice_html.replace (/<[^>]+>|\n| /g, '');
}
if (choice_html.replace (';', '').search (/\S/) == -1) {
errmsgs.push (T ('No word(s) given for [textentry] choice') + '. qwiz: ' + (i_qwiz + 1) + ', ' + T ('question') + ' ' + (1 + i_question) + ', ' + T ('choice') + ' ' + (1 + i_choice));
}
var alts = choice_html.split (/\s*;\s*/);
var nonblank_alts = [];
for (var i=0; i \n';
if (n_correct == 0) {
errmsgs.push (T ('No choice was marked correct') + '. qwiz: ' + (1 + i_qwiz) + ', ' + T ('question') + ' ' + (1 + i_question));
}
for (var i_choice=0; i_choice\n';
if (debug[2] || debug[12]) {
console.log ('[process_textentry] new_htm: ', new_htm);
}
return new_htm;
}
function process_hangman (i_qwiz, i_question, htm, opening_tags) {
var hangman_labeled_diagram_f = htm.indexOf ('hangman_img_wrapper') != -1;
var question_text = htm;
var c_pos = qqc.opening_tag_shortcode_pos ('([c*]|[c])', htm);
if (c_pos < htm.length) {
question_text = htm.substr (0, c_pos);
} else {
errmsgs.push (T ('Did not get [c] or [c*] (hangman answer) with [hangman]') + '. qwiz: ' + (1 + i_qwiz) + ', ' + T ('question') + ' ' + (1 + i_question));
c_pos = 0;
}
if (qwizdata[i_qwiz].qrecord_id) {
if (qqc.isInteger (qwizdata[i_qwiz].dataset_id[i_question])) {
var q_and_a_text = qqc.remove_tags_eols (question_text);
q_and_a_text = q_and_a_text.replace (/\[hangman[^\]]*\]/g, '_________');
qwizdata[i_qwiz].q_and_a_text[i_question] = qqc.q_and_a_hash (qqc.remove_tags_eols (q_and_a_text));
qwizdata[i_qwiz].q_and_a_crc32[i_question] = qwiz_crc32 (htm);
} else {
qwizdata[i_qwiz].q_and_a_text[i_question] = qwizdata[i_qwiz].dataset_id[i_question];
qwizdata[i_qwiz].q_and_a_crc32[i_question] = 'dataset';
}
}
var hangman_max_hints = default_hangman_max_hints;
var hangman_type_letters = true;
var m = htm.match (/\[hangman([^\]]*)\]/m);
var attributes = '';
if (m) {
attributes = m[1];
if (attributes) {
attributes = qqc.replace_smart_quotes (attributes);
var hints = get_attr (attributes, 'hints');
if (hints) {
if (hints.search (/[^0-9]/) == -1) {
hangman_max_hints = parseInt (hints, 10);
} else {
errmsgs.push (T ('"hints" for [hangman] should be a number') + '. qwiz: ' + (1 + i_qwiz) + ', ' + T ('question') + ' ' + (1 + i_question));
}
}
hangman_type_letters = ! (get_attr (attributes, 'type_letters') == 'false');
}
}
var type = 'hangman';
var labeled_diagram_opening_tags = opening_tags;
if (hangman_labeled_diagram_f) {
type = 'hangman_labeled_diagram';
labeled_diagram_opening_tags = '';
}
if (set_qwizard_data_b) {
qw.questions_cards[i_question].type = type;
qw.questions_cards[i_question].hangman_attributes = attributes;
question_text = qqc.shortcodes_to_video_elements (question_text);
qw.questions_cards[i_question].question_text = labeled_diagram_opening_tags + question_text;
qw.questions_cards[i_question].choices = [];
qw.questions_cards[i_question].correct_choice_fs = [];
qw.questions_cards[i_question].feedbacks = [];
}
var question_htm = htm;
if (c_pos) {
question_htm = htm.substr (0, c_pos);
}
var m = question_htm.match (/\[hangman/g);
var n_hangman = m.length;
var remaining_htm = htm.substr (c_pos);
var choice_start_tags = ['[c]', '[c*]'];
var choice_next_tags = ['[c]', '[c*]', '[x]', ']+>|\n| /g, '');
hangman_answer = qqc.trim (hangman_answer);
hangman_answer_length = hangman_answer.length;
if (debug[0]) {
console.log ('[process_hangman] hangman_answer:', hangman_answer);
}
}
if (typeof qwizdata[i_qwiz].hangman[i_question] == 'undefined') {
qwizdata[i_qwiz].hangman[i_question] = {};
}
if (! qwizdata[i_qwiz].hangman[i_question].hangman_answer) {
qwizdata[i_qwiz].hangman[i_question].hangman_answer = [];
qwizdata[i_qwiz].hangman[i_question].hangman_final_entry = [];
qwizdata[i_qwiz].hangman[i_question].hangman_current_entry = [];
qwizdata[i_qwiz].hangman[i_question].hangman_incorrect_chars = [];
qwizdata[i_qwiz].hangman[i_question].hangman_incorrect_chars_before_hint
= [];
qwizdata[i_qwiz].hangman[i_question].hangman_n_hints = [];
}
if (i_choice == 0) {
qwizdata[i_qwiz].hangman[i_question].n_hangman = n_hangman;
qwizdata[i_qwiz].hangman[i_question].hangman_max_hints = hangman_max_hints;
qwizdata[i_qwiz].hangman[i_question].hangman_type_letters = hangman_type_letters;
qwizdata[i_qwiz].hangman[i_question].n_hangman_done = 0;
qwizdata[i_qwiz].hangman[i_question].n_hangman_correct = 0;
}
qwizdata[i_qwiz].hangman[i_question].hangman_answer[i_choice] = hangman_answer;
if (set_qwizard_data_b) {
qw.questions_cards[i_question].choices[i_choice] = hangman_answer;
qw.questions_cards[i_question].correct_choice_fs[i_choice] = 1;
}
qwizdata[i_qwiz].hangman[i_question].hangman_n_hints[i_choice] = 0;
var hangman_final_entry = qqc.create_hangman_entry (hangman_answer);
qwizdata[i_qwiz].hangman[i_question].hangman_final_entry[i_choice] = hangman_final_entry;
if (! feedback_divs[i_choice]) {
var response = q.canned_feedback (true);
feedback_divs[i_choice] = create_feedback_div_html (i_qwiz, i_question, i_choice, response);
if (set_qwizard_data_b) {
qw.questions_cards[i_question].feedbacks[i_choice] = response;
}
}
var input_value = new Array (hangman_answer_length).join (' ');
var input_focus = q.qwizard_b ? ' onfocus="qwizard.update_hangman_options_menu_choice (this, ' + i_choice + ')"' : '';
var disabled = '';
var disabled_class = '';
if (q.qwizard_b && hangman_answer == 'placeholder') {
disabled = ' disabled';
disabled_class = ' qwiz_button_disabled';
}
var hangman_span = ''
+ ''
+ ''
+ '';
if (hangman_max_hints && qwizdata[i_qwiz].repeat_incorrect_b) {
var title;
if (hangman_max_hints < hangman_answer.replace (/[^a-z0-9]/i, '').length) {
if (hangman_max_hints == 1) {
title = ' title="' + T ('You can get one hint letter, but your answer will count as incorrect') + '"';
} else {
title = ' title="' + T ('You can get %s hint letters, but your answer will count as incorrect') + '"';
title = title.replace ('%s', qqc.number_to_word (hangman_max_hints));
}
} else {
title = ' title="' + T ('You can get hints, but your answer will count as incorrect') + '"';
}
hangman_span += '\n';
}
if (hangman_type_letters && ! q.qwizard_b
&& (! hangman_labeled_diagram_f
|| (hangman_labeled_diagram_f && i_choice == 0))) {
hangman_span += ''
+ '';
}
hangman_span += ''
+ ''
+ '';
if (q.qwizard_b && ! hangman_labeled_diagram_f) {
hangman_spans.push (hangman_span);
} else {
question_htm = question_htm.replace (hangman_re, hangman_span);
}
i_choice++;
}
question_htm = question_htm.replace (/\[(<\/code>)*q[^\]]*\]/, '');
if (i_choice != n_hangman) {
errmsgs.push ('Number of [hangman] shortcodes does not match number of hangman words [c]. qwiz: ' + (1 + i_qwiz) + ', ' + T ('question') + ' ' + (1 + i_question));
}
if (set_qwizard_data_b) {
qw.questions_cards[i_question].n_choices = n_hangman;
}
var new_htm;
if (q.qwizard_b && ! hangman_labeled_diagram_f) {
new_htm = create_hangman_textentry_editable_divs (i_qwiz, i_question,
labeled_diagram_opening_tags, hangman_spans,
'hangman', hangman_re,
question_htm);
} else {
if (q.qwizard_b) {
var canvas_pos = question_htm.search (/]+qwizzled_canvas/);
if (canvas_pos != -1) {
var hangman_fields_pos = question_htm.search (/]+hangman_labeled_diagram_fields/);
if (hangman_fields_pos != 1) {
var hangman_fields = qqc.find_matching_block (question_htm.substr (hangman_fields_pos));
question_htm = question_htm.replace (hangman_fields, '');
question_htm = question_htm.substr (0, canvas_pos) + hangman_fields
+ question_htm.substr (canvas_pos);
}
}
}
var bg_img_style = create_bg_img_style (i_qwiz, i_question);
new_htm = '\n'
+ labeled_diagram_opening_tags + question_htm;
}
if (debug[0]) {
console.log ('[process_hangman] new_htm:', new_htm);
}
new_htm += '\n';
new_htm += feedback_divs.join ('\n');
new_htm += '';
new_htm += '';
return new_htm;
}
var first_decode_err_f = true;
function cvt_feedback (htm, f_pos) {
var before_c;
var after_c;
const no_c = typeof f_pos != 'undefined';
if (no_c) {
before_c = htm.substr (0, f_pos);
after_c = htm.substr (f_pos);
} else {
c_pos = htm.indexOf ('[c]');
if (c_pos == -1) {
return htm;
}
before_c = htm.substr (0, c_pos);
after_c = htm.substr (c_pos + 3);
}
f_pos = after_c.indexOf ('[f]');
if (f_pos == -1) {
f_pos = after_c.indexOf ('[fx]');
}
var after_f;
var f_cvt;
var f = '';
if (f_pos != -1) {
after_f = after_c.substr (f_pos + 3);
after_c = after_c.substr (0, f_pos);
while (true) {
f_pos = after_f.indexOf ('[f]');
if (f_pos == -1) {
f_cvt = after_f;
} else {
f_cvt = after_f.substr (0, f_pos);
after_f = after_f.substr (f_pos + 3);
}
var r = feedback_decode (f_cvt);
var more_f = r.c;
if (more_f) {
f += '[f]' + more_f;
}
if (f_pos == -1) {
break;
}
}
}
var r = feedback_decode (after_c);
var sc = '';
var c = '';
if (! no_c) {
var sc = '[c' + r.star + ']';
var c = r.c;
}
/*
if (first_decode_err_f) {
c = '[Sorry, missing question data. Please contact support@qwizcards.com]';
first_decode_err_f = false;
}
console.log ('[cvt_feedback] unable to convert:', after_c);
*/
var c_htm = before_c + sc + c + f;
return c_htm;
}
function feedback_decode (s) {
var tag_pos = s.indexOf ('[Qq]');
var s_to_decode;
var s_rest = '';
if (tag_pos != -1) {
s_to_decode = s.substr (0, tag_pos);
s_rest = s.substr (tag_pos + 4);
} else {
s_to_decode = s;
}
if (debug[2]) {
console.log ('[feedback_decode] s_to_decode:', s_to_decode);
}
var star = '';
var decoded_s = '';
var fparts = s_to_decode.split (/<[^>]+>/);
if (fparts.length > 1) {
var splits = s_to_decode.match (/<[^>]+>/g)
var decoded_parts = [];
var n_splits = splits.length;
var first_f = true;
for (var i=0; i\n');
if (typeof qwizdata[i_qwiz].parts_htm[i_question] == 'undefined') {
qwizdata[i_qwiz].parts_htm[i_question] = []
}
var t_pos = 0;
var t_block;
var i_part = 1;
var htm_length = htm.length;
while (true) {
var remaining_htm = htm.substr (t_pos);
var ii_pos = remaining_htm.search (re);
if (ii_pos == -1) {
break;
}
t_pos = t_pos + ii_pos;
var part_htm = remaining_htm.substr (0, ii_pos);
if (i_part == 1) {
part_htm = opening_tags + part_htm;
}
part_htm = qqc.remove_unmatched_tag (part_htm, i_part == 1);
if (part_htm.search (/\S/) == -1) {
part_htm = ' ';
}
qwizdata[i_qwiz].parts_htm[i_question][i_part] = part_htm;
var m = remaining_htm.match (re);
if (debug[9]) {
console.log ('[create_hangman_textentry_editable_divs] m[0]:', m[0]);
}
t_pos += m[0].length;
new_htm.push ('\n');
new_htm.push ( part_htm);
new_htm.push ('');
new_htm.push (span_inputs[i_part-1]);
i_part++;
}
var part_htm = htm.substr (t_pos);
part_htm = qqc.remove_unmatched_tag (part_htm, false, true);
if (part_htm.search (/\S/) == -1) {
part_htm = ' ';
}
qwizdata[i_qwiz].parts_htm[i_question][i_part] = part_htm;
new_htm.push ('\n');
new_htm.push ( part_htm);
new_htm.push ('');
return new_htm.join ('');
}
this.hangman_keyup = function (input_el, event, default_value, i_qwiz, i_question, i_choice) {
if (qwizdata[i_qwiz].user_question_number == 1
&& (q.no_intro_b[i_qwiz] || qwizdata[i_qwiz].n_questions == 1)) {
$ ('div#icon_qwiz' + i_qwiz).hide ();
alert_not_logged_in (i_qwiz);
if (qwizdata[i_qwiz].qwiz_timer) {
start_timers (i_qwiz);
}
}
var value = input_el.value;
input_el.value = default_value;
if (debug[9]) {
console.log ('[hangman_keyup] value.charCodeAt:', value.charCodeAt (0), value.charCodeAt (1), value.charCodeAt (2), value.charCodeAt (3));
}
var keychars = value.replace (/[^a-z0-9]/gi, '');
if (keychars == '') {
return false;
}
keychars = keychars.toLowerCase ();
if (debug[9]) {
console.log ('[hangman_keyup] keychars:', keychars);
}
var current_entry = qwizdata[i_qwiz].hangman[i_question].hangman_current_entry[i_choice];
var final_entry = qwizdata[i_qwiz].hangman[i_question].hangman_final_entry[i_choice];
var done_f;
var n_chars = keychars.length;
for (var i=0; i' + keychar + '\t') == -1;
if (done_f) {
hangman.n_hangman_done++;
all_done_f = hangman.n_hangman_done == hangman.n_hangman;
}
} else {
keychar = keychar.toLowerCase ();
if (hangman_incorrect_chars.indexOf (keychar) == -1) {
hangman_incorrect_chars += keychar;
if (hangman_incorrect_chars.length > 6) {
done_f = true;
hangman.n_hangman_done++;
all_done_f = hangman.n_hangman_done == hangman.n_hangman;
}
}
hangman.hangman_incorrect_chars[i_choice] = hangman_incorrect_chars;
if (debug[9]) {
console.log ('[hangman_keyup] hangman_incorrect_chars:', hangman_incorrect_chars);
}
}
if (done_f) {
$ (input_el).on ('mousedown', function (e) {
e.preventDefault ();
});
input_el.parentElement.done_f = true;
const hangman_n_hints = hangman.hangman_n_hints[i_choice];
var correct_b = hangman_incorrect_chars.length <= 6
&& hangman_n_hints == 0;
if (correct_b) {
hangman.n_hangman_correct++;
if (hangman.n_hangman > 1) {
$ ('div#qwiz' + i_qwiz + '-q' + i_question + ' div.qwiz-feedback').hide ();
$ ('div#qwiz' + i_qwiz + '-q' + i_question + ' div.qwiz_hangman_msg').hide ();
}
$ ('#qwiz' + i_qwiz + '-q' + i_question + '-a' + i_choice).show ();
if (all_done_f && hangman.n_hangman_correct == hangman.n_hangman ) {
if (! q.qwizard_b) {
qwizdata[i_qwiz].n_correct++;
if (qwizdata[i_qwiz].n_qs_done) {
qwizdata[i_qwiz].n_qs_done.add (qwizdata[i_qwiz].dataset_id[i_question]);
}
}
}
} else {
if (hangman.n_hangman > 1) {
$ ('div#qwiz' + i_qwiz + '-q' + i_question + ' div.qwiz-feedback').hide ();
}
var msg = '
';
if (qwizdata[i_qwiz].repeat_incorrect_b) {
const hangman_correct_chars = current_entry.match (/[^\t]<\/u>/g);
if (hangman_correct_chars) {
const n_correct = hangman_correct_chars.length - hangman_n_hints;
if (hangman_correct_chars.length == 1) {
msg+= T ('You got one letter correct') + '. ';
} else {
msg+= T ('You got %s letters correct') + '. ';
msg = msg.replace ('%s', qqc.number_to_word (hangman_correct_chars.length));
}
if (hangman_n_hints == 1) {
msg += T ('You used one hint') + '. ';
} else if (hangman_n_hints > 1) {
msg += T ('You used %s hints') + '. ';
msg = msg.replace ('%s', qqc.number_to_word (hangman_n_hints));
}
if (hangman_incorrect_chars.length) {
msg += T ('Incorrect letters') + ': ' + hangman_incorrect_chars + '. ' + T ('Pick different letters when you see this word again.');
}
} else {
msg = '
' + T ('Sorry, you entered more than six incorrect letters') + ': ' + hangman_incorrect_chars + '. ' + T ('Choose different letters when you see this word again!');
}
} else {
msg = '
' + T ('Sorry, you entered more than six incorrect letters.');
}
$ ('div#qwiz' + i_qwiz + '-q' + i_question + ' div.qwiz_hangman_msg').html (msg).show ();
if (all_done_f && hangman.n_hangman_correct != hangman.n_hangman ) {
if (! q.qwizard_b) {
qwizdata[i_qwiz].n_incorrect++;
}
}
}
if (all_done_f) {
if (! q.qwizard_b) {
qwizdata[i_qwiz].answered_correctly[i_question]
= hangman.n_hangman == hangman.n_hangman_correct ? 1 : -1;
}
input_el.blur ();
if (qwizdata[i_qwiz].qrecord_id && document_qwiz_user_logged_in_b) {
var hangman_answer = hangman.hangman_answer[i_choice];
var data = {q_and_a_text: btoa (encodeURIComponent (qwizdata[i_qwiz].q_and_a_text[i_question])),
q_and_a_crc32: qwizdata[i_qwiz].q_and_a_crc32[i_question],
i_question: qwizdata[i_qwiz].dataset_id[i_question],
unit: qwizdata[i_qwiz].unit[i_question],
type: 'hangman',
response: hangman_answer,
correct_b: correct_b ? 1 : '',
confirm: 'js'};
record_response (i_qwiz, qwizdata[i_qwiz].qrecord_id, data);
}
update_topic_statistics (i_qwiz, i_question, correct_b);
update_progress_show_next (i_qwiz);
} else {
var first_f = true;
for (var i_choice=0; i_choice qwizdata[i_qwiz].hangman[i_question].hangman_max_hints) {
return false;
} else if (qwizdata[i_qwiz].hangman[i_question].hangman_n_hints[i_choice] == qwizdata[i_qwiz].hangman[i_question].hangman_max_hints) {
$ ('#hangman_hint-qwiz' + i_qwiz + '-q' + i_question + '-c' + i_choice)
.attr ('disabled', true)
.addClass ('qwiz_button_disabled');
} else {
qwizdata[i_qwiz].hangman[i_question].hangman_incorrect_chars_before_hint[i_choice]
= qwizdata[i_qwiz].hangman[i_question].hangman_incorrect_chars[i_choice].length;
}
var hangman_answer = qwizdata[i_qwiz].hangman[i_question].hangman_answer[i_choice];
var current_entry = qwizdata[i_qwiz].hangman[i_question].hangman_current_entry[i_choice];
var matches = current_entry.match (/.<\/u>/g);
var i_pos = matches.indexOf ('\t');
if (debug[9]) {
console.log ('[hangman_hint] matches:', matches);
console.log ('[hangman_hint] i_pos:', i_pos);
}
if (i_pos != -1) {
var final_entry = qwizdata[i_qwiz].hangman[i_question].hangman_final_entry[i_choice];
matches = final_entry.match (/.<\/u>/g);
var hint_char = matches[i_pos][3];
var qwizq_id = 'qwiz' + i_qwiz + '-q' + i_question;
var $qwizq = $ ('div#' + qwizq_id);
var $hangman_input = $qwizq.find ('span.qwiz_hangman.qwiz_hangman_c' + i_choice + ' input');
var input_el = $hangman_input[0];
update_hangman_input (hint_char, current_entry, final_entry,
i_qwiz, i_question, i_choice, input_el, true);
$hangman_input.focus ();
}
}
function single_char_textentry_keyup (e) {
var input_el = e.target;
if (debug[6]) {
console.log ('[single_char_textentry_keyup] input_el:', input_el);
}
var value = input_el.value;
if (value.search (/[a-z0-9]/i) == -1) {
input_el.value = '';
return false;
}
var id = input_el.id;
var i_qwiz = id.match (/qwiz([0-9]+)/)[1];
if (debug[6]) {
console.log ('[single_char_textentry_keyup] i_qwiz:', i_qwiz);
}
if (qwizdata[i_qwiz].user_question_number == 1) {
$ ('div#icon_qwiz' + i_qwiz).hide ();
alert_not_logged_in (i_qwiz);
if (qwizdata[i_qwiz].qwiz_timer) {
start_timers (i_qwiz);
}
}
q.textentry_check_answer (i_qwiz, true);
}
function process_feedback_item (choice_html, i_qwiz, i_question, i_choice) {
var feedback_start_tags = ['[f]', '[fx]'];
var feedback_next_tags = ['[f]', '[fx]', '[x]'];
if (debug[2]) {
console.log ('[process_feedback_item] choice_html: ', choice_html);
}
var feedback_item_html = qqc.parse_html_block (choice_html, feedback_start_tags,
feedback_next_tags);
var feedback_div = '';
var fx_b;
if (feedback_item_html != 'NA') {
choice_html = choice_html.replace (feedback_item_html, '');
if (debug[2]) {
console.log ('[process_feedback_item] feedback_item_html: ', feedback_item_html);
}
fx_b = feedback_item_html.indexOf ('[fx]') != -1;
feedback_item_html = feedback_item_html.replace (/\[fx{0,1}\]/, '');
feedback_div = create_feedback_div_html (i_qwiz, i_question, i_choice,
feedback_item_html);
} else {
feedback_item_html = '';
}
if (debug[2]) {
console.log ('[process_feedback_item] feedback_div:', feedback_div);
console.log ('[process_feedback_item] choice_html: ', choice_html);
console.log ('[process_feedback_item] fx_b: ', fx_b);
}
return {'feedback_div': feedback_div,
'choice_html': choice_html,
'feedback_item_html': feedback_item_html,
'fx_b': fx_b};
}
function init_hotspot_image_canvas (i_qwiz, i_question, $hotspot_image_stack) {
const $canvas = $hotspot_image_stack.find ('canvas.layer0_edited');
const canvas_el = $canvas[0];
const ctx = canvas_el.getContext ('2d');
qwizdata[i_qwiz].ctx[i_question] = ctx;
const $edited_img = $hotspot_image_stack.find ('img.layer0_edited');
const edited_img_el = $edited_img[0];
if (edited_img_el.complete) {
ctx.drawImage (edited_img_el, 0, 0, canvas_el.width, canvas_el.height);
} else {
const img = new Image ();
img.src = edited_img_el.src;
img.onload = function () {
ctx.drawImage (img, 0, 0, canvas_el.width, canvas_el.height);
}
}
}
this.create_hotspot_image = function (i_qwiz, i_question, current_hotspot_no,
$hotspot_image_stack, ctx) {
if (debug[0]) {
var start_msec = new Date ().getTime ();
}
const i_width = ctx.canvas.width;
const i_height = ctx.canvas.height;
const imageData = ctx.getImageData(0, 0, i_width, i_height);
const data = imageData.data;
const p32 = new Uint32Array (data.buffer);
const canvas_class = 'qwiz_tmp_hotspot-only_canvas-qwiz' + i_qwiz;
var $hotspot_only_canvas = $ ('canvas.' + canvas_class);
var erase_f = true;
if (! $hotspot_only_canvas.length) {
erase_f = false;
$ ('body').append ('');
$hotspot_only_canvas = $ ('canvas.' + canvas_class);
}
const hotspot_only_canvas_el = $hotspot_only_canvas[0];
var hotspot_only_ctx = hotspot_only_canvas_el.getContext ('2d');
const find_the_dot = qwizdata[i_qwiz].find_the_dot[i_question];
if (find_the_dot) {
find_the_dot.hotspot_only_new_f = false;
$hotspot_only_canvas.attr ('width', i_width);
$hotspot_only_canvas.attr ('height', i_height);
hotspot_only_ctx.clearRect (0, 0, i_width, i_height);
hotspot_only_ctx.beginPath ();
var [r, g, b] = qqc.hex_to_rgb (find_the_dot.background_color.substr (1));
r = 255 - r;
g = 255 - g;
b = 255 - b;
hotspot_only_ctx.strokeStyle = 'rgb(' + r + ', ' + g + ', ' + b + ')';
hotspot_only_ctx.lineWidth = 2;
hotspot_only_ctx.arc (1 + find_the_dot.ix, 1 + find_the_dot.iy, 10, 0, 2*Math.PI);
hotspot_only_ctx.stroke ();
const $hotspot_label = $hotspot_image_stack.find ('div.qwiz_hotspot_label.qwiz_hotspot' + current_hotspot_no);
$hotspot_label.css ({left: 8 + find_the_dot.ix, top: 8 + find_the_dot.iy});
} else {
if (erase_f) {
hotspot_only_ctx.clearRect (0, 0, i_width, i_height);
hotspot_only_ctx.beginPath ();
}
const ii = hotspot_indexof (qwizdata[i_qwiz].hotspot_nos[i_question], current_hotspot_no);
const ver2_f = qwizdata[i_qwiz].hotspot_ver2_f[i_question];
const [cur_r, cur_g, cur_b] = q.hotspot_color_from_no (current_hotspot_no, ver2_f);
if (! ver2_f) {
if (current_hotspot_no == 11) {
var [r1, g1, b1] = q.hotspot_color_from_no (1);
} else if (current_hotspot_no == 13) {
var [r1, g1, b1] = q.hotspot_color_from_no (3);
}
}
var highlighted_f = false;
const $qwizq = $ ('div#qwiz' + i_qwiz + '-q' + i_question);
const $label1 = $qwizq.find ('div.qwiz_hotspot_label.qwiz_hotspot1');
var border_hotspot_no = $label1.attr ('data-border_all');
var $label;
if (! border_hotspot_no) {
border_hotspot_no = current_hotspot_no;
}
$label = $qwizq.find ('div.qwiz_hotspot_label.qwiz_hotspot' + border_hotspot_no);
const border_width = $label.data ('border_width');
if (border_width && border_width != '0') {
highlighted_f = true;
}
var highlight_hotspot_no = $label1.attr ('data-highlight_all');
if (! highlight_hotspot_no) {
highlight_hotspot_no = current_hotspot_no;
}
$label = $qwizq.find ('div.qwiz_hotspot_label.qwiz_hotspot' + highlight_hotspot_no);
if (! highlighted_f) {
const highlight_brightness = $label.data ('highlight_brightness');
if (highlight_brightness && highlight_brightness != '0') {
highlighted_f = true;
}
}
if (! highlighted_f) {
const highlight_tint = $label.data ('highlight_tint');
highlighted_f = !! highlight_tint;
}
if (! qwizdata[i_qwiz].hotspot_highlighted_fs[i_question]) {
qwizdata[i_qwiz].hotspot_highlighted_fs[i_question] = {};
}
qwizdata[i_qwiz].hotspot_highlighted_fs[i_question][current_hotspot_no] = highlighted_f;
const n_pixels = i_width * i_height;
if (highlighted_f) {
const $style_layer_img = $qwizq.find ('img.qwiz_style_layer');
const style_layer_img_el = $style_layer_img[0];
if (style_layer_img_el.complete) {
hotspot_only_ctx.drawImage (style_layer_img_el, 0, 0, i_width, i_height);
} else {
const img = new Image ();
img.src = style_layer_img_el.src;
img.onload = function () {
hotspot_only_ctx.drawImage (img, 0, 0, i_width, i_height);
}
}
var hotspot_only_imageData = hotspot_only_ctx.getImageData(0, 0, i_width, i_height);
var hotspot_only_image_data = hotspot_only_imageData.data;
var hotspot_only_p32 = new Uint32Array (hotspot_only_image_data.buffer);
for (let i=0; i');
const hotspot_image_pos = question_htm.indexOf ('');
htm.push ( opening_tags + editable);
htm.push ('');
var hotspot_image_stack = question_htm.substr (hotspot_image_pos);
var hotspot_image_src = '';
var m = hotspot_image_stack.match (/ ');
htm.push ('');
htm.push ('');
} else {
htm.push (opening_tags + question_htm);
const hotspot_user_interaction = qwizdata[i_qwiz].hotspot_user_interaction[i_question];
if (! hotspot_user_interaction || hotspot_user_interaction != 'info_only') {
htm.push ('');
htm.push ('');
htm.push ('');
}
}
htm.push ('');
if (set_qwizard_data_b) {
qw.questions_cards[i_question].type = 'hotspot_diagram';
qw.questions_cards[i_question].question_text = editable;
qw.questions_cards[i_question].hotspot_image_src = hotspot_image_src;
qw.questions_cards[i_question].canvas_el = '';;
}
htm = htm.join ('\n');
if (debug[0]) {
console.log ('[process_hotspot_diagram] htm:', htm);
}
if (! qwizdata[i_qwiz].hotspot_nos) {
qwizdata[i_qwiz].hotspot_nos = {};
qwizdata[i_qwiz].hotspot_labels = {};
qwizdata[i_qwiz].hotspot_highlighted_fs = {};
qwizdata[i_qwiz].hotspot_ver2_f = {};
qwizdata[i_qwiz].n_hotspots_to_do = {};
qwizdata[i_qwiz].$hotspot_image_stack = {};
qwizdata[i_qwiz].hotspot_image_width = {};
qwizdata[i_qwiz].hotspot_image_height = {};
qwizdata[i_qwiz].spotmap = {};
qwizdata[i_qwiz].spotmap_width = {};
qwizdata[i_qwiz].spotmap_height = {};
qwizdata[i_qwiz].sparsemap = {};
qwizdata[i_qwiz].n_hotspots = {};
qwizdata[i_qwiz].current_query_hotspot_no = {};
}
if (qwizdata[i_qwiz].qrecord_id) {
if (qqc.isInteger (qwizdata[i_qwiz].dataset_id[i_question])) {
var question_text_wo_tags = qqc.remove_tags_eols (editable);
qwizdata[i_qwiz].q_and_a_text[i_question] = qqc.q_and_a_hash (question_text_wo_tags);
qwizdata[i_qwiz].q_and_a_crc32[i_question] = qwiz_crc32 (htm);
if (debug[0]) {
console.log ('[process_hotspot_diagram] qwizdata[i_qwiz].q_and_a_text[i_question]:', qwizdata[i_qwiz].q_and_a_text[i_question]);
console.log ('[process_hotspot_diagram] qwizdata[i_qwiz].q_and_a_crc32[i_question]:', qwizdata[i_qwiz].q_and_a_crc32[i_question]);
}
} else {
qwizdata[i_qwiz].q_and_a_text[i_question] = qwizdata[i_qwiz].dataset_id[i_question];
qwizdata[i_qwiz].q_and_a_crc32[i_question] = 'dataset';
}
}
if (qwizard_process_dataset_questions_f) {
qw.questions_cards[i_question].question_html = editable;
var m = question_htm.match (/qwiz_layer0[^"]+"\s+src="([^"]+)/);
if (m) {
qw.questions_cards[i_question].image_url = m[1];
} else {
console.log ('[process_hotspot_diagram] (did not find image) question_htm:', question_htm);
qw.questions_cards[i_question].image_url = 'NA';
}
var hotspot_labels = [];
var feedback_corrects = [];
var feedback_incorrects = [];
const re = /');
htm.push ( 'Width');
htm.push ( '');
htm.push ( 'Height');
htm.push ( '');
htm.push ( '');
htm.push ( ' ');
htm.push ( 'Dot color');
htm.push ( '');
htm.push ( '');
htm.push ( '');
htm.push ( ' ');
htm.push ( 'Background');
htm.push ( '');
htm.push ( '');
htm.push ( '');
htm.push ('');
var button_class = ' class="qwiz_button qwiz_smaller"';
var button_style = 'float: right;';
if (new_dot_button_style) {
button_class = '';
if (new_dot_button_style != 'none') {
button_style += new_dot_button_style;
}
}
htm.push ('');
if (controls) {
htm.push ('One in ');
}
htm.push ('
');
return htm.join ('\n');
}
function find_the_dot_color_selected (value, input_el) {
if (debug[0]) {
console.log ('[find_the_dot_color_selected] value:', value, ', input_el:', input_el);
}
const $qwiz = $ (input_el).parents ('div.qwiz');
const id = $qwiz[0].id;
const i_qwiz = id.substr (4);
const i_question = qwizdata[i_qwiz].i_question;
const dot_background_color = ($ (input_el).hasClass ('find_the_dot_dot_color') ? 'dot' : 'background') + '_color';
qwizdata[i_qwiz].find_the_dot[i_question][dot_background_color] = '#' + value;
q.update_find_the_dot (i_qwiz);
}
this.update_find_the_dot = function (i_qwiz, new_dot_only_f, init_f) {
const i_question = qwizdata[i_qwiz].i_question;
const $qwiz = $ ('div#qwiz' + i_qwiz);
const $qwizq = $ ('div#qwiz' + i_qwiz + '-q' + i_question);
const $hotspot_image_stack = $qwizq.find ('div.hotspot_image_stack')
const $canvas = $hotspot_image_stack.find ('canvas.layer0_edited');
const ctx = $canvas[0].getContext ('2d');
qwizdata[i_qwiz].ctx[i_question] = ctx;
const width = parseInt ($qwizq.find ('input.find_the_dot_width').val ());
const height = parseInt ($qwizq.find ('input.find_the_dot_height').val ());
if (width < 1 || width > 1000 || height < 1 || height > 1000) {
alert ('Please enter a number between 1 and 1000');
return;
}
var find_the_dot = qwizdata[i_qwiz].find_the_dot[i_question];
find_the_dot.hotspot_only_new_f = true;
if (! new_dot_only_f) {
$hotspot_image_stack.css ({width: width, height: height});
$canvas.attr ('width', width);
$canvas.attr ('height', height);
qwizdata[i_qwiz].hotspot_image_width[i_question] = width;
qwizdata[i_qwiz].hotspot_image_height[i_question] = height;
$qwizq.find ('span.find_the_dot_n_dots').html ((width * height).toLocaleString ());
const width10 = 10 + parseInt (width);
if (width10 > qwizdata[i_qwiz].initial_width) {
$qwiz.css ({width: width10 + 'px', 'max-width': 'none'});
qwizdata[i_qwiz].width_reset = true;
}
}
ctx.fillStyle = find_the_dot.background_color;
ctx.fillRect (0, 0, width, height);
if (new_dot_only_f || init_f) {
find_the_dot.ix = parseInt (Math.random ()*width);
find_the_dot.iy = parseInt (Math.random ()*height);
if (new_dot_only_f) {
qwizdata[i_qwiz].n_labels_correct = 0;
qwizdata[i_qwiz].n_label_attempts = 0;
q.display_diagram_progress (i_qwiz, S ('Visited'));
var hotspot_nos = qwizdata[i_qwiz].hotspot_nos[i_question];
const n = hotspot_nos.length;
for (let i=0; i 0;
if (hotspot_user_interaction == 'label_prompt') {
query_hotspot_no = current_query_hotspot_no;
ok_f = click_hotspot_no == current_query_hotspot_no;
} else {
query_hotspot_no = click_hotspot_no;
}
const $qwizq = $ ('#qwiz' + i_qwiz + '-q' + i_question);
$hotspot_label = $qwizq.find ('div.qwiz_hotspot_label.qwiz_hotspot' + query_hotspot_no);
if (query_hotspot_no) {
var ii = hotspot_indexof (hotspot_nos, query_hotspot_no);
if (ii == -1) {
alert ('Sorry, error');
ii = 0;
}
}
if (hotspot_user_interaction == 'find_hotspots') {
if (debug[0]) {
console.log ('[hotspot_diagram_click2] hotspot_nos:', hotspot_nos);
}
if (Math.abs (hotspot_nos[ii]) > 1000) {
click_hotspot_no = 0;
ok_f = false;
}
}
if (ok_f) {
hotspot_nos[ii] += Math.sign (hotspot_nos[ii]) * 1000;
if (show_hotspots && show_hotspots != 'always' && show_hotspots.indexOf ('hide') == -1) {
show_hotspot_on_hover ();
const $hotspot_only_image = $hotspot_image_stack.find ('img.qwiz_layer' + click_hotspot_no);
const keep_temporary
= qwizdata[i_qwiz].hotspot_highlighted_fs[i_question][click_hotspot_no]
? 'keep' : 'temporary';
$hotspot_image_stack.find ('img.hotspot_only_image.hotspot_temporary').removeClass ('hotspot_temporary').hide ();
if (show_hotspots.indexOf ('temporary') != -1) {
$hotspot_only_image.addClass ('hotspot_temporary').show ();
} else if (show_hotspots.indexOf ('keep') != -1) {
$hotspot_only_image.addClass ('hotspot_' + keep_temporary).show ();
}
}
if (hotspot_labels_stick == 'temporary') {
$hotspot_image_stack.find ('div.qwiz_hotspot_label').hide ();
}
if (hotspot_labels_stick == 'temporary' || hotspot_labels_stick == 'keep') {
var delay_show = function () {
$hotspot_label.css ({display: 'inline-block'});
}
setTimeout (delay_show, 100);
if (hotspot_labels_stick == 'keep') {
$hotspot_label.addClass ('hotspot_clicked');
}
}
qwizdata[i_qwiz].n_labels_correct++;
qwizdata[i_qwiz].n_hotspots_to_do[i_question]--;
feedback_msg = '';
var $feedback = $hotspot_label.find ('span.hotspot_label_feedback_correct_content');
if ($feedback.length) {
feedback_msg = $feedback.html ();
if (qqc.is_only_tags_and_whitespace (feedback_msg)) {
feedback_msg = q.canned_feedback (true);
} else {
feedback_msg = feedback_msg.replace (/ /g, ' ');
}
} else {
feedback_msg = q.canned_feedback (true);
}
if (qwizdata[i_qwiz].n_hotspots_to_do[i_question]) {
if (hotspot_user_interaction == 'label_prompt') {
feedback_msg += '' + S ('Now click on:') + '';
const current_query_hotspot_no = pick_random_hotspot (i_qwiz, i_question);
if (current_query_hotspot_no == 0) {
qwizdata[i_qwiz].n_hotspots_to_do[i_question] = 0;
} else {
qwizdata[i_qwiz].current_query_hotspot_no[i_question] = current_query_hotspot_no;
set_hotspot_label_query (i_qwiz, i_question, $qwizq);
}
}
}
if (! qwizdata[i_qwiz].n_hotspots_to_do[i_question]) {
finished_diagram_b = true;
set_hotspot_label_query (i_qwiz, i_question, $qwizq, true);
$hotspot_image_stack.off ('mousemove click.hotspot_diagram_click click.mobile_hover_eq');
if (! q.qwizard_b && ! q.preview) {
correct_b = qwizdata[i_qwiz].answered_correctly[i_question] == 1;
if (correct_b) {
qwizdata[i_qwiz].n_correct++;
if (qwizdata[i_qwiz].n_qs_done) {
qwizdata[i_qwiz].n_qs_done.add (qwizdata[i_qwiz].dataset_id[i_question]);
}
if (hotspot_user_interaction == 'label_prompt') {
feedback_msg += '' + S ('You identified all of the items on the first try!') + '';
} else if (hotspot_user_interaction == 'find_hotspots') {
const n_tries = qwizdata[i_qwiz].n_label_attempts;
if (n_tries == hotspot_nos.length) {
feedback_msg += '' + S ('You identified all of the items on the first try!') + '';
} else {
feedback_msg += '' + plural (S ('It took you one try'), S ('It took you %s tries'), n_tries) + ' ' + plural (S ('to identify this item'), S ('to identify these items'), qwizdata[i_qwiz].n_label_targets) + '.';
feedback_msg = feedback_msg.replace ('%s', qqc.number_to_word (n_tries));
}
}
} else {
const n_tries = qwizdata[i_qwiz].n_label_attempts;
feedback_msg += '' + plural (S ('It took you one try'), S ('It took you %s tries'), n_tries) + ' ' + plural (S ('to identify this item'), S ('to identify these items'), qwizdata[i_qwiz].n_label_targets) + '.';
feedback_msg = feedback_msg.replace ('%s', qqc.number_to_word (n_tries));
qwizdata[i_qwiz].n_incorrect++;
}
update_topic_statistics (i_qwiz, i_question, correct_b);
}
update_progress_show_next (i_qwiz);
}
} else {
if (hotspot_user_interaction == 'label_prompt' || click_hotspot_no > 0) {
hotspot_nos[ii] = - current_query_hotspot_no;
qwizdata[i_qwiz].answered_correctly[i_question] = -1;
}
if (show_hotspots && show_hotspots.indexOf ('keep') != -1) {
$hotspot_image_stack.find ('img.hotspot_only_image').removeClass ('hotspot_clicked').hide ();
}
if (hotspot_labels_stick == 'temporary') {
$hotspot_image_stack.find ('div.qwiz_hotspot_label').removeClass ('hotspot_clicked').hide ();
}
if (hotspot_user_interaction == 'label_prompt') {
feedback_msg = '';
var $feedback = $hotspot_label.find ('span.hotspot_label_feedback_incorrect_content');
if ($feedback.length) {
feedback_msg = $feedback.html ();
if (qqc.is_only_tags_and_whitespace (feedback_msg)) {
feedback_msg = q.canned_feedback (false);
} else {
feedback_msg = feedback_msg.replace (/ /g, ' ');
}
} else {
feedback_msg = q.canned_feedback (false);
}
if (qwizdata[i_qwiz].n_hotspots_to_do[i_question] > 1) {
feedback_msg += '' + S ('Now click on:') + '';
} else {
feedback_msg += '';
if (click_hotspot_no != 0) {
const label_htm = $hotspot_image_stack.find ('div.qwiz_hotspot_label.qwiz_hotspot' + click_hotspot_no).html ();
feedback_msg += 'You clicked on ' + label_htm;
}
feedback_msg += ' ' + S ('Please try again') + ':';
}
const current_query_hotspot_no = pick_random_hotspot (i_qwiz, i_question);
if (current_query_hotspot_no) {
qwizdata[i_qwiz].current_query_hotspot_no[i_question] = current_query_hotspot_no;
set_hotspot_label_query (i_qwiz, i_question, $qwizq);
}
}
}
$qwizq.find ('div.hotspot_click_feedback').html (feedback_msg);
const found_clicked = (! hotspot_user_interaction || hotspot_user_interaction) == 'label_prompt' ? S ('Correctly clicked') : S ('Found');
q.display_diagram_progress (i_qwiz, found_clicked);
if (qwizdata[i_qwiz].qrecord_id && document_qwiz_user_logged_in_b) {
const hotspot_labels = qwizdata[i_qwiz].hotspot_labels[i_question];
const correct_hotspot_label = hotspot_labels[ii];
var clicked_hotspot_label = '';
if (click_hotspot_no != query_hotspot_no) {
const jj = hotspot_indexof (hotspot_nos, click_hotspot_no);
if (jj != -1) {
clicked_hotspot_label = hotspot_labels[jj];
}
clicked_hotspot_label += '\t';
}
var data = {q_and_a_text: btoa (encodeURIComponent (qwizdata[i_qwiz].q_and_a_text[i_question])),
q_and_a_crc32: qwizdata[i_qwiz].q_and_a_crc32[i_question],
i_question: qwizdata[i_qwiz].dataset_id[i_question],
unit: qwizdata[i_qwiz].unit[i_question],
type: 'hotspot_diagram',
response: clicked_hotspot_label + correct_hotspot_label,
correct_b: '',
confirm: 'js'};
record_response (i_qwiz, qwizdata[i_qwiz].qrecord_id, data);
if (finished_diagram_b) {
var data = {q_and_a_text: btoa (encodeURIComponent (qwizdata[i_qwiz].q_and_a_text[i_question])),
q_and_a_crc32: qwizdata[i_qwiz].q_and_a_crc32[i_question],
i_question: qwizdata[i_qwiz].dataset_id[i_question],
unit: qwizdata[i_qwiz].unit[i_question],
type: 'hotspot_diagram',
response: 'done',
correct_b: correct_b ? 1 : '',
confirm: 'js'};
var delay_record_response = function () {
record_response (i_qwiz, qwizdata[i_qwiz].qrecord_id, data, true);
}
setTimeout (delay_record_response, 500);
}
}
}
var hotspot_long_hover_id;
var hotspot_label_hide_id;
var delay_hide_hotspot_no = -1;
function show_hotspot_on_hover () {
if (debug[0]) {
console.log ('[show_hotspot_on_hover] event:', event);
}
const $qwizq = $ (event.target).parents ('div.qwizq');
const m = $qwizq[0].id.match (/qwiz(\d+)/);
const i_qwiz = m[1];
const i_question = qwizdata[i_qwiz].i_question;
const prev_xy_hotspot_no = qwizdata[i_qwiz].current_xy_hotspot_no;
var className = event.target.className;
if (className.indexOf ('qwiz_hotspot_label') == -1 ) {
const $label = $ (event.target).parents ('div.qwiz_hotspot_label');
if ($label.length) {
className = $label[0].className;
} else {
className = '';
}
}
if (className) {
const m = className.match (/qwiz_hotspot(\d+)/);
if (m) {
const label_hotspot_no = m[1];
if (label_hotspot_no == prev_xy_hotspot_no
|| label_hotspot_no == delay_hide_hotspot_no) {
clearTimeout (hotspot_label_hide_id);
delay_hide_hotspot_no = -1;
qwizdata[i_qwiz].on_hotspot_label = true;
const hotspot_labels_stick = qwizdata[i_qwiz].hotspot_labels_stick[i_question];
if (hotspot_labels_stick
&& hotspot_labels_stick.indexOf ('keep') == -1
&& hotspot_labels_stick.indexOf ('temporary') == -1) {
const $hotspot_label = $qwizq.find ('div.qwiz_hotspot_label.qwiz_hotspot' + label_hotspot_no);
$hotspot_label.off ('mouseleave');
$hotspot_label.on ('mouseleave', function () {
$hotspot_label.hide ();
$hotspot_label.off ('mouseleave');
});
}
}
return;
}
}
qwizdata[i_qwiz].on_hotspot_label = false;
const new_xy_hotspot_no = is_xy_hotspot (i_qwiz, i_question, event.offsetX, event.offsetY);
if (new_xy_hotspot_no != prev_xy_hotspot_no) {
if (new_xy_hotspot_no) {
if (qwizdata[i_qwiz].user_question_number == 1) {
$ ('div#icon_qwiz' + i_qwiz).hide ();
}
const hotspot_user_interaction = qwizdata[i_qwiz].hotspot_user_interaction[i_question];
if (hotspot_user_interaction && hotspot_user_interaction == 'find_hotspots') {
const hotspot_nos = qwizdata[i_qwiz].hotspot_nos[i_question];
const ii = hotspot_indexof (hotspot_nos, new_xy_hotspot_no);
if (Math.abs (hotspot_nos[ii]) > 1000) {
return;
}
}
}
const $hotspot_image_stack = qwizdata[i_qwiz].$hotspot_image_stack[i_question];
const hotspot_user_interaction = qwizdata[i_qwiz].hotspot_user_interaction[i_question];
const show_hotspot_on_hover2 = function () {
const show_hotspots = qwizdata[i_qwiz].show_hotspots[i_question];
if (show_hotspots && show_hotspots != 'always' && show_hotspots.indexOf ('hide') == -1) {
var create_f = qwizdata[i_qwiz].find_the_dot[i_question]?.hotspot_only_new_f;
const img_class = 'qwiz_layer' + new_xy_hotspot_no;
if (! create_f) {
var $hotspot_only_image = $hotspot_image_stack.find ('img.' + img_class);
create_f = $hotspot_only_image.length == 0;
}
if (create_f) {
const ctx = qwizdata[i_qwiz].ctx[i_question];
const hotspot_only_img_src = q.create_hotspot_image (i_qwiz, i_question, new_xy_hotspot_no, $hotspot_image_stack, ctx);
$hotspot_image_stack.append ('');
$hotspot_only_image = $hotspot_image_stack.find ('img.' + img_class);
$hotspot_only_image[0].src = hotspot_only_img_src;
}
$hotspot_only_image.show ();
}
if (hotspot_user_interaction && hotspot_user_interaction == 'info_only') {
const hotspot_labels_stick = qwizdata[i_qwiz].hotspot_labels_stick[i_question];
if (hotspot_labels_stick && hotspot_labels_stick.indexOf ('hover_show') != -1) {
if (debug[0]) {
console.log ('[show_hotspot_on_hover2] (label) new_xy_hotspot_no:', new_xy_hotspot_no);
}
if (hotspot_labels_stick.indexOf ('keep') != -1) {
$qwizq.find ('div.qwiz_hotspot_label').css ({opacity: 0.5});
}
const $hotspot_label = $qwizq.find ('div.qwiz_hotspot_label.qwiz_hotspot' + new_xy_hotspot_no);
$hotspot_label.css ({display: 'inline-block', opacity: 1.0});
}
const hotspot_nos = qwizdata[i_qwiz].hotspot_nos[i_question];
const ii = hotspot_indexof (hotspot_nos, new_xy_hotspot_no);
if (hotspot_nos[ii] < 1000) {
qwizdata[i_qwiz].n_labels_correct++;
qwizdata[i_qwiz].n_hotspots_to_do[i_question]--;
q.display_diagram_progress (i_qwiz, S ('Visited'));
hotspot_nos[ii] += 1000;
}
}
}
qwizdata[i_qwiz].current_xy_hotspot_no = new_xy_hotspot_no;
var hide_previous = '';
if (prev_xy_hotspot_no > 0) {
if (debug[0]) {
console.log ('[show_hotspot_on_hover (hide previous)] prev_xy_hotspot_no:', prev_xy_hotspot_no, ', new_xy_hotspot_no:', new_xy_hotspot_no);
}
const hotspot_labels_stick = qwizdata[i_qwiz].hotspot_labels_stick[i_question];
const $prev_hotspot_only_image
= $hotspot_image_stack
.find ('img.qwiz_layer' + prev_xy_hotspot_no)
.not ('img.hotspot_keep');
hide_previous = 'hide';
if (new_xy_hotspot_no == 0) {
const show_hotspots = qwizdata[i_qwiz].show_hotspots[i_question];
if (hotspot_user_interaction && hotspot_user_interaction == 'info_only') {
if (show_hotspots && show_hotspots.indexOf ('keep') != -1) {
hide_previous = '';
}
}
if (hide_previous && hotspot_labels_stick && hotspot_labels_stick.indexOf ('hover_show') != -1) {
if (hotspot_user_interaction && hotspot_user_interaction == 'info_only') {
hide_previous = 'delay';
}
}
}
if (hide_previous) {
$prev_hotspot_only_image.hide ();
if (hotspot_user_interaction && hotspot_user_interaction == 'info_only') {
const hotspot_labels_stick = qwizdata[i_qwiz].hotspot_labels_stick[i_question];
if (hotspot_labels_stick
&& hotspot_labels_stick.indexOf ('hover_show') != -1
&& hotspot_labels_stick.indexOf ('keep') == -1
&& hotspot_labels_stick.indexOf ('temporary') == -1) {
const $hotspot_label = $qwizq.find ('div.qwiz_hotspot_label.qwiz_hotspot' + prev_xy_hotspot_no);
if (hide_previous == 'delay') {
const delay_hide = function () {
$hotspot_label.hide ();
};
clearTimeout (hotspot_label_hide_id);
hotspot_label_hide_id = setTimeout (delay_hide, 700);
delay_hide_hotspot_no = prev_xy_hotspot_no;
} else {
$hotspot_label.hide ();
}
} else {
$qwizq.find ('div.qwiz_hotspot_label').css ({opacity: 1.0});
}
}
}
}
if (new_xy_hotspot_no) {
const show_hotspots = qwizdata[i_qwiz].show_hotspots[i_question];
if (show_hotspots && show_hotspots.indexOf ('long_hover_show') != -1) {
clearTimeout (hotspot_long_hover_id);
hotspot_long_hover_id = setTimeout (show_hotspot_on_hover2, 700);
} else {
show_hotspot_on_hover2 ();
}
}
}
}
function hide_hotspots (e) {
if (debug[0]) {
console.log ('[hide_hotspots] e:', e);
}
const $qwizq = $ (event.target).parents ('div.qwizq');
const m = $qwizq[0].id.match (/qwiz(\d+)/);
const i_qwiz = m[1];
const i_question = qwizdata[i_qwiz].i_question;
qwizdata[i_qwiz].current_xy_hotspot_no = -1;
clearTimeout (hotspot_long_hover_id);
const show_hotspots = qwizdata[i_qwiz].show_hotspots[i_question];
const hotspot_user_interaction = qwizdata[i_qwiz].hotspot_user_interaction[i_question];
var hide_label_f = false;
if (hotspot_user_interaction && hotspot_user_interaction == 'info_only') {
const hotspot_labels_stick = qwizdata[i_qwiz].hotspot_labels_stick[i_question];
hide_label_f = hotspot_labels_stick && hotspot_labels_stick.indexOf ('hover_show') != -1 && hotspot_labels_stick.indexOf ('keep') == -1;
if (hide_label_f && qwizdata[i_qwiz].on_hotspot_label) {
return;
}
}
if (show_hotspots && show_hotspots.indexOf ('hide') == -1) {
if ( show_hotspots.indexOf ('temporary') != -1
|| show_hotspots.indexOf ('keep') != -1) {
$ (e.currentTarget).find ('img.hotspot_only_image')
.not ('img.hotspot_keep') .hide ();
if (hide_label_f) {
$ (e.currentTarget).find ('div.qwiz_hotspot_label')
.not ('div.hotspot_temporary')
.not ('div.hotspot_keep') .hide ();
}
} else {
$ (e.currentTarget).find ('img.hotspot_only_image').hide ();
if (hide_label_f) {
$ (e.currentTarget).find ('div.qwiz_hotspot_label').hide ();
}
}
}
}
this.hotspot_color_from_no = function (hotspot_no, ver2_f=false) {
var hotspot_color;
var hotspot_rgba;
const hotspot_colors = [[202,198,191], [143,131,102], [239,210,130], [106,80,0], [251,209,30],
[0,210,255], [0,123,201], [0,86,234], [123,132,147], [218,227,243]];
const variants = [[0, 0, 1],
[0, 1, 0],
[0, 1, 1],
[1, 0, 0],
[1, 1, 0],
[1, 1, 1]];
const ii = hotspot_no - 1;
const i_color = ii % 10;
hotspot_color = hotspot_colors[i_color];
if (ii > 9) {
const i_variant = ver2_f ? Math.floor (ii/10) % 5 : ii % 5;
const variant = variants[i_variant];
const i_scale = Math.floor (ii/60.0) + 1;
const offset = ver2_f ? 5 : 4;
hotspot_color[0] = add_sub_color_variant (hotspot_color[0], variant[0], i_scale, offset);
hotspot_color[1] = add_sub_color_variant (hotspot_color[1], variant[1], i_scale, offset);
hotspot_color[2] = add_sub_color_variant (hotspot_color[2], variant[2], i_scale, offset);
}
/*
if (debug[0]) {
console.log ('[hotspot_color_from_no] hotspot_color:', hotspot_color);
}
*/
hotspot_color.push (q.hotspot_alpha_value);
return hotspot_color;
}
function add_sub_color_variant (rgb, variant, i_scale, offset=4) {
var new_rgb = rgb;
const i_add_sub = variant * i_scale * offset;
if (rgb + i_add_sub <= 255) {
new_rgb += i_add_sub;
} else {
new_rgb -= i_add_sub;
}
return new_rgb;
}
function rgb_same (v1, v2) {
return Math.abs (v1 - v2) <= 3;
}
function hotspot_indexof (hotspot_nos, i) {
var jj = -1;
const n_hotspots = hotspot_nos.length;
for (var ii=0; ii= n_hotspots) {
ii = 0;
} else if (ii < 0) {
ii = n_hotspots - 1;
}
}
if (hotspot_no == 0) {
alert ('Sorry, error: no hotspot');
}
if (debug[0]) {
console.log ('[pick_random_hotspot] hotspot_nos:', hotspot_nos);
console.log ('[pick_random_hotspot] hotspot_no:', hotspot_no);
}
return hotspot_no;
}
function set_hotspot_label_query (i_qwiz, i_question, $qwizq, hide_f) {
var label_htm = '';
if (! hide_f) {
const current_query_hotspot_no = qwizdata[i_qwiz].current_query_hotspot_no[i_question];
const $hotspot_image_stack = qwizdata[i_qwiz].$hotspot_image_stack[i_question];
label_htm = $hotspot_image_stack.find ('div.qwiz_hotspot_label.qwiz_hotspot' + current_query_hotspot_no).html ();
}
const $hotspot_label_query = $qwizq.find ('div.hotspot_label_query');
$hotspot_label_query.html (label_htm);
}
function process_qwizzled (i_qwiz, i_question, question_htm, opening_tags,
question_shortcode) {
if (debug[0]) {
console.log ('[process_qwizzled] question_htm: ', question_htm);
}
var labels_position = '';
var m = question_shortcode.match (/\[(<\/code>)*q([^\]]*)\]/m);
if (m) {
var attributes = m[2];
if (attributes) {
attributes = qqc.replace_smart_quotes (attributes);
labels_position = get_attr (attributes, 'labels');
labels_position = labels_position.toLowerCase ();
if (debug[0]) {
console.log ('[process_qwizzled] labels_position:', labels_position);
}
}
}
var new_htm = ''
+ ''
+ '' + question_htm;
if (debug[0]) {
console.log ('[process_qwizzled] new_htm: ', new_htm);
}
var canvas_div_pos = new_htm.indexOf ('';
td_canvas = td_canvas.replace ('class="', 'class="' + qwizq_id + ' ');
if (qwizdata[i_qwiz].qrecord_id) {
if (qqc.isInteger (qwizdata[i_qwiz].dataset_id[i_question])) {
var question_htm_wo_tags = qqc.remove_tags_eols (question_htm);
qwizdata[i_qwiz].q_and_a_text[i_question] = qqc.q_and_a_hash (question_htm_wo_tags);
qwizdata[i_qwiz].q_and_a_crc32[i_question] = qwiz_crc32 (question_htm);
if (debug[0]) {
console.log ('[process_qwizzled] qwizdata[i_qwiz].q_and_a_text[i_question]:', qwizdata[i_qwiz].q_and_a_text[i_question]);
console.log ('[process_qwizzled] qwizdata[i_qwiz].q_and_a_crc32[i_question]:', qwizdata[i_qwiz].q_and_a_crc32[i_question]);
}
} else {
qwizdata[i_qwiz].q_and_a_text[i_question] = qwizdata[i_qwiz].dataset_id[i_question];
qwizdata[i_qwiz].q_and_a_crc32[i_question] = 'dataset';
}
}
var td_labels_style = '';
if (labels_position == 'left') {
td_labels_style = ' style="padding-right: 5px;"'
}
var td_labels_add_class = '';
if (labels_position != 'top' && labels_position != 'bottom') {
td_labels_add_class = ' qwizzled_labels_left_right';
}
var td_labels = ''
+ ''
+ 'Q-LABELS-Q'
+ '\n'
+ ''
+ ' ';
var td_feedback = 'QWIZZLED-FEEDBACK-Q ';
var table_html;
if (labels_position == "top") {
table_html = td_labels + ' '
+ '' + td_canvas + ' ';
} else if (labels_position == "bottom") {
table_html = td_canvas + ''
+ '' + td_labels + ' ';
} else if (labels_position == "left") {
table_html = td_labels + td_canvas + '';
+ '' + td_canvas + ' ';
} else {
table_html = td_canvas + td_labels + '';
+ '' + td_canvas + ' ';
}
if (debug[0]) {
console.log ('[process_qwizzled] table_html.substr (0, 100):', table_html.substr (0, 100));
}
table_html += '' + td_feedback + ' '
+ '
';
new_htm = new_htm.replace (div_html, table_html);
new_htm = new_htm.replace (/\[(<\/code>)*q[^\]]*\]/, '');
if (debug[0]) {
console.log ('[process_qwizzled] new_htm:', new_htm);
console.log ('[process_qwizzled] remaining_htm:', remaining_htm);
}
remaining_htm = remaining_htm.replace (/\[(<\/code>)*l\]/gm, '');
var label_divs = [];
var i_label = 0;
while (true) {
var label_div_pos = remaining_htm.search (/]+class=".*?qwizzled_label/m);
if (label_div_pos == -1) {
break;
}
var label_div = qqc.find_matching_block (remaining_htm.substr (label_div_pos));
if (debug[0]) {
console.log ('[process_qwizzled] label_div:', label_div);
}
var new_label_div = '';
label_divs.push (new_label_div);
if (set_qwizard_data_b) {
qw.questions_cards[i_question].labels.push (label_div);
}
remaining_htm = remaining_htm.replace (label_div, '');
i_label++;
}
if (debug[0]) {
console.log ('[process_qwizzled] label_divs:', label_divs);
}
var label_head = 'Move each item to its correct place
\n'
+ 'Click an item, then its correct place
\n'
+ 'Click the correct place for the label
';
var ul;
if (labels_position == "top" || labels_position == "bottom") {
ul = '';
} else {
ul = '';
}
new_htm = new_htm.replace ('Q-LABELS-Q', label_head + ul + label_divs.join ('\n') + '
');
var feedback_html = remaining_htm;
var feedback_divs = [];
var feedback_start_tags = ['[f*]', '[fx]'];
var feedback_next_tags = ['[f*]', '[fx]', '[x]', '\n';
feedback_divs.push (htm);
new_htm = new_htm.replace ('QWIZZLED-FEEDBACK-Q', feedback_divs.join (''));
new_htm += '
\n';
if (set_qwizard_data_b) {
qw.questions_cards[i_question].n_labels = n_labels;
}
if (debug[2]) {
console.log ('[process_qwizzled] new_htm: ', new_htm);
}
return new_htm;
}
this.init_drag_and_drop = function (qwizq_elm) {
if (debug[0]) {
console.log ('[init_drag_and_drop] qwizq_elm:', qwizq_elm);
}
var $qwizq = $ (qwizq_elm);
$qwizq.removeAttr ('onmouseover');
$qwizq.find ('td.qwizzled_labels div.qwizzled_label').each (function () {
if (debug[0] || debug[8]) {
console.log ('[init_drag_and_drop] $ (this):', $ (this));
console.log ('[init_drag_and_drop] \'td.qwizzled_labels div.qwizzled_label\':', $ (this)[0]);
}
var label_offset = $ (this).offset ();
if (debug[8]) {
console.log ('[init_drag_and_drop] label_offset:', label_offset);
}
$ (this).data ('label_x', label_offset.left).data ('label_y', label_offset.top);
$ (this).draggable ({
containment: $ (this).parents ('table.qwizzled_table'),
start: function (e, ui) {
var $qwiz = $ (this).parents ('div.qwiz');
if ($qwiz.length) {
var qwiz_el = $qwiz[0];
if (qwiz_el.qscale_fac) {
qwiz_el.qstart_left = ui.position.left;
if (ui.position.top) {
qwiz_el.qstart_top = ui.position.top;
} else {
qwiz_el.qstart_top = 0.1;
}
}
}
q.label_dragstart ($ (this));
},
drag: function (e, ui) {
var $qwiz = $ (this).parents ('div.qwiz');
if ($qwiz.length) {
var qwiz_el = $qwiz[0];
if (qwiz_el.qscale_fac) {
if (qwiz_el.qstart_top) {
var scale_fac = qwiz_el.qscale_fac;
ui.position.left = (ui.position.left - qwiz_el.qstart_left)/scale_fac + qwiz_el.qstart_left;
ui.position.top = (ui.position.top - qwiz_el.qstart_top )/scale_fac + qwiz_el.qstart_top;
}
}
}
}
}).addClass ('qwizzled_label_unplaced');
});
$qwizq.find ('.qwizzled_target').droppable ({
accept: '.qwizzled_label',
hoverClass: 'qwizzled_target_hover',
drop: function (event, ui) {
q.label_dropped ($ (this), ui.draggable);
},
tolerance: 'pointer',
});
}
function process_header (htm, i_qwiz, i_question, intro_b) {
var qtags = ['[h]'];
var qnext_tags = ['[q]', '[q ', ' ';
$qwiz_times_histogram.append (marker_html);
}
}
var h = [];
const leaderboard_graph_options = qwizdata[i_qwiz].leaderboard_graph_options;
const graph_selected = leaderboard_graph_options == 'Graph options' ? ' selected' : '';
h.push ('');
$qwiz_times_histogram.find ('div.qwiz_times_histogram_legend_header').html (h.join ('\n'));
if (leaderboard_graph_options && leaderboard_graph_options == 'Graph options') {
q.qwiz_times_histogram_graph_legend ($qwiz_times_histogram, i_qwiz, data.i_taker);
} else {
q.qwiz_times_histogram_leaderboard_legend (summary_leaderboard, $qwiz_times_histogram, i_qwiz, times, times_for_rank, ranks, i_takers, initialss, quiz_elapsed_time_ids, ii_new, data.i_taker);
}
const max_interval_sec = times_range/10;
var interval_sec;
if (max_interval_sec <= 5.0) {
interval_sec = 5;
} else if (max_interval_sec <= 10.0) {
interval_sec = 10;
} else if (max_interval_sec <= 20.0) {
interval_sec = 20;
} else if (max_interval_sec <= 30.0) {
interval_sec = 30;
} else {
interval_sec = Math.floor (max_interval_sec/60.0 + 1)*60;
}
if (debug[0]) {
console.log ('[draw_histogram] interval_sec:', interval_sec);
}
var tick_sec = interval_sec - (r.min % interval_sec);
var tick_label_sec = r.min - (r.min % interval_sec);
while (tick_sec <= times_range) {
const tick_pct = (tick_sec/times_range * 100.0).toFixed (2);
const tick_html = '';
$qwiz_times_histogram.append (tick_html);
tick_label_sec += interval_sec;
const hhmmss = qqc.hhmmss_from_sec (tick_label_sec);
const label_html = ''
+ hhmmss
+ '';
$qwiz_times_histogram.append (label_html);
tick_sec += interval_sec;
}
const approx_interval = max_bin_count / 8;
var interval;
if (approx_interval < 1.5) {
interval = 1;
} else if (approx_interval < 3.0) {
interval = 2;
} else if (approx_interval < 7.5) {
interval = 5;
} else if (approx_interval < 15.0) {
interval = 10;
} else {
interval = Math.round (approx_interval/20.0)*20;
}
if (debug[0]) {
console.log ('[draw_histogram] interval:', interval);
}
var tick = interval;
while (tick <= max_bin_count) {
const tick_pct = (tick/max_bin_count * 100.0).toFixed (2);
const tick_html = '';
$qwiz_times_histogram.append (tick_html);
const label_html = ''
+ tick
+ '';
$qwiz_times_histogram.append (label_html);
tick += interval;
}
const mmm_dd_hh_mm_top = DateFormat.format.date (d.max*1000, 'MMM dd h:ss a');
const mmm_dd_hh_mm_bot = DateFormat.format.date (d.min*1000, 'MMM dd h:ss a');
l = [];
l.push ('');
l.push ( '');
l.push ( mmm_dd_hh_mm_top);
l.push ( '');
for (var i_gray=0; i_gray<9; i_gray++) {
l.push ('');
l.push ('');
}
l.push ( '');
l.push ( mmm_dd_hh_mm_bot);
l.push ( '');
l.push ('');
$qwiz_times_histogram.append (l.join ('\n'));
if (qwizdata[i_qwiz].qwiz_times_histogram_color_by_date) {
$qwiz_times_histogram.find ('div.qwiz_times_histogram_marker').removeClass ('qwiz_times_histogram_marker_gray qwiz_times_histogram_taker_color qwiz_times_histogram_taker_color0 qwiz_times_histogram_taker_color1 qwiz_times_histogram_taker_color2 qwiz_times_histogram_taker_color3 qwiz_times_histogram_taker_color4 qwiz_times_histogram_taker_color5 qwiz_times_histogram_taker_color6 qwiz_times_histogram_taker_color7 qwiz_times_histogram_taker_color8');
$qwiz_times_histogram.find ('div.qwiz_times_histogram_date_legend').show ();
const $checkbox = $qwiz_times_histogram.find ('input.qwiz_times_histogram_color_by_date');
if ($checkbox.length) {
$checkbox[0].checked = true;
}
}
if (qwizdata[i_qwiz].qwiz_times_histogram_show_bin_counts) {
if (qwizdata[i_qwiz].qwiz_times_histogram_show_bars) {
$qwiz_times_histogram.find ('div.qwiz_times_histogram_bar_label').show ();
} else {
$qwiz_times_histogram.find ('div.qwiz_times_histogram_bin_label').show ();
}
const $checkbox = $qwiz_times_histogram.find ('input.qwiz_times_histogram_show_bin_counts');
if ($checkbox.length) {
$checkbox[0].checked = true;
}
}
if (qwizdata[i_qwiz].qwiz_times_histogram_show_bars) {
$qwiz_times_histogram.find ('div.qwiz_times_histogram_bar').show ();
$qwiz_times_histogram.find ('div.qwiz_times_histogram_v_axis').show ();
const $checkbox = $qwiz_times_histogram.find ('input.qwiz_times_histogram_show_bars');
if ($checkbox.length) {
$checkbox[0].checked = true;
}
}
}
function qwiz_times_histogram_class_everyone_html (i_qwiz, data, adjust_pos) {
var class_independent_students;
if (document_qwiz_school_id != 1) {
class_independent_students = S ('Your class');
} else {
class_independent_students = S ('Independent students');
}
var everyone_checked = '';
var class_checked = '';
if (qwizdata[i_qwiz].leaderboard_class_everyone) {
everyone_checked = ' checked';
} else {
class_checked = ' checked';
}
var style = '';
if (adjust_pos) {
style = ' style="right: 5px; top: 12px;"';
}
const htm = ''
+ ''
+ '
'
+ ''
+ '';
return htm;
}
this.qwiz_times_histogram_class_everyone = function (everyone, i_qwiz, summary) {
var data = {summary: summary,
everyone: everyone};
qwizdata[i_qwiz].leaderboard_class_everyone = everyone;
qqc.qjax (qname, i_qwiz, qwizdata[i_qwiz].qrecord_id, 'get_quiz_times', data);
}
this.qwiz_times_histogram_show_student = function (rect_el, i_qwiz, i_taker, current_taker) {
const $qwiz_times_histogram = qwizdata[i_qwiz].$qwiz_times_histogram;
$qwiz_times_histogram.find ('div.qwiz_times_histogram_marker_target').removeClass ('qwiz_times_histogram_taker_color qwiz_times_histogram_taker_color0 qwiz_times_histogram_taker_color1 qwiz_times_histogram_taker_color2 qwiz_times_histogram_taker_color3 qwiz_times_histogram_taker_color4 qwiz_times_histogram_taker_color5 qwiz_times_histogram_taker_color6 qwiz_times_histogram_taker_color7 qwiz_times_histogram_taker_color8');
const taker_color = i_taker == current_taker ? '' : i_taker % 9;
$qwiz_times_histogram.find ('div.qwiz_times_histogram_taker' + i_taker).parent ().addClass ('qwiz_times_histogram_taker_color' + taker_color);
const student_html = i_taker == current_taker ? 'You' : 'Student #' + (i_taker + 1);
$qwiz_times_histogram.find ('span.qwiz_times_histogram_legend_student').html (student_html);
$qwiz_times_histogram.find ('div.qwiz_times_histogram_legend_color').attr ('class', 'qwiz_times_histogram_legend_color qwiz_times_histogram_taker_color' + taker_color);
qwizdata[i_qwiz].i_taker_shown = i_taker;
}
this.qwiz_times_histogram_leaderboard_graph_change = function (leaderboard_graph_options,
i_qwiz, summary) {
qwizdata[i_qwiz].leaderboard_graph_options = leaderboard_graph_options;
var data = {summary: summary};
const qrecord_id = qwizdata[i_qwiz].qrecord_id;
if (qrecord_id.indexOf ('finish_times_demo') != -1) {
data.demo_taker_time = qwizdata[i_qwiz].elapsed_time;
}
qqc.qjax (qname, i_qwiz, qwizdata[i_qwiz].qrecord_id, 'get_quiz_times', data);
}
this.qwiz_times_histogram_leaderboard_legend
= function (summary_leaderboard, $qwiz_times_histogram, i_qwiz,
times, times_for_rank, ranks, i_takers, initialss,
quiz_elapsed_time_ids, ii_new, i_taker) {
const n = i_takers.length;
var initials_val = '';
if (summary_leaderboard == 'summary') {
for (var i=0; i');
l.push ( '');
if (! document_qwiz_maker_privileges) {
l.push ( '');
l.push ( '');
}
const plugin_url = qqc.get_qwiz_param ('url', './');
const n_leaders = document_qwiz_maker_privileges ? i_takers.length : Math.min (10, i_takers.length);
for (var i=0; i');
l.push ('');
l.push ('');
l.push ( '');
}
if (document_qwiz_maker_privileges) {
l.push ( '');
l.push ( '');
l.push ( '');
l.push ( ' ');
} else {
l.push ( ' ');
}
l.push ( '');
l.push ( ranks[ii] + 1);
l.push ( ' ');
l.push ( '');
var student;
if (initialss[ii]) {
student = initialss[ii];
if (i_taker == i_takers[ii]) {
student += ' (you)';
}
} else {
student = S ('Student') + ' #' + (i_takers[ii] + 1);
if (i_taker == i_takers[ii]) {
if (summary_leaderboard == 'summary' && ii == ii_new) {
student = qwiz_times_histogram_initials_html (i_qwiz, qwizdata[i_qwiz].quiz_elapsed_time_id, initials_val);
emoji_picker_f = true;
} else {
student = S ('You');
}
}
}
l.push ( student);
l.push ( ' ');
l.push ( '');
const hhmmss = qqc.hhmmss_from_sec (times[ii]);
l.push ( hhmmss);
l.push ( ' ');
l.push ( ' ');
}
if (! document_qwiz_maker_privileges) {
l.push ( '
');
l.push ( ' ');
}
l.push ( '');
l.push ('
');
$qwiz_times_histogram.find ('div.qwiz_times_histogram_legend_content').html (l.join ('\n'));
if (emoji_picker_f) {
$qwiz_times_histogram.find ('div.qwiz_times_histogram_legend_content emoji-picker')
.on ('emoji-click', function () {
pick_emoji (event, i_qwiz);
});
const $input = $qwiz_times_histogram.find ('input.qwiz_times_histogram_initials');
if (initials_val) {
$input.css ({background: 'white'});
} else {
$input.focus ();
}
}
}
this.delete_leaderboard_entry = function (i_qwiz, quiz_elapsed_time_id) {
data = {quiz_elapsed_time_id: quiz_elapsed_time_id};
qqc.jjax (qname, i_qwiz, '', 'delete_quiz_elapsed_time', data);
}
this.delete_leaderboard_entry_callback = function (data) {
if (debug[0]) {
console.log ('[delete_leaderboard_entry_callback] data:', data);
}
if (data.errmsg) {
alert (data.errmsg);
} else {
$ ('div#qwiz' + data.i_qwiz + ' div.qwiz_times_histogram_legend_content tr.quiz_elapsed_time_id' + data.quiz_elapsed_time_id).remove ();
}
}
function pick_emoji (e, i_qwiz) {
const input_el = $ ('input.qwiz_times_histogram_initials-qwiz' + i_qwiz)[0];
input_el.value = leaderboard_initials_ok (input_el.value + e.detail.unicode);
}
function leaderboard_initials_ok (input_value) {
if (input_value.toLowerCase () == 'fuk') {
return '';
}
const initials = Array.of (...input_value);
const n = initials.length;
var n_non_empty = 0;
var ok_initials = '';
for (var i=0; i '
+ ' '
+ ''
+ ''
+ ' '
+ ''
+ ''
+ '';
return htm;
}
this.show_hide_emoji_picker = function (i_qwiz) {
$ ('div.emoji-picker-qwiz' + i_qwiz).toggle ();
}
this.check_leaderboard_initials = function (input_el) {
input_el.value = leaderboard_initials_ok (input_el.value);
}
this.update_leaderboard_initials = function (initials, button_el, i_qwiz, quiz_elapsed_time_id) {
if (! initials) {
const $input = $ (button_el).prevAll ('input.qwiz_times_histogram_initials');
initials = $input.val ();
if (initials) {
const data = qwizdata[i_qwiz].qwiz_histogram_data;
const n = data.i_takers.length;
for (var i=0; i ';
const $histogram_div = $ ('div#summary-quiz_times_histogram-qwiz' + i_qwiz);
$histogram_div.find ('button.qwiz_times_histogram_initials').html (spinner);
const data = {quiz_elapsed_time_id: quiz_elapsed_time_id,
initials: initials,
callback: 'update_quiz_elapsed_time_callback'};
qqc.qjax (qname, i_qwiz, qwizdata[i_qwiz].qrecord_id, 'update_quiz_elapsed_time', data);
}
}
this.update_quiz_elapsed_time_callback = function (i_qwiz, errmsg) {
const $histogram_div = $ ('div#summary-quiz_times_histogram-qwiz' + i_qwiz);
$histogram_div.find ('button.qwiz_times_histogram_initials').html (T ('Save'));
if (errmsg) {
alert (errmsg);
}
}
this.qwiz_times_histogram_highlight_leader = function (on_off, td_el, i_qwiz,
i_rank) {
const $td = $ (td_el);
const $qwiz_times_histogram = qwizdata[i_qwiz].$qwiz_times_histogram;
const $marker_target = $qwiz_times_histogram.find ('div.qwiz_times_histogram_marker_target' + i_rank);
if (on_off == 1) {
$td.addClass ('qwiz_times_histogram_highlight');
$marker_target.addClass ('qwiz_times_histogram_highlight');
} else {
$td.removeClass ('qwiz_times_histogram_highlight');
$marker_target.removeClass ('qwiz_times_histogram_highlight');
}
}
this.qwiz_times_histogram_graph_legend = function ($qwiz_times_histogram,
i_qwiz, i_taker) {
var l = [];
const taker_color = i_taker > -1 ? ' qwiz_times_histogram_taker_color' : '';
l.push ('');
l.push ('');
l.push ('');
l.push ( 'You');
l.push ('');
l.push ('
');
l.push ('');
l.push (' ');
l.push ('');
l.push (' ');
l.push ('');
$qwiz_times_histogram.find ('div.qwiz_times_histogram_legend_content').html (l.join ('\n'));
qwizdata[i_qwiz].i_taker_shown = i_taker;
}
this.qwiz_times_histogram_legend_change = function (classname, checked, i_qwiz, current_taker) {
$qwiz_times_histogram = qwizdata[i_qwiz].$qwiz_times_histogram;
if (classname == 'qwiz_times_histogram_color_by_date') {
if (checked) {
$qwiz_times_histogram.find ('div.qwiz_times_histogram_marker').removeClass ('qwiz_times_histogram_marker_gray qwiz_times_histogram_taker_color qwiz_times_histogram_taker_color0 qwiz_times_histogram_taker_color1 qwiz_times_histogram_taker_color2 qwiz_times_histogram_taker_color3 qwiz_times_histogram_taker_color4 qwiz_times_histogram_taker_color5 qwiz_times_histogram_taker_color6 qwiz_times_histogram_taker_color7 qwiz_times_histogram_taker_color8');
$qwiz_times_histogram.find ('div.qwiz_times_histogram_date_legend').show ();
} else {
const i_taker_shown = qwizdata[i_qwiz].i_taker_shown;
$qwiz_times_histogram.find ('div.qwiz_times_histogram_marker').addClass ('qwiz_times_histogram_marker_gray');
$qwiz_times_histogram.find ('div.qwiz_times_histogram_taker' + i_taker_shown).addClass ('qwiz_times_histogram_taker');
const student_html = i_taker_shown == current_taker ? 'You' : 'Student #' + (i_taker_shown + 1);
$qwiz_times_histogram.find ('span.qwiz_times_histogram_legend_student').html (student_html);
const taker_color = i_taker_shown == current_taker ? '' : i_taker_shown % 9;
$qwiz_times_histogram.find ('div.qwiz_times_histogram_legend_color').attr ('class', 'qwiz_times_histogram_legend_color qwiz_times_histogram_taker_color' + taker_color);
$qwiz_times_histogram.find ('div.qwiz_times_histogram_date_legend').hide ();
}
qwizdata[i_qwiz].qwiz_times_histogram_color_by_date = checked;
} else if (classname == 'qwiz_times_histogram_show_bin_counts') {
if (checked) {
if (qwizdata[i_qwiz].qwiz_times_histogram_show_bars) {
$qwiz_times_histogram.find ('div.qwiz_times_histogram_bar_label').show ();
} else {
$qwiz_times_histogram.find ('div.qwiz_times_histogram_bin_label').show ();
$qwiz_times_histogram.find ('div.qwiz_times_histogram_bin_marker').show ();
}
} else {
$qwiz_times_histogram.find ('div.qwiz_times_histogram_bar_label').hide ();
$qwiz_times_histogram.find ('div.qwiz_times_histogram_bin_label').hide ();
$qwiz_times_histogram.find ('div.qwiz_times_histogram_bin_marker').hide ();
}
qwizdata[i_qwiz].qwiz_times_histogram_show_bin_counts = checked;
} else if (classname == 'qwiz_times_histogram_show_bars') {
if (checked) {
$qwiz_times_histogram.find ('div.qwiz_times_histogram_bar').show ();
$qwiz_times_histogram.find ('div.qwiz_times_histogram_v_axis').show ();
$qwiz_times_histogram.find ('div.qwiz_times_histogram_bin_marker').hide ();
if (qwizdata[i_qwiz].qwiz_times_histogram_show_bin_counts) {
$qwiz_times_histogram.find ('div.qwiz_times_histogram_bar_label').show ();
$qwiz_times_histogram.find ('div.qwiz_times_histogram_bin_label').hide ();
} else {
$qwiz_times_histogram.find ('div.qwiz_times_histogram_bar_label').hide ();
$qwiz_times_histogram.find ('div.qwiz_times_histogram_bin_label').hide ();
}
} else {
$qwiz_times_histogram.find ('div.qwiz_times_histogram_bar').hide ();
$qwiz_times_histogram.find ('div.qwiz_times_histogram_v_axis').hide ();
if (qwizdata[i_qwiz].qwiz_times_histogram_show_bin_counts) {
$qwiz_times_histogram.find ('div.qwiz_times_histogram_bin_marker').show ();
$qwiz_times_histogram.find ('div.qwiz_times_histogram_bin_label').show ();
}
}
qwizdata[i_qwiz].qwiz_times_histogram_show_bars = checked;
}
}
function stats (x_orig) {
const x = [...x_orig].sort (function (a, b) {
return b - a;
});
const n = x.length;
const max = x[0];
const min = x[n-1];
var sum = 0;
for (var i=0; i 0) {
const j = Math.floor (Math.random () * (i + 1));
const temp = a[i];
a[i] = a[j];
a[j] = temp;
i--;
}
if (debug[0]) {
console.log ('[shuffle] a:', a);
}
}
function check_qwiz_tag_pairs (htm) {
var new_htm = '';
var matches = htm.match (/\[qwiz|\[\/qwiz\]/gm);
if (matches) {
var n_tags = matches.length;
var error_b = false;
if (n_tags % 2 != 0) {
error_b = true;
} else {
for (var i=0; i \n';
if (debug[1]) {
console.log ('[create_radio_button_html] htm: ', htm);
}
return {'correct': correct,
'htm': htm};
}
this.process_choice = function (e, feedback_id, correct_b, got_it_more_practice_f) {
if (e) {
e.stopPropagation ();
}
var got_it_more_practice_f = got_it_more_practice_f ? 1 : 0;
var matches = feedback_id.match (/(.*)-/);
var qwizq_id = matches[1];
var qwiz_id = feedback_id.match (/(qwiz.*?)-/)[1];
i_qwiz = parseInt (qwiz_id.substr (4), 10);
var i_question = feedback_id.match (/-q([0-9]+)-/)[1];
if (debug[0]) {
console.log ('[process_choice] feedback_id: ', feedback_id, ', qwizq_id: ', qwizq_id, ', i_qwiz: ', i_qwiz);
}
var record_start_delay = 10;
if (! q.preview && qwizdata[i_qwiz].record_start_b && document_qwiz_user_logged_in_b) {
record_start_delay = 500;
qwizdata[i_qwiz].record_start_b = false;
var data = {qrecord_id_ok: qwizdata[i_qwiz].qrecord_id_ok, type: 'start', confirm: 'js'};
record_response (i_qwiz, qwizdata[i_qwiz].qrecord_id, data, true);
}
if (q.qwizard_b) {
var i_choice = feedback_id.match(/-a([0-9]+)$/)[1];
var selector = 'span.choice-qwiz' + i_qwiz + '-q' + i_question + '-a' + i_choice;
var $choice_text = $ (selector + ' span.qwiz-choice.qwiz_editable');
$choice_text.css ({position: 'unset'});
var choice_el = $choice_text[0];
qw.answer_choice_focus (choice_el);
}
var secure_f = qwizdata[i_qwiz].qrecord_id
&& qwizdata[i_qwiz].use_dataset
&& ! qqc.isInteger (qwizdata[i_qwiz].dataset_id[i_question]);
const mobile = feedback_id.substr (0, 7) == 'mobile_' ? 'mobile_' : '';
const local_feedback_id = mobile ? feedback_id.substr (7) : feedback_id;
var elm = document.getElementById ('radio-' + local_feedback_id);
if (elm) {
correct_b = !! $ ('#radio-' + local_feedback_id).data ('q');
}
var disabled;
const choice_class = correct_b ? 'qwiz_correct_choice' : 'qwiz_incorrect_choice';
const class_id = mobile ? '#' : '.';
if (mobile) {
$ ('#' + qwizq_id + ' li.mobile_choice').hide ();
$ ('#' + qwizq_id + ' .qwiz-feedback').hide ();
if (! secure_f) {
$ ('#' + feedback_id).show ();
if (! q.qwizard_b) {
$ (class_id + 'choice-' + feedback_id).addClass (choice_class);
}
}
const $choice = $ ('#choice-' + feedback_id);
$choice.show ();
disabled = '';
} else {
disabled = $ ('input[name=' + qwizq_id + ']').attr ('disabled');
}
if (disabled == 'disabled') {
return;
}
if (mobile) {
feedback_id = feedback_id.substr (7);
qwizq_id = qwizq_id.substr (7);
}
$ ('#' + qwizq_id + ' .qwiz-feedback').hide ();
process_choice_disable (feedback_id, qwizq_id);
if (! secure_f) {
$ ('#' + feedback_id).show ();
if (! q.qwizard_b) {
$ (class_id + 'choice-' + feedback_id).addClass (choice_class);
}
}
if (qwizdata[i_qwiz].user_question_number == 1
&& (q.no_intro_b[i_qwiz] || qwizdata[i_qwiz].n_questions == 1)) {
$ ('div#icon_qwiz' + i_qwiz).hide ();
alert_not_logged_in (i_qwiz);
if (qwizdata[i_qwiz].qwiz_timer) {
start_timers (i_qwiz);
}
}
if (secure_f || (qwizdata[i_qwiz].qrecord_id && document_qwiz_user_logged_in_b)) {
var i_choice = feedback_id.match(/-a([0-9]+)$/)[1];
var choice_text = $ ('#' + qwizq_id + ' .choice-' + feedback_id).html ();
if (choice_text) {
choice_text = qqc.remove_tags_eols (choice_text);
} else {
choice_text = qqc.remove_tags_eols ($ ('#' + qwizq_id + ' button.qwiz_button').html ())
+ '\t'
+ qqc.remove_tags_eols ($ ('#' + feedback_id).html ());
}
var delay_jjax = function () {
var data = {q_and_a_text: btoa (encodeURIComponent (qwizdata[i_qwiz].q_and_a_text[i_question])),
q_and_a_crc32: qwizdata[i_qwiz].q_and_a_crc32[i_question],
i_question: qwizdata[i_qwiz].dataset_id[i_question],
unit: qwizdata[i_qwiz].unit[i_question],
type: 'multiple_choice',
response: choice_text,
i_choice: i_choice,
correct_b: correct_b ? 1 : '',
feedback_id: mobile + feedback_id,
got_it_more_practice_f: got_it_more_practice_f,
confirm: 'js'};
if (secure_f) {
data.secure_f = 1;
}
if (q.preview_i_qwiz_plus1) {
data.preview_no_record = 1;
}
if (qwizdata[i_qwiz].cv_index) {
data.cv_index = qwizdata[i_qwiz].cv_index;
}
record_response (i_qwiz, qwizdata[i_qwiz].qrecord_id, data);
}
setTimeout (delay_jjax, record_start_delay);
}
if (! secure_f) {
q.process_choice2 (mobile + feedback_id, got_it_more_practice_f, correct_b, -1);
}
};
function process_choice_disable (feedback_id, qwizq_id) {
var mobile_b = feedback_id.substr (0, 6) == 'mobile';
if (mobile_b) {
feedback_id = feedback_id.substr (7);
qwizq_id = qwizq_id.substr (7);
}
var elm = document.getElementById ('radio-' + feedback_id);
if (elm) {
elm.checked = true;
if (! q.qwizard_b && ! q.preview) {
$ ('input[name=' + qwizq_id + ']').attr ('disabled', true);
}
$ (`#${qwizq_id} .choices-${qwizq_id}, #${qwizq_id} .choices-${qwizq_id} .qwiz-choice`)
.css ({'cursor': 'auto', 'color': 'black'});
}
}
this.process_choice2 = function (mobile_feedback_id, got_it_more_practice_f,
correct_b, feedback_html) {
const i_qwiz = mobile_feedback_id.match (/qwiz([0-9]+)-/)[1];
const i_question = mobile_feedback_id.match (/-q([0-9]+)-/)[1];
if (debug[0]) {
console.log ('[process_choice2] correct_b:', correct_b, ', feedback_html:', feedback_html);
console.log ('[process_choice2] i_question:', i_question);
}
const mobile_b = mobile_feedback_id.substr (0, 6) == 'mobile';
const choice_class = correct_b ? 'qwiz_correct_choice' : 'qwiz_incorrect_choice';
const class_id = mobile_b ? '#' : '.';
if (feedback_html != -1) {
if (preview_mode != 'show_answers') {
$ ('#' + mobile_feedback_id).html (feedback_html).show ();
$ (class_id + 'choice-' + mobile_feedback_id).addClass (choice_class);
}
if (mobile_b) {
const feedback_id = mobile_feedback_id.substr (7);
$ ('#' + feedback_id).html (feedback_html).show ();
$ (class_id + 'choice-' + feedback_id).addClass (choice_class);
}
}
if (! q.qwizard_b && ! q.preview) {
qwizdata[i_qwiz].answered_correctly[i_question] = correct_b ? 1 : -1;
if (correct_b) {
qwizdata[i_qwiz].n_correct++;
if (qwizdata[i_qwiz].n_qs_done) {
qwizdata[i_qwiz].n_qs_done.add (qwizdata[i_qwiz].dataset_id[i_question]);
}
} else {
qwizdata[i_qwiz].n_incorrect++;
}
update_topic_statistics (i_qwiz, i_question, correct_b);
}
if (got_it_more_practice_f == 1) {
$ ('#' + document_qwiz_mobile + 'show_answer_got_it_or_not-qwiz' + i_qwiz + '-q' + i_question).hide ();
$ ('#qwiz' + i_qwiz + '-q' + i_question).find ('button.show_the_answer').show ();
if (! q.qwizard_b) {
q.display_progress (i_qwiz);
}
q.next_question (i_qwiz);
} else {
update_progress_show_next (i_qwiz);
}
};
this.show_answer_got_it_or_not = function (i_qwiz, i_question, show_me_button_el) {
if (qwizdata[i_qwiz].user_question_number == 1) {
$ ('div#icon_qwiz' + i_qwiz).hide ();
alert_not_logged_in (i_qwiz);
if (qwizdata[i_qwiz].qwiz_timer) {
start_timers (i_qwiz);
}
}
if (! q.qwizard_b) {
show_me_button_el.style.display = 'none';
}
$ ('#' + document_qwiz_mobile + 'qwiz' + i_qwiz + '-q' + i_question + '-a0').show ();
if (! q.preview && ! qwizdata[i_qwiz].bck_f) {
$ ('#' + document_qwiz_mobile + 'show_answer_got_it_or_not-qwiz' + i_qwiz + '-q' + i_question).show ();
}
}
function create_got_it_or_not (mobile_, i_qwiz, i_question) {
var htm = '';
htm += '\n';
htm += '\n';
htm += ' ';
htm += '\n';
htm += '\n';
return htm;
}
function update_topic_statistics (i_qwiz, i_question, correct_b) {
var question_topics = qwizdata[i_qwiz].question_topics[i_question];
if (question_topics) {
for (var ii=0; ii 1 || qwizdata[i_qwiz].use_dataset) {
q.display_progress (i_qwiz);
var n_done = qwizdata[i_qwiz].n_correct;
if (! qwizdata[i_qwiz].repeat_incorrect_b) {
n_done += qwizdata[i_qwiz].n_incorrect;
}
if (n_done == qwizdata[i_qwiz].n_questions_for_done) {
if (qwizdata[i_qwiz].summary_b) {
$ ('#next_button_text-qwiz' + i_qwiz).html (T ('View summary report'));
} else {
$ ('#summary-qwiz' + i_qwiz).show ();
}
if (qwizdata[i_qwiz].qwiz_timer) {
if (qwizdata[i_qwiz].n_qs) {
if (qwizdata[i_qwiz].n_qs_done.size == qwizdata[i_qwiz].n_qs) {
stop_timer (i_qwiz);
qwizdata[i_qwiz].n_qs_done = new Set ();
}
} else {
stop_timer (i_qwiz);
}
}
if (qwizdata[i_qwiz].$question_timer) {
qwizdata[i_qwiz].$question_timer.hide ();
}
if (qwizdata[i_qwiz].qrecord_id && document_qwiz_user_logged_in_b) {
if ( qwizdata[i_qwiz].use_dataset
|| qwizdata[i_qwiz].repeat_incorrect_b
|| qwizdata[i_qwiz].n_incorrect == 0 ) {
var wait_completed = function () {
var data = {type: 'completed', confirm: 'js'};
record_response (i_qwiz, qwizdata[i_qwiz].qrecord_id, data, true);
}
setTimeout (wait_completed, 2000);
}
}
}
if (n_done < qwizdata[i_qwiz].n_questions_for_done || qwizdata[i_qwiz].summary_b) {
q.position_show_next_button (i_qwiz);
}
qwizdata[i_qwiz].next_button_show_b = true;
}
if (qwizdata[i_qwiz].n_questions == 1) {
$( '#qwiz' + i_qwiz + ' div.single-question_exit').show ();
const $overlay_times_up = $ ('div#overlay-times-up-qwiz' + i_qwiz);
if (! $overlay_times_up.is (':visible')) {
stop_timer (i_qwiz);
}
}
}
this.display_progress = function (i_qwiz, came_from_start_b) {
if (debug[0]) {
console.log ('[display_progress] qwizdata[i_qwiz].i_question:', qwizdata[i_qwiz].i_question, ', came_from_start_b:', came_from_start_b);
}
if (qwizdata[i_qwiz].hide_progress_b) {
return;
}
var progress_html;
var n_attempts = qwizdata[i_qwiz].n_correct + qwizdata[i_qwiz].n_incorrect;
var n_done = qwizdata[i_qwiz].n_correct;
if (! qwizdata[i_qwiz].repeat_incorrect_b) {
n_done += qwizdata[i_qwiz].n_incorrect;
}
if (q.qwizard_b) {
if (qwizdata[i_qwiz].i_question == -1 && ! came_from_start_b) {
progress_html = T ('Questions in this quiz:') + ' ' + qwizdata[i_qwiz].n_questions;
} else {
var display_i_question = qwizdata[i_qwiz].i_question + 1;
if (came_from_start_b) {
display_i_question++;
}
progress_html = 'Question ' + display_i_question + ' of ' + qwizdata[i_qwiz].n_questions;
}
} else {
const n_questions = qwizdata[i_qwiz].n_questions_for_done;
const n_to_go = n_questions - n_done;
if (n_attempts == 0) {
const n_qs = qwizdata[i_qwiz].n_qs
const set = n_qs && n_questions < n_qs;
if (set) {
progress_html = T ('Questions in this set:');
} else {
progress_html = T ('Questions in this quiz:');
}
progress_html += ' ' + n_to_go;
} else {
var questions;
var incorrect;
if (document_qwiz_mobile || qwizdata[i_qwiz].qwiz_timer) {
questions = T ('Qs');
incorrect = T ('not');
} else {
questions = T ('questions');
incorrect = T ('incorrect');
}
progress_html = n_questions + ' ' + questions + ', ' + n_attempts + ' ' + plural (T ('response'), T ('responses'), n_attempts) + ', ' + qwizdata[i_qwiz].n_correct + ' ' + T ('correct') + ', ' + qwizdata[i_qwiz].n_incorrect + ' ' + incorrect + ', ' + n_to_go + ' ' + T ('to go');
}
}
$ ('#progress-qwiz' + i_qwiz).html (progress_html).show ();
}
this.display_diagram_progress = function (i_qwiz, prefix='Correctly labeled', n_hotspots=-1) {
if (qwizdata[i_qwiz].hide_progress_b) {
return;
}
var i_question = qwizdata[i_qwiz].user_question_number;
var n_questions = qwizdata[i_qwiz].n_questions_for_done;
var progress_html = '';
if (n_questions > 1) {
progress_html = 'Q #' + i_question + '/' + n_questions + '; ';
}
var n_correct;
var n_items;
if (n_hotspots == -1) {
n_correct = qwizdata[i_qwiz].n_labels_correct;
n_items = qwizdata[i_qwiz].n_label_targets;
} else {
n_correct = n_hotspots;
n_items = n_hotspots;
}
if (prefix == 'Correctly labeled') {
prefix = S ('Correctly labeled');
}
progress_html += prefix + ' ' + n_correct + ' ' + S ('out of') + ' ' + n_items + ' ' + S ('items');
$ ('#progress-qwiz' + i_qwiz).html (progress_html).show ();
}
function create_feedback_div_html (i_qwiz, i_question, i_item, item_html, c_x) {
var local_c_x = '';
if (c_x != undefined) {
local_c_x = c_x;
}
var htm = '\n';
if (! local_c_x) {
htm += '
\n';
}
var classname = '';
if (local_c_x) {
if (local_c_x == 'c') {
classname = 'qwizzled-correct_feedback';
} else {
classname = 'qwizzled-incorrect_feedback';
}
htm += '' + item_html + '';
} else {
if (q.qwizard_b) {
item_html = qqc.shortcodes_to_video_elements (item_html);
}
item_html = create_restart_button (i_qwiz, item_html, true);
htm += '' + item_html + '';
}
htm += '\n';
htm += '\n';
if (debug[2]) {
console.log ('[create_feedback_div_html] htm: ', htm);
}
return htm;
}
this.canned_feedback = function (correct_b) {
var response;
if (correct_b) {
var i = Math.floor (Math.random () * correct.length);
response = correct[i];
} else {
var i = Math.floor (Math.random () * incorrect.length);
response = incorrect[i];
}
response = '' + response + '
';
if (debug[0]) {
console.log ('[canned_feedback] response:', response);
}
return response;
}
var find_matching_terms = function (request, response) {
if (qwizdata[textentry_i_qwiz].user_question_number == 1) {
$ ('div#icon_qwiz' + textentry_i_qwiz).hide ();
alert_not_logged_in (textentry_i_qwiz);
if (qwizdata[textentry_i_qwiz].qwiz_timer) {
start_timers (textentry_i_qwiz);
}
}
var entry = request.term.toLowerCase ();
var entry_metaphone = qqc.metaphone (entry);
if (debug[6]) {
console.log ('[find_matching_terms] entry_metaphone; ', entry_metaphone);
}
var required_entry_length = 100;
var required_metaphone_length = 100;
var i_question = qwizdata[textentry_i_qwiz].i_question;
var minlength = qwizdata[textentry_i_qwiz].textentry[i_question].textentry_minlength;
for (var i=0; i 4) {
required_metaphone_length = 4;
}
}
if (debug[6]) {
console.log ('[find_matching_terms] required_entry_length:', required_entry_length, ', required_metaphone_length:', required_metaphone_length);
}
var deduped_entry = entry.replace (/(.)\1{2,}/gi, '\$1');
if (deduped_entry.length < required_entry_length && entry_metaphone.length < required_metaphone_length) {
textentry_matches[textentry_i_qwiz] = [];
lc_textentry_matches[textentry_i_qwiz] = [];
find_matching_terms2 (response, deduped_entry);
} else {
if (debug[6]) {
console.log ('[find_matching_terms] request.term:', request.term,', entry_metaphone:', entry_metaphone, ', entry_metaphone.length:', entry_metaphone.length);
}
textentry_matches[textentry_i_qwiz]
= $.map (current_question_textentry_terms_metaphones[textentry_i_qwiz],
function (term_i) {
var ok_f;
if (entry_metaphone == '') {
ok_f = term_i[1] == ''
|| term_i[0].toLowerCase ().indexOf (entry) === 0;
} else {
ok_f = term_i[1].indexOf (entry_metaphone) === 0
|| term_i[0].toLowerCase ().indexOf (entry) === 0;
}
if (ok_f) {
if (debug[6]) {
console.log ('[find_matching_terms] term_i:', term_i);
}
return term_i[0];
}
});
if (debug[6]) {
console.log ('[find_matching_terms] textentry_matches[textentry_i_qwiz]:', textentry_matches[textentry_i_qwiz]);
}
if (qwizdata[textentry_i_qwiz].textentry[i_question].use_dict_b) {
var plural_f = qwizdata[textentry_i_qwiz].textentry[i_question].textentry_plural_b ? 1 : 0;
var data = {action: 'textentry_suggestions',
entry: encodeURIComponent (entry),
entry_metaphone: encodeURIComponent (entry_metaphone),
n_hints: qwizdata[textentry_i_qwiz].textentry_n_hints,
terms: textentry_matches[textentry_i_qwiz],
plural_f: plural_f};
var url;
if (qwizcards_page_f) {
url = qqc.get_qwiz_param ('server_loc', 'http://qwizcards.com/admin') + '/qwizard_textentry_suggestions.php';
} else {
url = qqc.get_qwiz_param ('ajaxurl', '');
}
$.ajax ({
type: 'POST',
url: url,
data: data,
dataType: 'json',
error: function (xhr, desc) {
if (debug[0]) {
console.log ('[find_matching_terms] error desc:', desc);
}
},
success: function (data) {
textentry_matches[textentry_i_qwiz] = data;
find_matching_terms2 (response, deduped_entry);
}
});
} else {
find_matching_terms2 (response, deduped_entry);
}
}
}
function find_matching_terms2 (response, deduped_entry) {
if (textentry_matches[textentry_i_qwiz].length) {
lc_textentry_matches[textentry_i_qwiz]
= textentry_matches[textentry_i_qwiz].map (function (item) {
return item.toLowerCase ();
});
if (debug[6]) {
console.log ('[find_matching_terms2] textentry_matches[textentry_i_qwiz]:', textentry_matches[textentry_i_qwiz]);
}
}
if (debug[6]) {
console.log ('[find_matching_terms2] deduped_entry.length: ', deduped_entry.length, ', textentry_matches[textentry_i_qwiz].length: ', textentry_matches[textentry_i_qwiz].length, ', qwizdata[textentry_i_qwiz].textentry_n_hints: ', qwizdata[textentry_i_qwiz].textentry_n_hints);
}
var i_question = qwizdata[textentry_i_qwiz].i_question;
var minlength = qwizdata[textentry_i_qwiz].textentry[i_question].textentry_minlength;
if (deduped_entry.length >= minlength && qwizdata[textentry_i_qwiz].textentry_n_hints < 5) {
var lc_first_correct_answer = qwizdata[textentry_i_qwiz].textentry[i_question].first_correct_answer.toLowerCase ();
if (typeof (lc_textentry_matches[textentry_i_qwiz]) == 'undefined'
|| lc_textentry_matches[textentry_i_qwiz].indexOf (lc_first_correct_answer) == -1) {
$ ('#textentry_check_answer_div-qwiz' + textentry_i_qwiz + '-q' + i_question + ' button.qwiz_textentry_hint')
.removeAttr ('disabled')
.removeClass ('qwiz_button_disabled')
.css ({display: 'inline-block'});
if (q.qwizard_b) {
$ ('#qwiz' + textentry_i_qwiz + '-q' + i_question + ' .qwiz-feedback').hide ();
}
}
}
response (textentry_matches[textentry_i_qwiz]);
}
function menu_closed (e) {
var lc_entry = e.target.value.toLowerCase ();
var i_question = qwizdata[textentry_i_qwiz].i_question;
var n_hints = qwizdata[textentry_i_qwiz].textentry_n_hints;
if (lc_entry.length < n_hints) {
var textentry_hint_val = qwizdata[textentry_i_qwiz].textentry[i_question].first_correct_answer.substr (0, n_hints);
e.target.value = textentry_hint_val;
}
if (! qwizdata[textentry_i_qwiz].check_answer_disabled_b) {
if (debug[6]) {
console.log ('[menu_closed] textentry_matches[textentry_i_qwiz]: ', textentry_matches[textentry_i_qwiz]);
}
if (typeof (lc_textentry_matches[textentry_i_qwiz]) == 'undefined'
|| lc_textentry_matches[textentry_i_qwiz].indexOf (lc_entry) == -1) {
$ ('#textentry_check_answer_div-qwiz' + textentry_i_qwiz + '-q' + i_question + ' button.textentry_check_answer')
.addClass ('qwiz_button_disabled')
.html (qwizdata[textentry_i_qwiz].check_answer);
qwizdata[textentry_i_qwiz].check_answer_disabled_b = true;
if (q.qwizard_b) {
$ ('#qwiz' + textentry_i_qwiz + '-q' + i_question + ' .qwiz-feedback').hide ();
}
}
}
if (show_hint_timeout[textentry_i_qwiz]) {
var $textentry = $ ('#textentry-qwiz' + textentry_i_qwiz + '-q' + i_question);
var n_chars = $textentry.val ().length;
var minlength = qwizdata[textentry_i_qwiz].textentry[i_question].textentry_minlength;
if (n_chars >= minlength) {
clearTimeout (show_hint_timeout[textentry_i_qwiz]);
show_hint_timeout[textentry_i_qwiz] = 0;
}
}
}
function menu_shown (e) {
if (qwizdata[textentry_i_qwiz].record_start_b && document_qwiz_user_logged_in_b) {
qwizdata[textentry_i_qwiz].record_start_b = false;
var data = {qrecord_id_ok: qwizdata[textentry_i_qwiz].qrecord_id_ok, type: 'start', confirm: 'js'};
record_response (textentry_i_qwiz, qwizdata[textentry_i_qwiz].qrecord_id, data, true);
}
var lc_entry = e.target.value.toLowerCase ();
var i_question = qwizdata[textentry_i_qwiz].i_question;
var lc_first_correct_answer = qwizdata[textentry_i_qwiz].textentry[i_question].first_correct_answer.toLowerCase ();
if (lc_textentry_matches[textentry_i_qwiz].indexOf (lc_first_correct_answer) != -1) {
$ ('#textentry_check_answer_div-qwiz' + textentry_i_qwiz + '-q' + i_question + ' button.qwiz_textentry_hint')
.attr ('disabled', true)
.addClass ('qwiz_button_disabled');
}
if (lc_textentry_matches[textentry_i_qwiz].indexOf (lc_entry) != -1) {
$ ('#textentry_check_answer_div-qwiz' + textentry_i_qwiz + '-q' + i_question + ' button.textentry_check_answer')
.removeClass ('qwiz_button_disabled')
.html (T ('Check answer'));
qwizdata[textentry_i_qwiz].check_answer_disabled_b = false;
} else {
$ ('#textentry_check_answer_div-qwiz' + textentry_i_qwiz + '-q' + i_question + ' button.textentry_check_answer')
.addClass ('qwiz_button_disabled')
.html (qwizdata[textentry_i_qwiz].check_answer);
qwizdata[textentry_i_qwiz].check_answer_disabled_b = true;
}
}
this.textentry_check_answer = function (i_qwiz, single_char_b, qwizard_i_choice) {
var i_question = qwizdata[i_qwiz].i_question;
var $textentry = $ ('#textentry-qwiz' + i_qwiz + '-q' + i_question);
if (debug[6]) {
entry = $textentry.val ();
console.log ('[textentry_check_answer] $textentry.val ():', $textentry.val ());
}
if (! qwizdata[i_qwiz].textentry[i_question].textentry_suggest_b) {
if (qwizdata[i_qwiz].record_start_b && document_qwiz_user_logged_in_b) {
qwizdata[i_qwiz].record_start_b = false;
var data = {qrecord_id_ok: qwizdata[i_qwiz].qrecord_id_ok, type: 'start', confirm: 'js'};
record_response (i_qwiz, qwizdata[i_qwiz].qrecord_id, data, true);
}
var entry = $textentry.val ();
if (entry == '') {
return false;
}
}
if (! single_char_b) {
if (! q.qwizard_b && ! q.preview) {
if (qwizdata[i_qwiz].check_answer_disabled_b) {
alert (Tcheck_answer_message);
$ ('#textentry_check_answer_div-qwiz' + i_qwiz + '-q' + i_question + ' button.qwiz_textentry_hint')
.removeAttr ('disabled')
.removeClass ('qwiz_button_disabled')
.css ({display: 'inline-block'});
return;
}
$ ('#textentry_check_answer_div-qwiz' + i_qwiz + '-q' + i_question).hide ();
}
}
$textentry.blur ();
if (! q.qwizard_b && ! q.preview) {
$textentry.attr ('disabled', true);
}
var entry = $textentry.val ().toLowerCase ();
var i_choice = -1;
var correct_b = false;
var n_choices = qwizdata[i_qwiz].textentry[i_question].choices.length;
var i_default_choice;
for (var i=0; i= 0) {
show_hint_timeout[i_qwiz] = setTimeout (show_hint_button, hint_timeout_sec*1000);
}
}
this.set_textentry_i_qwiz = function (e, input_el) {
var id = input_el.id;
textentry_i_qwiz = id.match (/[0-9]+/)[0];
if (debug[6]) {
console.log ('[set_textentry_i_qwiz] textentry_i_qwiz: ', textentry_i_qwiz);
}
e.stopPropagation ();
if (q.qwizard_b) {
var qwizq = id.match (/qwiz.*/)[0];
$ ('#' + qwizq + ' .qwiz-feedback').hide ();
}
}
this.item_selected = function () {
var i_question = qwizdata[textentry_i_qwiz].i_question;
$ ('#textentry_check_answer_div-qwiz' + textentry_i_qwiz + '-q' + i_question + ' button.textentry_check_answer')
.removeClass ('qwiz_button_disabled')
.html (T ('Check answer'));
qwizdata[textentry_i_qwiz].check_answer_disabled_b = false;
}
this.keep_next_button_active = function () {
next_button_active_b = true;
$ ('.next_button').show ();
}
this.position_show_next_button = function (i_qwiz) {
var $next_button = $ ('#next_button-qwiz' + i_qwiz);
$next_button.show ();
}
this.hide_menu_and_display_login = function (i_qwiz, add_team_member_f,
login_alt, msg, proceed_to_pay,
pay_now_sign_up) {
var $container = $ ('div.qwiz_icon_and_menu_container.qwiz' + i_qwiz + ' div.qwiz_icon_trigger_and_menu');
$container.removeClass ('qwiz-hover');
q.display_login (i_qwiz, add_team_member_f, login_alt, msg, proceed_to_pay,
pay_now_sign_up);
var delay_reset = function () {
$container.addClass ('qwiz-hover');
}
setTimeout (delay_reset, 500);
}
this.display_login = function (i_qwiz, add_team_member_f, login_alt, msg,
proceed_to_pay, pay_now_sign_up) {
if (! login_alt) {
login_alt = '';
}
if (! add_team_member_f && ! login_alt) {
$ ('div.qwiz-usermenu_icon').removeClass ('qwiz-icon-bounce');
}
var i_question = qwizdata[i_qwiz].i_question;
if (i_question == -1) {
$ ('.intro-qwiz' + i_qwiz).hide ();
if (! q.no_intro_b[i_qwiz]) {
$ ('div#icon_qwiz' + i_qwiz).hide ();
}
} else if (i_question >= qwizdata[i_qwiz].n_questions) {
$ ('#summary-qwiz' + i_qwiz).hide ();
} else {
$textentry_check_answer_div = $ ('#textentry_check_answer_div-qwiz' + i_qwiz + '-q' + i_question);
if ($textentry_check_answer_div.is (':visible')) {
$textentry_check_answer_div.hide ();
qwizdata[i_qwiz].textentry_check_answer_show_b = true;
} else {
qwizdata[i_qwiz].textentry_check_answer_show_b = false;
}
hide_current_question (i_qwiz, qwizdata[i_qwiz].i_user_question);
$ ('.bbfe-qwiz' + i_qwiz).css ({visibility: 'hidden'});
$ ('span.question-number-qwiz' + i_qwiz).css ({visibility: 'hidden'});
}
$ ('#next_button-qwiz' + i_qwiz).hide ();
if (login_alt == 'progress_bars' || login_alt == 'leaderboard') {
const display_pay_screen = qwizdata[i_qwiz].display_pay_screen;
if (display_pay_screen == 'register' || display_pay_screen == 'subscribe' || display_pay_screen == 'free_trial') {
$ ('.intro-qwiz' + i_qwiz).show ();
} else {
qwizdata[i_qwiz].leaderboard_class_everyone = 0;
qqc.create_progress_bars (qname, qwizdata, i_qwiz, login_alt);
}
} else if (login_alt == 'feedback') {
qqc.create_provide_feedback_screen (qname, i_qwiz, qwizdata[i_qwiz].i_question);
} else if (login_alt == 'use_dataset_options') {
qqc.create_use_dataset_options (qname, qwizdata, i_qwiz);
} else if (login_alt == 'pay') {
qqc.create_pay_screen (qname, qwizdata, i_qwiz, msg, pay_now_sign_up);
} else if (login_alt == 'maker_pay') {
qqc.create_maker_pay_screen (qname, qwizdata, i_qwiz, msg);
} else if (login_alt == 'enroll') {
qqc.create_enroll_screen (qname, i_qwiz);
} else if (login_alt == 'register') {
qqc.create_register_taker_screen (qname, i_qwiz, proceed_to_pay, msg);
} else if (login_alt == 'free_trial') {
qqc.create_paypal_subscription_screen (qname, i_qwiz);
} else if (login_alt == 'special_offer') {
qqc.create_paypal_subscription_screen (qname, i_qwiz, true);
} else if (document_qwiz_wp_user_session_id) {
qqc.create_refresh_page_notice (qname, i_qwiz);
} else {
$ ('#qwiz_login-qwiz' + i_qwiz).html (get_login_html (i_qwiz, add_team_member_f, msg, proceed_to_pay)).show ();
qqc.init_hide_show_password ('#qwiz_password-qwiz' + i_qwiz);
if (! qwizdata[i_qwiz].display_pay_screen) {
$ ('#qwiz_username-qwiz' + i_qwiz).focus ();
}
}
qwizdata[i_qwiz].login_show_b = true;
}
this.login = function (i_qwiz, add_team_member_f, proceed_to_pay) {
add_team_member_f = add_team_member_f ? 1 : 0;
proceed_to_pay = proceed_to_pay ? 1 : 0;
$.removeCookie ('qwiz_declined_login', {path: '/'});
document_qwiz_declined_login_b = false;
var $username = $ ('#qwiz_username-qwiz' + i_qwiz);
var username = $username.val ();
if (! username ) {
alert (T ('Please enter Login name'));
$username.focus ();
return false;
}
if (add_team_member_f) {
var usernames = document_qwiz_username.split ('; ');
if (usernames.indexOf (username) != -1) {
alert ('User ' + username + ' is already on your team.');
return false;
}
}
var $password = $ ('#qwiz_password-qwiz' + i_qwiz);
var password = $password.val ();
if (! password) {
alert (T ('Please enter Password'));
$password.focus ();
return false;
}
$password.blur ();
var sha3_password = CryptoJS.SHA3 (password).toString ();
var remember_f;
if (add_team_member_f) {
remember_f = document_qwiz_remember_f;
} else {
remember_f = $ ('#qwiz_login-qwiz' + i_qwiz + ' input[type="checkbox"]').prop('checked') ? 1 : 0;
document_qwiz_remember_f = remember_f;
}
var data = {username: username, sha3_password: sha3_password, remember_f: remember_f, add_team_member_f: add_team_member_f};
if (add_team_member_f) {
data.previous_username = document_qwiz_username;
}
if (proceed_to_pay) {
data.proceed_to_pay_f = '1';
}
qqc.jjax (qname, i_qwiz, qwizdata[i_qwiz].qrecord_id, 'login', data);
return false;
}
this.login_ok = function (i_qwiz, session_id, remember_f, proceed_to_pay) {
var options = {path: '/'};
if (remember_f == 1) {
options.expires = 1;
}
$.cookie ('qwiz_session_id', document_qwiz_session_id, options);
options.expires = 30;
$.cookie ('qwiz_user_login', 1, options);
document_qwiz_user_logged_in_b = true;
var login_timeout_min = qqc.get_qwiz_param ('login_timeout_min', 40);
options.expires = login_timeout_min/(24.0*60.0);
$.cookie ('qwiz_current_login_lt_nmin_ago', 1, options);
qqc.set_user_menus_and_icons ();
if (qwiz_ && qwiz_.any_pay_quiz_f) {
qwiz_.pay_lock_settings ();
}
if (qcard_ && qcard_.any_pay_deck_f) {
qcard_.pay_lock_settings ();
}
$ ('#qwiz_login-qwiz' + i_qwiz).hide ();
qwizdata[i_qwiz].login_show_b = false;
if (q.qrecord_b) {
for (var ii_qwiz=0; ii_qwiz