Skip to content

Commit

Permalink
fixed issue with video shortcode on front end
Browse files Browse the repository at this point in the history
  • Loading branch information
iam-pranav committed Nov 28, 2023
1 parent d447036 commit f8d8584
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions js/qsm-quiz.js
Original file line number Diff line number Diff line change
Expand Up @@ -1485,29 +1485,30 @@ 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 videoRegex = /\[video(?:(?:\ssrc="([^"]+)")|(?:\smp4="([^"]+)")|(?:\sm4v="([^"]+)")|(?:\swebm="([^"]+)")|(?:\sogv="([^"]+)")|(?:\swmv="([^"]+)")|(?:\sflv="([^"]+)")|(?:\swidth="(\d+)")|(?:\sheight="(\d+)")){0,3}\s*\](.*?)\[\/video\]/g;
let videoMatch = message.match(videoRegex);

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(videoRegex, function(match, src, mp4, m4v, webm, ogv, wmv, flv, width, height, content) {
const videoSource = src || mp4 || m4v || webm || ogv || wmv || flv || '';
const videoTag = '<video src="' + videoSource + '" 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 f8d8584

Please sign in to comment.