From 7e33142437f7a928b34a1072b66ce1fa6377d53c Mon Sep 17 00:00:00 2001
From: krishana7911
Date: Wed, 28 May 2025 14:16:22 +0530
Subject: [PATCH 01/22] add a constant to check godam activation
---
index.php | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/index.php b/index.php
index 3d92d9395..cc6d7e95c 100644
--- a/index.php
+++ b/index.php
@@ -55,6 +55,22 @@
define( 'RTMEDIA_BASE_NAME', plugin_basename( __FILE__ ) );
}
+/**
+ * To prevent fatal errors when calling is_plugin_active(), we first check if the
+ * function exists. If it doesn't, we include the file manually to ensure the
+ * function is available.
+ */
+if ( ! function_exists( 'is_plugin_active' ) ) {
+ require_once ABSPATH . 'wp-admin/includes/plugin.php';
+}
+
+if ( ! defined( 'RTMEDIA_GODAM_ACTIVE' ) ) {
+ /**
+ * Check if Godam plugin is active and set constant accordingly.
+ */
+ define( 'RTMEDIA_GODAM_ACTIVE', is_plugin_active( 'godam/godam.php' ) );
+}
+
/**
* Auto Loader Function
*
From 7a4095e85c9f70dd21866df514a8075a9c832d8e Mon Sep 17 00:00:00 2001
From: krishana7911
Date: Wed, 28 May 2025 14:37:45 +0530
Subject: [PATCH 02/22] Add rest_pre_dispatch filter for media GET requests in
rtMedia GoDAM integration
---
app/main/controllers/api/RTMediaJsonApi.php | 39 +++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/app/main/controllers/api/RTMediaJsonApi.php b/app/main/controllers/api/RTMediaJsonApi.php
index f95984678..8186ed542 100644
--- a/app/main/controllers/api/RTMediaJsonApi.php
+++ b/app/main/controllers/api/RTMediaJsonApi.php
@@ -161,6 +161,10 @@ public function __construct() {
add_action( 'wp_ajax_nopriv_rtmedia_api', array( $this, 'rtmedia_api_process_request' ) );
add_action( 'wp_ajax_rtmedia_api', array( $this, 'rtmedia_api_process_request' ) );
+
+ if ( defined( 'RTMEDIA_GODAM_ACTIVE' ) && RTMEDIA_GODAM_ACTIVE ) {
+ add_action( 'rest_api_init', [ $this, 'register_rest_pre_dispatch_filter' ] );
+ }
}
/**
@@ -1469,4 +1473,39 @@ public function api_new_media_upload_dir( $args ) {
return $args;
}
}
+
+ /**
+ * Registers the rest_pre_dispatch filter during rest_api_init.
+ */
+ public function register_rest_pre_dispatch_filter() {
+ add_filter( 'rest_pre_dispatch', [ $this, 'handle_rest_pre_dispatch' ], 10, 3 );
+ }
+
+ /**
+ * Callback for rest_pre_dispatch filter.
+ *
+ * @param mixed $result Result to return instead of the request. Default null to continue with request.
+ * @param WP_REST_Server $server Server instance.
+ * @param WP_REST_Request $request Request object.
+ *
+ * @return mixed Modified result or original $result.
+ */
+ public function handle_rest_pre_dispatch( $result, $server, $request ) {
+ $route = $request->get_route();
+ $method = $request->get_method();
+
+ if ( 'GET' === $method && preg_match( '#^/wp/v2/media/(\d+)$#', $route, $matches ) ) {
+ $media_id = (int) $matches[1];
+ $post = get_post( $media_id );
+
+ if ( $post && 'attachment' === $post->post_type ) {
+ $controller = new WP_REST_Attachments_Controller( 'attachment' );
+ $response = $controller->prepare_item_for_response( $post, $request );
+
+ return rest_ensure_response( $response );
+ }
+ }
+
+ return $result;
+ }
}
From d8cf22d6ad95c2a02e4e6a7c8ab8c69ff8e37eb9 Mon Sep 17 00:00:00 2001
From: krishana7911
Date: Wed, 28 May 2025 16:32:44 +0530
Subject: [PATCH 03/22] add godam player shortcode integration for activity
page
---
.../template/rtmedia-functions.php | 166 ++++++++++++++++++
1 file changed, 166 insertions(+)
diff --git a/app/main/controllers/template/rtmedia-functions.php b/app/main/controllers/template/rtmedia-functions.php
index 8c9984346..049ee5563 100644
--- a/app/main/controllers/template/rtmedia-functions.php
+++ b/app/main/controllers/template/rtmedia-functions.php
@@ -5177,3 +5177,169 @@ function rtmedia_like_eraser( $email_address, $page = 1 ) {
'done' => $done,
);
}
+
+
+// ------------------------GODAM INTEGRATION-----------------------//
+
+if ( defined( 'RTMEDIA_GODAM_ACTIVE' ) && RTMEDIA_GODAM_ACTIVE ) {
+
+ /**
+ * Filter BuddyPress activity content to replace rtMedia video list
+ * with Godam player shortcodes.
+ */
+ add_filter( 'bp_get_activity_content_body', function( $content ) {
+ global $activities_template;
+
+ // Bail early if activity object is not available
+ if ( empty( $activities_template->activity ) || ! is_object( $activities_template->activity ) ) {
+ return $content;
+ }
+
+ $activity = $activities_template->activity;
+
+ // Allow only certain activity types
+ $valid_types = [ 'rtmedia_update', 'activity_update', 'activity_comment' ];
+ if ( ! isset( $activity->type ) || ! in_array( $activity->type, $valid_types, true ) ) {
+ return $content;
+ }
+
+ // Ensure RTMediaModel class exists
+ if ( ! class_exists( 'RTMediaModel' ) ) {
+ return $content;
+ }
+
+ $model = new RTMediaModel();
+ $media_items = $model->get( [ 'activity_id' => $activity->id ] );
+
+ if ( empty( $media_items ) || ! is_array( $media_items ) ) {
+ return $content;
+ }
+
+ // Remove rtMedia default video
+ $clean_content = preg_replace(
+ '#]*class="[^"]*rtmedia-list[^"]*rtm-activity-media-list[^"]*rtmedia-activity-media-length-[0-9]+[^"]*rtm-activity-video-list[^"]*"[^>]*>.*? #si',
+ '',
+ $activity->content
+ );
+
+ // Group media by type
+ $grouped_media = [];
+ foreach ( $media_items as $media ) {
+ $grouped_media[ $media->media_type ][] = $media;
+ }
+
+ $godam_videos = '';
+
+ // Build Godam player shortcodes for videos
+ if ( ! empty( $grouped_media['video'] ) ) {
+ foreach ( $grouped_media['video'] as $index => $video ) {
+ $player_id = 'godam-activity-' . esc_attr( $activity->id ) . '-' . $index;
+ $godam_videos .= do_shortcode(
+ '[godam_video id="' . esc_attr( $video->media_id ) .
+ '" context="buddypress" player_id="' . esc_attr( $player_id ) . '"]'
+ );
+ }
+ }
+
+ // Process video media in activity comments
+ if ( ! empty( $activity->children ) && is_array( $activity->children ) ) {
+ foreach ( $activity->children as $child ) {
+ $child_media = $model->get( [ 'activity_id' => $child->id ] );
+
+ if ( empty( $child_media ) ) {
+ continue;
+ }
+
+ $child_videos = '';
+
+ foreach ( $child_media as $index => $video ) {
+ $player_id = 'godam-comment-' . esc_attr( $child->id ) . '-' . $index;
+ $child_videos .= do_shortcode(
+ '[godam_video id="' . esc_attr( $video->media_id ) . '"]'
+ );
+ }
+
+ if ( $child_videos ) {
+ // Remove rtMedia from comment
+ $child->content = preg_replace(
+ '#]*class="[^"]*rtmedia-list[^"]*rtm-activity-media-list[^"]*rtmedia-activity-media-length-[0-9]+[^"]*rtm-activity-video-list[^"]*"[^>]*>.*? #si',
+ '',
+ $child->content
+ );
+
+ // Append Godam video players
+ $child->content .= '' . $child_videos . '
';
+ }
+ }
+ }
+
+ // Final video output appended to cleaned content
+ if ( $godam_videos ) {
+ $godam_videos = '' . $godam_videos . '
';
+ }
+
+ return wp_kses_post( $clean_content ) . $godam_videos;
+ }, 10 );
+
+
+ /**
+ * Enqueue frontend JS for Godam AJAX refresh.
+ */
+ add_action( 'wp_enqueue_scripts', function() {
+ wp_enqueue_script(
+ 'godam-ajax-refresh',
+ RTMEDIA_URL . 'app/assets/js/godam-ajax-refresh.js',
+ [],
+ null,
+ true
+ );
+
+ wp_localize_script( 'godam-ajax-refresh', 'GodamAjax', [
+ 'ajax_url' => admin_url( 'admin-ajax.php' ),
+ 'nonce' => wp_create_nonce( 'godam-ajax-nonce' ),
+ ]);
+ });
+
+
+ /**
+ * Handle AJAX request for loading a single activity comment's HTML.
+ */
+ add_action( 'wp_ajax_get_single_activity_comment_html', 'handle_get_single_activity_comment_html' );
+ add_action( 'wp_ajax_nopriv_get_single_activity_comment_html', 'handle_get_single_activity_comment_html' );
+
+ function handle_get_single_activity_comment_html() {
+ check_ajax_referer( 'godam-ajax-nonce', 'nonce' );
+
+ $activity_id = isset( $_POST['comment_id'] ) ? intval( $_POST['comment_id'] ) : 0;
+
+ if ( ! $activity_id ) {
+ wp_send_json_error( 'Invalid activity ID' );
+ }
+
+ $activity = new BP_Activity_Activity( $activity_id );
+ if ( empty( $activity->id ) ) {
+ wp_send_json_error( 'Activity comment not found' );
+ }
+
+ global $activities_template;
+
+ // Backup original activity
+ $original_activity = $activities_template->activity ?? null;
+
+ // Replace global for template rendering
+ $activities_template = new stdClass();
+ $activities_template->activity = $activity;
+
+ ob_start();
+ bp_get_template_part( 'activity/entry' );
+ $html = ob_get_clean();
+
+ // Restore original
+ if ( $original_activity ) {
+ $activities_template->activity = $original_activity;
+ }
+
+ wp_send_json_success( [ 'html' => $html ] );
+ }
+
+}
From 352bff71419e137a94575ed279b02a19902043dd Mon Sep 17 00:00:00 2001
From: krishana7911
Date: Wed, 28 May 2025 16:40:45 +0530
Subject: [PATCH 04/22] add script for ajax refresh for videos in comment
replies
---
app/assets/js/godam-ajax-refresh.js | 87 +++++++++++++++++++++++++++++
1 file changed, 87 insertions(+)
create mode 100644 app/assets/js/godam-ajax-refresh.js
diff --git a/app/assets/js/godam-ajax-refresh.js b/app/assets/js/godam-ajax-refresh.js
new file mode 100644
index 000000000..5b39a2531
--- /dev/null
+++ b/app/assets/js/godam-ajax-refresh.js
@@ -0,0 +1,87 @@
+document.addEventListener('DOMContentLoaded', () => {
+ const commentsContainers = document.querySelectorAll('.activity-comments');
+
+ // If no comment containers exist, exit early
+ if (commentsContainers.length === 0) {
+ return;
+ }
+
+ commentsContainers.forEach((container) => {
+ // Initialize GODAMPlayer on existing comment container
+ GODAMPlayer(container);
+
+ // Observe DOM changes to detect new comments being added dynamically
+ const observer = new MutationObserver((mutations) => {
+ mutations.forEach((mutation) => {
+ mutation.addedNodes.forEach((node) => {
+ if (node.nodeType === 1 && node.matches('li[id^="acomment-"]')) {
+ // Initialize GODAMPlayer on the new comment node
+ GODAMPlayer(node);
+
+ // Extract the comment ID and refresh the comment via AJAX
+ const commentId = node.id.replace('acomment-', '');
+ refreshSingleComment(commentId, node);
+ }
+ });
+ });
+ });
+
+ observer.observe(container, {
+ childList: true,
+ subtree: true
+ });
+ });
+ });
+
+ /**
+ * Refreshes a single BuddyPress comment via AJAX to fetch updated content,
+ * including Godam video player shortcode rendering.
+ *
+ * @param {string} commentId - The ID of the comment to refresh
+ * @param {Element} node - The existing DOM node being replaced
+ */
+ function refreshSingleComment(commentId, node) {
+ 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,
+ }),
+ })
+ .then(response => response.json())
+ .then(data => {
+ if (data.success) {
+ // Identify the parent activity from the comment DOM node
+ const parentActivityId = node.closest('.activity-item').id.replace('activity-', '');
+
+ // Locate or create the container for activity comments
+ let commentList = document.querySelector(`#activity-${parentActivityId} .activity-comments`);
+ if (!commentList) {
+ commentList = document.createElement('ul');
+ commentList.classList.add('activity-comments');
+ document.querySelector(`#activity-${parentActivityId}`).appendChild(commentList);
+ }
+
+ // Inject the freshly rendered comment HTML
+ commentList.insertAdjacentHTML('beforeend', data.data.html);
+
+ // Remove the placeholder node that triggered the refresh
+ if (node.parentNode) {
+ node.parentNode.removeChild(node);
+ }
+
+ // Reinitialize GODAMPlayer for the new comment node
+ const refreshedNode = document.querySelector(`#acomment-${commentId}`);
+ if (refreshedNode) GODAMPlayer(refreshedNode);
+ } else {
+ console.error('AJAX error:', data.data);
+ }
+ })
+ .catch(error => {
+ console.error('Fetch error:', error);
+ });
+ }
From 02e043ae49503db2966e2cbb73859f7caccbeed2 Mon Sep 17 00:00:00 2001
From: krishana7911
Date: Wed, 28 May 2025 16:44:57 +0530
Subject: [PATCH 05/22] add godam plugin check in rtmedia_media function before
executing shortcode
---
.../template/rtmedia-functions.php | 46 ++++++++++---------
1 file changed, 24 insertions(+), 22 deletions(-)
diff --git a/app/main/controllers/template/rtmedia-functions.php b/app/main/controllers/template/rtmedia-functions.php
index 049ee5563..52bcf949b 100644
--- a/app/main/controllers/template/rtmedia-functions.php
+++ b/app/main/controllers/template/rtmedia-functions.php
@@ -584,33 +584,35 @@ function rtmedia_media( $size_flag = true, $echo = true, $media_size = 'rt_media
$youtube_url = get_rtmedia_meta( $rtmedia_media->id, 'video_url_uploaded_from' );
$height = $rtmedia->options['defaultSizes_video_singlePlayer_height'];
- $height = ( $height * 75 ) / 640;
- $size = ' width="' . esc_attr( $rtmedia->options['defaultSizes_video_singlePlayer_width'] ) . '" height="' . esc_attr( $height ) . '%" ';
- $html = "";
-
- if ( empty( $youtube_url ) ) {
-
- // added poster for showing thumbnail and changed preload value to fix rtMedia GL-209.
- $html .= sprintf(
- '
',
- esc_url( $rtmedia_media->cover_art || '' ),
- esc_url( wp_get_attachment_url( $rtmedia_media->media_id ) ),
- esc_attr( $size ),
- esc_attr( $rtmedia_media->id )
- );
+ $width = $rtmedia->options['defaultSizes_video_singlePlayer_width'];
+ $height_pct = ( $height * 75 ) / 640;
+ $size_attr = ' width="' . esc_attr( $width ) . '" height="' . esc_attr( $height_pct ) . '%" ';
- } else {
-
- $html .= sprintf(
- '
',
- esc_attr( $rtmedia_media->id ),
- esc_url( wp_get_attachment_url( $rtmedia_media->media_id ) )
- );
+ $html = '
';
+ // Check if Godam plugin is active.
+ if ( defined( 'RTMEDIA_GODAM_ACTIVE' ) && RTMEDIA_GODAM_ACTIVE ) {
+ $html .= do_shortcode( '[godam_video id="' . esc_attr( $rtmedia_media->media_id ) . '"]' );
+ } else {
+ // Fallback to native or YouTube player.
+ if ( empty( $youtube_url ) ) {
+ $html .= sprintf(
+ ' ',
+ esc_url( $rtmedia_media->cover_art ?: '' ),
+ esc_url( wp_get_attachment_url( $rtmedia_media->media_id ) ),
+ $size_attr,
+ esc_attr( $rtmedia_media->id )
+ );
+ } else {
+ $html .= sprintf(
+ ' ',
+ esc_attr( $rtmedia_media->id ),
+ esc_url( $youtube_url )
+ );
+ }
}
$html .= '
';
-
} elseif ( 'music' === $rtmedia_media->media_type ) {
$width = $rtmedia->options['defaultSizes_music_singlePlayer_width'];
From 0697f3f4fe1bb406ad9e4600ad5e3711b80317a9 Mon Sep 17 00:00:00 2001
From: krishana7911
Date: Thu, 29 May 2025 08:23:11 +0530
Subject: [PATCH 06/22] enqeue godam integration script and godam js render
scripts globally when rtmedia is active
---
.../template/rtmedia-functions.php | 20 +++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/app/main/controllers/template/rtmedia-functions.php b/app/main/controllers/template/rtmedia-functions.php
index 52bcf949b..41b6f0cb8 100644
--- a/app/main/controllers/template/rtmedia-functions.php
+++ b/app/main/controllers/template/rtmedia-functions.php
@@ -5296,12 +5296,32 @@ function rtmedia_like_eraser( $email_address, $page = 1 ) {
true
);
+ wp_enqueue_script(
+ 'godam-rtmedia-integration',
+ RTMEDIA_URL . 'app/assets/js/godam-integration.js',
+ [],
+ null,
+ true
+ );
+
wp_localize_script( 'godam-ajax-refresh', 'GodamAjax', [
'ajax_url' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'godam-ajax-nonce' ),
]);
});
+ // add_action( 'wp_enqueue_scripts', array( $this, 'register_scripts' ) );
+ add_action( 'wp_enqueue_scripts', 'enqueue_scripts_globally', 20 );
+
+ /**
+ * Enqueue GoDAM scripts and styles globally.
+ */
+ function enqueue_scripts_globally() {
+ wp_enqueue_script( 'godam-player-frontend-script' );
+ wp_enqueue_script( 'godam-player-analytics-script' );
+ wp_enqueue_style( 'godam-player-frontend-style' );
+ wp_enqueue_style( 'godam-player-style' );
+ }
/**
* Handle AJAX request for loading a single activity comment's HTML.
From 79d74349158750983116e0d671e018509e0a1a0b Mon Sep 17 00:00:00 2001
From: krishana7911
Date: Thu, 29 May 2025 08:24:25 +0530
Subject: [PATCH 07/22] add godam player render for comments in the single
media
---
.../template/rtmedia-functions.php | 40 +++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/app/main/controllers/template/rtmedia-functions.php b/app/main/controllers/template/rtmedia-functions.php
index 41b6f0cb8..ece82581f 100644
--- a/app/main/controllers/template/rtmedia-functions.php
+++ b/app/main/controllers/template/rtmedia-functions.php
@@ -1468,6 +1468,46 @@ function rmedia_single_comment( $comment, $count = false, $i = false ) {
);
}
+ /**
+ * Replaces tags with Godam shortcodes for comment videos in single media page.
+ * Execute this when GoDAM is active
+ *
+ * Searches for elements with IDs like 'rt_media_video_{id}', fetches the
+ * corresponding `media_id` from the `rt_rtm_media` table, and replaces the tag
+ * with the [godam_video] shortcode.
+ *
+ * @var string $html HTML content containing video tags.
+ * @return string Modified HTML with Godam shortcodes (if applicable).
+ */
+ if ( defined( 'RTMEDIA_GODAM_ACTIVE' ) && RTMEDIA_GODAM_ACTIVE ) {
+ global $wpdb;
+
+ // Replace all tags with ID pattern rt_media_video_{id}
+ $html = preg_replace_callback(
+ '#]*id="rt_media_video_(\d+)"[^>]*>.*? #is',
+ function( $matches ) use ( $wpdb ) {
+ $extracted_id = intval( $matches[1] ); // Extract numeric ID from video tag
+
+ // Fetch media_id from rt_rtm_media table using the extracted ID
+ $media_id = $wpdb->get_var(
+ $wpdb->prepare(
+ "SELECT media_id FROM {$wpdb->prefix}rt_rtm_media WHERE id = %d",
+ $extracted_id
+ )
+ );
+
+ // If media_id exists, return Godam video shortcode
+ if ( ! empty( $media_id ) ) {
+ return do_shortcode( '[godam_video id="' . $media_id . '"]' );
+ }
+
+ // If no media_id found, return original video HTML
+ return $matches[0];
+ },
+ $html
+ );
+ }
+
$html .= '
';
return apply_filters( 'rtmedia_single_comment', $html, $comment );
From d1203b62ed9f52152899e06d34354f892da65218 Mon Sep 17 00:00:00 2001
From: krishana7911
Date: Thu, 29 May 2025 08:47:23 +0530
Subject: [PATCH 08/22] add enqeueing at the top of the section
---
.../template/rtmedia-functions.php | 81 ++++++++++---------
1 file changed, 41 insertions(+), 40 deletions(-)
diff --git a/app/main/controllers/template/rtmedia-functions.php b/app/main/controllers/template/rtmedia-functions.php
index ece82581f..c801b920b 100644
--- a/app/main/controllers/template/rtmedia-functions.php
+++ b/app/main/controllers/template/rtmedia-functions.php
@@ -5225,6 +5225,47 @@ function rtmedia_like_eraser( $email_address, $page = 1 ) {
if ( defined( 'RTMEDIA_GODAM_ACTIVE' ) && RTMEDIA_GODAM_ACTIVE ) {
+ /**
+ * Enqueue frontend scripts for Godam integration and AJAX refresh.
+ */
+ add_action( 'wp_enqueue_scripts', function() {
+ // Enqueue the script responsible for AJAX-based comment refresh.
+ wp_enqueue_script(
+ 'godam-ajax-refresh',
+ RTMEDIA_URL . 'app/assets/js/godam-ajax-refresh.js',
+ [],
+ null,
+ true
+ );
+
+ // Pass AJAX URL and nonce to the script.
+ wp_localize_script( 'godam-ajax-refresh', 'GodamAjax', [
+ 'ajax_url' => admin_url( 'admin-ajax.php' ),
+ 'nonce' => wp_create_nonce( 'godam-ajax-nonce' ),
+ ]);
+
+ // Enqueue integration script for rtMedia and Godam.
+ wp_enqueue_script(
+ 'godam-rtmedia-integration',
+ RTMEDIA_URL . 'app/assets/js/godam-integration.js',
+ [],
+ null,
+ true
+ );
+ } );
+
+ /**
+ * Enqueue GoDAM scripts and styles globally (player, analytics, and styles).
+ */
+ add_action( 'wp_enqueue_scripts', 'enqueue_scripts_globally', 20 );
+
+ function enqueue_scripts_globally() {
+ wp_enqueue_script( 'godam-player-frontend-script' );
+ wp_enqueue_script( 'godam-player-analytics-script' );
+ wp_enqueue_style( 'godam-player-frontend-style' );
+ wp_enqueue_style( 'godam-player-style' );
+ }
+
/**
* Filter BuddyPress activity content to replace rtMedia video list
* with Godam player shortcodes.
@@ -5323,46 +5364,6 @@ function rtmedia_like_eraser( $email_address, $page = 1 ) {
return wp_kses_post( $clean_content ) . $godam_videos;
}, 10 );
-
- /**
- * Enqueue frontend JS for Godam AJAX refresh.
- */
- add_action( 'wp_enqueue_scripts', function() {
- wp_enqueue_script(
- 'godam-ajax-refresh',
- RTMEDIA_URL . 'app/assets/js/godam-ajax-refresh.js',
- [],
- null,
- true
- );
-
- wp_enqueue_script(
- 'godam-rtmedia-integration',
- RTMEDIA_URL . 'app/assets/js/godam-integration.js',
- [],
- null,
- true
- );
-
- wp_localize_script( 'godam-ajax-refresh', 'GodamAjax', [
- 'ajax_url' => admin_url( 'admin-ajax.php' ),
- 'nonce' => wp_create_nonce( 'godam-ajax-nonce' ),
- ]);
- });
-
- // add_action( 'wp_enqueue_scripts', array( $this, 'register_scripts' ) );
- add_action( 'wp_enqueue_scripts', 'enqueue_scripts_globally', 20 );
-
- /**
- * Enqueue GoDAM scripts and styles globally.
- */
- function enqueue_scripts_globally() {
- wp_enqueue_script( 'godam-player-frontend-script' );
- wp_enqueue_script( 'godam-player-analytics-script' );
- wp_enqueue_style( 'godam-player-frontend-style' );
- wp_enqueue_style( 'godam-player-style' );
- }
-
/**
* Handle AJAX request for loading a single activity comment's HTML.
*/
From 5d1fb35e5672536a5fd946d0224e16147ee8e4bc Mon Sep 17 00:00:00 2001
From: krishana7911
Date: Thu, 29 May 2025 09:53:23 +0530
Subject: [PATCH 09/22] fix styles for the video container for comments
---
.../template/rtmedia-functions.php | 31 ++++++++++---------
1 file changed, 17 insertions(+), 14 deletions(-)
diff --git a/app/main/controllers/template/rtmedia-functions.php b/app/main/controllers/template/rtmedia-functions.php
index c801b920b..263d65e01 100644
--- a/app/main/controllers/template/rtmedia-functions.php
+++ b/app/main/controllers/template/rtmedia-functions.php
@@ -1498,7 +1498,10 @@ function( $matches ) use ( $wpdb ) {
// If media_id exists, return Godam video shortcode
if ( ! empty( $media_id ) ) {
- return do_shortcode( '[godam_video id="' . $media_id . '"]' );
+ return ''
+ . ''
+ . do_shortcode( '[godam_video id="' . $media_id . '"]' )
+ . '
';
}
// If no media_id found, return original video HTML
@@ -5225,6 +5228,18 @@ function rtmedia_like_eraser( $email_address, $page = 1 ) {
if ( defined( 'RTMEDIA_GODAM_ACTIVE' ) && RTMEDIA_GODAM_ACTIVE ) {
+ /**
+ * Enqueue GoDAM scripts and styles globally (player, analytics, and styles).
+ */
+ add_action( 'wp_enqueue_scripts', 'enqueue_scripts_globally', 20 );
+
+ function enqueue_scripts_globally() {
+ wp_enqueue_script( 'godam-player-frontend-script' );
+ wp_enqueue_script( 'godam-player-analytics-script' );
+ wp_enqueue_style( 'godam-player-frontend-style' );
+ wp_enqueue_style( 'godam-player-style' );
+ }
+
/**
* Enqueue frontend scripts for Godam integration and AJAX refresh.
*/
@@ -5248,24 +5263,12 @@ function rtmedia_like_eraser( $email_address, $page = 1 ) {
wp_enqueue_script(
'godam-rtmedia-integration',
RTMEDIA_URL . 'app/assets/js/godam-integration.js',
- [],
+ [ 'godam-player-frontend-script' ],
null,
true
);
} );
- /**
- * Enqueue GoDAM scripts and styles globally (player, analytics, and styles).
- */
- add_action( 'wp_enqueue_scripts', 'enqueue_scripts_globally', 20 );
-
- function enqueue_scripts_globally() {
- wp_enqueue_script( 'godam-player-frontend-script' );
- wp_enqueue_script( 'godam-player-analytics-script' );
- wp_enqueue_style( 'godam-player-frontend-style' );
- wp_enqueue_style( 'godam-player-style' );
- }
-
/**
* Filter BuddyPress activity content to replace rtMedia video list
* with Godam player shortcodes.
From 5b74681f83410c14b9e6c0c17d3601c078cdd747 Mon Sep 17 00:00:00 2001
From: krishana7911
Date: Thu, 29 May 2025 10:40:12 +0530
Subject: [PATCH 10/22] remove magnific enqeueing from this file
---
app/main/RTMedia.php | 12 +-----------
1 file changed, 1 insertion(+), 11 deletions(-)
diff --git a/app/main/RTMedia.php b/app/main/RTMedia.php
index ccc1809ed..2efc61ff6 100755
--- a/app/main/RTMedia.php
+++ b/app/main/RTMedia.php
@@ -1248,16 +1248,6 @@ public function enqueue_scripts_styles() {
}
if ( '' === $suffix ) {
- wp_enqueue_script(
- 'rtmedia-magnific-popup',
- RTMEDIA_URL . 'app/assets/js/vendors/magnific-popup.js',
- array(
- 'jquery',
- 'rt-mediaelement-wp',
- ),
- RTMEDIA_VERSION,
- true
- );
wp_enqueue_script(
'rtmedia-admin-tabs',
RTMEDIA_URL . 'app/assets/admin/js/vendors/tabs.js',
@@ -1277,7 +1267,7 @@ public function enqueue_scripts_styles() {
'rtmedia-emoji-picker',
),
RTMEDIA_VERSION,
- true
+ args: true
);
} else {
wp_enqueue_script(
From e8f9ef8db20e0d4e09279a9e6eee4d6c623c9257 Mon Sep 17 00:00:00 2001
From: krishana7911
Date: Thu, 29 May 2025 10:48:52 +0530
Subject: [PATCH 11/22] add godam-integration and godam-ajax-refresh for
minification
---
Gruntfile.js | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/Gruntfile.js b/Gruntfile.js
index a59c033fb..418ba7ce9 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -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']
+ }
}
}
});
From c7eabd58d618039d613cc2a1f8b3db16426b71ad Mon Sep 17 00:00:00 2001
From: krishana7911
Date: Thu, 29 May 2025 10:50:05 +0530
Subject: [PATCH 12/22] add godam integration js files
---
app/assets/js/godam-ajax-refresh.min.js | 1 +
app/assets/js/godam-integration.js | 171 ++++++++++++++++++++++++
app/assets/js/godam-integration.min.js | 1 +
app/assets/js/rtmedia.min.js | 7 +-
4 files changed, 174 insertions(+), 6 deletions(-)
create mode 100644 app/assets/js/godam-ajax-refresh.min.js
create mode 100644 app/assets/js/godam-integration.js
create mode 100644 app/assets/js/godam-integration.min.js
diff --git a/app/assets/js/godam-ajax-refresh.min.js b/app/assets/js/godam-ajax-refresh.min.js
new file mode 100644
index 000000000..90121c489
--- /dev/null
+++ b/app/assets/js/godam-ajax-refresh.min.js
@@ -0,0 +1 @@
+function refreshSingleComment(e,t){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:e,nonce:GodamAjax.nonce})}).then((e=>e.json())).then((o=>{if(o.success){const c=t.closest(".activity-item").id.replace("activity-","");let n=document.querySelector(`#activity-${c} .activity-comments`);n||(n=document.createElement("ul"),n.classList.add("activity-comments"),document.querySelector(`#activity-${c}`).appendChild(n)),n.insertAdjacentHTML("beforeend",o.data.html),t.parentNode&&t.parentNode.removeChild(t);const a=document.querySelector(`#acomment-${e}`);a&&GODAMPlayer(a)}else console.error("AJAX error:",o.data)})).catch((e=>{console.error("Fetch error:",e)}))}document.addEventListener("DOMContentLoaded",(()=>{const e=document.querySelectorAll(".activity-comments");0!==e.length&&e.forEach((e=>{GODAMPlayer(e);new MutationObserver((e=>{e.forEach((e=>{e.addedNodes.forEach((e=>{if(1===e.nodeType&&e.matches('li[id^="acomment-"]')){GODAMPlayer(e);refreshSingleComment(e.id.replace("acomment-",""),e)}}))}))})).observe(e,{childList:!0,subtree:!0})}))}));
\ No newline at end of file
diff --git a/app/assets/js/godam-integration.js b/app/assets/js/godam-integration.js
new file mode 100644
index 000000000..f9d9e4bf5
--- /dev/null
+++ b/app/assets/js/godam-integration.js
@@ -0,0 +1,171 @@
+/**
+ * This script ensures GODAMPlayer is initialized dynamically across:
+ * - BuddyPress activity streams updated via AJAX.
+ * - Magnific Popup content.
+ * - Any newly added video elements in the DOM (e.g., via infinite scroll or modals).
+ *
+ * It uses MutationObservers and event listeners to watch for new content and
+ * initializes the player only when necessary, avoiding duplicate setups.
+ */
+
+GODAMPlayer();
+
+const activityStream = document.querySelector('#buddypress #activity-stream');
+if (activityStream) {
+ const observer = new MutationObserver((mutations) => {
+ for (const mutation of mutations) {
+ mutation.addedNodes.forEach((node) => {
+ if (node.nodeType === 1 && node.matches('.activity')) {
+ requestAnimationFrame(() => GODAMPlayer(node));
+ }
+ });
+ }
+ });
+ observer.observe(activityStream, { childList: true, subtree: true });
+}
+
+document.addEventListener('DOMContentLoaded', () => {
+ GODAMPlayer();
+
+ const initializedElements = new WeakSet();
+
+ const safeGODAMInit = (element) => {
+ if (!element) {
+ GODAMPlayer();
+ return;
+ }
+
+ if (initializedElements.has(element)) {
+ return;
+ }
+
+ const existingPlayers = element.querySelectorAll('[data-godam-initialized], .godam-player-initialized');
+ if (existingPlayers.length > 0) {
+ return;
+ }
+
+ GODAMPlayer(element);
+ initializedElements.add(element);
+ if (element.setAttribute) {
+ element.setAttribute('data-godam-processed', 'true');
+ }
+ };
+
+ const activityStream = document.querySelector('#buddypress #activity-stream');
+ if (activityStream) {
+ const observer = new MutationObserver((mutations) => {
+ for (const mutation of mutations) {
+ mutation.addedNodes.forEach((node) => {
+ if (
+ node.nodeType === 1 &&
+ node.matches('.activity') &&
+ !node.hasAttribute('data-godam-processed')
+ ) {
+ requestAnimationFrame(() => safeGODAMInit(node));
+ }
+ });
+ }
+ });
+
+ observer.observe(activityStream, { childList: true, subtree: true });
+ }
+
+ let popupInitializationTimeout = null;
+
+ const setupMagnificObserver = () => {
+ const magnificObserver = new MutationObserver((mutations) => {
+ for (const mutation of mutations) {
+ mutation.addedNodes.forEach((node) => {
+ if (node.nodeType === 1) {
+ let mfpContent = null;
+
+ if (node.classList && node.classList.contains('mfp-content')) {
+ mfpContent = node;
+ } else {
+ mfpContent = node.querySelector('.mfp-content');
+ }
+
+ if (mfpContent && !mfpContent.hasAttribute('data-godam-processed')) {
+ if (popupInitializationTimeout) {
+ clearTimeout(popupInitializationTimeout);
+ }
+
+ popupInitializationTimeout = setTimeout(() => {
+ safeGODAMInit(mfpContent);
+ popupInitializationTimeout = null;
+ }, 300);
+ }
+ }
+ });
+ }
+ });
+
+ magnificObserver.observe(document.body, {
+ childList: true,
+ subtree: true
+ });
+ };
+
+ setupMagnificObserver();
+
+ if (typeof $.magnificPopup !== 'undefined') {
+ let eventTimeout = null;
+
+ const handleMagnificEvent = () => {
+ if (eventTimeout) {
+ clearTimeout(eventTimeout);
+ }
+
+ eventTimeout = setTimeout(() => {
+ const mfpContent = document.querySelector('.mfp-content:not([data-godam-processed])');
+ if (mfpContent) {
+ safeGODAMInit(mfpContent);
+ }
+ eventTimeout = null;
+ }, 250);
+ };
+
+ $(document).on('mfpOpen mfpChange', handleMagnificEvent);
+ }
+
+ if (typeof $ !== 'undefined') {
+ $(document).on('mfpClose', function () {
+ if (popupInitializationTimeout) {
+ clearTimeout(popupInitializationTimeout);
+ popupInitializationTimeout = null;
+ }
+ });
+ }
+
+ const videoObserver = new MutationObserver((mutations) => {
+ for (const mutation of mutations) {
+ mutation.addedNodes.forEach((node) => {
+ if (node.nodeType === 1) {
+ const isInMfpContent = node.closest('.mfp-content') ||
+ (node.classList && node.classList.contains('mfp-content'));
+
+ if (isInMfpContent) {
+ const videos = node.tagName === 'VIDEO' ? [node] : node.querySelectorAll('video');
+ if (videos.length > 0) {
+ const container = node.closest('.mfp-content') || node;
+ if (!container.hasAttribute('data-godam-processed')) {
+ requestAnimationFrame(() => safeGODAMInit(container));
+ }
+ }
+ }
+ }
+ });
+ }
+ });
+
+ videoObserver.observe(document.body, {
+ childList: true,
+ subtree: true
+ });
+});
+
+
+
+
+
+
diff --git a/app/assets/js/godam-integration.min.js b/app/assets/js/godam-integration.min.js
new file mode 100644
index 000000000..cae38cf2e
--- /dev/null
+++ b/app/assets/js/godam-integration.min.js
@@ -0,0 +1 @@
+GODAMPlayer();const activityStream=document.querySelector("#buddypress #activity-stream");if(activityStream){new MutationObserver((e=>{for(const t of e)t.addedNodes.forEach((e=>{1===e.nodeType&&e.matches(".activity")&&requestAnimationFrame((()=>GODAMPlayer(e)))}))})).observe(activityStream,{childList:!0,subtree:!0})}document.addEventListener("DOMContentLoaded",(()=>{GODAMPlayer();const e=new WeakSet,t=t=>{if(!t)return void GODAMPlayer();if(e.has(t))return;t.querySelectorAll("[data-godam-initialized], .godam-player-initialized").length>0||(GODAMPlayer(t),e.add(t),t.setAttribute&&t.setAttribute("data-godam-processed","true"))},o=document.querySelector("#buddypress #activity-stream");if(o){new MutationObserver((e=>{for(const o of e)o.addedNodes.forEach((e=>{1===e.nodeType&&e.matches(".activity")&&!e.hasAttribute("data-godam-processed")&&requestAnimationFrame((()=>t(e)))}))})).observe(o,{childList:!0,subtree:!0})}let a=null;if(new MutationObserver((e=>{for(const o of e)o.addedNodes.forEach((e=>{if(1===e.nodeType){let o=null;o=e.classList&&e.classList.contains("mfp-content")?e:e.querySelector(".mfp-content"),o&&!o.hasAttribute("data-godam-processed")&&(a&&clearTimeout(a),a=setTimeout((()=>{t(o),a=null}),300))}}))})).observe(document.body,{childList:!0,subtree:!0}),void 0!==$.magnificPopup){let e=null;const o=()=>{e&&clearTimeout(e),e=setTimeout((()=>{const o=document.querySelector(".mfp-content:not([data-godam-processed])");o&&t(o),e=null}),250)};$(document).on("mfpOpen mfpChange",o)}"undefined"!=typeof $&&$(document).on("mfpClose",(function(){a&&(clearTimeout(a),a=null)}));new MutationObserver((e=>{for(const o of e)o.addedNodes.forEach((e=>{if(1===e.nodeType){if(e.closest(".mfp-content")||e.classList&&e.classList.contains("mfp-content")){if(("VIDEO"===e.tagName?[e]:e.querySelectorAll("video")).length>0){const o=e.closest(".mfp-content")||e;o.hasAttribute("data-godam-processed")||requestAnimationFrame((()=>t(o)))}}}}))})).observe(document.body,{childList:!0,subtree:!0})}));
\ No newline at end of file
diff --git a/app/assets/js/rtmedia.min.js b/app/assets/js/rtmedia.min.js
index 7c5ab5084..24b945aa1 100644
--- a/app/assets/js/rtmedia.min.js
+++ b/app/assets/js/rtmedia.min.js
@@ -1,6 +1 @@
-/*!
- * rtMedia JavaScript Library
- * @package rtMedia
- */
-
-var rtMagnificPopup,rtm_masonry_container;!function(e){"function"==typeof define&&define.amd?define(["jquery"],e):"object"==typeof exports?e(require("jquery")):e(window.jQuery||window.Zepto)}(function(d){function e(){}function m(e,t){y.ev.on(i+e+b,t)}function u(e,t,i,a){var r=document.createElement("div");return r.className="mfp-"+e,i&&(r.innerHTML=i),a?t&&t.appendChild(r):(r=d(r),t&&r.appendTo(t)),r}function p(e,t){y.ev.triggerHandler(i+e,t),y.st.callbacks&&(e=e.charAt(0).toLowerCase()+e.slice(1),y.st.callbacks[e]&&y.st.callbacks[e].apply(y,d.isArray(t)?t:[t]))}function f(e){return e===t&&y.currTemplate.closeBtn||(y.currTemplate.closeBtn=d(y.st.closeMarkup.replace("%title%",y.st.tClose)),t=e),y.currTemplate.closeBtn}function n(){d.magnificPopup.instance||((y=new e).init(),d.magnificPopup.instance=y)}var y,a,_,r,v,t,l="Close",c="BeforeClose",g="MarkupParse",h="Open",o="Change",i="mfp",b="."+i,j="mfp-ready",s="mfp-removing",w="mfp-prevent-close",Q=!!window.jQuery,C=d(window);e.prototype={constructor:e,init:function(){var e=navigator.appVersion;y.isIE7=-1!==e.indexOf("MSIE 7."),y.isIE8=-1!==e.indexOf("MSIE 8."),y.isLowIE=y.isIE7||y.isIE8,y.isAndroid=/android/gi.test(e),y.isIOS=/iphone|ipad|ipod/gi.test(e),y.supportsTransition=function(){var e=document.createElement("p").style,t=["ms","O","Moz","Webkit"];if(void 0!==e.transition)return!0;for(;t.length;)if(t.pop()+"Transition"in e)return!0;return!1}(),y.probablyMobile=y.isAndroid||y.isIOS||/(Opera Mini)|Kindle|webOS|BlackBerry|(Opera Mobi)|(Windows Phone)|IEMobile/i.test(navigator.userAgent),_=d(document),y.popupsCache={}},open:function(e){var t;if(!1===e.isObj){y.items=e.items.toArray(),y.index=0;var i,a=e.items;for(t=0;t(e||C.height())},_setFocus:function(){(y.st.focus?y.content.find(y.st.focus).eq(0):y.wrap).focus()},_onFocusIn:function(e){if(e.target!==y.wrap[0]&&!d.contains(y.wrap[0],e.target))return y._setFocus(),!1},_parseMarkup:function(r,e,t){var n;t.data&&(e=d.extend(t.data,e)),p(g,[r,e,t]),d.each(e,function(e,t){if(void 0===t||!1===t)return!0;if(1<(n=e.split("_")).length){var i=r.find(b+"-"+n[0]);if(0 '):i.attr(n[1],t)}}else r.find(b+"-"+e).html(t)})},_getScrollbarSize:function(){if(void 0===y.scrollbarSize){var e=document.createElement("div");e.style.cssText="width: 99px; height: 99px; overflow: scroll; position: absolute; top: -9999px;",document.body.appendChild(e),y.scrollbarSize=e.offsetWidth-e.clientWidth,document.body.removeChild(e)}return y.scrollbarSize}},d.magnificPopup={instance:null,proto:e.prototype,modules:[],open:function(e,t){return n(),(e=e?d.extend(!0,{},e):{}).isObj=!0,e.index=t||0,this.instance.open(e)},close:function(){return d.magnificPopup.instance&&d.magnificPopup.instance.close()},registerModule:function(e,t){t.options&&(d.magnificPopup.defaults[e]=t.options),d.extend(this.proto,t.proto),this.modules.push(e)},defaults:{disableOn:0,key:null,midClick:!1,mainClass:"",preloader:!0,focus:"",closeOnContentClick:!1,closeOnBgClick:!0,closeBtnInside:!0,showCloseBtn:!0,enableEscapeKey:!0,modal:!1,alignTop:!1,removalDelay:0,prependTo:null,fixedContentPos:"auto",fixedBgPos:"auto",overflowY:"auto",closeMarkup:'× ',tClose:"Close (Esc)",tLoading:"Loading..."}},d.fn.magnificPopup=function(e){n();var t=d(this);if("string"==typeof e)if("open"===e){var i,a=Q?t.data("magnificPopup"):t[0].magnificPopup,r=parseInt(arguments[1],10)||0;i=a.items?a.items[r]:(i=t,a.delegate&&(i=i.find(a.delegate)),i.eq(r)),y._openClick({mfpEl:i},t,a)}else y.isOpen&&y[e].apply(y,Array.prototype.slice.call(arguments,1));else e=d.extend(!0,{},e),Q?t.data("magnificPopup",e):t[0].magnificPopup=e,y.addGroup(t,e);return t};function k(){I&&(T.after(I.addClass(x)).detach(),I=null)}var x,T,I,M="inline";d.magnificPopup.registerModule(M,{options:{hiddenClass:"hide",markup:"",tNotFound:"Content not found"},proto:{initInline:function(){y.types.push(M),m(l+"."+M,function(){k()})},getInline:function(e,t){if(k(),e.src){var i=y.st.inline,a=d(e.src);if(a.length){var r=a[0].parentNode;r&&r.tagName&&(T||(x=i.hiddenClass,T=u(x),x="mfp-"+x),I=a.after(T).detach().removeClass(x)),y.updateStatus("ready")}else y.updateStatus("error",i.tNotFound),a=d("");return e.inlineElement=a}return y.updateStatus("ready"),y._parseMarkup(t,{},e),t}}});function P(){E&&d(document.body).removeClass(E)}function S(){P(),y.req&&y.req.abort()}var E,O="ajax";d.magnificPopup.registerModule(O,{options:{settings:null,cursor:"mfp-ajax-cur",tError:'
The content could not be loaded.'},proto:{initAjax:function(){y.types.push(O),E=y.st.ajax.cursor,m(l+"."+O,S),m("BeforeChange."+O,S)},getAjax:function(r){E&&d(document.body).addClass(E),y.updateStatus("loading");var e=d.extend({url:r.src,success:function(e,t,i){var a={data:e,xhr:i};p("ParseAjax",a),y.appendContent(d(a.data),O),r.finished=!0,P(),y._setFocus(),setTimeout(function(){y.wrap.addClass(j)},16),y.updateStatus("ready"),p("AjaxContentAdded")},error:function(){P(),r.finished=r.loadError=!0,y.updateStatus("error",y.st.ajax.tError.replace("%url%",r.src))}},y.st.ajax.settings);return y.req=d.ajax(e),""}}});var z;d.magnificPopup.registerModule("image",{options:{markup:'
',cursor:"mfp-zoom-out-cur",titleSrc:"title",verticalFit:!0,tError:'
The image could not be loaded.'},proto:{initImage:function(){var e=y.st.image,t=".image";y.types.push("image"),m(h+t,function(){"image"===y.currItem.type&&e.cursor&&d(document.body).addClass(e.cursor)}),m(l+t,function(){e.cursor&&d(document.body).removeClass(e.cursor),C.off("resize"+b)}),m("Resize"+t,y.resizeImage),y.isLowIE&&m("AfterChange",y.resizeImage)},resizeImage:function(){var e=y.currItem;if(e&&e.img&&y.st.image.verticalFit){var t=0;y.isLowIE&&(t=parseInt(e.img.css("padding-top"),10)+parseInt(e.img.css("padding-bottom"),10)),e.img.css("max-height",y.wH-t)}},_onImageHasSize:function(e){e.img&&(e.hasSize=!0,z&&clearInterval(z),e.isCheckingImgSize=!1,p("ImageHasSize",e),e.imgHidden&&(y.content&&y.content.removeClass("mfp-loading"),e.imgHidden=!1))},findImageSize:function(t){var i=0,a=t.img[0],r=function(e){z&&clearInterval(z),z=setInterval(function(){0
',srcAction:"iframe_src",patterns:{youtube:{index:"youtube.com",id:"v=",src:"//www.youtube.com/embed/%id%?autoplay=1"},vimeo:{index:"vimeo.com/",id:"/",src:"//player.vimeo.com/video/%id%?autoplay=1"},gmaps:{index:"//maps.google.",src:"%id%&output=embed"}}},proto:{initIframe:function(){y.types.push(L),m("BeforeChange",function(e,t,i){t!==i&&(t===L?B():i===L&&B(!0))}),m(l+"."+L,function(){B()})},getIframe:function(e,t){var i=e.src,a=y.st.iframe;d.each(a.patterns,function(){if(-1',preload:[0,2],navigateByImgClick:!0,arrows:!0,tPrev:"Previous (Left arrow key)",tNext:"Next (Right arrow key)",tCounter:"%curr% of %total%"},proto:{initGallery:function(){var n=y.st.gallery,e=".mfp-gallery",r=Boolean(d.fn.mfpFastClick);if(y.direction=!0,!n||!n.enabled)return!1;v+=" mfp-gallery",m(h+e,function(){n.navigateByImgClick&&y.wrap.on("click"+e,".mfp-img",function(){if(1=y.index,y.index=e,y.updateItemHTML()},preloadNearbyImages:function(){var e,t=y.st.gallery.preload,i=Math.min(t[0],y.items.length),a=Math.min(t[1],y.items.length);for(e=1;e<=(y.direction?a:i);e++)y._preloadItem(y.index+e);for(e=1;e<=(y.direction?i:a);e++)y._preloadItem(y.index-e)},_preloadItem:function(e){if(e=A(e),!y.items[e].preloaded){var t=y.items[e];t.parsed||(t=y.parseEl(e)),p("LazyLoad",t),"image"===t.type&&(t.img=d(' ').on("load.mfploader",function(){t.hasSize=!0}).on("error.mfploader",function(){t.hasSize=!0,t.loadError=!0,p("LazyLoadError",t)}).attr("src",t.src)),t.preloaded=!0}}}});var F,R,D="retina";function W(){C.off("touchmove"+R+" touchend"+R)}d.magnificPopup.registerModule(D,{options:{replaceSrc:function(e){return e.src.replace(/\.\w+$/,function(e){return"@2x"+e})},ratio:1},proto:{initRetina:function(){if(1 a").siblings("p").children("a").length&&s(".activity-item .rtmedia-activity-container .rtmedia-list-item > a").siblings("p").children("a").addClass("no-popup"),rtMagnificPopup=jQuery(t).magnificPopup({delegate:"a:not(.no-popup, .mejs-time-slider, .mejs-volume-slider, .mejs-horizontal-volume-slider)",type:"ajax",fixedContentPos:!0,fixedBgPos:!0,tLoading:e+" #%curr%...",mainClass:"mfp-img-mobile",preload:[1,3],closeOnBgClick:!0,gallery:{enabled:!0,navigateByImgClick:!0,arrowMarkup:"",preload:[0,1]},image:{tError:'The image #%curr% could not be loaded.',titleSrc:function(e){return e.el.attr("title")+"by Marsel Van Oosten "}},callbacks:{ajaxContentAdded:function(){e=jQuery.magnificPopup.instance,1===jQuery(e.items).size()&&jQuery(".mfp-arrow").remove();var e=jQuery.magnificPopup.instance,t=e.currItem.el,i=t.parent();if(i.is("li")||(i=i.parent()),(i.is(":nth-last-child(2)")||i.is(":last-child"))&&i.find("a").hasClass("rtmedia-list-item-a")){i.next();"block"==jQuery("#rtMedia-galary-next").css("display")&&(c||(n=e.ev.children(),c=!0,l=nextpage),jQuery("#rtMedia-galary-next").click())}var a=e.items.length;if(e.index!=a-1||i.is(":last-child")){"undefined"!=typeof _wpmejsSettings&&_wpmejsSettings.pluginPath;var o=jQuery(".rtmedia-container .rtmedia-single-meta").height(),r=!1;void 0!==e&&void 0!==e.probablyMobile&&1==e.probablyMobile&&(r=!0),s(".mfp-content .rtmedia-single-media .wp-audio-shortcode,.mfp-content .rtmedia-single-media .wp-video-shortcode,.mfp-content .rtmedia-single-media .bp_media_content video").attr("autoplay",!0),r&&s(".mfp-content .rtmedia-single-media .wp-video-shortcode,.mfp-content .rtmedia-single-media .bp_media_content video").attr("muted",!1),s(".mfp-content .rtmedia-single-media .wp-audio-shortcode,.mfp-content .rtmedia-single-media .wp-video-shortcode,.mfp-content .rtmedia-single-media .bp_media_content video").mediaelementplayer({classPrefix:"mejs-",defaultVideoWidth:480,hideVolumeOnTouchDevices:!1,features:["playpause","progress","current","volume","fullscreen"],defaultVideoHeight:270,alwaysShowControls:r,enableAutosize:!0,clickToPlayPause:!0,videoHeight:-1,success:function(n,e){n.addEventListener("loadeddata",function(e){var t=s(n).height(),i=s(window).height(),a=jQuery("div.rtm-ltb-action-container").height(),r=o-(a=a+50);i span,"+e+" .click-nav > div").toggleClass("no-js js"),jQuery(e+" .click-nav .js ul").hide(),jQuery(e+" .click-nav .clicker").click(function(e){t=jQuery("#rtm-media-options .click-nav .clicker").next("ul"),i=jQuery(this).next("ul"),jQuery.each(t,function(e,t){jQuery(t).html()!=i.html()&&jQuery(t).hide()}),jQuery(i).toggle(),e.stopPropagation()})}function bp_media_create_element(e){return!1}function rtmedia_version_compare(e,t){if(typeof e+typeof t!="stringstring")return!1;for(var i=e.split("."),a=t.split("."),r=0,n=Math.max(i.length,a.length);rparseInt(a[r]))return!0;if(a[r]&&!i[r]&&0",{title:"Click to dismiss",class:"rtmedia-message-container"+(i?" rtmedia-empty-comment-error-class":""),style:"margin:1em 0;"}),s=jQuery("",{class:a});s.html(e),s.appendTo(o),i?(n=jQuery("#rt_media_comment_form"),jQuery("#comment_content").focus()):void 0===i&&(n=jQuery(".rtmedia-single-media .rtmedia-media")).css("opacity","0.2"),n.after(o),r&&(s.css({border:"2px solid #884646"}),setTimeout(function(){s.css({border:"none"})},500)),setTimeout(function(){o.remove(),void 0===i&&n.css("opacity","1")},3e3),o.click(function(){o.remove(),void 0===i&&n.css("opacity","1")})}function rtmedia_gallery_action_alert_message(e,t){var i="rtmedia-success";"warning"==t&&(i="rtmedia-warning");jQuery("body").append('
'),jQuery(".rtmedia-gallery-alert-container").append(""+e+"
"),setTimeout(function(){jQuery(".rtmedia-gallery-alert-container").remove()},3e3),jQuery(".rtmedia-gallery-message-box").click(function(){jQuery(".rtmedia-gallery-alert-container").remove()})}function rtmedia_activity_masonry(){jQuery("#activity-stream .rtmedia-activity-container .rtmedia-list").masonry({itemSelector:".rtmedia-list-item",gutter:7});var e=0,t=setInterval(function(){5===(e+=1)&&clearInterval(t),jQuery.each(jQuery(".rtmedia-activity-container .rtmedia-list.masonry .rtmedia-item-title"),function(e,t){jQuery(t).width(jQuery(t).siblings(".rtmedia-item-thumbnail").children("img").width())}),rtm_masonry_reload(jQuery("#activity-stream .rtmedia-activity-container .rtmedia-list"))},1e3)}function get_parameter(e,t){if(!e)return!1;t=t||window.location.href;e=e.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var i=new RegExp(e+"=([^]*)").exec(t);return null!==i&&i[1]}function rtm_upload_terms_activity(){if(0 audio.wp-audio-shortcode, ul.activity-list li.rtmedia_update div.rtmedia-item-thumbnail > video.wp-video-shortcode").mediaelementplayer({classPrefix:"mejs-",defaultVideoWidth:480,defaultVideoHeight:270}),setTimeout(function(){rtmedia_activity_stream_comment_media()},900),rtMediaHook.call("rtmedia_js_after_activity_added",[])}}}),jQuery(".rtmedia-container").on("click",".select-all",function(e){jQuery(this).toggleClass("unselect-all").toggleClass("select-all"),jQuery(this).attr("title",rtmedia_unselect_all_visible),jQuery(".rtmedia-list input").each(function(){jQuery(this).prop("checked",!0)}),jQuery(".rtmedia-list-item").addClass("bulk-selected")}),jQuery(".rtmedia-container").on("click",".unselect-all",function(e){jQuery(this).toggleClass("select-all").toggleClass("unselect-all"),jQuery(this).attr("title",rtmedia_select_all_visible),jQuery(".rtmedia-list input").each(function(){jQuery(this).prop("checked",!1)}),jQuery(".rtmedia-list-item").removeClass("bulk-selected")}),jQuery(".rtmedia-container").on("click",".rtmedia-move",function(e){jQuery(".rtmedia-delete-container").slideUp(),jQuery(".rtmedia-move-container").slideToggle()}),jQuery("#rtmedia-create-album-modal").on("click","#rtmedia_create_new_album",function(e){if($albumname=jQuery(" ").text(jQuery.trim(jQuery("#rtmedia_album_name").val())).html(),$album_description=jQuery("#rtmedia_album_description"),$context=jQuery.trim(jQuery("#rtmedia_album_context").val()),$context_id=jQuery.trim(jQuery("#rtmedia_album_context_id").val()),$privacy=jQuery.trim(jQuery("#rtmedia_select_album_privacy").val()),$create_album_nonce=jQuery.trim(jQuery("#rtmedia_create_album_nonce").val()),""!=$albumname){var t={action:"rtmedia_create_album",name:$albumname,description:$album_description.val(),context:$context,context_id:$context_id,create_album_nonce:$create_album_nonce};""!==$privacy&&(t.privacy=$privacy),n("#rtmedia_create_new_album").attr("disabled","disabled");var r=n("#rtmedia_create_new_album").html();n("#rtmedia_create_new_album").prepend(" "),jQuery.post(rtmedia_ajax_url,t,function(i){if(void 0!==i.album){i=jQuery.trim(i.album);var a=!0;$album_description.val(""),n("#rtmedia_album_name").focus(),jQuery(".rtmedia-user-album-list").each(function(){if(jQuery(this).children("optgroup").each(function(){if(jQuery(this).attr("value")===$context)return a=!1,void jQuery(this).append(''+$albumname+" ")}),a){var e=$context.charAt(0).toUpperCase()+$context.slice(1)+" "+rtmedia_main_js_strings.rtmedia_albums,t=''+$albumname+" ";jQuery(this).append(t)}}),jQuery('select.rtmedia-user-album-list option[value="'+i+'"]').prop("selected",!0),jQuery(".rtmedia-create-new-album-container").slideToggle(),jQuery("#rtmedia_album_name").val(""),jQuery("#rtmedia-create-album-modal").append(""+$albumname+" "+rtmedia_album_created_msg+"
"),setTimeout(function(){jQuery(".rtmedia-create-album-alert").remove()},4e3),setTimeout(function(){galleryObj.reloadView(),window.location.reload(),jQuery(".close-reveal-modal").click()},2e3)}else void 0!==i.error?rtmedia_gallery_action_alert_message(i.error,"warning"):rtmedia_gallery_action_alert_message(rtmedia_something_wrong_msg,"warning");n("#rtmedia_create_new_album").removeAttr("disabled"),n("#rtmedia_create_new_album").html(r)})}else rtmedia_gallery_action_alert_message(rtmedia_empty_album_name_msg,"warning")}),jQuery(".rtmedia-container").on("click",".rtmedia-delete-selected",function(e){0'+t+"
"),setTimeout(function(){jQuery(a).siblings(".rtm-ac-privacy-updated").remove()},2e3)})}),jQuery(".media_search_input").on("keyup",function(){rtm_search_media_text_validation()}),r(),rtMediaHook.register("rtmedia_js_popup_after_content_added",function(){r(),jQuery(".rtmedia-container").on("click",".rtmedia-delete-media",function(e){e.preventDefault(),confirm(rtmedia_media_delete_confirmation)&&jQuery(this).closest("form").submit()}),mfp=jQuery.magnificPopup.instance,1"+rtmedia_drop_media_msg+""),"undefined"!=typeof rtmedia_bp_enable_activity&&"1"==rtmedia_bp_enable_activity&&jQuery("#whats-new-textarea").append(""+rtmedia_drop_media_msg+"
"),jQuery(document).on("dragover",function(e){e.preventDefault(),e.target!=this&&(jQuery("#rtm-media-gallery-uploader").show(),"undefined"!=typeof rtmedia_bp_enable_activity&&"1"==rtmedia_bp_enable_activity&&i.addClass("rtm-drag-drop-active"),t.addClass("rtm-drag-drop-active"),jQuery("#rtm-drop-files-title").show())}).on("dragleave",function(e){if(e.preventDefault(),0!=e.originalEvent.pageX&&0!=e.originalEvent.pageY)return!1;"undefined"!=typeof rtmedia_bp_enable_activity&&"1"==rtmedia_bp_enable_activity&&(i.removeClass("rtm-drag-drop-active"),i.removeAttr("style")),t.removeClass("rtm-drag-drop-active"),jQuery("#rtm-drop-files-title").hide()}).on("drop",function(e){e.preventDefault(),jQuery(".bp-suggestions").focus(),"undefined"!=typeof rtmedia_bp_enable_activity&&"1"==rtmedia_bp_enable_activity&&(i.removeClass("rtm-drag-drop-active"),i.removeAttr("style")),t.removeClass("rtm-drag-drop-active"),jQuery("#rtm-drop-files-title").hide()}),jQuery(".rtmedia-container").on("click",".rtmedia-delete-album",function(e){e.preventDefault(),confirm(rtmedia_album_delete_confirmation)&&jQuery(this).closest("form").submit()}),jQuery(".rtmedia-container").on("click",".rtmedia-delete-media",function(e){e.preventDefault(),confirm(rtmedia_media_delete_confirmation)&&jQuery(this).closest("form").submit()}),rtmedia_init_action_dropdown(""),n(document).click(function(){n(".click-nav ul").is(":visible")&&n(".click-nav ul",this).hide()}),jQuery(".rtmedia-comment-link").on("click",function(e){e.preventDefault(),jQuery("#comment_content").focus()}),0m.showChars+m.minHideChars){var i=t.substr(0,m.showChars);if(0<=i.indexOf("<")){for(var a=!1,r="",n=0,o=[],s=null,l=0,c=0;c<=m.showChars;l++)if("<"!=t[l]||a||(a=!0,"/"==(s=t.substring(l+1,t.indexOf(">",l)))[0]?s!="/"+o[0]?m.errMsg="ERROR en HTML: the top of the stack should be the tag that closes":o.shift():"br"!=s.toLowerCase()&&o.unshift(s)),a&&">"==t[l]&&(a=!1),a)r+=t.charAt(l);else if(c++,n<=m.showChars)r+=t.charAt(l),n++;else if(0";break}i=u("
").html(r+''+m.ellipsesText+" ").html()}else i+=m.ellipsesText;var d=''+i+'
'+t+'
'+m.moreText+" ";e.html(d),e.find(".allcontent").hide(),u(".shortcontent p:last",e).css("margin-bottom",0)}}))}}(jQuery),window.onload=function(){"undefined"!=typeof rtmedia_masonry_layout&&"true"==rtmedia_masonry_layout&&0==jQuery(".rtmedia-container .rtmedia-list.rtm-no-masonry").length&&rtm_masonry_reload(rtm_masonry_container),rtm_search_media_text_validation(),check_condition("search")&&jQuery("#media_search_remove").show()},jQuery(document).ready(function(){rtm_upload_terms_activity(),jQuery("body").hasClass("has-sidebar")&&0===jQuery("#secondary").length&&(jQuery(".rtmedia-single-container").length||jQuery(".rtmedia-container").length)&&jQuery("body").removeClass("has-sidebar"),rtmedia_main&&("undefined"!==rtmedia_main.rtmedia_direct_download_link&&parseInt(rtmedia_main.rtmedia_direct_download_link)||jQuery(document).on("bp_ajax_request",function(e){setTimeout(function(){jQuery("video").each(function(){jQuery(this).attr("controlsList","nodownload"),jQuery(this).attr("playsinline","playsinline"),jQuery(this).load()})},200)}))});
\ No newline at end of file
+var rtMagnificPopup,rtm_masonry_container,comment_media=!1;function apply_rtMagnificPopup(e){jQuery("document").ready((function(t){var i="";if(i="undefined"==typeof rtmedia_load_more?"Loading media":rtmedia_load_more,"undefined"!=typeof rtmedia_lightbox_enabled&&"1"==rtmedia_lightbox_enabled){var a,r,n=!1;t(".activity-item .rtmedia-activity-container .rtmedia-list-item > a").siblings("p").children("a").length>0&&t(".activity-item .rtmedia-activity-container .rtmedia-list-item > a").siblings("p").children("a").addClass("no-popup"),rtMagnificPopup=jQuery(e).magnificPopup({delegate:"a:not(.no-popup, .mejs-time-slider, .mejs-volume-slider, .mejs-horizontal-volume-slider)",type:"ajax",fixedContentPos:!0,fixedBgPos:!0,tLoading:i+" #%curr%...",mainClass:"mfp-img-mobile",preload:[1,3],closeOnBgClick:!0,gallery:{enabled:!0,navigateByImgClick:!0,arrowMarkup:"",preload:[0,1]},image:{tError:'The image #%curr% could not be loaded.',titleSrc:function(e){return e.el.attr("title")+"by Marsel Van Oosten "}},callbacks:{ajaxContentAdded:function(){e=jQuery.magnificPopup.instance,1===jQuery(e.items).size()&&jQuery(".mfp-arrow").remove();var e=jQuery.magnificPopup.instance,i=e.currItem.el,o=i.parent();if(o.is("li")||(o=o.parent()),(o.is(":nth-last-child(2)")||o.is(":last-child"))&&o.find("a").hasClass("rtmedia-list-item-a")){o.next();"block"==jQuery("#rtMedia-galary-next").css("display")&&(n||(a=e.ev.children(),n=!0,r=nextpage),jQuery("#rtMedia-galary-next").click())}var m=e.items.length;if(e.index!=m-1||o.is(":last-child")){"undefined"!=typeof _wpmejsSettings&&_wpmejsSettings.pluginPath;var d=jQuery(".rtmedia-container .rtmedia-single-meta").height(),l=!1;void 0!==e&&void 0!==e.probablyMobile&&1==e.probablyMobile&&(l=!0),t(".mfp-content .rtmedia-single-media .wp-audio-shortcode,.mfp-content .rtmedia-single-media .wp-video-shortcode,.mfp-content .rtmedia-single-media .bp_media_content video").attr("autoplay",!0),l&&t(".mfp-content .rtmedia-single-media .wp-video-shortcode,.mfp-content .rtmedia-single-media .bp_media_content video").attr("muted",!1),t(".mfp-content .rtmedia-single-media .wp-audio-shortcode,.mfp-content .rtmedia-single-media .wp-video-shortcode,.mfp-content .rtmedia-single-media .bp_media_content video").mediaelementplayer({classPrefix:"mejs-",defaultVideoWidth:480,hideVolumeOnTouchDevices:!1,features:["playpause","progress","current","volume","fullscreen"],defaultVideoHeight:270,alwaysShowControls:l,enableAutosize:!0,clickToPlayPause:!0,videoHeight:-1,success:function(e,i){e.addEventListener("loadeddata",(function(i){var a=t(e).height(),r=t(window).height(),n=jQuery("div.rtm-ltb-action-container").height(),o=d-(n=n+50);a>r&&jQuery(".rtmedia-container #rtmedia-single-media-container .mejs-container").attr("style","height:"+o+"px !important; transition:0.2s")}),!1),l&&t(e).hasClass("wp-video-shortcode")?jQuery("body").on("touchstart",".mejs-overlay-button",(function(t){e.paused?e.play():e.pause()})):e.pause()}}),t(".mfp-content .mejs-audio .mejs-controls").css("position","relative"),rtMediaHook.call("rtmedia_js_popup_after_content_added",[]),"undefined"!=typeof bp&&void 0!==bp.mentions&&void 0!==bp.mentions.users&&(t("#atwho-container #atwho-ground-comment_content").remove(),t("#comment_content").bp_mentions(bp.mentions.users)),rtmedia_reset_video_and_audio_for_popup(),apply_rtMagnificPopup(".rtmedia-list-media.rtm-gallery-list, .rtmedia-activity-container ul.rtmedia-list, #bp-media-list,.bp-media-sc-list, li.media.album_updated ul,ul.bp-media-list-media, li.activity-item div.activity-content div.activity-inner div.bp_media_content, .rtm-bbp-container, ul.rtm-comment-container")}else i.click()},open:function(){var e=jQuery(".mfp-bg"),t=jQuery(".mfp-wrap");e.height(e.height()+t.height())},close:function(e){n&&(mfp.ev.empty(),mfp.ev.append(a),nextpage=r,n=!1,nextpage>1&&jQuery("#rtMedia-galary-next").show()),rtmedia_single_page_popup_close()},BeforeChange:function(e){}}})}jQuery(document).ajaxComplete((function(){jQuery("[id^=imgedit-leaving]").filter((function(){var e=jQuery(this).text();jQuery(this).text(e.replace("OK","Save"))}))}))}))}jQuery(document).ready((function(){if("object"==typeof rtmedia_bp)for(var e in rtmedia_bp)window[e]=rtmedia_bp[e];if("object"==typeof rtmedia_main)for(var e in rtmedia_main)window[e]=rtmedia_main[e];if("object"==typeof rtmedia_upload_terms)for(var e in rtmedia_upload_terms)window[e]=rtmedia_upload_terms[e];if("object"==typeof rtmedia_magnific)for(var e in rtmedia_magnific)window[e]=rtmedia_magnific[e]}));var rtMediaHook={hooks:[],is_break:!1,register:function(e,t){void 0===rtMediaHook.hooks[e]&&(rtMediaHook.hooks[e]=[]),rtMediaHook.hooks[e].push(t)},call:function(e,arguments){if(void 0!==rtMediaHook.hooks[e])for(i=0;i span,"+e+" .click-nav > div").toggleClass("no-js js"),jQuery(e+" .click-nav .js ul").hide(),jQuery(e+" .click-nav .clicker").click((function(e){t=jQuery("#rtm-media-options .click-nav .clicker").next("ul"),i=jQuery(this).next("ul"),jQuery.each(t,(function(e,t){jQuery(t).html()!=i.html()&&jQuery(t).hide()})),jQuery(i).toggle(),e.stopPropagation()}))}function bp_media_create_element(e){return!1}function rtmedia_version_compare(e,t){if(typeof e+typeof t!="stringstring")return!1;for(var i=e.split("."),a=t.split("."),r=0,n=Math.max(i.length,a.length);r0||parseInt(i[r])>parseInt(a[r]))return!0;if(a[r]&&!i[r]&&parseInt(a[r])>0||parseInt(i[r])0}function rtm_masonry_reload(e){setTimeout((function(){e.masonry("reload")}),250)}function rtm_search_media_text_validation(){""===jQuery("#media_search_input").val()?jQuery("#media_search").css("cursor","not-allowed"):jQuery("#media_search").css("cursor","pointer")}function rtmediaGetParameterByName(e){e=e.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var t=new RegExp("[\\?&]"+e+"=([^]*)").exec(location.search);return null==t?"":decodeURIComponent(t[1].replace(/\+/g," "))}function rtmedia_single_media_alert_message(e,t,i){var a="rtmedia-success";"warning"==t&&(a="rtmedia-warning");var r=!1;jQuery(".rtmedia-message-container").each((function(e,t){return t=jQuery(t),i&&t.hasClass("rtmedia-empty-comment-error-class")?(t.remove(),r=!0,!1):void 0!==i||t.hasClass("rtmedia-empty-comment-error-class")?void 0:(t.remove(),r=!0,!1)}));var n,o=jQuery("",{title:"Click to dismiss",class:"rtmedia-message-container"+(i?" rtmedia-empty-comment-error-class":""),style:"margin:1em 0;"}),m=jQuery("
",{class:a});m.html(e),m.appendTo(o),i?(n=jQuery("#rt_media_comment_form"),jQuery("#comment_content").focus()):void 0===i&&(n=jQuery(".rtmedia-single-media .rtmedia-media")).css("opacity","0.2"),n.after(o),r&&(m.css({border:"2px solid #884646"}),setTimeout((function(){m.css({border:"none"})}),500)),setTimeout((function(){o.remove(),void 0===i&&n.css("opacity","1")}),3e3),o.click((function(){o.remove(),void 0===i&&n.css("opacity","1")}))}function rtmedia_gallery_action_alert_message(e,t){var i="rtmedia-success";"warning"==t&&(i="rtmedia-warning");jQuery("body").append('
'),jQuery(".rtmedia-gallery-alert-container").append(""+e+"
"),setTimeout((function(){jQuery(".rtmedia-gallery-alert-container").remove()}),3e3),jQuery(".rtmedia-gallery-message-box").click((function(){jQuery(".rtmedia-gallery-alert-container").remove()}))}function rtmedia_activity_masonry(){jQuery("#activity-stream .rtmedia-activity-container .rtmedia-list").masonry({itemSelector:".rtmedia-list-item",gutter:7});var e=0,t=setInterval((function(){5===(e+=1)&&clearInterval(t),jQuery.each(jQuery(".rtmedia-activity-container .rtmedia-list.masonry .rtmedia-item-title"),(function(e,t){jQuery(t).width(jQuery(t).siblings(".rtmedia-item-thumbnail").children("img").width())})),rtm_masonry_reload(jQuery("#activity-stream .rtmedia-activity-container .rtmedia-list"))}),1e3)}function get_parameter(e,t){if(!e)return!1;t||(t=window.location.href);e=e.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var i=new RegExp(e+"=([^]*)").exec(t);return null!==i&&i[1]}function rtm_upload_terms_activity(){if(jQuery("#rtmedia_upload_terms_conditions").length>0){jQuery("#bp-nouveau-activity-form").on("click","#aw-whats-new-submit",(function(e){var t=jQuery("#whats-new-form"),i=t.find("#rtmedia_upload_terms_conditions");if(0!==i.length&&!1===i.prop("checked")&&0===t.find("#message").length){e.preventDefault();var a=t.find(".rtmedia-upload-terms");rtp_display_terms_warning(a,rtmedia_upload_terms_check_terms_message)}}));var e=jQuery("#whats-new-form");e.length>0&&jQuery("#whats-new-form, #rtmedia_upload_terms_conditions").on("click",(function(t){e.find("input:hidden").each((function(){jQuery(this).prop("disabled",!1)}))}))}}jQuery("document").ready((function(e){function t(){if(jQuery("#rtmedia-media-view-form").length>0){var e=jQuery("#rtmedia-media-view-form").attr("action");jQuery.post(e,{},(function(e){}))}}function i(e,t,i){var a=new Date;a.setTime(a.getTime()+24*i*60*60*1e3);var r="expires="+a.toUTCString();document.cookie=e+"="+t+";"+r+";path=/"}jQuery(document).ajaxComplete((function(e,t,i){if("legacy"!==bp_template_pack&&bp_template_pack){var a=get_parameter("action",i.data);"activity_filter"!==a&&"post_update"!==a&&"get_single_activity_content"!==a&&"activity_get_older_updates"!==a||"undefined"==typeof rtmedia_masonry_layout||"true"!==rtmedia_masonry_layout||"undefined"==typeof rtmedia_masonry_layout_activity||"true"!==rtmedia_masonry_layout_activity?"activity_filter"!==a&&"post_update"!==a&&"get_single_activity_content"!==a&&"activity_get_older_updates"!==a||setTimeout((function(){apply_rtMagnificPopup(".rtmedia-list-media.rtm-gallery-list, .rtmedia-activity-container ul.rtmedia-list, #bp-media-list,.bp-media-sc-list, li.media.album_updated ul,ul.bp-media-list-media, li.activity-item div.activity-content div.activity-inner div.bp_media_content, .rtm-bbp-container, ul.rtm-comment-container"),rtmedia_activity_stream_comment_media()}),1e3):setTimeout((function(){apply_rtMagnificPopup(".rtmedia-list-media.rtm-gallery-list, .rtmedia-activity-container ul.rtmedia-list, #bp-media-list,.bp-media-sc-list, li.media.album_updated ul,ul.bp-media-list-media, li.activity-item div.activity-content div.activity-inner div.bp_media_content, .rtm-bbp-container, ul.rtm-comment-container"),rtmedia_activity_masonry(),rtmedia_activity_stream_comment_media()}),1e3)}})),jQuery(".rtmedia-uploader-div").css({opacity:"1",display:"block",visibility:"visible"}),jQuery(" #whats-new-options ").css({opacity:"1"}),void 0!==e.fn.rtTab&&e(".rtm-tabs").rtTab(),jQuery(".rtmedia-modal-link").length>0&&e(".rtmedia-modal-link").magnificPopup({type:"inline",midClick:!0,closeBtnInside:!0}),e("#rt_media_comment_form").submit((function(t){return""!=e.trim(e("#comment_content").val())||(0==jQuery("#rtmedia-single-media-container").length?rtmedia_gallery_action_alert_message(rtmedia_empty_comment_msg,"warning"):rtmedia_single_media_alert_message(rtmedia_empty_comment_msg,"warning"),!1)})),e("li.rtmedia-list-item p a").each((function(t){e(this).addClass("no-popup")})),e("li.rtmedia-list-item p a").each((function(t){e(this).addClass("no-popup")})),"undefined"!=typeof rtmedia_lightbox_enabled&&"1"==rtmedia_lightbox_enabled&&apply_rtMagnificPopup(".rtmedia-list-media.rtm-gallery-list, .rtmedia-activity-container ul.rtmedia-list, #bp-media-list,.bp-media-sc-list, li.media.album_updated ul,ul.bp-media-list-media, li.activity-item div.activity-content div.activity-inner div.bp_media_content, .rtm-bbp-container, ul.rtm-comment-container"),jQuery.ajaxPrefilter((function(e,t,i){try{if(null==t.data||void 0===t.data||void 0===t.data.action)return!0}catch(e){return!0}if("activity_get_older_updates"==t.data.action){var a=t.success;e.success=function(e){"function"==typeof a&&a(e),apply_rtMagnificPopup(".rtmedia-activity-container ul.rtmedia-list, #bp-media-list, .bp-media-sc-list, li.media.album_updated ul,ul.bp-media-list-media, li.activity-item div.activity-content div.activity-inner div.bp_media_content"),rtMediaHook.call("rtmedia_js_after_activity_added",[])}}else if("get_single_activity_content"==t.data.action){a=t.success;e.success=function(e){"function"==typeof a&&a(e),setTimeout((function(){apply_rtMagnificPopup(".rtmedia-activity-container ul.rtmedia-list, #bp-media-list, .bp-media-sc-list, li.media.album_updated ul,ul.bp-media-list-media, li.activity-item div.activity-content div.activity-inner div.bp_media_content"),jQuery("ul.activity-list li.rtmedia_update:first-child .wp-audio-shortcode, ul.activity-list li.rtmedia_update:first-child .wp-video-shortcode").mediaelementplayer({classPrefix:"mejs-",defaultVideoWidth:480,defaultVideoHeight:270})}),900)}}})),jQuery.ajaxPrefilter((function(e,t,i){try{if(null==t.data||void 0===t.data||void 0===t.data.action)return!0}catch(e){return!0}if("activity_get_older_updates"==t.data.action){var a=t.success;e.success=function(e){"function"==typeof a&&a(e),apply_rtMagnificPopup(".rtmedia-activity-container ul.rtmedia-list, #bp-media-list, .bp-media-sc-list, li.media.album_updated ul,ul.bp-media-list-media, li.activity-item div.activity-content div.activity-inner div.bp_media_content"),jQuery("ul.activity-list li.rtmedia_update div.rtmedia-item-thumbnail > audio.wp-audio-shortcode, ul.activity-list li.rtmedia_update div.rtmedia-item-thumbnail > video.wp-video-shortcode").mediaelementplayer({classPrefix:"mejs-",defaultVideoWidth:480,defaultVideoHeight:270}),setTimeout((function(){rtmedia_activity_stream_comment_media()}),900),rtMediaHook.call("rtmedia_js_after_activity_added",[])}}})),jQuery(".rtmedia-container").on("click",".select-all",(function(e){jQuery(this).toggleClass("unselect-all").toggleClass("select-all"),jQuery(this).attr("title",rtmedia_unselect_all_visible),jQuery(".rtmedia-list input").each((function(){jQuery(this).prop("checked",!0)})),jQuery(".rtmedia-list-item").addClass("bulk-selected")})),jQuery(".rtmedia-container").on("click",".unselect-all",(function(e){jQuery(this).toggleClass("select-all").toggleClass("unselect-all"),jQuery(this).attr("title",rtmedia_select_all_visible),jQuery(".rtmedia-list input").each((function(){jQuery(this).prop("checked",!1)})),jQuery(".rtmedia-list-item").removeClass("bulk-selected")})),jQuery(".rtmedia-container").on("click",".rtmedia-move",(function(e){jQuery(".rtmedia-delete-container").slideUp(),jQuery(".rtmedia-move-container").slideToggle()})),jQuery("#rtmedia-create-album-modal").on("click","#rtmedia_create_new_album",(function(t){if($albumname=jQuery(" ").text(jQuery.trim(jQuery("#rtmedia_album_name").val())).html(),$album_description=jQuery("#rtmedia_album_description"),$context=jQuery.trim(jQuery("#rtmedia_album_context").val()),$context_id=jQuery.trim(jQuery("#rtmedia_album_context_id").val()),$privacy=jQuery.trim(jQuery("#rtmedia_select_album_privacy").val()),$create_album_nonce=jQuery.trim(jQuery("#rtmedia_create_album_nonce").val()),""!=$albumname){var i={action:"rtmedia_create_album",name:$albumname,description:$album_description.val(),context:$context,context_id:$context_id,create_album_nonce:$create_album_nonce};""!==$privacy&&(i.privacy=$privacy),e("#rtmedia_create_new_album").attr("disabled","disabled");var a=e("#rtmedia_create_new_album").html();e("#rtmedia_create_new_album").prepend(" "),jQuery.post(rtmedia_ajax_url,i,(function(t){if(void 0!==t.album){t=jQuery.trim(t.album);var i=!0;$album_description.val(""),e("#rtmedia_album_name").focus(),jQuery(".rtmedia-user-album-list").each((function(){if(jQuery(this).children("optgroup").each((function(){if(jQuery(this).attr("value")===$context)return i=!1,void jQuery(this).append(''+$albumname+" ")})),i){var e=$context.charAt(0).toUpperCase()+$context.slice(1)+" "+rtmedia_main_js_strings.rtmedia_albums,a=''+$albumname+" ";jQuery(this).append(a)}})),jQuery('select.rtmedia-user-album-list option[value="'+t+'"]').prop("selected",!0),jQuery(".rtmedia-create-new-album-container").slideToggle(),jQuery("#rtmedia_album_name").val(""),jQuery("#rtmedia-create-album-modal").append(""+$albumname+" "+rtmedia_album_created_msg+"
"),setTimeout((function(){jQuery(".rtmedia-create-album-alert").remove()}),4e3),setTimeout((function(){galleryObj.reloadView(),window.location.reload(),jQuery(".close-reveal-modal").click()}),2e3)}else void 0!==t.error?rtmedia_gallery_action_alert_message(t.error,"warning"):rtmedia_gallery_action_alert_message(rtmedia_something_wrong_msg,"warning");e("#rtmedia_create_new_album").removeAttr("disabled"),e("#rtmedia_create_new_album").html(a)}))}else rtmedia_gallery_action_alert_message(rtmedia_empty_album_name_msg,"warning")})),jQuery(".rtmedia-container").on("click",".rtmedia-delete-selected",(function(e){jQuery(".rtmedia-list :checkbox:checked").length>0?confirm(rtmedia_selected_media_delete_confirmation)&&jQuery(this).closest("form").attr("action","../../../"+rtmedia_media_slug+"/delete").submit():rtmedia_gallery_action_alert_message(rtmedia_no_media_selected,"warning")})),jQuery(".rtmedia-container").on("click",".rtmedia-move-selected",(function(e){jQuery(".rtmedia-list :checkbox:checked").length>0?confirm(rtmedia_selected_media_move_confirmation)&&jQuery(this).closest("form").attr("action","").submit():rtmedia_gallery_action_alert_message(rtmedia_no_media_selected,"warning")})),jQuery("#buddypress").on("change",".rtm-activity-privacy-opt",(function(){var e=jQuery(this).attr("id");e=(e=e.split("-"))[e.length-1];var t=this;data={activity_id:e,privacy:jQuery(this).val(),nonce:jQuery("#rtmedia_activity_privacy_nonce").val(),action:"rtm_change_activity_privacy"},jQuery.post(ajaxurl,data,(function(e){var i="",a="";"true"==e?(i=rtmedia_main_js_strings.privacy_update_success,a="rtmedia-success"):(i=rtmedia_main_js_strings.privacy_update_error,a="fail"),jQuery(t).after(''+i+"
"),setTimeout((function(){jQuery(t).siblings(".rtm-ac-privacy-updated").remove()}),2e3)}))})),jQuery(".media_search_input").on("keyup",(function(){rtm_search_media_text_validation()})),t(),rtMediaHook.register("rtmedia_js_popup_after_content_added",(function(){t(),jQuery(".rtmedia-container").on("click",".rtmedia-delete-media",(function(e){e.preventDefault(),confirm(rtmedia_media_delete_confirmation)&&jQuery(this).closest("form").submit()})),mfp=jQuery.magnificPopup.instance,jQuery(mfp.items).size()>1&&0==comment_media?function(){var e=jQuery.magnificPopup.instance,t=e.probablyMobile,a=function(e){for(var t=e+"=",i=document.cookie.split(";"),a=0;a"+rtmedia_drop_media_msg+" "),"undefined"!=typeof rtmedia_bp_enable_activity&&"1"==rtmedia_bp_enable_activity&&jQuery("#whats-new-textarea").append(""+rtmedia_drop_media_msg+"
"),jQuery(document).on("dragover",(function(e){e.preventDefault(),e.target!=this&&(jQuery("#rtm-media-gallery-uploader").show(),"undefined"!=typeof rtmedia_bp_enable_activity&&"1"==rtmedia_bp_enable_activity&&r.addClass("rtm-drag-drop-active"),a.addClass("rtm-drag-drop-active"),jQuery("#rtm-drop-files-title").show())})).on("dragleave",(function(e){if(e.preventDefault(),0!=e.originalEvent.pageX&&0!=e.originalEvent.pageY)return!1;"undefined"!=typeof rtmedia_bp_enable_activity&&"1"==rtmedia_bp_enable_activity&&(r.removeClass("rtm-drag-drop-active"),r.removeAttr("style")),a.removeClass("rtm-drag-drop-active"),jQuery("#rtm-drop-files-title").hide()})).on("drop",(function(e){e.preventDefault(),jQuery(".bp-suggestions").focus(),"undefined"!=typeof rtmedia_bp_enable_activity&&"1"==rtmedia_bp_enable_activity&&(r.removeClass("rtm-drag-drop-active"),r.removeAttr("style")),a.removeClass("rtm-drag-drop-active"),jQuery("#rtm-drop-files-title").hide()})),jQuery(".rtmedia-container").on("click",".rtmedia-delete-album",(function(e){e.preventDefault(),confirm(rtmedia_album_delete_confirmation)&&jQuery(this).closest("form").submit()})),jQuery(".rtmedia-container").on("click",".rtmedia-delete-media",(function(e){e.preventDefault(),confirm(rtmedia_media_delete_confirmation)&&jQuery(this).closest("form").submit()})),rtmedia_init_action_dropdown(""),e(document).click((function(){e(".click-nav ul").is(":visible")&&e(".click-nav ul",this).hide()})),jQuery(".rtmedia-comment-link").on("click",(function(e){e.preventDefault(),jQuery("#comment_content").focus()})),jQuery(".rtm-more").length>0&&e(".rtm-more").shorten({showChars:200}),"undefined"!=typeof rtmedia_masonry_layout&&"true"==rtmedia_masonry_layout&&"undefined"!=typeof rtmedia_masonry_layout_activity&&"true"==rtmedia_masonry_layout_activity&&rtmedia_activity_masonry(),jQuery(document).ajaxComplete((function(e,t,i){var a=get_parameter("action",i.data);"post_update"!==a&&"get_single_activity_content"!==a&&"activity_get_older_updates"!==a||"undefined"==typeof rtmedia_masonry_layout||"true"!=rtmedia_masonry_layout||"undefined"==typeof rtmedia_masonry_layout_activity||"true"!=rtmedia_masonry_layout_activity||rtmedia_activity_masonry()})),"undefined"!=typeof rtmedia_masonry_layout&&"true"==rtmedia_masonry_layout&&0==jQuery(".rtmedia-container .rtmedia-list.rtm-no-masonry").length&&((rtm_masonry_container=jQuery(".rtmedia-container .rtmedia-list")).masonry({itemSelector:".rtmedia-list-item"}),setInterval((function(){jQuery.each(jQuery(".rtmedia-list.masonry .rtmedia-item-title"),(function(e,t){jQuery(t).width(jQuery(t).siblings(".rtmedia-item-thumbnail").children("img").width())})),rtm_masonry_reload(rtm_masonry_container)}),1e3),jQuery.each(jQuery(".rtmedia-list.masonry .rtmedia-item-title"),(function(e,t){jQuery(t).width(jQuery(t).siblings(".rtmedia-item-thumbnail").children("img").width())}))),jQuery(".rtm-uploader-tabs").length>0&&jQuery(".rtm-uploader-tabs li").click((function(e){jQuery(this).hasClass("active")||(jQuery(this).siblings().removeClass("active"),jQuery(this).parents(".rtm-uploader-tabs").siblings().hide(),class_name=jQuery(this).attr("class"),jQuery(this).parents(".rtm-uploader-tabs").siblings('[data-id="'+class_name+'"]').show(),jQuery(this).addClass("active"),"rtm-upload-tab"!=class_name?jQuery("div.moxie-shim").hide():jQuery("div.moxie-shim").show())})),jQuery(".rtmedia-container").on("click",".rtm-delete-media",(function(e){e.preventDefault();var t=RTMedia_Main_JS.media_delete_confirmation;if(confirm(t)){var i=jQuery(this).closest("li"),a=jQuery("#rtmedia_media_delete_nonce").val(),r=jQuery(this).parents(".rtmedia-list-item").data("media_type"),n={action:"delete_uploaded_media",nonce:a,media_id:i.attr("id"),media_type:r};jQuery.ajax({url:RTMedia_Main_JS.rtmedia_ajaxurl,type:"POST",data:n,dataType:"JSON",success:function(e){window.location.reload(),"rtmedia-media-deleted"===e.data.code?(rtmedia_gallery_action_alert_message(RTMedia_Main_JS.media_delete_success,"success"),i.remove(),"undefined"!=typeof rtmedia_masonry_layout&&"true"===rtmedia_masonry_layout&&rtm_masonry_reload(rtm_masonry_container),jQuery("#user-media span, #media-groups-li #media span, #rtmedia-nav-item-all span").text(e.data.all_media_count),jQuery("#rtmedia-nav-item-photo span").text(e.data.photos_count),jQuery("#rtmedia-nav-item-music span").text(e.data.music_count),jQuery("#rtmedia-nav-item-video span").text(e.data.videos_count)):rtmedia_gallery_action_alert_message(e.data.message,"warning")}})}}))})),function(e){e.fn.shorten=function(t){"use strict";var i={showChars:100,minHideChars:10,ellipsesText:"...",moreText:rtmedia_read_more,lessText:rtmedia__show_less,onLess:function(){},onMore:function(){},errMsg:null,force:!1};return t&&e.extend(i,t),!(e(this).data("jquery.shorten")&&!i.force)&&(e(this).data("jquery.shorten",!0),e(document).off("click",".morelink"),e(document).on({click:function(){var t=e(this);return t.hasClass("less")?(t.removeClass("less"),t.html(i.moreText),t.parent().prev().hide(0,(function(){t.parent().prev().prev().show()})).hide(0,(function(){i.onLess()}))):(t.addClass("less"),t.html(i.lessText),t.parent().prev().show(0,(function(){t.parent().prev().prev().hide()})).show(0,(function(){i.onMore()}))),!1}},".morelink"),this.each((function(){var t=e(this),a=t.html();if(t.text().length>i.showChars+i.minHideChars){var r=a.substr(0,i.showChars);if(r.indexOf("<")>=0){for(var n=!1,o="",m=0,d=[],l=null,s=0,c=0;c<=i.showChars;s++)if("<"!=a[s]||n||(n=!0,"/"==(l=a.substring(s+1,a.indexOf(">",s)))[0]?l!="/"+d[0]?i.errMsg="ERROR en HTML: the top of the stack should be the tag that closes":d.shift():"br"!=l.toLowerCase()&&d.unshift(l)),n&&">"==a[s]&&(n=!1),n)o+=a.charAt(s);else if(c++,m<=i.showChars)o+=a.charAt(s),m++;else if(d.length>0){for(j=0;j";break}r=e("
").html(o+''+i.ellipsesText+" ").html()}else r+=i.ellipsesText;var u=''+r+'
'+a+'
'+i.moreText+" ";t.html(u),t.find(".allcontent").hide(),e(".shortcontent p:last",t).css("margin-bottom",0)}})))}}(jQuery),window.onload=function(){"undefined"!=typeof rtmedia_masonry_layout&&"true"==rtmedia_masonry_layout&&0==jQuery(".rtmedia-container .rtmedia-list.rtm-no-masonry").length&&rtm_masonry_reload(rtm_masonry_container),rtm_search_media_text_validation(),check_condition("search")&&jQuery("#media_search_remove").show()},jQuery(document).ready((function(){rtm_upload_terms_activity(),jQuery("body").hasClass("has-sidebar")&&0===jQuery("#secondary").length&&(jQuery(".rtmedia-single-container").length||jQuery(".rtmedia-container").length)&&jQuery("body").removeClass("has-sidebar"),rtmedia_main&&("undefined"!==rtmedia_main.rtmedia_direct_download_link&&parseInt(rtmedia_main.rtmedia_direct_download_link)||jQuery(document).on("bp_ajax_request",(function(e){setTimeout((function(){jQuery("video").each((function(){jQuery(this).attr("controlsList","nodownload"),jQuery(this).attr("playsinline","playsinline"),jQuery(this).load()}))}),200)})))}));
\ No newline at end of file
From 3b2a7cdb5c71033fde69e8eb76330cb1e27ecb06 Mon Sep 17 00:00:00 2001
From: krishana7911
Date: Thu, 29 May 2025 10:51:13 +0530
Subject: [PATCH 13/22] enqueue magnific popup conditionally to work with all
the activation and deactivation conditions
---
.../template/rtmedia-functions.php | 49 ++++++++++++++++++-
1 file changed, 47 insertions(+), 2 deletions(-)
diff --git a/app/main/controllers/template/rtmedia-functions.php b/app/main/controllers/template/rtmedia-functions.php
index 263d65e01..6a2d3a5fa 100644
--- a/app/main/controllers/template/rtmedia-functions.php
+++ b/app/main/controllers/template/rtmedia-functions.php
@@ -5247,7 +5247,7 @@ function enqueue_scripts_globally() {
// Enqueue the script responsible for AJAX-based comment refresh.
wp_enqueue_script(
'godam-ajax-refresh',
- RTMEDIA_URL . 'app/assets/js/godam-ajax-refresh.js',
+ RTMEDIA_URL . 'app/assets/js/godam-ajax-refresh.min.js',
[],
null,
true
@@ -5262,7 +5262,7 @@ function enqueue_scripts_globally() {
// Enqueue integration script for rtMedia and Godam.
wp_enqueue_script(
'godam-rtmedia-integration',
- RTMEDIA_URL . 'app/assets/js/godam-integration.js',
+ RTMEDIA_URL . 'app/assets/js/godam-integration.min.js',
[ 'godam-player-frontend-script' ],
null,
true
@@ -5409,3 +5409,48 @@ function handle_get_single_activity_comment_html() {
}
}
+
+/**
+ * Enqueue the Magnific Popup script for rtMedia.
+ *
+ * This function ensures that the Magnific Popup script is loaded correctly on the frontend
+ * so that popup functionality works seamlessly with all combinations of plugin states:
+ * - When only rtMedia is active
+ * - When both rtMedia and Godam plugins are active
+ * - When Godam plugin is deactivated
+ *
+ * To achieve this, the script is deregistered first if already registered or enqueued,
+ * preventing conflicts or duplicates.
+ *
+ * When Godam plugin is active, the script is loaded without dependencies to avoid
+ * redundant or conflicting scripts. When Godam is not active, dependencies such as
+ * jQuery and rt-mediaelement-wp are included to ensure proper functionality.
+ *
+ * Enqueuing here guarantees consistent script loading regardless of Godam’s activation status.
+ *
+ * Hooked into 'wp_enqueue_scripts' to load on frontend pages.
+ */
+function enqueue_rtmedia_magnific_popup_script() {
+ $handle = 'rtmedia-magnific-popup';
+ $script_src = RTMEDIA_URL . 'app/assets/js/vendors/magnific-popup.js';
+ $version = RTMEDIA_VERSION;
+ $in_footer = true;
+
+ // Deregister the script if already registered or enqueued to prevent conflicts
+ if (wp_script_is($handle, 'registered') || wp_script_is($handle, 'enqueued')) {
+ wp_deregister_script($handle);
+ }
+
+ // Determine dependencies based on whether Godam integration is active
+ $dependencies = [];
+
+ // If Godam plugin is NOT active, add dependencies for jQuery and mediaelement
+ if (!defined('RTMEDIA_GODAM_ACTIVE') || !RTMEDIA_GODAM_ACTIVE) {
+ $dependencies = ['jquery', 'rt-mediaelement-wp'];
+ }
+
+ // Enqueue the Magnific Popup script with the appropriate dependencies
+ wp_enqueue_script($handle, $script_src, $dependencies, $version, $in_footer);
+}
+
+add_action('wp_enqueue_scripts', 'enqueue_rtmedia_magnific_popup_script');
From d93d91d4d8004aa5b05137be864347fc0cccda4a Mon Sep 17 00:00:00 2001
From: krishana7911
Date: Thu, 29 May 2025 11:08:33 +0530
Subject: [PATCH 14/22] add condition for groups in mutation
---
app/assets/js/godam-integration.js | 2 +-
app/assets/js/godam-integration.min.js | 2 +-
app/main/controllers/template/rtmedia-functions.php | 2 --
3 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/app/assets/js/godam-integration.js b/app/assets/js/godam-integration.js
index f9d9e4bf5..a03a16a38 100644
--- a/app/assets/js/godam-integration.js
+++ b/app/assets/js/godam-integration.js
@@ -15,7 +15,7 @@ if (activityStream) {
const observer = new MutationObserver((mutations) => {
for (const mutation of mutations) {
mutation.addedNodes.forEach((node) => {
- if (node.nodeType === 1 && node.matches('.activity')) {
+ if (node.nodeType === 1 && (node.matches('.activity') || node.matches('.groups'))) {
requestAnimationFrame(() => GODAMPlayer(node));
}
});
diff --git a/app/assets/js/godam-integration.min.js b/app/assets/js/godam-integration.min.js
index cae38cf2e..5094e1344 100644
--- a/app/assets/js/godam-integration.min.js
+++ b/app/assets/js/godam-integration.min.js
@@ -1 +1 @@
-GODAMPlayer();const activityStream=document.querySelector("#buddypress #activity-stream");if(activityStream){new MutationObserver((e=>{for(const t of e)t.addedNodes.forEach((e=>{1===e.nodeType&&e.matches(".activity")&&requestAnimationFrame((()=>GODAMPlayer(e)))}))})).observe(activityStream,{childList:!0,subtree:!0})}document.addEventListener("DOMContentLoaded",(()=>{GODAMPlayer();const e=new WeakSet,t=t=>{if(!t)return void GODAMPlayer();if(e.has(t))return;t.querySelectorAll("[data-godam-initialized], .godam-player-initialized").length>0||(GODAMPlayer(t),e.add(t),t.setAttribute&&t.setAttribute("data-godam-processed","true"))},o=document.querySelector("#buddypress #activity-stream");if(o){new MutationObserver((e=>{for(const o of e)o.addedNodes.forEach((e=>{1===e.nodeType&&e.matches(".activity")&&!e.hasAttribute("data-godam-processed")&&requestAnimationFrame((()=>t(e)))}))})).observe(o,{childList:!0,subtree:!0})}let a=null;if(new MutationObserver((e=>{for(const o of e)o.addedNodes.forEach((e=>{if(1===e.nodeType){let o=null;o=e.classList&&e.classList.contains("mfp-content")?e:e.querySelector(".mfp-content"),o&&!o.hasAttribute("data-godam-processed")&&(a&&clearTimeout(a),a=setTimeout((()=>{t(o),a=null}),300))}}))})).observe(document.body,{childList:!0,subtree:!0}),void 0!==$.magnificPopup){let e=null;const o=()=>{e&&clearTimeout(e),e=setTimeout((()=>{const o=document.querySelector(".mfp-content:not([data-godam-processed])");o&&t(o),e=null}),250)};$(document).on("mfpOpen mfpChange",o)}"undefined"!=typeof $&&$(document).on("mfpClose",(function(){a&&(clearTimeout(a),a=null)}));new MutationObserver((e=>{for(const o of e)o.addedNodes.forEach((e=>{if(1===e.nodeType){if(e.closest(".mfp-content")||e.classList&&e.classList.contains("mfp-content")){if(("VIDEO"===e.tagName?[e]:e.querySelectorAll("video")).length>0){const o=e.closest(".mfp-content")||e;o.hasAttribute("data-godam-processed")||requestAnimationFrame((()=>t(o)))}}}}))})).observe(document.body,{childList:!0,subtree:!0})}));
\ No newline at end of file
+GODAMPlayer();const activityStream=document.querySelector("#buddypress #activity-stream");if(activityStream){new MutationObserver((e=>{for(const t of e)t.addedNodes.forEach((e=>{1===e.nodeType&&(e.matches(".activity")||e.matches(".groups"))&&requestAnimationFrame((()=>GODAMPlayer(e)))}))})).observe(activityStream,{childList:!0,subtree:!0})}document.addEventListener("DOMContentLoaded",(()=>{GODAMPlayer();const e=new WeakSet,t=t=>{if(!t)return void GODAMPlayer();if(e.has(t))return;t.querySelectorAll("[data-godam-initialized], .godam-player-initialized").length>0||(GODAMPlayer(t),e.add(t),t.setAttribute&&t.setAttribute("data-godam-processed","true"))},o=document.querySelector("#buddypress #activity-stream");if(o){new MutationObserver((e=>{for(const o of e)o.addedNodes.forEach((e=>{1===e.nodeType&&e.matches(".activity")&&!e.hasAttribute("data-godam-processed")&&requestAnimationFrame((()=>t(e)))}))})).observe(o,{childList:!0,subtree:!0})}let a=null;if(new MutationObserver((e=>{for(const o of e)o.addedNodes.forEach((e=>{if(1===e.nodeType){let o=null;o=e.classList&&e.classList.contains("mfp-content")?e:e.querySelector(".mfp-content"),o&&!o.hasAttribute("data-godam-processed")&&(a&&clearTimeout(a),a=setTimeout((()=>{t(o),a=null}),300))}}))})).observe(document.body,{childList:!0,subtree:!0}),void 0!==$.magnificPopup){let e=null;const o=()=>{e&&clearTimeout(e),e=setTimeout((()=>{const o=document.querySelector(".mfp-content:not([data-godam-processed])");o&&t(o),e=null}),250)};$(document).on("mfpOpen mfpChange",o)}"undefined"!=typeof $&&$(document).on("mfpClose",(function(){a&&(clearTimeout(a),a=null)}));new MutationObserver((e=>{for(const o of e)o.addedNodes.forEach((e=>{if(1===e.nodeType){if(e.closest(".mfp-content")||e.classList&&e.classList.contains("mfp-content")){if(("VIDEO"===e.tagName?[e]:e.querySelectorAll("video")).length>0){const o=e.closest(".mfp-content")||e;o.hasAttribute("data-godam-processed")||requestAnimationFrame((()=>t(o)))}}}}))})).observe(document.body,{childList:!0,subtree:!0})}));
\ No newline at end of file
diff --git a/app/main/controllers/template/rtmedia-functions.php b/app/main/controllers/template/rtmedia-functions.php
index 6a2d3a5fa..53c0d5185 100644
--- a/app/main/controllers/template/rtmedia-functions.php
+++ b/app/main/controllers/template/rtmedia-functions.php
@@ -5427,8 +5427,6 @@ function handle_get_single_activity_comment_html() {
* jQuery and rt-mediaelement-wp are included to ensure proper functionality.
*
* Enqueuing here guarantees consistent script loading regardless of Godam’s activation status.
- *
- * Hooked into 'wp_enqueue_scripts' to load on frontend pages.
*/
function enqueue_rtmedia_magnific_popup_script() {
$handle = 'rtmedia-magnific-popup';
From 317889459a12b1e531bf903acea984fe7ea74b68 Mon Sep 17 00:00:00 2001
From: krishana7911
Date: Thu, 29 May 2025 16:49:25 +0530
Subject: [PATCH 15/22] fix re-rendering of godam player in modal for prev and
next btns
---
app/assets/js/godam-ajax-refresh.js | 16 ++
app/assets/js/godam-integration.js | 163 ++++++++++++++++--
app/assets/js/godam-integration.min.js | 2 +-
.../template/rtmedia-functions.php | 21 +--
4 files changed, 181 insertions(+), 21 deletions(-)
diff --git a/app/assets/js/godam-ajax-refresh.js b/app/assets/js/godam-ajax-refresh.js
index 5b39a2531..74a4f9f2a 100644
--- a/app/assets/js/godam-ajax-refresh.js
+++ b/app/assets/js/godam-ajax-refresh.js
@@ -1,3 +1,19 @@
+/**
+ * BuddyPress Activity Comment Enhancer
+ * -------------------------------------
+ * This script enhances dynamically added BuddyPress activity comments by:
+ *
+ * On detecting a new comment (via MutationObserver), it:
+ * - Initializes GODAMPlayer for the new comment node.
+ * - Extracts the comment ID.
+ * - Makes an AJAX request to re-fetch the complete HTML for that comment.
+ * - Replaces the placeholder node with the freshly rendered comment HTML.
+ * - Re-initializes GODAMPlayer on the updated content to ensure video playback and * shortcodes are rendered correctly.
+ *
+ * This ensures any dynamically loaded comment (e.g. via AJAX or frontend frameworks)
+ * is fully initialized with expected behavior and media handling.
+ */
+
document.addEventListener('DOMContentLoaded', () => {
const commentsContainers = document.querySelectorAll('.activity-comments');
diff --git a/app/assets/js/godam-integration.js b/app/assets/js/godam-integration.js
index a03a16a38..ad3074aa5 100644
--- a/app/assets/js/godam-integration.js
+++ b/app/assets/js/godam-integration.js
@@ -1,11 +1,25 @@
/**
- * This script ensures GODAMPlayer is initialized dynamically across:
- * - BuddyPress activity streams updated via AJAX.
- * - Magnific Popup content.
- * - Any newly added video elements in the DOM (e.g., via infinite scroll or modals).
+ * Enhanced GODAM Player Initialization Script
*
- * It uses MutationObservers and event listeners to watch for new content and
- * initializes the player only when necessary, avoiding duplicate setups.
+ * This script handles automatic initialization and reinitialization of the GODAM video player
+ * across various WordPress/BuddyPress contexts, with special support for RTMedia galleries.
+ *
+ * Key Features:
+ * - Initializes GODAM player on page load and dynamic content changes
+ * - Handles BuddyPress activity streams with AJAX loading
+ * - Supports Magnific Popup lightbox integration
+ * - Automatically reinitializes when RTMedia gallery navigation occurs (prev/next arrows)
+ * - Tracks dynamic RTMedia element IDs (rtmedia-media-###) and reinitializes on changes
+ * - Prevents duplicate initializations using WeakSet tracking
+ * - Handles video element detection in popups and dynamic content
+ *
+ * RTMedia Integration:
+ * - Monitors for changes in elements with IDs matching pattern "rtmedia-media-{number}"
+ * - Detects navigation events (previous/next arrows) that change video content
+ * - Automatically reinitializes GODAM player when new media is loaded
+ * - Cleans up tracking when popups are closed
+ *
+ * Dependencies: GODAM Player, jQuery (optional), Magnific Popup (optional)
*/
GODAMPlayer();
@@ -26,8 +40,8 @@ if (activityStream) {
document.addEventListener('DOMContentLoaded', () => {
GODAMPlayer();
-
const initializedElements = new WeakSet();
+ let currentRTMediaId = null; // Track current RTMedia ID
const safeGODAMInit = (element) => {
if (!element) {
@@ -51,6 +65,36 @@ document.addEventListener('DOMContentLoaded', () => {
}
};
+ // Function to check for RTMedia ID changes
+ const checkRTMediaIdChange = () => {
+ const rtmediaElement = document.querySelector('[id^="rtmedia-media-"]');
+ if (rtmediaElement) {
+ const newId = rtmediaElement.id;
+ if (newId !== currentRTMediaId) {
+ currentRTMediaId = newId;
+ console.log('RTMedia ID changed to:', newId);
+
+ // Remove from initialized set to allow reinitialization
+ initializedElements.delete(rtmediaElement);
+
+ // Find the container (could be the element itself or its parent)
+ const container = rtmediaElement.closest('.mfp-content') || rtmediaElement;
+ if (container) {
+ container.removeAttribute('data-godam-processed');
+ initializedElements.delete(container);
+
+ // Reinitialize after a short delay to ensure content is loaded
+ setTimeout(() => {
+ safeGODAMInit(container);
+ }, 100);
+ }
+ return true;
+ }
+ }
+ return false;
+ };
+
+ // BuddyPress Activity Stream Observer
const activityStream = document.querySelector('#buddypress #activity-stream');
if (activityStream) {
const observer = new MutationObserver((mutations) => {
@@ -72,9 +116,19 @@ document.addEventListener('DOMContentLoaded', () => {
let popupInitializationTimeout = null;
+ // Enhanced Magnific Popup Observer with RTMedia support
const setupMagnificObserver = () => {
const magnificObserver = new MutationObserver((mutations) => {
+ let shouldCheckRTMedia = false;
+
for (const mutation of mutations) {
+ // Check for attribute changes on RTMedia elements
+ if (mutation.type === 'attributes' &&
+ mutation.target.id &&
+ mutation.target.id.startsWith('rtmedia-media-')) {
+ shouldCheckRTMedia = true;
+ }
+
mutation.addedNodes.forEach((node) => {
if (node.nodeType === 1) {
let mfpContent = null;
@@ -85,6 +139,12 @@ document.addEventListener('DOMContentLoaded', () => {
mfpContent = node.querySelector('.mfp-content');
}
+ // Check if this node or its children contain RTMedia elements
+ const hasRTMedia = node.querySelector && node.querySelector('[id^="rtmedia-media-"]');
+ if (hasRTMedia) {
+ shouldCheckRTMedia = true;
+ }
+
if (mfpContent && !mfpContent.hasAttribute('data-godam-processed')) {
if (popupInitializationTimeout) {
clearTimeout(popupInitializationTimeout);
@@ -97,17 +157,34 @@ document.addEventListener('DOMContentLoaded', () => {
}
}
});
+
+ // Handle removed nodes (cleanup)
+ mutation.removedNodes.forEach((node) => {
+ if (node.nodeType === 1 && node.id && node.id.startsWith('rtmedia-media-')) {
+ if (currentRTMediaId === node.id) {
+ currentRTMediaId = null;
+ }
+ }
+ });
+ }
+
+ // Check for RTMedia ID changes if needed
+ if (shouldCheckRTMedia) {
+ setTimeout(checkRTMediaIdChange, 100);
}
});
magnificObserver.observe(document.body, {
childList: true,
- subtree: true
+ subtree: true,
+ attributes: true,
+ attributeFilter: ['id', 'class']
});
};
setupMagnificObserver();
+ // Enhanced Magnific Popup event handlers
if (typeof $.magnificPopup !== 'undefined') {
let eventTimeout = null;
@@ -121,11 +198,22 @@ document.addEventListener('DOMContentLoaded', () => {
if (mfpContent) {
safeGODAMInit(mfpContent);
}
+
+ // Also check for RTMedia changes
+ checkRTMediaIdChange();
+
eventTimeout = null;
}, 250);
};
- $(document).on('mfpOpen mfpChange', handleMagnificEvent);
+ $(document).on('mfpOpen mfpChange mfpBeforeChange', handleMagnificEvent);
+
+ // Handle navigation events specifically
+ $(document).on('mfpNext mfpPrev', () => {
+ setTimeout(() => {
+ checkRTMediaIdChange();
+ }, 300);
+ });
}
if (typeof $ !== 'undefined') {
@@ -134,9 +222,12 @@ document.addEventListener('DOMContentLoaded', () => {
clearTimeout(popupInitializationTimeout);
popupInitializationTimeout = null;
}
+ // Reset RTMedia tracking on close
+ currentRTMediaId = null;
});
}
+ // Enhanced Video Observer with RTMedia support
const videoObserver = new MutationObserver((mutations) => {
for (const mutation of mutations) {
mutation.addedNodes.forEach((node) => {
@@ -153,6 +244,15 @@ document.addEventListener('DOMContentLoaded', () => {
}
}
}
+
+ // Check for RTMedia elements specifically
+ const rtmediaElement = node.id && node.id.startsWith('rtmedia-media-') ?
+ node :
+ node.querySelector && node.querySelector('[id^="rtmedia-media-"]');
+
+ if (rtmediaElement) {
+ setTimeout(checkRTMediaIdChange, 100);
+ }
}
});
}
@@ -162,10 +262,53 @@ document.addEventListener('DOMContentLoaded', () => {
childList: true,
subtree: true
});
-});
+ // Additional RTMedia-specific observer for DOM changes
+ const rtmediaObserver = new MutationObserver((mutations) => {
+ let hasRTMediaChanges = false;
+
+ for (const mutation of mutations) {
+ // Check for changes in elements with RTMedia IDs
+ if (mutation.target.id && mutation.target.id.startsWith('rtmedia-media-')) {
+ hasRTMediaChanges = true;
+ break;
+ }
+
+ // Check added/removed nodes for RTMedia elements
+ const checkNodes = (nodes) => {
+ for (const node of nodes) {
+ if (node.nodeType === 1) {
+ if ((node.id && node.id.startsWith('rtmedia-media-')) ||
+ (node.querySelector && node.querySelector('[id^="rtmedia-media-"]'))) {
+ hasRTMediaChanges = true;
+ return true;
+ }
+ }
+ }
+ return false;
+ };
+
+ if (checkNodes(mutation.addedNodes) || checkNodes(mutation.removedNodes)) {
+ break;
+ }
+ }
+
+ if (hasRTMediaChanges) {
+ setTimeout(checkRTMediaIdChange, 150);
+ }
+ });
+ // Observe the document for RTMedia changes
+ rtmediaObserver.observe(document.body, {
+ childList: true,
+ subtree: true,
+ attributes: true,
+ attributeFilter: ['id']
+ });
+ // Initialize RTMedia tracking on load
+ setTimeout(checkRTMediaIdChange, 500);
+});
diff --git a/app/assets/js/godam-integration.min.js b/app/assets/js/godam-integration.min.js
index 5094e1344..9dcb94323 100644
--- a/app/assets/js/godam-integration.min.js
+++ b/app/assets/js/godam-integration.min.js
@@ -1 +1 @@
-GODAMPlayer();const activityStream=document.querySelector("#buddypress #activity-stream");if(activityStream){new MutationObserver((e=>{for(const t of e)t.addedNodes.forEach((e=>{1===e.nodeType&&(e.matches(".activity")||e.matches(".groups"))&&requestAnimationFrame((()=>GODAMPlayer(e)))}))})).observe(activityStream,{childList:!0,subtree:!0})}document.addEventListener("DOMContentLoaded",(()=>{GODAMPlayer();const e=new WeakSet,t=t=>{if(!t)return void GODAMPlayer();if(e.has(t))return;t.querySelectorAll("[data-godam-initialized], .godam-player-initialized").length>0||(GODAMPlayer(t),e.add(t),t.setAttribute&&t.setAttribute("data-godam-processed","true"))},o=document.querySelector("#buddypress #activity-stream");if(o){new MutationObserver((e=>{for(const o of e)o.addedNodes.forEach((e=>{1===e.nodeType&&e.matches(".activity")&&!e.hasAttribute("data-godam-processed")&&requestAnimationFrame((()=>t(e)))}))})).observe(o,{childList:!0,subtree:!0})}let a=null;if(new MutationObserver((e=>{for(const o of e)o.addedNodes.forEach((e=>{if(1===e.nodeType){let o=null;o=e.classList&&e.classList.contains("mfp-content")?e:e.querySelector(".mfp-content"),o&&!o.hasAttribute("data-godam-processed")&&(a&&clearTimeout(a),a=setTimeout((()=>{t(o),a=null}),300))}}))})).observe(document.body,{childList:!0,subtree:!0}),void 0!==$.magnificPopup){let e=null;const o=()=>{e&&clearTimeout(e),e=setTimeout((()=>{const o=document.querySelector(".mfp-content:not([data-godam-processed])");o&&t(o),e=null}),250)};$(document).on("mfpOpen mfpChange",o)}"undefined"!=typeof $&&$(document).on("mfpClose",(function(){a&&(clearTimeout(a),a=null)}));new MutationObserver((e=>{for(const o of e)o.addedNodes.forEach((e=>{if(1===e.nodeType){if(e.closest(".mfp-content")||e.classList&&e.classList.contains("mfp-content")){if(("VIDEO"===e.tagName?[e]:e.querySelectorAll("video")).length>0){const o=e.closest(".mfp-content")||e;o.hasAttribute("data-godam-processed")||requestAnimationFrame((()=>t(o)))}}}}))})).observe(document.body,{childList:!0,subtree:!0})}));
\ No newline at end of file
+GODAMPlayer();const activityStream=document.querySelector("#buddypress #activity-stream");if(activityStream){new MutationObserver((e=>{for(const t of e)t.addedNodes.forEach((e=>{1===e.nodeType&&(e.matches(".activity")||e.matches(".groups"))&&requestAnimationFrame((()=>GODAMPlayer(e)))}))})).observe(activityStream,{childList:!0,subtree:!0})}document.addEventListener("DOMContentLoaded",(()=>{GODAMPlayer();const e=new WeakSet;let t=null;const o=t=>{if(!t)return void GODAMPlayer();if(e.has(t))return;t.querySelectorAll("[data-godam-initialized], .godam-player-initialized").length>0||(GODAMPlayer(t),e.add(t),t.setAttribute&&t.setAttribute("data-godam-processed","true"))},r=()=>{const r=document.querySelector('[id^="rtmedia-media-"]');if(r){const i=r.id;if(i!==t){t=i,console.log("RTMedia ID changed to:",i),e.delete(r);const d=r.closest(".mfp-content")||r;return d&&(d.removeAttribute("data-godam-processed"),e.delete(d),setTimeout((()=>{o(d)}),100)),!0}}return!1},i=document.querySelector("#buddypress #activity-stream");if(i){new MutationObserver((e=>{for(const t of e)t.addedNodes.forEach((e=>{1===e.nodeType&&e.matches(".activity")&&!e.hasAttribute("data-godam-processed")&&requestAnimationFrame((()=>o(e)))}))})).observe(i,{childList:!0,subtree:!0})}let d=null;if(new MutationObserver((e=>{let i=!1;for(const r of e)"attributes"===r.type&&r.target.id&&r.target.id.startsWith("rtmedia-media-")&&(i=!0),r.addedNodes.forEach((e=>{if(1===e.nodeType){let t=null;t=e.classList&&e.classList.contains("mfp-content")?e:e.querySelector(".mfp-content"),e.querySelector&&e.querySelector('[id^="rtmedia-media-"]')&&(i=!0),t&&!t.hasAttribute("data-godam-processed")&&(d&&clearTimeout(d),d=setTimeout((()=>{o(t),d=null}),300))}})),r.removedNodes.forEach((e=>{1===e.nodeType&&e.id&&e.id.startsWith("rtmedia-media-")&&t===e.id&&(t=null)}));i&&setTimeout(r,100)})).observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["id","class"]}),void 0!==$.magnificPopup){let e=null;const t=()=>{e&&clearTimeout(e),e=setTimeout((()=>{const t=document.querySelector(".mfp-content:not([data-godam-processed])");t&&o(t),r(),e=null}),250)};$(document).on("mfpOpen mfpChange mfpBeforeChange",t),$(document).on("mfpNext mfpPrev",(()=>{setTimeout((()=>{r()}),300)}))}"undefined"!=typeof $&&$(document).on("mfpClose",(function(){d&&(clearTimeout(d),d=null),t=null}));new MutationObserver((e=>{for(const t of e)t.addedNodes.forEach((e=>{if(1===e.nodeType){if(e.closest(".mfp-content")||e.classList&&e.classList.contains("mfp-content")){if(("VIDEO"===e.tagName?[e]:e.querySelectorAll("video")).length>0){const t=e.closest(".mfp-content")||e;t.hasAttribute("data-godam-processed")||requestAnimationFrame((()=>o(t)))}}(e.id&&e.id.startsWith("rtmedia-media-")?e:e.querySelector&&e.querySelector('[id^="rtmedia-media-"]'))&&setTimeout(r,100)}}))})).observe(document.body,{childList:!0,subtree:!0});new MutationObserver((e=>{let t=!1;for(const o of e){if(o.target.id&&o.target.id.startsWith("rtmedia-media-")){t=!0;break}const e=e=>{for(const o of e)if(1===o.nodeType&&(o.id&&o.id.startsWith("rtmedia-media-")||o.querySelector&&o.querySelector('[id^="rtmedia-media-"]')))return t=!0,!0;return!1};if(e(o.addedNodes)||e(o.removedNodes))break}t&&setTimeout(r,150)})).observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["id"]}),setTimeout(r,500)}));
\ No newline at end of file
diff --git a/app/main/controllers/template/rtmedia-functions.php b/app/main/controllers/template/rtmedia-functions.php
index 53c0d5185..545fdbcb7 100644
--- a/app/main/controllers/template/rtmedia-functions.php
+++ b/app/main/controllers/template/rtmedia-functions.php
@@ -5244,10 +5244,20 @@ function enqueue_scripts_globally() {
* Enqueue frontend scripts for Godam integration and AJAX refresh.
*/
add_action( 'wp_enqueue_scripts', function() {
+
+ // Enqueue integration script for rtMedia and Godam.
+ wp_enqueue_script(
+ 'godam-rtmedia-integration',
+ RTMEDIA_URL . 'app/assets/js/godam-integration.min.js',
+ [ 'godam-player-frontend-script' ],
+ null,
+ true
+ );
+
// Enqueue the script responsible for AJAX-based comment refresh.
wp_enqueue_script(
'godam-ajax-refresh',
- RTMEDIA_URL . 'app/assets/js/godam-ajax-refresh.min.js',
+ RTMEDIA_URL . 'app/assets/js/godam-ajax-refresh.js',
[],
null,
true
@@ -5258,15 +5268,6 @@ function enqueue_scripts_globally() {
'ajax_url' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'godam-ajax-nonce' ),
]);
-
- // Enqueue integration script for rtMedia and Godam.
- wp_enqueue_script(
- 'godam-rtmedia-integration',
- RTMEDIA_URL . 'app/assets/js/godam-integration.min.js',
- [ 'godam-player-frontend-script' ],
- null,
- true
- );
} );
/**
From 595e732d456884e32cbf86a47a36a8b75b22871e Mon Sep 17 00:00:00 2001
From: krishana7911
Date: Thu, 29 May 2025 16:51:35 +0530
Subject: [PATCH 16/22] Enqueue minified file for ajax script
---
app/main/controllers/template/rtmedia-functions.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/main/controllers/template/rtmedia-functions.php b/app/main/controllers/template/rtmedia-functions.php
index 545fdbcb7..6652e85b7 100644
--- a/app/main/controllers/template/rtmedia-functions.php
+++ b/app/main/controllers/template/rtmedia-functions.php
@@ -5257,7 +5257,7 @@ function enqueue_scripts_globally() {
// Enqueue the script responsible for AJAX-based comment refresh.
wp_enqueue_script(
'godam-ajax-refresh',
- RTMEDIA_URL . 'app/assets/js/godam-ajax-refresh.js',
+ RTMEDIA_URL . 'app/assets/js/godam-ajax-refresh.min.js',
[],
null,
true
From 0abbe6f6bcb83af1e3118930bfe393d86b50b355 Mon Sep 17 00:00:00 2001
From: krishana7911
Date: Thu, 29 May 2025 19:24:36 +0530
Subject: [PATCH 17/22] Fix race condition for comment render
---
app/assets/js/godam-ajax-refresh.js | 237 +++++++++++++++---------
app/assets/js/godam-ajax-refresh.min.js | 2 +-
app/assets/js/godam-integration.js | 3 -
3 files changed, 153 insertions(+), 89 deletions(-)
diff --git a/app/assets/js/godam-ajax-refresh.js b/app/assets/js/godam-ajax-refresh.js
index 74a4f9f2a..260e83a10 100644
--- a/app/assets/js/godam-ajax-refresh.js
+++ b/app/assets/js/godam-ajax-refresh.js
@@ -1,103 +1,170 @@
-/**
- * BuddyPress Activity Comment Enhancer
- * -------------------------------------
- * This script enhances dynamically added BuddyPress activity comments by:
- *
- * On detecting a new comment (via MutationObserver), it:
- * - Initializes GODAMPlayer for the new comment node.
- * - Extracts the comment ID.
- * - Makes an AJAX request to re-fetch the complete HTML for that comment.
- * - Replaces the placeholder node with the freshly rendered comment HTML.
- * - Re-initializes GODAMPlayer on the updated content to ensure video playback and * shortcodes are rendered correctly.
- *
- * This ensures any dynamically loaded comment (e.g. via AJAX or frontend frameworks)
- * is fully initialized with expected behavior and media handling.
- */
-
document.addEventListener('DOMContentLoaded', () => {
- const commentsContainers = document.querySelectorAll('.activity-comments');
+ const commentsContainers = document.querySelectorAll('.activity-comments');
+ const processingComments = new Set(); // Track comments being processed
- // If no comment containers exist, exit early
- if (commentsContainers.length === 0) {
- return;
- }
+ // If no comment containers exist, exit early
+ if (commentsContainers.length === 0) {
+ return;
+ }
+
+ commentsContainers.forEach((container) => {
+ // Initialize GODAMPlayer on existing comment container
+ GODAMPlayer(container);
- commentsContainers.forEach((container) => {
- // Initialize GODAMPlayer on existing comment container
- GODAMPlayer(container);
-
- // Observe DOM changes to detect new comments being added dynamically
- const observer = new MutationObserver((mutations) => {
- mutations.forEach((mutation) => {
- mutation.addedNodes.forEach((node) => {
- if (node.nodeType === 1 && node.matches('li[id^="acomment-"]')) {
- // Initialize GODAMPlayer on the new comment node
- GODAMPlayer(node);
-
- // Extract the comment ID and refresh the comment via AJAX
- const commentId = node.id.replace('acomment-', '');
- refreshSingleComment(commentId, node);
+ // Observe DOM changes to detect new comments being added dynamically
+ const observer = new MutationObserver((mutations) => {
+ mutations.forEach((mutation) => {
+ mutation.addedNodes.forEach((node) => {
+ if (node.nodeType === 1 && node.matches('li[id^="acomment-"]')) {
+ // Extract the comment ID
+ const commentId = node.id.replace('acomment-', '');
+
+ // Prevent duplicate processing
+ if (processingComments.has(commentId)) {
+ return;
}
- });
+
+ // Add delay to ensure node is fully rendered
+ setTimeout(() => {
+ // Check if node still exists and needs processing
+ if (document.getElementById(`acomment-${commentId}`)) {
+ // Initialize GODAMPlayer on the new comment node
+ GODAMPlayer(node);
+
+ // Only refresh if it looks like a placeholder/incomplete node
+ if (shouldRefreshComment(node)) {
+ refreshSingleComment(commentId, node);
+ }
+ }
+ }, 100); // Small delay to avoid race conditions
+ }
});
});
+ });
- observer.observe(container, {
- childList: true,
- subtree: true
- });
+ observer.observe(container, {
+ childList: true,
+ subtree: true
});
});
+});
+
+/**
+ * Determines if a comment node needs to be refreshed
+ * @param {Element} node - The comment node to check
+ * @returns {boolean} - Whether the comment should be refreshed
+ */
+function shouldRefreshComment(node) {
+ // Add your logic here to determine if the comment is a placeholder
+ // For example, check if it's missing expected content or has placeholder classes
+ return node.classList.contains('loading') ||
+ node.querySelector('.godam-placeholder') ||
+ !node.querySelector('.comment-content');
+}
+
+/**
+ * Refreshes a single BuddyPress comment via AJAX to fetch updated content,
+ * including Godam video player shortcode rendering.
+ *
+ * @param {string} commentId - The ID of the comment to refresh
+ * @param {Element} node - The existing DOM node being replaced
+ */
+function refreshSingleComment(commentId, node) {
+ const processingComments = window.processingComments || (window.processingComments = new Set());
- /**
- * Refreshes a single BuddyPress comment via AJAX to fetch updated content,
- * including Godam video player shortcode rendering.
- *
- * @param {string} commentId - The ID of the comment to refresh
- * @param {Element} node - The existing DOM node being replaced
- */
- function refreshSingleComment(commentId, node) {
- 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,
- }),
- })
- .then(response => response.json())
- .then(data => {
- if (data.success) {
- // Identify the parent activity from the comment DOM node
- const parentActivityId = node.closest('.activity-item').id.replace('activity-', '');
-
- // Locate or create the container for activity comments
- let commentList = document.querySelector(`#activity-${parentActivityId} .activity-comments`);
- if (!commentList) {
- commentList = document.createElement('ul');
- commentList.classList.add('activity-comments');
- document.querySelector(`#activity-${parentActivityId}`).appendChild(commentList);
+ // Prevent duplicate requests
+ if (processingComments.has(commentId)) {
+ return;
+ }
+
+ processingComments.add(commentId);
+
+ // Add loading indicator
+ const originalContent = node.innerHTML;
+ node.classList.add('loading');
+
+ // Create AbortController for timeout handling
+ const controller = new AbortController();
+ const timeoutId = setTimeout(() => controller.abort(), 30000); // 30 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);
+
+ if (!response.ok) {
+ throw new Error(`HTTP error! status: ${response.status}`);
+ }
+
+ return response.json();
+ })
+ .then(data => {
+ if (data.success && data.data && data.data.html) {
+ // Identify the parent activity from the comment DOM node
+ const parentActivityId = node.closest('.activity-item')?.id?.replace('activity-', '');
+
+ if (!parentActivityId) {
+ throw new Error('Could not find parent activity ID');
+ }
+
+ // Locate or create the container for activity comments
+ let commentList = document.querySelector(`#activity-${parentActivityId} .activity-comments`);
+ if (!commentList) {
+ commentList = document.createElement('ul');
+ commentList.classList.add('activity-comments');
+ const activityElement = document.querySelector(`#activity-${parentActivityId}`);
+ if (!activityElement) {
+ throw new Error('Parent activity element not found');
}
+ activityElement.appendChild(commentList);
+ }
- // Inject the freshly rendered comment HTML
- commentList.insertAdjacentHTML('beforeend', data.data.html);
+ // Create a temporary container to parse the HTML
+ const tempDiv = document.createElement('div');
+ tempDiv.innerHTML = data.data.html;
+ const newCommentNode = tempDiv.firstElementChild;
- // Remove the placeholder node that triggered the refresh
+ if (newCommentNode) {
+ // Replace the old node with the new one
if (node.parentNode) {
- node.parentNode.removeChild(node);
+ node.parentNode.replaceChild(newCommentNode, node);
}
// Reinitialize GODAMPlayer for the new comment node
- const refreshedNode = document.querySelector(`#acomment-${commentId}`);
- if (refreshedNode) GODAMPlayer(refreshedNode);
- } else {
- console.error('AJAX error:', data.data);
+ GODAMPlayer(newCommentNode);
}
- })
- .catch(error => {
- console.error('Fetch error:', error);
- });
- }
+ } else {
+ throw new Error(data.data || 'Unknown server error');
+ }
+ })
+ .catch(error => {
+ console.error('AJAX error for comment', commentId, ':', error);
+
+ // Restore original content on error
+ node.innerHTML = originalContent;
+ node.classList.remove('loading');
+
+ // Retry logic (optional)
+ if (!error.name === 'AbortError') { // Don't retry timeouts
+ setTimeout(() => {
+ processingComments.delete(commentId);
+ // Could implement retry logic here
+ }, 5000);
+ }
+ })
+ .finally(() => {
+ clearTimeout(timeoutId);
+ processingComments.delete(commentId);
+ node.classList.remove('loading');
+ });
+}
diff --git a/app/assets/js/godam-ajax-refresh.min.js b/app/assets/js/godam-ajax-refresh.min.js
index 90121c489..ffea65a2a 100644
--- a/app/assets/js/godam-ajax-refresh.min.js
+++ b/app/assets/js/godam-ajax-refresh.min.js
@@ -1 +1 @@
-function refreshSingleComment(e,t){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:e,nonce:GodamAjax.nonce})}).then((e=>e.json())).then((o=>{if(o.success){const c=t.closest(".activity-item").id.replace("activity-","");let n=document.querySelector(`#activity-${c} .activity-comments`);n||(n=document.createElement("ul"),n.classList.add("activity-comments"),document.querySelector(`#activity-${c}`).appendChild(n)),n.insertAdjacentHTML("beforeend",o.data.html),t.parentNode&&t.parentNode.removeChild(t);const a=document.querySelector(`#acomment-${e}`);a&&GODAMPlayer(a)}else console.error("AJAX error:",o.data)})).catch((e=>{console.error("Fetch error:",e)}))}document.addEventListener("DOMContentLoaded",(()=>{const e=document.querySelectorAll(".activity-comments");0!==e.length&&e.forEach((e=>{GODAMPlayer(e);new MutationObserver((e=>{e.forEach((e=>{e.addedNodes.forEach((e=>{if(1===e.nodeType&&e.matches('li[id^="acomment-"]')){GODAMPlayer(e);refreshSingleComment(e.id.replace("acomment-",""),e)}}))}))})).observe(e,{childList:!0,subtree:!0})}))}));
\ No newline at end of file
+function shouldRefreshComment(e){return e.classList.contains("loading")||e.querySelector(".godam-placeholder")||!e.querySelector(".comment-content")}function refreshSingleComment(e,t){const n=window.processingComments||(window.processingComments=new Set);if(n.has(e))return;n.add(e);const o=t.innerHTML;t.classList.add("loading");const r=new AbortController,a=setTimeout((()=>r.abort()),3e4);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:e,nonce:GodamAjax.nonce}),signal:r.signal}).then((e=>{if(clearTimeout(a),!e.ok)throw new Error(`HTTP error! status: ${e.status}`);return e.json()})).then((e=>{if(!(e.success&&e.data&&e.data.html))throw new Error(e.data||"Unknown server error");{const n=t.closest(".activity-item")?.id?.replace("activity-","");if(!n)throw new Error("Could not find parent activity ID");let o=document.querySelector(`#activity-${n} .activity-comments`);if(!o){o=document.createElement("ul"),o.classList.add("activity-comments");const e=document.querySelector(`#activity-${n}`);if(!e)throw new Error("Parent activity element not found");e.appendChild(o)}const r=document.createElement("div");r.innerHTML=e.data.html;const a=r.firstElementChild;a&&(t.parentNode&&t.parentNode.replaceChild(a,t),GODAMPlayer(a))}})).catch((r=>{console.error("AJAX error for comment",e,":",r),t.innerHTML=o,t.classList.remove("loading"),"AbortError"===!r.name&&setTimeout((()=>{n.delete(e)}),5e3)})).finally((()=>{clearTimeout(a),n.delete(e),t.classList.remove("loading")}))}document.addEventListener("DOMContentLoaded",(()=>{const e=document.querySelectorAll(".activity-comments"),t=new Set;0!==e.length&&e.forEach((e=>{GODAMPlayer(e);new MutationObserver((e=>{e.forEach((e=>{e.addedNodes.forEach((e=>{if(1===e.nodeType&&e.matches('li[id^="acomment-"]')){const n=e.id.replace("acomment-","");if(t.has(n))return;setTimeout((()=>{document.getElementById(`acomment-${n}`)&&(GODAMPlayer(e),shouldRefreshComment(e)&&refreshSingleComment(n,e))}),100)}}))}))})).observe(e,{childList:!0,subtree:!0})}))}));
\ No newline at end of file
diff --git a/app/assets/js/godam-integration.js b/app/assets/js/godam-integration.js
index ad3074aa5..ccf9143de 100644
--- a/app/assets/js/godam-integration.js
+++ b/app/assets/js/godam-integration.js
@@ -309,6 +309,3 @@ document.addEventListener('DOMContentLoaded', () => {
// Initialize RTMedia tracking on load
setTimeout(checkRTMediaIdChange, 500);
});
-
-
-
From c18c43127316616f14439a83e36d346c8496d1ec Mon Sep 17 00:00:00 2001
From: krishana7911
Date: Fri, 30 May 2025 08:37:03 +0530
Subject: [PATCH 18/22] fix godam player rendering on comments
---
app/assets/js/godam-ajax-refresh.js | 376 ++++++++++++++++--------
app/assets/js/godam-ajax-refresh.min.js | 2 +-
app/assets/js/godam-integration.js | 166 +----------
app/assets/js/godam-integration.min.js | 2 +-
4 files changed, 267 insertions(+), 279 deletions(-)
diff --git a/app/assets/js/godam-ajax-refresh.js b/app/assets/js/godam-ajax-refresh.js
index 260e83a10..a6692e2ec 100644
--- a/app/assets/js/godam-ajax-refresh.js
+++ b/app/assets/js/godam-ajax-refresh.js
@@ -1,91 +1,31 @@
-document.addEventListener('DOMContentLoaded', () => {
- const commentsContainers = document.querySelectorAll('.activity-comments');
- const processingComments = new Set(); // Track comments being processed
-
- // If no comment containers exist, exit early
- if (commentsContainers.length === 0) {
+// Enhanced AJAX function with better error handling and retry logic
+function refreshSingleComment(commentId, node) {
+ // Validation checks
+ if (!commentId || !node) {
return;
}
- commentsContainers.forEach((container) => {
- // Initialize GODAMPlayer on existing comment container
- GODAMPlayer(container);
-
- // Observe DOM changes to detect new comments being added dynamically
- const observer = new MutationObserver((mutations) => {
- mutations.forEach((mutation) => {
- mutation.addedNodes.forEach((node) => {
- if (node.nodeType === 1 && node.matches('li[id^="acomment-"]')) {
- // Extract the comment ID
- const commentId = node.id.replace('acomment-', '');
-
- // Prevent duplicate processing
- if (processingComments.has(commentId)) {
- return;
- }
-
- // Add delay to ensure node is fully rendered
- setTimeout(() => {
- // Check if node still exists and needs processing
- if (document.getElementById(`acomment-${commentId}`)) {
- // Initialize GODAMPlayer on the new comment node
- GODAMPlayer(node);
-
- // Only refresh if it looks like a placeholder/incomplete node
- if (shouldRefreshComment(node)) {
- refreshSingleComment(commentId, node);
- }
- }
- }, 100); // Small delay to avoid race conditions
- }
- });
- });
- });
-
- observer.observe(container, {
- childList: true,
- subtree: true
- });
- });
-});
-
-/**
- * Determines if a comment node needs to be refreshed
- * @param {Element} node - The comment node to check
- * @returns {boolean} - Whether the comment should be refreshed
- */
-function shouldRefreshComment(node) {
- // Add your logic here to determine if the comment is a placeholder
- // For example, check if it's missing expected content or has placeholder classes
- return node.classList.contains('loading') ||
- node.querySelector('.godam-placeholder') ||
- !node.querySelector('.comment-content');
-}
+ // Check if GodamAjax object exists
+ if (typeof GodamAjax === 'undefined' || !GodamAjax.ajax_url || !GodamAjax.nonce) {
+ return;
+ }
-/**
- * Refreshes a single BuddyPress comment via AJAX to fetch updated content,
- * including Godam video player shortcode rendering.
- *
- * @param {string} commentId - The ID of the comment to refresh
- * @param {Element} node - The existing DOM node being replaced
- */
-function refreshSingleComment(commentId, node) {
- const processingComments = window.processingComments || (window.processingComments = new Set());
+ // Check if node is still in the DOM
+ if (!document.contains(node)) {
+ return;
+ }
// Prevent duplicate requests
- if (processingComments.has(commentId)) {
+ if (node.classList.contains('refreshing')) {
return;
}
-
- processingComments.add(commentId);
-
- // Add loading indicator
- const originalContent = node.innerHTML;
- node.classList.add('loading');
+ node.classList.add('refreshing');
// Create AbortController for timeout handling
const controller = new AbortController();
- const timeoutId = setTimeout(() => controller.abort(), 30000); // 30 second timeout
+ const timeoutId = setTimeout(() => {
+ controller.abort();
+ }, 15000); // 15 second timeout
fetch(GodamAjax.ajax_url, {
method: 'POST',
@@ -102,69 +42,263 @@ function refreshSingleComment(commentId, node) {
.then(response => {
clearTimeout(timeoutId);
+ // Check if response is ok
if (!response.ok) {
- throw new Error(`HTTP error! status: ${response.status}`);
+ 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.success && data.data && data.data.html) {
- // Identify the parent activity from the comment DOM node
- const parentActivityId = node.closest('.activity-item')?.id?.replace('activity-', '');
+ 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);
- if (!parentActivityId) {
- throw new Error('Could not find parent activity ID');
- }
+ // Optional: Retry once after a delay
+ setTimeout(() => {
+ retryRefreshComment(commentId, node, 1);
+ }, 2000);
+ }
+ })
+ .catch(error => {
+ clearTimeout(timeoutId);
+ console.error('Fetch error:', error);
- // Locate or create the container for activity comments
- let commentList = document.querySelector(`#activity-${parentActivityId} .activity-comments`);
- if (!commentList) {
- commentList = document.createElement('ul');
- commentList.classList.add('activity-comments');
- const activityElement = document.querySelector(`#activity-${parentActivityId}`);
- if (!activityElement) {
- throw new Error('Parent activity element not found');
+ // 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);
}
- activityElement.appendChild(commentList);
}
+ })
+ .catch(error => {
+ console.error(`Retry ${attempt} failed:`, error);
+ if (attempt < maxRetries) {
+ retryRefreshComment(commentId, node, attempt + 1);
+ }
+ });
+ }, delay);
+}
- // Create a temporary container to parse the HTML
- const tempDiv = document.createElement('div');
- tempDiv.innerHTML = data.data.html;
- const newCommentNode = tempDiv.firstElementChild;
+// 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;
+ }
- if (newCommentNode) {
- // Replace the old node with the new one
- if (node.parentNode) {
- node.parentNode.replaceChild(newCommentNode, node);
- }
+ 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;
- // Reinitialize GODAMPlayer for the new comment node
- GODAMPlayer(newCommentNode);
+ 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 {
- throw new Error(data.data || 'Unknown server error');
+ console.error('No valid comment node found in response HTML');
}
- })
- .catch(error => {
- console.error('AJAX error for comment', commentId, ':', error);
+ } catch (error) {
+ console.error('Error handling successful response:', error);
+ }
+}
- // Restore original content on error
- node.innerHTML = originalContent;
- node.classList.remove('loading');
+// Enhanced DOM observer with debouncing
+document.addEventListener('DOMContentLoaded', () => {
+ const commentsContainers = document.querySelectorAll('.activity-comments');
- // Retry logic (optional)
- if (!error.name === 'AbortError') { // Don't retry timeouts
- setTimeout(() => {
- processingComments.delete(commentId);
- // Could implement retry logic here
- }, 5000);
+ 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
+ });
+ });
+});
+
+// Debug function to test AJAX connectivity
+function testAjaxConnection() {
+ if (typeof GodamAjax === 'undefined') {
+ console.error('GodamAjax not defined');
+ return;
+ }
+
+ fetch(GodamAjax.ajax_url, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/x-www-form-urlencoded',
+ },
+ body: new URLSearchParams({
+ action: 'heartbeat',
+ nonce: GodamAjax.nonce,
+ }),
})
- .finally(() => {
- clearTimeout(timeoutId);
- processingComments.delete(commentId);
- node.classList.remove('loading');
+ .then(response => response.json())
+ .then(data => {
+ console.log('AJAX connection test:', data);
+ })
+ .catch(error => {
+ console.error('AJAX connection test failed:', error);
});
}
+
+// Uncomment to test AJAX connection
+// testAjaxConnection();
diff --git a/app/assets/js/godam-ajax-refresh.min.js b/app/assets/js/godam-ajax-refresh.min.js
index ffea65a2a..adff27638 100644
--- a/app/assets/js/godam-ajax-refresh.min.js
+++ b/app/assets/js/godam-ajax-refresh.min.js
@@ -1 +1 @@
-function shouldRefreshComment(e){return e.classList.contains("loading")||e.querySelector(".godam-placeholder")||!e.querySelector(".comment-content")}function refreshSingleComment(e,t){const n=window.processingComments||(window.processingComments=new Set);if(n.has(e))return;n.add(e);const o=t.innerHTML;t.classList.add("loading");const r=new AbortController,a=setTimeout((()=>r.abort()),3e4);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:e,nonce:GodamAjax.nonce}),signal:r.signal}).then((e=>{if(clearTimeout(a),!e.ok)throw new Error(`HTTP error! status: ${e.status}`);return e.json()})).then((e=>{if(!(e.success&&e.data&&e.data.html))throw new Error(e.data||"Unknown server error");{const n=t.closest(".activity-item")?.id?.replace("activity-","");if(!n)throw new Error("Could not find parent activity ID");let o=document.querySelector(`#activity-${n} .activity-comments`);if(!o){o=document.createElement("ul"),o.classList.add("activity-comments");const e=document.querySelector(`#activity-${n}`);if(!e)throw new Error("Parent activity element not found");e.appendChild(o)}const r=document.createElement("div");r.innerHTML=e.data.html;const a=r.firstElementChild;a&&(t.parentNode&&t.parentNode.replaceChild(a,t),GODAMPlayer(a))}})).catch((r=>{console.error("AJAX error for comment",e,":",r),t.innerHTML=o,t.classList.remove("loading"),"AbortError"===!r.name&&setTimeout((()=>{n.delete(e)}),5e3)})).finally((()=>{clearTimeout(a),n.delete(e),t.classList.remove("loading")}))}document.addEventListener("DOMContentLoaded",(()=>{const e=document.querySelectorAll(".activity-comments"),t=new Set;0!==e.length&&e.forEach((e=>{GODAMPlayer(e);new MutationObserver((e=>{e.forEach((e=>{e.addedNodes.forEach((e=>{if(1===e.nodeType&&e.matches('li[id^="acomment-"]')){const n=e.id.replace("acomment-","");if(t.has(n))return;setTimeout((()=>{document.getElementById(`acomment-${n}`)&&(GODAMPlayer(e),shouldRefreshComment(e)&&refreshSingleComment(n,e))}),100)}}))}))})).observe(e,{childList:!0,subtree:!0})}))}));
\ No newline at end of file
+function refreshSingleComment(e,t){if(!e||!t)return;if("undefined"==typeof GodamAjax||!GodamAjax.ajax_url||!GodamAjax.nonce)return;if(!document.contains(t))return;if(t.classList.contains("refreshing"))return;t.classList.add("refreshing");const o=new AbortController,n=setTimeout((()=>{o.abort()}),15e3);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:e,nonce:GodamAjax.nonce}),signal:o.signal}).then((e=>{if(clearTimeout(n),!e.ok)throw new Error(`HTTP ${e.status}: ${e.statusText}`);const t=e.headers.get("content-type");if(!t||!t.includes("application/json"))throw new Error("Server returned non-JSON response");return e.json()})).then((o=>{if(o&&o.success&&o.data&&o.data.html)handleSuccessfulResponse(o,e,t);else{const n=o&&o.data?o.data:"Unknown AJAX error";console.error("AJAX error:",n),setTimeout((()=>{retryRefreshComment(e,t,1)}),2e3)}})).catch((o=>{clearTimeout(n),console.error("Fetch error:",o),"AbortError"===o.name?console.error("Request timed out"):o.message.includes("Failed to fetch")&&(console.error("Network error - possible connectivity issue"),setTimeout((()=>{retryRefreshComment(e,t,1)}),3e3))})).finally((()=>{clearTimeout(n),document.contains(t)&&t.classList.remove("refreshing")}))}function retryRefreshComment(e,t,o=1){if(o>2)return void console.error(`Failed to refresh comment ${e} after 2 retries`);if(!document.contains(t))return;const n=1e3*Math.pow(2,o);setTimeout((()=>{t.classList.remove("refreshing"),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:e,nonce:GodamAjax.nonce,retry:o.toString()})}).then((e=>e.json())).then((n=>{n&&n.success&&n.data&&n.data.html?handleSuccessfulResponse(n,e,t):o<2&&retryRefreshComment(e,t,o+1)})).catch((n=>{console.error(`Retry ${o} failed:`,n),o<2&&retryRefreshComment(e,t,o+1)}))}),n)}function handleSuccessfulResponse(e,t,o){try{const n=o.closest(".activity-item");if(!n)return void console.error("Could not find parent activity item");const r=n.id.replace("activity-","");let a=document.querySelector(`#activity-${r} .activity-comments`);a||(a=document.createElement("ul"),a.classList.add("activity-comments"),n.appendChild(a));const c=document.createElement("div");c.innerHTML=e.data.html.trim();const i=c.firstElementChild;if(i){if(a.appendChild(i),o.parentNode&&document.contains(o)&&o.parentNode.removeChild(o),"function"==typeof GODAMPlayer)try{GODAMPlayer(i)}catch(e){console.error("GODAMPlayer initialization failed:",e)}document.dispatchEvent(new CustomEvent("commentRefreshed",{detail:{commentId:t,node:i}}))}else console.error("No valid comment node found in response HTML")}catch(e){console.error("Error handling successful response:",e)}}function testAjaxConnection(){"undefined"!=typeof GodamAjax?fetch(GodamAjax.ajax_url,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({action:"heartbeat",nonce:GodamAjax.nonce})}).then((e=>e.json())).then((e=>{console.log("AJAX connection test:",e)})).catch((e=>{console.error("AJAX connection test failed:",e)})):console.error("GodamAjax not defined")}document.addEventListener("DOMContentLoaded",(()=>{const e=document.querySelectorAll(".activity-comments");0!==e.length&&e.forEach((e=>{if("function"==typeof GODAMPlayer)try{GODAMPlayer(e)}catch(e){console.error("GODAMPlayer initialization failed:",e)}const t=function(e,t){let o;return function(...n){clearTimeout(o),o=setTimeout((()=>{clearTimeout(o),e(...n)}),t)}}((e=>{e.forEach((e=>{e.addedNodes.forEach((e=>{if(1===e.nodeType&&e.matches&&e.matches('li[id^="acomment-"]')){if("function"==typeof GODAMPlayer)try{GODAMPlayer(e)}catch(e){console.error("GODAMPlayer initialization failed:",e)}const t=e.id.replace("acomment-","");setTimeout((()=>{document.contains(e)&&refreshSingleComment(t,e)}),250)}}))}))}),100);new MutationObserver(t).observe(e,{childList:!0,subtree:!0})}))}));
\ No newline at end of file
diff --git a/app/assets/js/godam-integration.js b/app/assets/js/godam-integration.js
index ccf9143de..1cf048c80 100644
--- a/app/assets/js/godam-integration.js
+++ b/app/assets/js/godam-integration.js
@@ -1,25 +1,11 @@
/**
- * Enhanced GODAM Player Initialization Script
+ * This script ensures GODAMPlayer is initialized dynamically across:
+ * - BuddyPress activity streams updated via AJAX.
+ * - Magnific Popup content.
+ * - Any newly added video elements in the DOM (e.g., via infinite scroll or modals).
*
- * This script handles automatic initialization and reinitialization of the GODAM video player
- * across various WordPress/BuddyPress contexts, with special support for RTMedia galleries.
- *
- * Key Features:
- * - Initializes GODAM player on page load and dynamic content changes
- * - Handles BuddyPress activity streams with AJAX loading
- * - Supports Magnific Popup lightbox integration
- * - Automatically reinitializes when RTMedia gallery navigation occurs (prev/next arrows)
- * - Tracks dynamic RTMedia element IDs (rtmedia-media-###) and reinitializes on changes
- * - Prevents duplicate initializations using WeakSet tracking
- * - Handles video element detection in popups and dynamic content
- *
- * RTMedia Integration:
- * - Monitors for changes in elements with IDs matching pattern "rtmedia-media-{number}"
- * - Detects navigation events (previous/next arrows) that change video content
- * - Automatically reinitializes GODAM player when new media is loaded
- * - Cleans up tracking when popups are closed
- *
- * Dependencies: GODAM Player, jQuery (optional), Magnific Popup (optional)
+ * It uses MutationObservers and event listeners to watch for new content and
+ * initializes the player only when necessary, avoiding duplicate setups.
*/
GODAMPlayer();
@@ -29,7 +15,7 @@ if (activityStream) {
const observer = new MutationObserver((mutations) => {
for (const mutation of mutations) {
mutation.addedNodes.forEach((node) => {
- if (node.nodeType === 1 && (node.matches('.activity') || node.matches('.groups'))) {
+ if (node.nodeType === 1 && node.matches('.activity')) {
requestAnimationFrame(() => GODAMPlayer(node));
}
});
@@ -40,8 +26,8 @@ if (activityStream) {
document.addEventListener('DOMContentLoaded', () => {
GODAMPlayer();
+
const initializedElements = new WeakSet();
- let currentRTMediaId = null; // Track current RTMedia ID
const safeGODAMInit = (element) => {
if (!element) {
@@ -65,36 +51,6 @@ document.addEventListener('DOMContentLoaded', () => {
}
};
- // Function to check for RTMedia ID changes
- const checkRTMediaIdChange = () => {
- const rtmediaElement = document.querySelector('[id^="rtmedia-media-"]');
- if (rtmediaElement) {
- const newId = rtmediaElement.id;
- if (newId !== currentRTMediaId) {
- currentRTMediaId = newId;
- console.log('RTMedia ID changed to:', newId);
-
- // Remove from initialized set to allow reinitialization
- initializedElements.delete(rtmediaElement);
-
- // Find the container (could be the element itself or its parent)
- const container = rtmediaElement.closest('.mfp-content') || rtmediaElement;
- if (container) {
- container.removeAttribute('data-godam-processed');
- initializedElements.delete(container);
-
- // Reinitialize after a short delay to ensure content is loaded
- setTimeout(() => {
- safeGODAMInit(container);
- }, 100);
- }
- return true;
- }
- }
- return false;
- };
-
- // BuddyPress Activity Stream Observer
const activityStream = document.querySelector('#buddypress #activity-stream');
if (activityStream) {
const observer = new MutationObserver((mutations) => {
@@ -116,19 +72,9 @@ document.addEventListener('DOMContentLoaded', () => {
let popupInitializationTimeout = null;
- // Enhanced Magnific Popup Observer with RTMedia support
const setupMagnificObserver = () => {
const magnificObserver = new MutationObserver((mutations) => {
- let shouldCheckRTMedia = false;
-
for (const mutation of mutations) {
- // Check for attribute changes on RTMedia elements
- if (mutation.type === 'attributes' &&
- mutation.target.id &&
- mutation.target.id.startsWith('rtmedia-media-')) {
- shouldCheckRTMedia = true;
- }
-
mutation.addedNodes.forEach((node) => {
if (node.nodeType === 1) {
let mfpContent = null;
@@ -139,12 +85,6 @@ document.addEventListener('DOMContentLoaded', () => {
mfpContent = node.querySelector('.mfp-content');
}
- // Check if this node or its children contain RTMedia elements
- const hasRTMedia = node.querySelector && node.querySelector('[id^="rtmedia-media-"]');
- if (hasRTMedia) {
- shouldCheckRTMedia = true;
- }
-
if (mfpContent && !mfpContent.hasAttribute('data-godam-processed')) {
if (popupInitializationTimeout) {
clearTimeout(popupInitializationTimeout);
@@ -157,34 +97,17 @@ document.addEventListener('DOMContentLoaded', () => {
}
}
});
-
- // Handle removed nodes (cleanup)
- mutation.removedNodes.forEach((node) => {
- if (node.nodeType === 1 && node.id && node.id.startsWith('rtmedia-media-')) {
- if (currentRTMediaId === node.id) {
- currentRTMediaId = null;
- }
- }
- });
- }
-
- // Check for RTMedia ID changes if needed
- if (shouldCheckRTMedia) {
- setTimeout(checkRTMediaIdChange, 100);
}
});
magnificObserver.observe(document.body, {
childList: true,
- subtree: true,
- attributes: true,
- attributeFilter: ['id', 'class']
+ subtree: true
});
};
setupMagnificObserver();
- // Enhanced Magnific Popup event handlers
if (typeof $.magnificPopup !== 'undefined') {
let eventTimeout = null;
@@ -198,22 +121,11 @@ document.addEventListener('DOMContentLoaded', () => {
if (mfpContent) {
safeGODAMInit(mfpContent);
}
-
- // Also check for RTMedia changes
- checkRTMediaIdChange();
-
eventTimeout = null;
}, 250);
};
- $(document).on('mfpOpen mfpChange mfpBeforeChange', handleMagnificEvent);
-
- // Handle navigation events specifically
- $(document).on('mfpNext mfpPrev', () => {
- setTimeout(() => {
- checkRTMediaIdChange();
- }, 300);
- });
+ $(document).on('mfpOpen mfpChange', handleMagnificEvent);
}
if (typeof $ !== 'undefined') {
@@ -222,12 +134,9 @@ document.addEventListener('DOMContentLoaded', () => {
clearTimeout(popupInitializationTimeout);
popupInitializationTimeout = null;
}
- // Reset RTMedia tracking on close
- currentRTMediaId = null;
});
}
- // Enhanced Video Observer with RTMedia support
const videoObserver = new MutationObserver((mutations) => {
for (const mutation of mutations) {
mutation.addedNodes.forEach((node) => {
@@ -244,15 +153,6 @@ document.addEventListener('DOMContentLoaded', () => {
}
}
}
-
- // Check for RTMedia elements specifically
- const rtmediaElement = node.id && node.id.startsWith('rtmedia-media-') ?
- node :
- node.querySelector && node.querySelector('[id^="rtmedia-media-"]');
-
- if (rtmediaElement) {
- setTimeout(checkRTMediaIdChange, 100);
- }
}
});
}
@@ -262,50 +162,4 @@ document.addEventListener('DOMContentLoaded', () => {
childList: true,
subtree: true
});
-
- // Additional RTMedia-specific observer for DOM changes
- const rtmediaObserver = new MutationObserver((mutations) => {
- let hasRTMediaChanges = false;
-
- for (const mutation of mutations) {
- // Check for changes in elements with RTMedia IDs
- if (mutation.target.id && mutation.target.id.startsWith('rtmedia-media-')) {
- hasRTMediaChanges = true;
- break;
- }
-
- // Check added/removed nodes for RTMedia elements
- const checkNodes = (nodes) => {
- for (const node of nodes) {
- if (node.nodeType === 1) {
- if ((node.id && node.id.startsWith('rtmedia-media-')) ||
- (node.querySelector && node.querySelector('[id^="rtmedia-media-"]'))) {
- hasRTMediaChanges = true;
- return true;
- }
- }
- }
- return false;
- };
-
- if (checkNodes(mutation.addedNodes) || checkNodes(mutation.removedNodes)) {
- break;
- }
- }
-
- if (hasRTMediaChanges) {
- setTimeout(checkRTMediaIdChange, 150);
- }
- });
-
- // Observe the document for RTMedia changes
- rtmediaObserver.observe(document.body, {
- childList: true,
- subtree: true,
- attributes: true,
- attributeFilter: ['id']
- });
-
- // Initialize RTMedia tracking on load
- setTimeout(checkRTMediaIdChange, 500);
});
diff --git a/app/assets/js/godam-integration.min.js b/app/assets/js/godam-integration.min.js
index 9dcb94323..cae38cf2e 100644
--- a/app/assets/js/godam-integration.min.js
+++ b/app/assets/js/godam-integration.min.js
@@ -1 +1 @@
-GODAMPlayer();const activityStream=document.querySelector("#buddypress #activity-stream");if(activityStream){new MutationObserver((e=>{for(const t of e)t.addedNodes.forEach((e=>{1===e.nodeType&&(e.matches(".activity")||e.matches(".groups"))&&requestAnimationFrame((()=>GODAMPlayer(e)))}))})).observe(activityStream,{childList:!0,subtree:!0})}document.addEventListener("DOMContentLoaded",(()=>{GODAMPlayer();const e=new WeakSet;let t=null;const o=t=>{if(!t)return void GODAMPlayer();if(e.has(t))return;t.querySelectorAll("[data-godam-initialized], .godam-player-initialized").length>0||(GODAMPlayer(t),e.add(t),t.setAttribute&&t.setAttribute("data-godam-processed","true"))},r=()=>{const r=document.querySelector('[id^="rtmedia-media-"]');if(r){const i=r.id;if(i!==t){t=i,console.log("RTMedia ID changed to:",i),e.delete(r);const d=r.closest(".mfp-content")||r;return d&&(d.removeAttribute("data-godam-processed"),e.delete(d),setTimeout((()=>{o(d)}),100)),!0}}return!1},i=document.querySelector("#buddypress #activity-stream");if(i){new MutationObserver((e=>{for(const t of e)t.addedNodes.forEach((e=>{1===e.nodeType&&e.matches(".activity")&&!e.hasAttribute("data-godam-processed")&&requestAnimationFrame((()=>o(e)))}))})).observe(i,{childList:!0,subtree:!0})}let d=null;if(new MutationObserver((e=>{let i=!1;for(const r of e)"attributes"===r.type&&r.target.id&&r.target.id.startsWith("rtmedia-media-")&&(i=!0),r.addedNodes.forEach((e=>{if(1===e.nodeType){let t=null;t=e.classList&&e.classList.contains("mfp-content")?e:e.querySelector(".mfp-content"),e.querySelector&&e.querySelector('[id^="rtmedia-media-"]')&&(i=!0),t&&!t.hasAttribute("data-godam-processed")&&(d&&clearTimeout(d),d=setTimeout((()=>{o(t),d=null}),300))}})),r.removedNodes.forEach((e=>{1===e.nodeType&&e.id&&e.id.startsWith("rtmedia-media-")&&t===e.id&&(t=null)}));i&&setTimeout(r,100)})).observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["id","class"]}),void 0!==$.magnificPopup){let e=null;const t=()=>{e&&clearTimeout(e),e=setTimeout((()=>{const t=document.querySelector(".mfp-content:not([data-godam-processed])");t&&o(t),r(),e=null}),250)};$(document).on("mfpOpen mfpChange mfpBeforeChange",t),$(document).on("mfpNext mfpPrev",(()=>{setTimeout((()=>{r()}),300)}))}"undefined"!=typeof $&&$(document).on("mfpClose",(function(){d&&(clearTimeout(d),d=null),t=null}));new MutationObserver((e=>{for(const t of e)t.addedNodes.forEach((e=>{if(1===e.nodeType){if(e.closest(".mfp-content")||e.classList&&e.classList.contains("mfp-content")){if(("VIDEO"===e.tagName?[e]:e.querySelectorAll("video")).length>0){const t=e.closest(".mfp-content")||e;t.hasAttribute("data-godam-processed")||requestAnimationFrame((()=>o(t)))}}(e.id&&e.id.startsWith("rtmedia-media-")?e:e.querySelector&&e.querySelector('[id^="rtmedia-media-"]'))&&setTimeout(r,100)}}))})).observe(document.body,{childList:!0,subtree:!0});new MutationObserver((e=>{let t=!1;for(const o of e){if(o.target.id&&o.target.id.startsWith("rtmedia-media-")){t=!0;break}const e=e=>{for(const o of e)if(1===o.nodeType&&(o.id&&o.id.startsWith("rtmedia-media-")||o.querySelector&&o.querySelector('[id^="rtmedia-media-"]')))return t=!0,!0;return!1};if(e(o.addedNodes)||e(o.removedNodes))break}t&&setTimeout(r,150)})).observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["id"]}),setTimeout(r,500)}));
\ No newline at end of file
+GODAMPlayer();const activityStream=document.querySelector("#buddypress #activity-stream");if(activityStream){new MutationObserver((e=>{for(const t of e)t.addedNodes.forEach((e=>{1===e.nodeType&&e.matches(".activity")&&requestAnimationFrame((()=>GODAMPlayer(e)))}))})).observe(activityStream,{childList:!0,subtree:!0})}document.addEventListener("DOMContentLoaded",(()=>{GODAMPlayer();const e=new WeakSet,t=t=>{if(!t)return void GODAMPlayer();if(e.has(t))return;t.querySelectorAll("[data-godam-initialized], .godam-player-initialized").length>0||(GODAMPlayer(t),e.add(t),t.setAttribute&&t.setAttribute("data-godam-processed","true"))},o=document.querySelector("#buddypress #activity-stream");if(o){new MutationObserver((e=>{for(const o of e)o.addedNodes.forEach((e=>{1===e.nodeType&&e.matches(".activity")&&!e.hasAttribute("data-godam-processed")&&requestAnimationFrame((()=>t(e)))}))})).observe(o,{childList:!0,subtree:!0})}let a=null;if(new MutationObserver((e=>{for(const o of e)o.addedNodes.forEach((e=>{if(1===e.nodeType){let o=null;o=e.classList&&e.classList.contains("mfp-content")?e:e.querySelector(".mfp-content"),o&&!o.hasAttribute("data-godam-processed")&&(a&&clearTimeout(a),a=setTimeout((()=>{t(o),a=null}),300))}}))})).observe(document.body,{childList:!0,subtree:!0}),void 0!==$.magnificPopup){let e=null;const o=()=>{e&&clearTimeout(e),e=setTimeout((()=>{const o=document.querySelector(".mfp-content:not([data-godam-processed])");o&&t(o),e=null}),250)};$(document).on("mfpOpen mfpChange",o)}"undefined"!=typeof $&&$(document).on("mfpClose",(function(){a&&(clearTimeout(a),a=null)}));new MutationObserver((e=>{for(const o of e)o.addedNodes.forEach((e=>{if(1===e.nodeType){if(e.closest(".mfp-content")||e.classList&&e.classList.contains("mfp-content")){if(("VIDEO"===e.tagName?[e]:e.querySelectorAll("video")).length>0){const o=e.closest(".mfp-content")||e;o.hasAttribute("data-godam-processed")||requestAnimationFrame((()=>t(o)))}}}}))})).observe(document.body,{childList:!0,subtree:!0})}));
\ No newline at end of file
From 328d631ca9f4be64185412c5c82a763919f47e92 Mon Sep 17 00:00:00 2001
From: krishana7911
Date: Mon, 2 Jun 2025 11:56:13 +0530
Subject: [PATCH 19/22] remove test function from the godam ajax script
---
app/assets/js/godam-ajax-refresh.js | 29 -------------------------
app/assets/js/godam-ajax-refresh.min.js | 2 +-
2 files changed, 1 insertion(+), 30 deletions(-)
diff --git a/app/assets/js/godam-ajax-refresh.js b/app/assets/js/godam-ajax-refresh.js
index a6692e2ec..52ddada66 100644
--- a/app/assets/js/godam-ajax-refresh.js
+++ b/app/assets/js/godam-ajax-refresh.js
@@ -273,32 +273,3 @@ document.addEventListener('DOMContentLoaded', () => {
});
});
});
-
-// Debug function to test AJAX connectivity
-function testAjaxConnection() {
- if (typeof GodamAjax === 'undefined') {
- console.error('GodamAjax not defined');
- return;
- }
-
- fetch(GodamAjax.ajax_url, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded',
- },
- body: new URLSearchParams({
- action: 'heartbeat',
- nonce: GodamAjax.nonce,
- }),
- })
- .then(response => response.json())
- .then(data => {
- console.log('AJAX connection test:', data);
- })
- .catch(error => {
- console.error('AJAX connection test failed:', error);
- });
-}
-
-// Uncomment to test AJAX connection
-// testAjaxConnection();
diff --git a/app/assets/js/godam-ajax-refresh.min.js b/app/assets/js/godam-ajax-refresh.min.js
index adff27638..25ba334bc 100644
--- a/app/assets/js/godam-ajax-refresh.min.js
+++ b/app/assets/js/godam-ajax-refresh.min.js
@@ -1 +1 @@
-function refreshSingleComment(e,t){if(!e||!t)return;if("undefined"==typeof GodamAjax||!GodamAjax.ajax_url||!GodamAjax.nonce)return;if(!document.contains(t))return;if(t.classList.contains("refreshing"))return;t.classList.add("refreshing");const o=new AbortController,n=setTimeout((()=>{o.abort()}),15e3);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:e,nonce:GodamAjax.nonce}),signal:o.signal}).then((e=>{if(clearTimeout(n),!e.ok)throw new Error(`HTTP ${e.status}: ${e.statusText}`);const t=e.headers.get("content-type");if(!t||!t.includes("application/json"))throw new Error("Server returned non-JSON response");return e.json()})).then((o=>{if(o&&o.success&&o.data&&o.data.html)handleSuccessfulResponse(o,e,t);else{const n=o&&o.data?o.data:"Unknown AJAX error";console.error("AJAX error:",n),setTimeout((()=>{retryRefreshComment(e,t,1)}),2e3)}})).catch((o=>{clearTimeout(n),console.error("Fetch error:",o),"AbortError"===o.name?console.error("Request timed out"):o.message.includes("Failed to fetch")&&(console.error("Network error - possible connectivity issue"),setTimeout((()=>{retryRefreshComment(e,t,1)}),3e3))})).finally((()=>{clearTimeout(n),document.contains(t)&&t.classList.remove("refreshing")}))}function retryRefreshComment(e,t,o=1){if(o>2)return void console.error(`Failed to refresh comment ${e} after 2 retries`);if(!document.contains(t))return;const n=1e3*Math.pow(2,o);setTimeout((()=>{t.classList.remove("refreshing"),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:e,nonce:GodamAjax.nonce,retry:o.toString()})}).then((e=>e.json())).then((n=>{n&&n.success&&n.data&&n.data.html?handleSuccessfulResponse(n,e,t):o<2&&retryRefreshComment(e,t,o+1)})).catch((n=>{console.error(`Retry ${o} failed:`,n),o<2&&retryRefreshComment(e,t,o+1)}))}),n)}function handleSuccessfulResponse(e,t,o){try{const n=o.closest(".activity-item");if(!n)return void console.error("Could not find parent activity item");const r=n.id.replace("activity-","");let a=document.querySelector(`#activity-${r} .activity-comments`);a||(a=document.createElement("ul"),a.classList.add("activity-comments"),n.appendChild(a));const c=document.createElement("div");c.innerHTML=e.data.html.trim();const i=c.firstElementChild;if(i){if(a.appendChild(i),o.parentNode&&document.contains(o)&&o.parentNode.removeChild(o),"function"==typeof GODAMPlayer)try{GODAMPlayer(i)}catch(e){console.error("GODAMPlayer initialization failed:",e)}document.dispatchEvent(new CustomEvent("commentRefreshed",{detail:{commentId:t,node:i}}))}else console.error("No valid comment node found in response HTML")}catch(e){console.error("Error handling successful response:",e)}}function testAjaxConnection(){"undefined"!=typeof GodamAjax?fetch(GodamAjax.ajax_url,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({action:"heartbeat",nonce:GodamAjax.nonce})}).then((e=>e.json())).then((e=>{console.log("AJAX connection test:",e)})).catch((e=>{console.error("AJAX connection test failed:",e)})):console.error("GodamAjax not defined")}document.addEventListener("DOMContentLoaded",(()=>{const e=document.querySelectorAll(".activity-comments");0!==e.length&&e.forEach((e=>{if("function"==typeof GODAMPlayer)try{GODAMPlayer(e)}catch(e){console.error("GODAMPlayer initialization failed:",e)}const t=function(e,t){let o;return function(...n){clearTimeout(o),o=setTimeout((()=>{clearTimeout(o),e(...n)}),t)}}((e=>{e.forEach((e=>{e.addedNodes.forEach((e=>{if(1===e.nodeType&&e.matches&&e.matches('li[id^="acomment-"]')){if("function"==typeof GODAMPlayer)try{GODAMPlayer(e)}catch(e){console.error("GODAMPlayer initialization failed:",e)}const t=e.id.replace("acomment-","");setTimeout((()=>{document.contains(e)&&refreshSingleComment(t,e)}),250)}}))}))}),100);new MutationObserver(t).observe(e,{childList:!0,subtree:!0})}))}));
\ No newline at end of file
+function refreshSingleComment(e,t){if(!e||!t)return;if("undefined"==typeof GodamAjax||!GodamAjax.ajax_url||!GodamAjax.nonce)return;if(!document.contains(t))return;if(t.classList.contains("refreshing"))return;t.classList.add("refreshing");const o=new AbortController,n=setTimeout((()=>{o.abort()}),15e3);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:e,nonce:GodamAjax.nonce}),signal:o.signal}).then((e=>{if(clearTimeout(n),!e.ok)throw new Error(`HTTP ${e.status}: ${e.statusText}`);const t=e.headers.get("content-type");if(!t||!t.includes("application/json"))throw new Error("Server returned non-JSON response");return e.json()})).then((o=>{if(o&&o.success&&o.data&&o.data.html)handleSuccessfulResponse(o,e,t);else{const n=o&&o.data?o.data:"Unknown AJAX error";console.error("AJAX error:",n),setTimeout((()=>{retryRefreshComment(e,t,1)}),2e3)}})).catch((o=>{clearTimeout(n),console.error("Fetch error:",o),"AbortError"===o.name?console.error("Request timed out"):o.message.includes("Failed to fetch")&&(console.error("Network error - possible connectivity issue"),setTimeout((()=>{retryRefreshComment(e,t,1)}),3e3))})).finally((()=>{clearTimeout(n),document.contains(t)&&t.classList.remove("refreshing")}))}function retryRefreshComment(e,t,o=1){if(o>2)return void console.error(`Failed to refresh comment ${e} after 2 retries`);if(!document.contains(t))return;const n=1e3*Math.pow(2,o);setTimeout((()=>{t.classList.remove("refreshing"),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:e,nonce:GodamAjax.nonce,retry:o.toString()})}).then((e=>e.json())).then((n=>{n&&n.success&&n.data&&n.data.html?handleSuccessfulResponse(n,e,t):o<2&&retryRefreshComment(e,t,o+1)})).catch((n=>{console.error(`Retry ${o} failed:`,n),o<2&&retryRefreshComment(e,t,o+1)}))}),n)}function handleSuccessfulResponse(e,t,o){try{const n=o.closest(".activity-item");if(!n)return void console.error("Could not find parent activity item");const r=n.id.replace("activity-","");let a=document.querySelector(`#activity-${r} .activity-comments`);a||(a=document.createElement("ul"),a.classList.add("activity-comments"),n.appendChild(a));const c=document.createElement("div");c.innerHTML=e.data.html.trim();const i=c.firstElementChild;if(i){if(a.appendChild(i),o.parentNode&&document.contains(o)&&o.parentNode.removeChild(o),"function"==typeof GODAMPlayer)try{GODAMPlayer(i)}catch(e){console.error("GODAMPlayer initialization failed:",e)}document.dispatchEvent(new CustomEvent("commentRefreshed",{detail:{commentId:t,node:i}}))}else console.error("No valid comment node found in response HTML")}catch(e){console.error("Error handling successful response:",e)}}document.addEventListener("DOMContentLoaded",(()=>{const e=document.querySelectorAll(".activity-comments");0!==e.length&&e.forEach((e=>{if("function"==typeof GODAMPlayer)try{GODAMPlayer(e)}catch(e){console.error("GODAMPlayer initialization failed:",e)}const t=function(e,t){let o;return function(...n){clearTimeout(o),o=setTimeout((()=>{clearTimeout(o),e(...n)}),t)}}((e=>{e.forEach((e=>{e.addedNodes.forEach((e=>{if(1===e.nodeType&&e.matches&&e.matches('li[id^="acomment-"]')){if("function"==typeof GODAMPlayer)try{GODAMPlayer(e)}catch(e){console.error("GODAMPlayer initialization failed:",e)}const t=e.id.replace("acomment-","");setTimeout((()=>{document.contains(e)&&refreshSingleComment(t,e)}),250)}}))}))}),100);new MutationObserver(t).observe(e,{childList:!0,subtree:!0})}))}));
\ No newline at end of file
From 485acab0428c5df44640bd7cecb4006f7798bf77 Mon Sep 17 00:00:00 2001
From: krishana7911
Date: Mon, 2 Jun 2025 12:32:29 +0530
Subject: [PATCH 20/22] update re-initialization to fix render in magnific
popup
---
app/assets/js/godam-integration.js | 238 +++++++++----------------
app/assets/js/godam-integration.min.js | 2 +-
2 files changed, 81 insertions(+), 159 deletions(-)
diff --git a/app/assets/js/godam-integration.js b/app/assets/js/godam-integration.js
index 1cf048c80..f30b940d6 100644
--- a/app/assets/js/godam-integration.js
+++ b/app/assets/js/godam-integration.js
@@ -1,165 +1,87 @@
/**
- * This script ensures GODAMPlayer is initialized dynamically across:
- * - BuddyPress activity streams updated via AJAX.
- * - Magnific Popup content.
- * - Any newly added video elements in the DOM (e.g., via infinite scroll or modals).
+ * GODAMPlayer Integration Script
*
- * It uses MutationObservers and event listeners to watch for new content and
- * initializes the player only when necessary, avoiding duplicate setups.
+ * Initializes GODAMPlayer safely across the site, including:
+ * - Initial load
+ * - Popups using Magnific Popup
+ * - Dynamically added elements (e.g., via BuddyPress activities)
+ *
+ * Ensures robust handling of null or invalid elements and minimizes the risk of runtime errors.
*/
-GODAMPlayer();
-
-const activityStream = document.querySelector('#buddypress #activity-stream');
-if (activityStream) {
- const observer = new MutationObserver((mutations) => {
- for (const mutation of mutations) {
- mutation.addedNodes.forEach((node) => {
- if (node.nodeType === 1 && node.matches('.activity')) {
- requestAnimationFrame(() => GODAMPlayer(node));
- }
- });
- }
- });
- observer.observe(activityStream, { childList: true, subtree: true });
-}
+const safeGODAMPlayer = (element = null) => {
+ try {
+ if (element) {
+ if (element.nodeType === 1 && element.isConnected) {
+ GODAMPlayer(element);
+ } else {
+ GODAMPlayer();
+ }
+ } else {
+ GODAMPlayer();
+ }
+ return true;
+ } catch (error) {
+ return false;
+ }
+};
+
+// Initial load
+safeGODAMPlayer();
+
+// Debounced popup initializer
+let popupInitTimeout = null;
+const initializePopupVideos = () => {
+ clearTimeout(popupInitTimeout);
+ popupInitTimeout = setTimeout(() => {
+ const popupContent = document.querySelector('.mfp-content');
+ if (popupContent) {
+ const videos = popupContent.querySelectorAll('video');
+ if (videos.length > 0) {
+ if (!safeGODAMPlayer(popupContent)) {
+ safeGODAMPlayer();
+ }
+ }
+ }
+ }, 200);
+};
document.addEventListener('DOMContentLoaded', () => {
- GODAMPlayer();
-
- const initializedElements = new WeakSet();
-
- const safeGODAMInit = (element) => {
- if (!element) {
- GODAMPlayer();
- return;
- }
-
- if (initializedElements.has(element)) {
- return;
- }
-
- const existingPlayers = element.querySelectorAll('[data-godam-initialized], .godam-player-initialized');
- if (existingPlayers.length > 0) {
- return;
- }
-
- GODAMPlayer(element);
- initializedElements.add(element);
- if (element.setAttribute) {
- element.setAttribute('data-godam-processed', 'true');
- }
- };
-
- const activityStream = document.querySelector('#buddypress #activity-stream');
- if (activityStream) {
- const observer = new MutationObserver((mutations) => {
- for (const mutation of mutations) {
- mutation.addedNodes.forEach((node) => {
- if (
- node.nodeType === 1 &&
- node.matches('.activity') &&
- !node.hasAttribute('data-godam-processed')
- ) {
- requestAnimationFrame(() => safeGODAMInit(node));
- }
- });
- }
- });
-
- observer.observe(activityStream, { childList: true, subtree: true });
- }
-
- let popupInitializationTimeout = null;
-
- const setupMagnificObserver = () => {
- const magnificObserver = new MutationObserver((mutations) => {
- for (const mutation of mutations) {
- mutation.addedNodes.forEach((node) => {
- if (node.nodeType === 1) {
- let mfpContent = null;
-
- if (node.classList && node.classList.contains('mfp-content')) {
- mfpContent = node;
- } else {
- mfpContent = node.querySelector('.mfp-content');
- }
-
- if (mfpContent && !mfpContent.hasAttribute('data-godam-processed')) {
- if (popupInitializationTimeout) {
- clearTimeout(popupInitializationTimeout);
- }
-
- popupInitializationTimeout = setTimeout(() => {
- safeGODAMInit(mfpContent);
- popupInitializationTimeout = null;
- }, 300);
- }
- }
- });
- }
- });
-
- magnificObserver.observe(document.body, {
- childList: true,
- subtree: true
- });
- };
-
- setupMagnificObserver();
-
- if (typeof $.magnificPopup !== 'undefined') {
- let eventTimeout = null;
-
- const handleMagnificEvent = () => {
- if (eventTimeout) {
- clearTimeout(eventTimeout);
- }
-
- eventTimeout = setTimeout(() => {
- const mfpContent = document.querySelector('.mfp-content:not([data-godam-processed])');
- if (mfpContent) {
- safeGODAMInit(mfpContent);
- }
- eventTimeout = null;
- }, 250);
- };
-
- $(document).on('mfpOpen mfpChange', handleMagnificEvent);
- }
-
- if (typeof $ !== 'undefined') {
- $(document).on('mfpClose', function () {
- if (popupInitializationTimeout) {
- clearTimeout(popupInitializationTimeout);
- popupInitializationTimeout = null;
- }
- });
- }
-
- const videoObserver = new MutationObserver((mutations) => {
- for (const mutation of mutations) {
- mutation.addedNodes.forEach((node) => {
- if (node.nodeType === 1) {
- const isInMfpContent = node.closest('.mfp-content') ||
- (node.classList && node.classList.contains('mfp-content'));
-
- if (isInMfpContent) {
- const videos = node.tagName === 'VIDEO' ? [node] : node.querySelectorAll('video');
- if (videos.length > 0) {
- const container = node.closest('.mfp-content') || node;
- if (!container.hasAttribute('data-godam-processed')) {
- requestAnimationFrame(() => safeGODAMInit(container));
- }
- }
- }
- }
- });
- }
- });
-
- videoObserver.observe(document.body, {
- childList: true,
- subtree: true
- });
+ safeGODAMPlayer();
+
+ const observer = new MutationObserver((mutations) => {
+ for (const mutation of mutations) {
+ for (const node of mutation.addedNodes) {
+ if (node.nodeType === 1) {
+ const isPopup = node.classList?.contains('mfp-content') ||
+ node.querySelector?.('.mfp-content');
+ const hasVideos = node.tagName === 'VIDEO' ||
+ node.querySelector?.('video');
+
+ if (isPopup || (hasVideos && node.closest('.mfp-content'))) {
+ initializePopupVideos();
+ }
+
+ if (node.classList?.contains('activity')) {
+ setTimeout(() => safeGODAMPlayer(node), 100);
+ }
+ }
+ }
+ }
+ });
+
+ observer.observe(document.body, {
+ childList: true,
+ subtree: true
+ });
+
+ if (typeof $ !== 'undefined' && $.magnificPopup) {
+ $(document).on('mfpOpen mfpChange', () => {
+ initializePopupVideos();
+ });
+
+ $(document).on('mfpOpen', () => {
+ setTimeout(initializePopupVideos, 500);
+ });
+ }
});
diff --git a/app/assets/js/godam-integration.min.js b/app/assets/js/godam-integration.min.js
index cae38cf2e..6d059872d 100644
--- a/app/assets/js/godam-integration.min.js
+++ b/app/assets/js/godam-integration.min.js
@@ -1 +1 @@
-GODAMPlayer();const activityStream=document.querySelector("#buddypress #activity-stream");if(activityStream){new MutationObserver((e=>{for(const t of e)t.addedNodes.forEach((e=>{1===e.nodeType&&e.matches(".activity")&&requestAnimationFrame((()=>GODAMPlayer(e)))}))})).observe(activityStream,{childList:!0,subtree:!0})}document.addEventListener("DOMContentLoaded",(()=>{GODAMPlayer();const e=new WeakSet,t=t=>{if(!t)return void GODAMPlayer();if(e.has(t))return;t.querySelectorAll("[data-godam-initialized], .godam-player-initialized").length>0||(GODAMPlayer(t),e.add(t),t.setAttribute&&t.setAttribute("data-godam-processed","true"))},o=document.querySelector("#buddypress #activity-stream");if(o){new MutationObserver((e=>{for(const o of e)o.addedNodes.forEach((e=>{1===e.nodeType&&e.matches(".activity")&&!e.hasAttribute("data-godam-processed")&&requestAnimationFrame((()=>t(e)))}))})).observe(o,{childList:!0,subtree:!0})}let a=null;if(new MutationObserver((e=>{for(const o of e)o.addedNodes.forEach((e=>{if(1===e.nodeType){let o=null;o=e.classList&&e.classList.contains("mfp-content")?e:e.querySelector(".mfp-content"),o&&!o.hasAttribute("data-godam-processed")&&(a&&clearTimeout(a),a=setTimeout((()=>{t(o),a=null}),300))}}))})).observe(document.body,{childList:!0,subtree:!0}),void 0!==$.magnificPopup){let e=null;const o=()=>{e&&clearTimeout(e),e=setTimeout((()=>{const o=document.querySelector(".mfp-content:not([data-godam-processed])");o&&t(o),e=null}),250)};$(document).on("mfpOpen mfpChange",o)}"undefined"!=typeof $&&$(document).on("mfpClose",(function(){a&&(clearTimeout(a),a=null)}));new MutationObserver((e=>{for(const o of e)o.addedNodes.forEach((e=>{if(1===e.nodeType){if(e.closest(".mfp-content")||e.classList&&e.classList.contains("mfp-content")){if(("VIDEO"===e.tagName?[e]:e.querySelectorAll("video")).length>0){const o=e.closest(".mfp-content")||e;o.hasAttribute("data-godam-processed")||requestAnimationFrame((()=>t(o)))}}}}))})).observe(document.body,{childList:!0,subtree:!0})}));
\ No newline at end of file
+const safeGODAMPlayer=(e=null)=>{try{return e&&1===e.nodeType&&e.isConnected?GODAMPlayer(e):GODAMPlayer(),!0}catch(e){return!1}};safeGODAMPlayer();let popupInitTimeout=null;const initializePopupVideos=()=>{clearTimeout(popupInitTimeout),popupInitTimeout=setTimeout((()=>{const e=document.querySelector(".mfp-content");if(e){e.querySelectorAll("video").length>0&&(safeGODAMPlayer(e)||safeGODAMPlayer())}}),200)};document.addEventListener("DOMContentLoaded",(()=>{safeGODAMPlayer();new MutationObserver((e=>{for(const t of e)for(const e of t.addedNodes)if(1===e.nodeType){const t=e.classList?.contains("mfp-content")||e.querySelector?.(".mfp-content"),o="VIDEO"===e.tagName||e.querySelector?.("video");(t||o&&e.closest(".mfp-content"))&&initializePopupVideos(),e.classList?.contains("activity")&&setTimeout((()=>safeGODAMPlayer(e)),100)}})).observe(document.body,{childList:!0,subtree:!0}),"undefined"!=typeof $&&$.magnificPopup&&($(document).on("mfpOpen mfpChange",(()=>{initializePopupVideos()})),$(document).on("mfpOpen",(()=>{setTimeout(initializePopupVideos,500)})))}));
\ No newline at end of file
From 84ebb6939fae74c30f27bc6fc0777654a7f9c6e6 Mon Sep 17 00:00:00 2001
From: krishana7911
Date: Mon, 2 Jun 2025 12:55:04 +0530
Subject: [PATCH 21/22] fix phpcs for indent instead of spaces
---
app/main/controllers/api/RTMediaJsonApi.php | 66 +++++++++----------
.../template/rtmedia-functions.php | 40 +++++------
index.php | 6 +-
3 files changed, 56 insertions(+), 56 deletions(-)
diff --git a/app/main/controllers/api/RTMediaJsonApi.php b/app/main/controllers/api/RTMediaJsonApi.php
index 8186ed542..a5d402de9 100644
--- a/app/main/controllers/api/RTMediaJsonApi.php
+++ b/app/main/controllers/api/RTMediaJsonApi.php
@@ -163,8 +163,8 @@ public function __construct() {
add_action( 'wp_ajax_rtmedia_api', array( $this, 'rtmedia_api_process_request' ) );
if ( defined( 'RTMEDIA_GODAM_ACTIVE' ) && RTMEDIA_GODAM_ACTIVE ) {
- add_action( 'rest_api_init', [ $this, 'register_rest_pre_dispatch_filter' ] );
- }
+ add_action( 'rest_api_init', [ $this, 'register_rest_pre_dispatch_filter' ] );
+ }
}
/**
@@ -1475,37 +1475,37 @@ public function api_new_media_upload_dir( $args ) {
}
/**
- * Registers the rest_pre_dispatch filter during rest_api_init.
- */
- public function register_rest_pre_dispatch_filter() {
- add_filter( 'rest_pre_dispatch', [ $this, 'handle_rest_pre_dispatch' ], 10, 3 );
- }
+ * Registers the rest_pre_dispatch filter during rest_api_init.
+ */
+ public function register_rest_pre_dispatch_filter() {
+ add_filter( 'rest_pre_dispatch', [ $this, 'handle_rest_pre_dispatch' ], 10, 3 );
+ }
/**
- * Callback for rest_pre_dispatch filter.
- *
- * @param mixed $result Result to return instead of the request. Default null to continue with request.
- * @param WP_REST_Server $server Server instance.
- * @param WP_REST_Request $request Request object.
- *
- * @return mixed Modified result or original $result.
- */
- public function handle_rest_pre_dispatch( $result, $server, $request ) {
- $route = $request->get_route();
- $method = $request->get_method();
-
- if ( 'GET' === $method && preg_match( '#^/wp/v2/media/(\d+)$#', $route, $matches ) ) {
- $media_id = (int) $matches[1];
- $post = get_post( $media_id );
-
- if ( $post && 'attachment' === $post->post_type ) {
- $controller = new WP_REST_Attachments_Controller( 'attachment' );
- $response = $controller->prepare_item_for_response( $post, $request );
-
- return rest_ensure_response( $response );
- }
- }
-
- return $result;
- }
+ * Callback for rest_pre_dispatch filter.
+ *
+ * @param mixed $result Result to return instead of the request. Default null to continue with request.
+ * @param WP_REST_Server $server Server instance.
+ * @param WP_REST_Request $request Request object.
+ *
+ * @return mixed Modified result or original $result.
+ */
+ public function handle_rest_pre_dispatch( $result, $server, $request ) {
+ $route = $request->get_route();
+ $method = $request->get_method();
+
+ if ( 'GET' === $method && preg_match( '#^/wp/v2/media/(\d+)$#', $route, $matches ) ) {
+ $media_id = (int) $matches[1];
+ $post = get_post( $media_id );
+
+ if ( $post && 'attachment' === $post->post_type ) {
+ $controller = new WP_REST_Attachments_Controller( 'attachment' );
+ $response = $controller->prepare_item_for_response( $post, $request );
+
+ return rest_ensure_response( $response );
+ }
+ }
+
+ return $result;
+ }
}
diff --git a/app/main/controllers/template/rtmedia-functions.php b/app/main/controllers/template/rtmedia-functions.php
index 6652e85b7..a2c53b6b7 100644
--- a/app/main/controllers/template/rtmedia-functions.php
+++ b/app/main/controllers/template/rtmedia-functions.php
@@ -5430,26 +5430,26 @@ function handle_get_single_activity_comment_html() {
* Enqueuing here guarantees consistent script loading regardless of Godam’s activation status.
*/
function enqueue_rtmedia_magnific_popup_script() {
- $handle = 'rtmedia-magnific-popup';
- $script_src = RTMEDIA_URL . 'app/assets/js/vendors/magnific-popup.js';
- $version = RTMEDIA_VERSION;
- $in_footer = true;
-
- // Deregister the script if already registered or enqueued to prevent conflicts
- if (wp_script_is($handle, 'registered') || wp_script_is($handle, 'enqueued')) {
- wp_deregister_script($handle);
- }
-
- // Determine dependencies based on whether Godam integration is active
- $dependencies = [];
-
- // If Godam plugin is NOT active, add dependencies for jQuery and mediaelement
- if (!defined('RTMEDIA_GODAM_ACTIVE') || !RTMEDIA_GODAM_ACTIVE) {
- $dependencies = ['jquery', 'rt-mediaelement-wp'];
- }
-
- // Enqueue the Magnific Popup script with the appropriate dependencies
- wp_enqueue_script($handle, $script_src, $dependencies, $version, $in_footer);
+ $handle = 'rtmedia-magnific-popup';
+ $script_src = RTMEDIA_URL . 'app/assets/js/vendors/magnific-popup.js';
+ $version = RTMEDIA_VERSION;
+ $in_footer = true;
+
+ // Deregister the script if already registered or enqueued to prevent conflicts
+ if (wp_script_is($handle, 'registered') || wp_script_is($handle, 'enqueued')) {
+ wp_deregister_script($handle);
+ }
+
+ // Determine dependencies based on whether Godam integration is active
+ $dependencies = [];
+
+ // If Godam plugin is NOT active, add dependencies for jQuery and mediaelement
+ if (!defined('RTMEDIA_GODAM_ACTIVE') || !RTMEDIA_GODAM_ACTIVE) {
+ $dependencies = ['jquery', 'rt-mediaelement-wp'];
+ }
+
+ // Enqueue the Magnific Popup script with the appropriate dependencies
+ wp_enqueue_script($handle, $script_src, $dependencies, $version, $in_footer);
}
add_action('wp_enqueue_scripts', 'enqueue_rtmedia_magnific_popup_script');
diff --git a/index.php b/index.php
index cc6d7e95c..bfc7671ee 100644
--- a/index.php
+++ b/index.php
@@ -61,14 +61,14 @@
* function is available.
*/
if ( ! function_exists( 'is_plugin_active' ) ) {
- require_once ABSPATH . 'wp-admin/includes/plugin.php';
+ require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
if ( ! defined( 'RTMEDIA_GODAM_ACTIVE' ) ) {
- /**
+ /**
* Check if Godam plugin is active and set constant accordingly.
*/
- define( 'RTMEDIA_GODAM_ACTIVE', is_plugin_active( 'godam/godam.php' ) );
+ define( 'RTMEDIA_GODAM_ACTIVE', is_plugin_active( 'godam/godam.php' ) );
}
/**
From 84aa91a52f904f1ae0378c70a2ce2a56c997fb88 Mon Sep 17 00:00:00 2001
From: krishana7911
Date: Mon, 2 Jun 2025 15:41:05 +0530
Subject: [PATCH 22/22] Version update v4.7.0
---
README.md | 12 ++++++++++++
index.php | 4 ++--
readme.txt | 19 +++++++++++++++++--
3 files changed, 31 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
index c58967c00..70ff3f11c 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/index.php b/index.php
index bfc7671ee..558567272 100644
--- a/index.php
+++ b/index.php
@@ -3,7 +3,7 @@
* Plugin Name: rtMedia for WordPress, BuddyPress and bbPress
* Plugin URI: https://rtmedia.io/?utm_source=dashboard&utm_medium=plugin&utm_campaign=buddypress-media
* Description: This plugin adds missing media rich features like photos, videos and audio uploading to BuddyPress which are essential if you are building social network, seriously!
- * Version: 4.6.23
+ * Version: 4.7.0
* Author: rtCamp
* Text Domain: buddypress-media
* Author URI: http://rtcamp.com/?utm_source=dashboard&utm_medium=plugin&utm_campaign=buddypress-media
@@ -19,7 +19,7 @@
/**
* The version of the plugin
*/
- define( 'RTMEDIA_VERSION', '4.6.23' );
+ define( 'RTMEDIA_VERSION', '4.7.0' );
}
if ( ! defined( 'RTMEDIA_PATH' ) ) {
diff --git a/readme.txt b/readme.txt
index 1b67646b4..b4ea9aeb8 100644
--- a/readme.txt
+++ b/readme.txt
@@ -4,8 +4,8 @@ Tags: BuddyPress, media, multimedia, album, audio, music, video, photo, upload,
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Requires at least: WordPress 4.1
-Tested up to: 6.8
-Stable tag: 4.6.23
+Tested up to: 6.8.1
+Stable tag: 4.7.0
Add albums, photo, audio/video upload, privacy, sharing, front-end uploads & more. All this works on mobile/tablets devices.
@@ -133,6 +133,18 @@ http://www.youtube.com/watch?v=dJrykKQGDcs
== Changelog ==
+= 4.7.0 [June 2, 2025] =
+
+* 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 [April 18, 2025] =
* Fixed
@@ -1922,6 +1934,9 @@ http://www.youtube.com/watch?v=dJrykKQGDcs
== Upgrade Notice ==
+= 4.7.0 =
+This update introduces comprehensive support for the GoDAM video player across rtMedia galleries and all BuddyPress components, including activity streams, groups, and forums.
+
= 4.6.23 =
rtMedia 4.6.23 with WP v6.8 compatibility, node package enhancements and updated admin notices.