From 5b084a4d3464c43b407a5619f00f02784d4d990a Mon Sep 17 00:00:00 2001 From: PranavAwasthi Date: Tue, 28 Nov 2023 12:34:58 +0530 Subject: [PATCH] fixed issue with video shortcode on front end --- js/qsm-quiz.js | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/js/qsm-quiz.js b/js/qsm-quiz.js index e140da5db..28becd64c 100644 --- a/js/qsm-quiz.js +++ b/js/qsm-quiz.js @@ -1485,23 +1485,37 @@ jQuery(function () { }); function qsm_check_shortcode(message = null) { - const videoAttributesRegex = /(?:\ssrc="([^"]+)")|(?:\smp4="([^"]+)")|(?:\sm4v="([^"]+)")|(?:\swebm="([^"]+)")|(?:\sogv="([^"]+)")|(?:\swmv="([^"]+)")|(?:\sflv="([^"]+)")|(?:\swidth="(\d+)")|(?:\sheight="(\d+)")/g; - const videoContentRegex = /\[video(?:(?:\s(?:src|mp4|m4v|webm|ogv|wmv|flv|width|height)="[^"]*")*)\](.*?)\[\/video\]/g; - + 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(videoContentRegex, function(match, content) { - let attributesMatch; let src = ''; let width = ''; let height = ''; - while ((attributesMatch = videoAttributesRegex.exec(match)) !== null) { - src = src || attributesMatch[1] || attributesMatch[2] || attributesMatch[3] || attributesMatch[4] || attributesMatch[5] || attributesMatch[6] || attributesMatch[7] || ''; - width = width || attributesMatch[8] || ''; - height = height || attributesMatch[9] || ''; - } + 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 = ``; return `
${videoTag}
`;