Skip to content

Commit

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

fixed attribute issue in shortcode
  • Loading branch information
zubairraeen authored Nov 28, 2023
2 parents 951649f + 0d02fff commit 1144fc9
Showing 1 changed file with 39 additions and 29 deletions.
68 changes: 39 additions & 29 deletions js/qsm-quiz.js
Original file line number Diff line number Diff line change
Expand Up @@ -1484,40 +1484,50 @@ jQuery(function () {
});
});

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

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) {
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>`;
const { src, width, height } = parseAttributes(match);
const videoTag = generateVideoTag(src, width, height, content);
return `<div class="video-content">${videoTag}</div>`;
});
return videoHTML;
Expand Down

0 comments on commit 1144fc9

Please sign in to comment.