Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7e33142
add a constant to check godam activation
krishana7911 May 28, 2025
7a4095e
Add rest_pre_dispatch filter for media GET requests in rtMedia GoDAM …
krishana7911 May 28, 2025
d8cf22d
add godam player shortcode integration for activity page
krishana7911 May 28, 2025
352bff7
add script for ajax refresh for videos in comment replies
krishana7911 May 28, 2025
02e043a
add godam plugin check in rtmedia_media function before executing sho…
krishana7911 May 28, 2025
0697f3f
enqeue godam integration script and godam js render scripts globally …
krishana7911 May 29, 2025
79d7434
add godam player render for comments in the single media
krishana7911 May 29, 2025
d1203b6
add enqeueing at the top of the section
krishana7911 May 29, 2025
5d1fb35
fix styles for the video container for comments
krishana7911 May 29, 2025
5b74681
remove magnific enqeueing from this file
krishana7911 May 29, 2025
e8f9ef8
add godam-integration and godam-ajax-refresh for minification
krishana7911 May 29, 2025
c7eabd5
add godam integration js files
krishana7911 May 29, 2025
3b2a7cd
enqueue magnific popup conditionally to work with all the activation …
krishana7911 May 29, 2025
d93d91d
add condition for groups in mutation
krishana7911 May 29, 2025
3178894
fix re-rendering of godam player in modal for prev and next btns
krishana7911 May 29, 2025
595e732
Enqueue minified file for ajax script
krishana7911 May 29, 2025
0abbe6f
Fix race condition for comment render
krishana7911 May 29, 2025
c18c431
fix godam player rendering on comments
krishana7911 May 30, 2025
328d631
remove test function from the godam ajax script
krishana7911 Jun 2, 2025
485acab
update re-initialization to fix render in magnific popup
krishana7911 Jun 2, 2025
84ebb69
fix phpcs for indent instead of spaces
krishana7911 Jun 2, 2025
e4a29c0
Merge pull request #2146 from rtCamp/update/godam-integration
krishana7911 Jun 2, 2025
84aa91a
Version update v4.7.0
krishana7911 Jun 2, 2025
781c25d
Merge pull request #2147 from rtCamp/version-update/v4.7.0
krishana7911 Jun 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ module.exports = function (grunt) {
files: {
'app/assets/admin/js/admin.min.js': ['app/assets/admin/js/scripts.js']
}
},
godam: {
files: {
'app/assets/js/godam-integration.min.js': ['app/assets/js/godam-integration.js']
}
},
godam_ajax_refresh: {
files: {
'app/assets/js/godam-ajax-refresh.min.js': ['app/assets/js/godam-ajax-refresh.js']
}
}
}
});
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,18 @@ https://www.youtube.com/watch?v=dJrykKQGDcs

## Changelog ##

### 4.7.0

* ENHANCEMENTS
* Added integration with GoDAM plugin's video player.
* Enabled support for GoDAM video player in rtMedia media gallery, BuddyPress activity stream, groups, and forums.
* Improved handling of player enqueue conditions based on GoDAM plugin status.
* Refined script loading to ensure compatibility across WordPress, BuddyPress, and rtMedia components.

* FIXED
* Prevented conflicts with `mediaelement.js` when GoDAM plugin is active.
* Deregistered conflicting scripts to ensure seamless fallback and prevent duplication in player initialization.

### 4.6.23

* Fixed
Expand Down
275 changes: 275 additions & 0 deletions app/assets/js/godam-ajax-refresh.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,275 @@
// Enhanced AJAX function with better error handling and retry logic
function refreshSingleComment(commentId, node) {
// Validation checks
if (!commentId || !node) {
return;
}

// Check if GodamAjax object exists
if (typeof GodamAjax === 'undefined' || !GodamAjax.ajax_url || !GodamAjax.nonce) {
return;
}

// Check if node is still in the DOM
if (!document.contains(node)) {
return;
}

// Prevent duplicate requests
if (node.classList.contains('refreshing')) {
return;
}
node.classList.add('refreshing');

// Create AbortController for timeout handling
const controller = new AbortController();
const timeoutId = setTimeout(() => {
controller.abort();
}, 15000); // 15 second timeout

fetch(GodamAjax.ajax_url, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({
action: 'get_single_activity_comment_html',
comment_id: commentId,
nonce: GodamAjax.nonce,
}),
signal: controller.signal
})
.then(response => {
clearTimeout(timeoutId);

// Check if response is ok
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}

// Check content type
const contentType = response.headers.get('content-type');
if (!contentType || !contentType.includes('application/json')) {
throw new Error('Server returned non-JSON response');
}

return response.json();
})
.then(data => {
if (data && data.success && data.data && data.data.html) {
// Success - handle the response
handleSuccessfulResponse(data, commentId, node);
} else {
// AJAX returned error
const errorMsg = data && data.data ? data.data : 'Unknown AJAX error';
console.error('AJAX error:', errorMsg);

// Optional: Retry once after a delay
setTimeout(() => {
retryRefreshComment(commentId, node, 1);
}, 2000);
}
})
.catch(error => {
clearTimeout(timeoutId);
console.error('Fetch error:', error);

// Handle specific error types
if (error.name === 'AbortError') {
console.error('Request timed out');
} else if (error.message.includes('Failed to fetch')) {
console.error('Network error - possible connectivity issue');
// Retry after network error
setTimeout(() => {
retryRefreshComment(commentId, node, 1);
}, 3000);
}
})
.finally(() => {
clearTimeout(timeoutId);
// Always remove refreshing class
if (document.contains(node)) {
node.classList.remove('refreshing');
}
});
}

