Skip to content

Commit

Permalink
Merge pull request #2405 from QuizandSurveyMaster/CU-86797ux42-issue-…
Browse files Browse the repository at this point in the history
…shortcode-correct-answer-info

fixed issue with video shortcode on front end
  • Loading branch information
zubairraeen authored Nov 28, 2023
2 parents d447036 + 5b084a4 commit 951649f
Showing 1 changed file with 36 additions and 10 deletions.
46 changes: 36 additions & 10 deletions js/qsm-quiz.js
Original file line number Diff line number Diff line change
Expand Up @@ -1485,29 +1485,55 @@ jQuery(function () {
});

function qsm_check_shortcode(message = null) {

// Check if message contains a video shortcode
let videoRegex = /\[video(?:(?:\ssrc="([^"]+)")|(?:\swidth="(\d+)")|(?:\sheight="(\d+)")){0,3}\s*\]/g;
let videoMatch = message.match(videoRegex);
const videoAttributePatterns = [
/\ssrc="([^"]+)"/,
/\smp4="([^"]+)"/,
/\sm4v="([^"]+)"/,
/\swebm="([^"]+)"/,
/\sogv="([^"]+)"/,
/\swmv="([^"]+)"/,
/\sflv="([^"]+)"/,
/\swidth="(\d+)"/,
/\sheight="(\d+)"/
];

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(videoRegex, function(match, src, width, height) {
return '<video src="' + (src || '') + '" width="' + (width || '') + '" height="' + (height || '') + '" controls></video>';
let videoHTML = message.replace(videoContentRegex, function(match, content) {
let src = '';
let width = '';
let height = '';

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

const videoTag = `<video src="${src}" width="${width}" height="${height}" controls>${content}</video>`;
return `<div class="video-content">${videoTag}</div>`;
});
return '<div class="video-content">' + videoHTML + '</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;
}

Expand Down

0 comments on commit 951649f

Please sign in to comment.