Skip to content

Commit

Permalink
Merge pull request #2452 from QuizandSurveyMaster/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
zubairraeen authored Jan 25, 2024
2 parents c50375d + f82ebe5 commit d68155a
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 94 deletions.
194 changes: 101 additions & 93 deletions js/qsm-quiz.js
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,6 @@ function qmnInitPagination(quiz_id) {

jQuery(document).trigger('qsm_init_pagination_after', [quiz_id, qmn_quiz_data]);
}

jQuery(document).on('qsm_next_button_click_after qsm_previous_button_click_after', function(event, quiz_id) {
let video_sections = jQuery('.qsm-quiz-container-' + quiz_id + '.qmn_quiz_container').find('video');
let iframeVideos = jQuery('.qsm-quiz-container-' + quiz_id + '.qmn_quiz_container .qsm-page, .qsm-quiz-container-' + quiz_id + '.qmn_quiz_container .qsm-auto-page-row').find('iframe');
Expand Down Expand Up @@ -1483,98 +1482,8 @@ jQuery(function () {
}, 2000);
});

const videoAttributePatterns = [
/\ssrc="([^"]+)"/,
/\smp4="([^"]+)"/,
/\sm4v="([^"]+)"/,
/\swebm="([^"]+)"/,
/\sogv="([^"]+)"/,
/\swmv="([^"]+)"/,
/\sflv="([^"]+)"/,
/\swidth="(\d+)"/,
/\sheight="(\d+)"/
];

function parseAttributes(match, src, width, height) {
let videoAttrs = { src: '', width: '', height: '' };

videoAttributePatterns.forEach(pattern => {
const attrMatch = match.match(pattern);
if (attrMatch) {
const value = attrMatch[1] || '';
if (pattern.toString().includes('width')) {
videoAttrs.width = value;
} else if (pattern.toString().includes('height')) {
videoAttrs.height = value;
} else {
videoAttrs.src = value;
}
}
});

return videoAttrs;
}

function generateVideoTag(src, width, height, content) {
return `<video src="${src}" width="${width}" height="${height}" controls>${content}</video>`;
}

function qsm_check_shortcode(message = null) {
const videoContentRegex = /\[video(?:\s(?:src|mp4|m4v|webm|ogv|wmv|flv|width|height)="[^"]*")*\](.*?)\[\/video\]/g;
let videoMatch = message.match(videoContentRegex);

if (videoMatch) {
let videoHTML = message.replace(videoContentRegex, function(match, content) {
const { src, width, height } = parseAttributes(match);
const videoTag = generateVideoTag(src, width, height, content);
return `<div class="video-content">${videoTag}</div>`;
});
return videoHTML;
}

// Check if message contains an image shortcode
let imageRegex = /\[img(?:(?:\ssrc="([^"]+)")|(?:\salt="([^"]+)")|(?:\swidth="(\d+)")|(?:\sheight="(\d+)")){0,4}\s*\]/g;
let imageMatch = message.match(imageRegex);

if (imageMatch) {
let imageHTML = message.replace(imageRegex, function(match, src, alt, width, height) {
return '<img src="' + (src || '') + '" alt="' + (alt || '') + '" width="' + (width || '') + '" height="' + (height || '') + '">';
});
return '<div class="image-content">' + imageHTML + '</div>';
}

return message;
}

//inline result status function
function qsm_show_inline_result(quizID, question_id, value, $this, answer_type, $i_this, index = null) {
jQuery('.qsm-spinner-loader').remove();
addSpinnerLoader($this,$i_this);
let data = qsm_question_quick_result_js(question_id, value, answer_type, qmn_quiz_data[quizID].enable_quick_correct_answer_info,quizID);
$this.find('.quick-question-res-p, .qsm-inline-correct-info').remove();
$this.find('.qmn_radio_answers').children().removeClass('data-correct-answer');
if ( 0 < value.length && data.success == 'correct') {
$this.append('<div style="color: green" class="quick-question-res-p qsm-correct-answer-info">' + qmn_quiz_data[quizID].quick_result_correct_answer_text + '</div>')
$this.append('<div class="qsm-inline-correct-info">' + qsm_check_shortcode(data.message) + '</div>');
} else if ( 0 < value.length && data.success == 'incorrect') {
$this.find('.qmn_radio_answers').children().eq(parseInt(data.correct_index)).addClass('data-correct-answer');
$this.append('<div style="color: red" class="quick-question-res-p qsm-incorrect-answer-info">' + qmn_quiz_data[quizID].quick_result_wrong_answer_text + '</div>')
$this.append('<div class="qsm-inline-correct-info">' + qsm_check_shortcode(data.message) + '</div>');
}
if (1 != qmn_quiz_data[quizID].disable_mathjax) {
MathJax.typesetPromise();
}
jQuery('.qsm-spinner-loader').remove();
}
function addSpinnerLoader($this,$i_this) {
if ($this.find('.mlw_answer_open_text').length) {
$this.find('.mlw_answer_open_text').after('<div class="qsm-spinner-loader" style="font-size: 2.5px;margin-left:10px;"></div>');
} else if ($this.find('.mlw_answer_number').length) {
$this.find('.mlw_answer_number').after('<div class="qsm-spinner-loader" style="font-size: 2.5px;margin-left:10px;"></div>');
} else {
$i_this.next('.qsm-input-label').after('<div class="qsm-spinner-loader" style="font-size: 2.5px;"></div>');
}
}

// Autocomplete off
jQuery('.qsm-quiz-container').find('.qmn_quiz_id').each(function () {
var quizID = jQuery(this).val();
Expand Down Expand Up @@ -1732,6 +1641,98 @@ jQuery(function () {
});
});

const videoAttributePatterns = [
/\ssrc="([^"]+)"/,
/\smp4="([^"]+)"/,
/\sm4v="([^"]+)"/,
/\swebm="([^"]+)"/,
/\sogv="([^"]+)"/,
/\swmv="([^"]+)"/,
/\sflv="([^"]+)"/,
/\swidth="(\d+)"/,
/\sheight="(\d+)"/
];