// Retry function with exponential backoff
function retryRefreshComment(commentId, node, attempt = 1) {
const maxRetries = 2;

if (attempt > maxRetries) {
console.error(`Failed to refresh comment ${commentId} after ${maxRetries} retries`);
return;
}

// Check if node still exists
if (!document.contains(node)) {
return;
}

// Exponential backoff delay
const delay = Math.pow(2, attempt) * 1000; // 2s, 4s, 8s...

setTimeout(() => {
// Remove any existing refreshing class
node.classList.remove('refreshing');

// Try again with modified fetch (more conservative approach)
fetch(GodamAjax.ajax_url, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Cache-Control': 'no-cache',
},
body: new URLSearchParams({
action: 'get_single_activity_comment_html',
comment_id: commentId,
nonce: GodamAjax.nonce,
retry: attempt.toString()
}),
})
.then(response => response.json())
.then(data => {
if (data && data.success && data.data && data.data.html) {
handleSuccessfulResponse(data, commentId, node);
} else {
// Retry again if not max attempts
if (attempt < maxRetries) {
retryRefreshComment(commentId, node, attempt + 1);
}
}
})
.catch(error => {
console.error(`Retry ${attempt} failed:`, error);
if (attempt < maxRetries) {
retryRefreshComment(commentId, node, attempt + 1);
}
});
}, delay);
}

// Handle successful AJAX response
function handleSuccessfulResponse(data, commentId, node) {
try {
// Find parent activity more safely
const activityItem = node.closest('.activity-item');
if (!activityItem) {
console.error('Could not find parent activity item');
return;
}

const parentActivityId = activityItem.id.replace('activity-', '');

// Locate comment container
let commentList = document.querySelector(`#activity-${parentActivityId} .activity-comments`);
if (!commentList) {
commentList = document.createElement('ul');
commentList.classList.add('activity-comments');
activityItem.appendChild(commentList);
}

// Create temporary container for HTML parsing
const tempDiv = document.createElement('div');
tempDiv.innerHTML = data.data.html.trim();
const newCommentNode = tempDiv.firstElementChild;

if (newCommentNode) {
// Insert new comment
commentList.appendChild(newCommentNode);

// Remove old node safely
if (node.parentNode && document.contains(node)) {
node.parentNode.removeChild(node);
}

// Initialize GODAMPlayer if available
if (typeof GODAMPlayer === 'function') {
try {
GODAMPlayer(newCommentNode);
} catch (playerError) {
console.error('GODAMPlayer initialization failed:', playerError);
}
}

// Dispatch custom event for other scripts
document.dispatchEvent(new CustomEvent('commentRefreshed', {
detail: { commentId, node: newCommentNode }
}));

} else {
console.error('No valid comment node found in response HTML');
}
} catch (error) {
console.error('Error handling successful response:', error);
}
}

// Enhanced DOM observer with debouncing
document.addEventListener('DOMContentLoaded', () => {
const commentsContainers = document.querySelectorAll('.activity-comments');

if (commentsContainers.length === 0) {
return;
}

// Debounce function to prevent rapid-fire calls
function debounce(func, wait) {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
}

commentsContainers.forEach((container) => {
// Initialize GODAMPlayer on existing comments
if (typeof GODAMPlayer === 'function') {
try {
GODAMPlayer(container);
} catch (error) {
console.error('GODAMPlayer initialization failed:', error);
}
}

// Debounced mutation handler
const debouncedHandler = debounce((mutations) => {
mutations.forEach((mutation) => {
mutation.addedNodes.forEach((node) => {
if (node.nodeType === 1 && node.matches && node.matches('li[id^="acomment-"]')) {
// Initialize GODAMPlayer first
if (typeof GODAMPlayer === 'function') {
try {
GODAMPlayer(node);
} catch (error) {
console.error('GODAMPlayer initialization failed:', error);
}
}

// Extract comment ID and refresh with delay
const commentId = node.id.replace('acomment-', '');

// Add longer delay to ensure DOM stability
setTimeout(() => {
if (document.contains(node)) {
refreshSingleComment(commentId, node);
}
}, 250);
}
});
});
}, 100); // 100ms debounce

// Create observer
const observer = new MutationObserver(debouncedHandler);

observer.observe(container, {
childList: true,
subtree: true
});
});
});
1 change: 1 addition & 0 deletions app/assets/js/godam-ajax-refresh.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading