From 0d02fffe5f1f7d187e3144b990a2308d210861d4 Mon Sep 17 00:00:00 2001 From: PranavAwasthi Date: Tue, 28 Nov 2023 15:49:21 +0530 Subject: [PATCH] fixed attribute issue in shortcode --- js/qsm-quiz.js | 69 ++++++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/js/qsm-quiz.js b/js/qsm-quiz.js index fecfcce84..8251fd880 100644 --- a/js/qsm-quiz.js +++ b/js/qsm-quiz.js @@ -1484,41 +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 ``; + } + + 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 => { - const attrMatch = match.match(pattern); - if (attrMatch) { - if (pattern.toString().includes('width')) { - width = attrMatch[1] || ''; - } else if (pattern.toString().includes('height')) { - height = attrMatch[1] || ''; - } else { - src = attrMatch[1] || ''; - } - } - }); - const videoTag = ``; + const { src, width, height } = parseAttributes(match); + const videoTag = generateVideoTag(src, width, height, content); return `
${videoTag}
`; }); return videoHTML;