function parseAttributes(match, src, width, height) {
let videoAttrs = { src: '', width: '', height: '' };

videoAttributePatterns.forEach(pattern => {
const attrMatch = match.match(pattern);
if (attrMatch) {
const value = attrMatch[1] || '';
if (pattern.toString().includes('width')) {
videoAttrs.width = value;
} else if (pattern.toString().includes('height')) {
videoAttrs.height = value;
} else {
videoAttrs.src = value;
}
}
});

return videoAttrs;
}

function generateVideoTag(src, width, height, content) {
return `<video src="${src}" width="${width}" height="${height}" controls>${content}</video>`;
}

function qsm_check_shortcode(message = null) {
const videoContentRegex = /\[video(?:\s(?:src|mp4|m4v|webm|ogv|wmv|flv|width|height)="[^"]*")*\](.*?)\[\/video\]/g;
let videoMatch = message.match(videoContentRegex);

if (videoMatch) {
let videoHTML = message.replace(videoContentRegex, function(match, content) {
const { src, width, height } = parseAttributes(match);
const videoTag = generateVideoTag(src, width, height, content);
return `<div class="video-content">${videoTag}</div>`;
});
return videoHTML;
}

// Check if message contains an image shortcode
let imageRegex = /\[img(?:(?:\ssrc="([^"]+)")|(?:\salt="([^"]+)")|(?:\swidth="(\d+)")|(?:\sheight="(\d+)")){0,4}\s*\]/g;
let imageMatch = message.match(imageRegex);

if (imageMatch) {
let imageHTML = message.replace(imageRegex, function(match, src, alt, width, height) {
return '<img src="' + (src || '') + '" alt="' + (alt || '') + '" width="' + (width || '') + '" height="' + (height || '') + '">';
});
return '<div class="image-content">' + imageHTML + '</div>';
}

return message;
}

function qsm_show_inline_result(quizID, question_id, value, $this, answer_type, $i_this, index = null) {
jQuery('.qsm-spinner-loader').remove();
addSpinnerLoader($this,$i_this);
let data = qsm_question_quick_result_js(question_id, value, answer_type, qmn_quiz_data[quizID].enable_quick_correct_answer_info,quizID);
$this.find('.quick-question-res-p, .qsm-inline-correct-info').remove();
$this.find('.qmn_radio_answers').children().removeClass('data-correct-answer');
if ( 0 < value.length && data.success == 'correct') {
$this.append('<div style="color: green" class="quick-question-res-p qsm-correct-answer-info">' + qmn_quiz_data[quizID].quick_result_correct_answer_text + '</div>')
$this.append('<div class="qsm-inline-correct-info">' + qsm_check_shortcode(data.message) + '</div>');
} else if ( 0 < value.length && data.success == 'incorrect') {
$this.find('.qmn_radio_answers').children().eq(parseInt(data.correct_index)).addClass('data-correct-answer');
$this.append('<div style="color: red" class="quick-question-res-p qsm-incorrect-answer-info">' + qmn_quiz_data[quizID].quick_result_wrong_answer_text + '</div>')
$this.append('<div class="qsm-inline-correct-info">' + qsm_check_shortcode(data.message) + '</div>');
}
if (1 != qmn_quiz_data[quizID].disable_mathjax) {
MathJax.typesetPromise();
}
jQuery('.qsm-spinner-loader').remove();
}
function addSpinnerLoader($this,$i_this) {
if ($this.find('.mlw_answer_open_text').length) {
$this.find('.mlw_answer_open_text').after('<div class="qsm-spinner-loader" style="font-size: 2.5px;margin-left:10px;"></div>');
} else if ($this.find('.mlw_answer_number').length) {
$this.find('.mlw_answer_number').after('<div class="qsm-spinner-loader" style="font-size: 2.5px;margin-left:10px;"></div>');
} else {
$i_this.next('.qsm-input-label').after('<div class="qsm-spinner-loader" style="font-size: 2.5px;"></div>');
}
}

// captcha question type
var mlw_code;
jQuery(document).ready(function () {
Expand Down Expand Up @@ -1867,6 +1868,13 @@ function qsm_question_quick_result_js(question_id, answer, answer_type = '', sho
got_ans = true;
}

return { "correct_index": correct_index, "success": correct_answer ? 'correct' : 'incorrect', "message": show_correct_info && got_ans ? correct_info_text : "" };
let returnObject = {
"correct_index": correct_index,
"success": correct_answer ? 'correct' : 'incorrect',
"message": show_correct_info && got_ans ? correct_info_text : ""
};

jQuery(document).trigger('qsm_question_quick_result_js_after', [returnObject, correct_answer, answer, answer_array, answer_type, settings, decrypt, question_id]);
return returnObject;
}
}
1 change: 1 addition & 0 deletions php/classes/class-qmn-quiz-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,7 @@ public function display_quiz( $options, $quiz_data, $question_amount, $shortcode
wp_enqueue_script( 'jquery-ui-core' );
wp_enqueue_script( 'jquery-ui-tooltip' );
wp_enqueue_style( 'jquery-redmond-theme', QSM_PLUGIN_CSS_URL . '/jquery-ui.css', array(), $mlwQuizMasterNext->version );
wp_enqueue_style( 'qsm_quiz_common_style', $this->common_css, array(), $mlwQuizMasterNext->version );

global $qmn_json_data;
$qmn_json_data['error_messages'] = array(
Expand Down
2 changes: 1 addition & 1 deletion php/question-types/qsm-question-title.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function qsm_question_title_func( $question, $question_type = '', $new_question_
$deselect_answer_text = ! empty( $qmn_quiz_options->deselect_answer_text ) ? $qmn_quiz_options->deselect_answer_text : $default_texts['deselect_answer_text'];
$deselect_answer = '<a href="javascript:void(0)" class="qsm-deselect-answer">'. $mlwQuizMasterNext->pluginHelper->qsm_language_support( $deselect_answer_text, "deselect_answer_text-{$qmn_quiz_options->quiz_id}" ) .'</a>';
}
do_action('qsm_question_title_func_before',$question, $question_type, $new_question_title, $question_id );
do_action('qsm_question_title_function_before',$question, $question_type, $new_question_title, $question_id );
if ( '' !== $new_question_title ) {
$new_question_title = $mlwQuizMasterNext->pluginHelper->qsm_language_support( htmlspecialchars_decode( $new_question_title, ENT_QUOTES ), "Question-{$question_id}", "QSM Questions");
$new_question_title = apply_filters( 'qsm_question_title_before', $new_question_title, $question_type, $question_id );
Expand Down

0 comments on commit d68155a

Please sign in to comment.