PageSourceSearch

https://prepuce.com/wp-content/plugins/buddypress-media/app/assets/js/rtMedia.backbone.js?ver=4.6.21

js prepuce.com collected 2026-10-03 02:38:26 UTC 107,218 bytes, 3,032 lines download raw bytes

1var galleryObj;
2var nextpage = 2;
3var upload_sync = false;
4var activity_id = -1;
5var uploaderObj;
6var objUploadView;
7var rtmedia_load_template_flag = true;
8var rtmedia_add_media_button_post_update = false;
9
10
11jQuery( document ).ready( function () {
12
13	// Need to pass the object[key] as global variable.
14	if ( 'object' === typeof rtmedia_backbone ) {
15		for ( var key in rtmedia_backbone ) {
16			window[key] = rtmedia_backbone[key];
17		}
18	}
19	if ( 'object' === typeof rtMedia_plupload ) {
20		for( var key in rtMedia_plupload ) {
21			window[key] = rtMedia_plupload[key];
22		}
23	}
24	if ( 'object' === typeof rtmedia_template ) {
25		for( var key in rtmedia_template ) {
26			window[key] = rtmedia_template[key];
27		}
28	}
29	if ( 'object' === typeof rtMedia_activity ) {
30		for( var key in rtMedia_activity ) {
31			window[key] = rtMedia_activity[key];
32		}
33	}
34	if ( 'object' === typeof rtmedia_bp ) {
35		for( var key in rtmedia_bp ) {
36			window[key] = rtmedia_bp[key];
37		}
38	}
39	if ( 'object' === typeof rtmedia_main ) {
40		for( var key in rtmedia_main ) {
41			window[key] = rtmedia_main[key];
42		}
43	}
44} );
45
46jQuery( function( $ ) {
47	/**
48	 * Issue 1059 fixed: negative comment count
49	 */
50	$( document ).ready( function () {
51		/**
52		 * Bind dynamic event on delete button to remove media ul
53		 */
54		$( '#activity-stream' ).on( 'click', '.acomment-delete', function () {
55			/**
56			 * get media ul
57			 */
58			let media_children = $( this ).closest('li').find( 'div.acomment-content ul.rtmedia-list' );
59			if ( media_children.length > 0 ) {
60				/**
61				 * remove ul if exists, so buddypress comment js doesn't get confused between media ul and child comment ul
62				 */
63				media_children.remove();
64			}
65		});
66
67		/**
68		 * Remove imageEdit.save function call and add it only when image is being modified in WP editor.
69		 */
70		$( '#rtmedia_media_single_edit .rtm-button-save' ).on( 'click', function() {
71			var $media_id = $( '#rtmedia-editor-media-id' ).val();
72			var $nonce = $( '#rtmedia-editor-nonce' ).val();
73			if ( 'undefined' === typeof $nonce || '' === $nonce.trim() || 'undefined' === typeof $media_id || '' === $media_id.trim() ) {
74				return;
75			}
76			$media_id = parseInt( $media_id );
77			$media_head = $( '#media-head-' + $media_id );
78			if ( ! $media_head.length || 'undefined' === typeof $media_head.css( 'display' ) || 'none' !== $media_head.css( 'display' ).trim() ) {
79				return;
80			}
81
82			imageEdit.save( $media_id, $nonce );
83		} );
84
85		/**
86		 * Reload page when rtmedia_update type of activity is edited.
87		 */
88		function filterBeaSaveSuccess() {
89			location.reload();
90		}
91		/**
92		 * Prefilters ajax call which saves edited activity content.
93		 * Needed with BuddyPress Edit Activity plugin.
94		 * https://wordpress.org/plugins/buddypress-edit-activity/
95		 */
96		$.ajaxPrefilter( function( options, originalOptions, jqXHR ) {
97			// Modify options, control originalOptions, store jqXHR, etc
98			try {
99				if ( null === originalOptions.data || typeof ( originalOptions.data ) === 'undefined' || typeof ( originalOptions.data.action ) === 'undefined' || 'buddypress-edit-activity-save' !== originalOptions.data.action ) {
100					return true;
101				}
102			} catch ( e ) {
103				return true;
104			}
105
106			if ( ! $( '#activity-' + originalOptions.data.activity_id ).hasClass( 'rtmedia_update' ) ) {
107				return;
108			}
109
110			// Change the callback function to our own function, which reloads the page.
111			originalOptions.success = filterBeaSaveSuccess;
112			options.success = filterBeaSaveSuccess;
113		} );
114	});
115	/**
116	 * End of issue 1059 fix
117	 */
118
119
120	var o_is_album, o_is_edit_allowed;
121	if ( typeof ( is_album ) == 'undefined' ) {
122		o_is_album = new Array( '' );
123	} else {
124		o_is_album = is_album;
125	}
126	if ( typeof ( is_edit_allowed ) == 'undefined' ) {
127		o_is_edit_allowed = new Array( '' );
128	} else {
129		o_is_edit_allowed = is_edit_allowed;
130	}
131
132	rtMedia = window.rtMedia || { };
133
134	rtMedia = window.rtMedia || { };
135
136	rtMedia.Context = Backbone.Model.extend( {
137		url: function() {
138			var url = rtmedia_media_slug + '/';
139
140			if ( ! upload_sync && nextpage > 0 ) {
141				url += 'pg/' + nextpage + '/';
142			}
143
144			return url;
145		},
146		defaults: {
147			'context': 'post',
148			'context_id': false
149		}
150	} );
151
152	rtMedia.Media = Backbone.Model.extend( {
153		defaults: {
154			'id': 0,
155			'blog_id': false,
156			'media_id': false,
157			'media_author': false,
158			'media_title': false,
159			'album_id': false,
160			'media_type': 'photo',
161			'activity_id': false,
162			'privacy': 0,
163			'views': 0,
164			'downloads': 0,
165			'ratings_average': 0,
166			'ratings_total': 0,
167			'ratings_count': 0,
168			'likes': 0,
169			'dislikes': 0,
170			'guid': false,
171			'width': 0,
172			'height': 0,
173			'rt_permalink': false,
174			'duration': '0:00'
175			//"next": -1,
176			//"prev": -1
177		}
178
179	} );
180
181	rtMedia.Gallery = Backbone.Collection.extend( {
182		model: rtMedia.Media,
183		url: function() {
184			var temp = window.location.pathname;
185			var url = '';
186			if ( temp.indexOf( '/' + rtmedia_media_slug + '/' ) == -1 ) {
187				url = rtmedia_media_slug + '/';
188			} else {
189				if ( temp.indexOf( 'pg/' ) == -1 ) {
190					url = temp;
191				} else {
192					url = window.location.pathname.substr( 0, window.location.pathname.lastIndexOf( 'pg/' ) );
193				}
194			}
195			if ( ! upload_sync && nextpage >= 1 ) {
196				if ( url.substr( url.length - 1 ) != '/' ) {
197					url += '/';
198				}
199
200				url += 'pg/' + nextpage + '/';
201			}
202
203			return url;
204		},
205		getNext: function( page, el, element) {
206
207			if ( jQuery( '.rtmedia-no-media-found' ).length > 0 ) {
208				var rtmediaListUl = jQuery( '<ul/>', {
209					'class': 'rtmedia-list rtmedia-list-media rtm-pro-allow-action',
210				});
211				jQuery( '.rtmedia-no-media-found' ).replaceWith( rtmediaListUl );
212			}
213			that = this;
214			if ( rtmedia_load_template_flag == true ) {
215				if ( jQuery( '.rtmedia_gallery_wrapper' ).find( 'input[name=media_title]' ).length > 0 ) {
216					template_url += '&media_title=' + jQuery( '.rtmedia_gallery_wrapper' ).find( 'input[name=media_title]' ).val();
217				}
218				if ( jQuery( '.rtmedia_gallery_wrapper' ).find( 'input[name=lightbox]' ).length > 0 ) {
219					template_url += '&lightbox=' + jQuery( '.rtmedia_gallery_wrapper' ).find( 'input[name=lightbox]' ).val();
220				}
221				$( '#rtmedia-gallery-item-template' ).load( template_url, { backbone: true, is_album: o_is_album, is_edit_allowed: o_is_edit_allowed }, function() {
222					rtmedia_load_template_flag = false;
223					that.getNext( page, el, element);
224				} );
225			}
226
227			if ( ! rtmedia_load_template_flag ) {
228				var query = {
229					json: true,
230				};
231
232				//media search
233				if( check_condition( 'search' ) ) {
234					if ( '' !== $( '#media_search_input' ).val() ) {
235						var search = check_url( 'search' );
236						if ( search ) {
237							query.search = search;
238						}
239						if ( check_condition( 'search_by' ) ) {
240							var search_by = check_url( 'search_by' );
241							if ( search_by ) {
242								query.search_by = search_by;
243							}
244						}
245					}
246				}
247
248				query.rtmedia_page = nextpage;
249
250				if ( el == undefined ) {
251					el = jQuery( '.rtmedia-list' ).parent().parent();
252				}
253
254				if ( el != undefined ) {
255					if ( element != undefined ) {
256						$( element ).parent().parent().prevAll( 'input[type=hidden]' ).not( 'input[name=_wp_http_referer], input[name=rtmedia_media_delete_nonce], input[name=rtmedia_bulk_delete_nonce], input[name=bulk-action], input[name=rtmedia_create_album_nonce], input[name=rtmedia_media_nonce], input[name=rtmedia_upload_nonce], input[name=rtmedia_allow_upload_attribute]' ).each( function( e ) {
257							if ( $( this ).attr( 'name' ) ) {
258								query[ $( this ).attr( 'name' ) ] = $( this ).val();
259							}
260						} );
261					}
262
263					$( el ).find( 'input[type=hidden]' ).not( 'input[name=_wp_http_referer], input[name=rtmedia_media_delete_nonce], input[name=rtmedia_bulk_delete_nonce], input[name=bulk-action], input[name=rtmedia_create_album_nonce], input[name=rtmedia_media_nonce], input[name=rtmedia_upload_nonce], input[name=rtmedia_allow_upload_attribute]' ).each( function( e ) {
264						if ( $( this ).attr( 'name' ) ) {
265							query[ $( this ).attr( 'name' ) ] = $( this ).val();
266						}
267					} );
268				}
269				this.fetch( {
270					data: query,
271					success: function( model, response ) {
272
273						jQuery( '.rtm-media-loading' ).hide();
274						var list_el = '';
275
276						if ( typeof ( element ) === 'undefined' ) {
277							if ( jQuery( el ).find( '.rtmedia-list' ).length > 0 ) {
278								list_el = jQuery( el ).find( '.rtmedia-list' );
279							} else {
280								list_el = $( '.rtmedia-list' )[0];
281							}
282						} else {
283							list_el = element.parent().siblings( '.rtmedia-list' );
284						}
285						nextpage = response.next;
286
287						if ( nextpage < 1 ) {
288							if ( typeof el == 'object' ) {
289								jQuery( el ).find( '.rtmedia_next_prev' ).children( '#rtMedia-galary-next' ).hide();
290							}
291						}
292
293						rtMedia.gallery = {};
294						rtMedia.gallery.page = page;
295
296						var galleryViewObj = new rtMedia.GalleryView( {
297							collection: new rtMedia.Gallery( response.data ),
298							el: list_el,
299						} );
300						//Element.show();
301
302						// get current gallery container object
303						var current_gallery = galleryViewObj.$el.parents( '.rtmedia-container' );
304						var current_gallery_id = current_gallery.attr( 'id' );
305
306						rtMediaHook.call( 'rtmedia_after_gallery_load' );
307
308						jQuery( '#' + current_gallery_id + ' .rtmedia_next_prev .rtm-pagination' ).remove();
309						jQuery( '#' + current_gallery_id + ' .rtmedia_next_prev .clear' ).remove();
310						jQuery( '#' + current_gallery_id + ' .rtmedia_next_prev .rtm-media-loading' ).remove();
311						jQuery( '#' + current_gallery_id + ' .rtmedia_next_prev br' ).remove();
312						jQuery( '#' + current_gallery_id + ' .rtmedia_next_prev' ).append( response.pagination );
313
314						// Update the media count in user profile & group's media tab.
315						jQuery( '#user-media span, #media-groups-li #media span, #rtmedia-nav-item-all span' ).text( response.media_count.all_media_count );
316
317
318						// Update the count on sub navigations (Albums)
319						// jQuery( '#rtmedia-nav-item-albums span' ).text( response.media_count.albums_count );
320
321						// Update the count on sub navigations (Photo, Video & Music)
322						jQuery( '#rtmedia-nav-item-photo span' ).text( response.media_count.photos_count );
323						jQuery( '#rtmedia-nav-item-music span' ).text( response.media_count.music_count );
324						jQuery( '#rtmedia-nav-item-video span' ).text( response.media_count.videos_count );
325						jQuery( '#rtmedia-nav-item-document span' ).text( response.media_count.docs_count );
326						
327
328						if ( jQuery( 'li#rtm-url-upload' ).length === 0 ) {
329							jQuery( '#' + current_gallery_id + ' .rtmedia-list' ).css( { 'opacity': 1, 'height': 'auto', 'overflow': 'auto' } );
330							if ( rtMediaHook.call( 'rtmedia_js_uploader_slide_after_gallery_reload' ) ) {
331								jQuery( '#rtm-media-gallery-uploader' ).slideUp();
332							}
333						}
334					}
335				} );
336			}
337
338		},
339		reloadView: function( parent_el ) {
340			upload_sync = true;
341			nextpage = 1;
342			jQuery( '.rtmedia-container .rtmedia-list' ).css( 'opacity', '0.5' );
343			this.getNext( undefined, parent_el, undefined );
344		}
345	} );
346
347	rtMedia.MediaView = Backbone.View.extend( {
348		tagName: 'li',
349		className: 'rtmedia-list-item',
350		initialize: function() {
351			this.template = _.template( $( '#rtmedia-gallery-item-template' ).html() );
352			this.model.bind( 'change', this.render );
353			this.model.bind( 'remove', this.unrender );
354			this.render();
355		},
356		render: function() {
357			$( this.el ).html( this.template( this.model.toJSON() ) );
358			return this.el;
359		},
360		unrender: function() {
361			$( this.el ).remove();
362		},
363		remove: function() {
364			this.model.destroy();
365		}
366	} );
367
368	rtMedia.GalleryView = Backbone.View.extend( {
369		tagName: 'ul',
370		className: 'rtmedia-list',
371		initialize: function() {
372
373			this.template = _.template( $( '#rtmedia-gallery-item-template' ).html() );
374			this.render();
375		},
376		render: function() {
377
378			that = this;
379			var rtmedia_gallery_container_nodata = $( 'div[id^="rtmedia_gallery_container_"] .rtmedia-nodata' );
380			if ( upload_sync ) {
381				$( that.el ).html( '' );
382			}
383
384			if ( typeof ( rtmedia_load_more_or_pagination ) != 'undefined' && rtmedia_load_more_or_pagination == 'pagination' || ( 1 == rtMedia.gallery.page ) ) {
385				$( that.el ).html( '' );
386			}
387
388			// Remove no data found message if it's there.
389			if ( rtmedia_gallery_container_nodata.length > 0 ) {
390				rtmedia_gallery_container_nodata.remove();
391			}
392			if ( 0 === this.collection.length ) {
393				$( 'div[id^="rtmedia_gallery_container_"]' ).append( '<p class="rtmedia-nodata">' + rtmedia_no_media_found + '</p>' );
394			} else {
395				$.each( this.collection.toJSON(), function( key, media ) {
396					$( that.el ).append( that.template( media ) );
397				} );
398			}
399
400			if ( upload_sync ) {
401				upload_sync = false;
402			}
403			if ( nextpage > 1 ) {
404				$( that.el ).siblings( '.rtmedia_next_prev' ).children( '#rtMedia-galary-next' ).show();
405				//$("#rtMedia-galary-next").show();
406			}
407			if ( 'undefined' != typeof rtmedia_masonry_layout && 'true' == rtmedia_masonry_layout && 0 == jQuery( '.rtmedia-container .rtmedia-list.rtm-no-masonry' ).length ) {
408				rtm_masonry_reload( rtm_masonry_container );
409			}
410			$( '#media_fatch_loader' ).removeClass('load');
411		},
412		appendTo: function( media ) {
413			var mediaView = new rtMedia.MediaView( {
414				model: media
415			} );
416			$( this.el ).append( mediaView.render().el );
417		}
418	} );
419
420	galleryObj = new rtMedia.Gallery();
421
422	$( 'body' ).append( '<script id="rtmedia-gallery-item-template" type="text/template"></script>' );
423
424	$( document ).on( 'click', '#rtMedia-galary-next', function( e ) {
425		if ( jQuery( '.rtm-media-loading' ).length == 0 ) {
426			$( this ).before( '<div class=\'rtm-media-loading\'><img src=\'' + rMedia_loading_media + '\' /></div>' );
427		} else {
428			jQuery( '.rtm-media-loading' ).show();
429		}
430		$( this ).hide();
431		e.preventDefault();
432
433		//commented beacuse it was creating a problem when gallery shortcode was used with bulk edit
434		//galleryObj.getNext( nextpage, $( this ).parent().parent().parent(), $( this ) );
435
436		//Added beacuse it was creating a problem when gallery shortcode was used with bulk edit
437		var parent_object = $( this ).closest( '.rtmedia-container' ).parent();
438		galleryObj.getNext( nextpage, parent_object, $( this ) );
439	} );
440
441	/**
442	 * onClick Show all comment
443	 */
444	$( document ).on( 'click', '#rtmedia_show_all_comment', function() {
445		var show_comment = $( '#rtmedia_show_all_comment' ).parent().next();
446		$( show_comment ).each(function() {
447			$( this ).find('li').each(function() {
448				$(this).removeClass('hide');
449			} );
450		} );
451		$( this ).parent().remove();
452
453		/** Scroll function called */
454		rtMediaScrollComments();
455	} );
456
457		$( document ).on( 'keypress', '#rtmedia_go_to_num', function( e ) {
458			if ( e.keyCode == 13 ) {
459				e.preventDefault();
460
461				var current_gallery = $(this).parents( '.rtmedia-container' );
462				var current_gallery_id = current_gallery.attr( 'id' );
463
464
465				if ( $( '#' + current_gallery_id + ' .rtm-media-loading' ).length == 0 ) {
466					$( '#' + current_gallery_id + ' .rtm-pagination' ).before( '<div class=\'rtm-media-loading\'><img src=\'' + rMedia_loading_media + '\' /></div>' );
467				} else {
468					$( '#' + current_gallery_id + ' .rtm-media-loading' ).show();
469				}
470
471				if ( parseInt( $( '#' + current_gallery_id + ' #rtmedia_go_to_num' ).val() ) > parseInt( $( '#' + current_gallery_id + ' #rtmedia_last_page' ).val() ) ) {
472					nextpage = parseInt( $( '#' + current_gallery_id + ' #rtmedia_last_page' ).val() );
473				} else {
474					nextpage = parseInt( $( '#' + current_gallery_id + ' #rtmedia_go_to_num' ).val() );
475				}
476
477				var page_base_url = $( '#' + current_gallery_id + ' .rtmedia-p
477age-no .rtmedia-page-link' ).data( 'page-base-url' );
478				var href = page_base_url + nextpage;
479
480				change_rtBrowserAddressUrl( href, '' );
481
482				galleryObj.getNext( nextpage, $( this ).parents( '.rtmedia_gallery_wrapper' ), $( this ).parents( '.rtm-pagination' ) );
483				return false;
484			}
485		} );
486
487		$( document ).on( 'click', '.rtmedia-page-link', function( e ) {
488
489			/* Get current clicked href value */
490			href = $( this ).attr( 'href' );
491
492			var current_gallery = $(this).parents( '.rtmedia-container' );
493			var current_gallery_id = current_gallery.attr( 'id' );
494
495			if ( $( '#' + current_gallery_id + ' .rtm-media-loading' ).length == 0 ) {
496					$( '#' + current_gallery_id + ' .rtm-pagination' ).before( '<div class=\'rtm-media-loading\'><img src=\'' + rMedia_loading_media + '\' /></div>' );
497				} else {
498					$( '#' + current_gallery_id + ' .rtm-media-loading' ).show();
499				}
500
501				e.preventDefault();
502				if ( $( this ).data( 'page-type' ) == 'page' ) {
503					nextpage = $( this ).data( 'page' );
504				} else if ( $( this ).data( 'page-type' ) == 'prev' ) {
505					if ( nextpage == -1 ) {
506						nextpage = parseInt( $( '#' + current_gallery_id + ' #rtmedia_last_page' ).val() ) - 1;
507					} else {
508						nextpage -= 2;
509					}
510				} else if ( $( this ).data( 'page-type' ) == 'num' ) {
511					if ( parseInt( $( '#' + current_gallery_id + ' #rtmedia_go_to_num' ).val() ) > parseInt( $( '#rtmedia_last_page' ).val() ) ) {
512						nextpage = parseInt( $( '#' + current_gallery_id + ' #rtmedia_last_page' ).val() );
513					} else {
514						nextpage = parseInt( $( '#' + current_gallery_id + ' #rtmedia_go_to_num' ).val() );
515				}
516
517				/* Set page url for input type num pagination */
518				page_base_url = $( this ).data( 'page-base-url' );
519				href = page_base_url + nextpage;
520				}
521
522			var media_search_input = $( '#media_search_input' );
523			if( check_condition( 'search' ) ) {
524				if ( media_search_input.length > 0 && '' !== media_search_input.val() ) {
525					var search_val = check_url( 'search' );
526					href += '?search=' + search_val;
527
528					if( check_condition( 'search_by' ) ) {
529						var search_by = check_url( 'search_by' );
530						href += '&search_by=' + search_by;
531					}
532				}
533			}
534
535			change_rtBrowserAddressUrl( href, '' );
536			galleryObj.getNext( nextpage, $( this ).closest( '.rtmedia-container' ).parent(), $( this ).closest( '.rtm-pagination' ) );
537		} );
538
539		$( document ).on( 'submit', 'form#media_search_form', function( e ) {
540			e.preventDefault();
541
542			var $media_search_input = $( '#media_search_input' ).val();
543			var $media_search       = $( '#media_search' );
544			var $media_fatch_loader = $( '#media_fatch_loader' );
545			var $media_type         = $( 'input[type="hidden"][name="media_type"]' );
546
547			if ( '' === $media_search_input ) {
548				return false;
549			}
550
551			$media_search.css( 'cursor', 'pointer');
552			$media_fatch_loader.addClass('load');
553			nextpage = 1;
554
555			var href = window.location.href;
556			// Remove query string.
557			if ( href.indexOf('?') > -1) {
558				href = window.location.pathname;
559			}
560
561			href += '?search=' + $media_search_input;
562			if ( $( '#search_by' ).length > 0 ) {
563				href += '&search_by=' + $( '#search_by' ).val();
564			}
565
566			if ( $media_type.length > 0 && 'album' === $media_type.val() ) {
567				href += '&media_type=' + $media_type.val();
568			}
569
570			href = encodeURI( href );
571
572			change_rtBrowserAddressUrl( href, '' );
573			galleryObj.getNext( nextpage, $( this ).closest( '.rtmedia-container' ).parent() );
574
575			$( '#media_search_remove' ).show();
576		} );
577
578		// media search remove
579		$( document ).on( 'click', '#media_search_remove', function( e ) {
580			$( '#media_search' ).css( 'cursor', 'not-allowed');
581			$( '#media_fatch_loader' ).addClass('load');
582			jQuery( '#media_search_input' ).val('');
583			nextpage = 1;
584			var href = window.location.pathname;
585			if ( check_condition( '/pg' ) ) {
586				remove_index = href.indexOf('pg');
587				remove_href =  href.substring( remove_index );
588				href = href.replace( remove_href, '' );
589			}
590
591			change_rtBrowserAddressUrl( href, '' );
592			galleryObj.getNext( nextpage, $( this ).parent().parent().parent().parent().parent());
593			$( '#media_search_remove' ).hide();
594		} );
595
596		if ( window.location.pathname.indexOf( rtmedia_media_slug ) != -1 ) {
597			var tempNext = window.location.pathname.substring( window.location.pathname.lastIndexOf( 'pg/' ) + 5, window.location.pathname.lastIndexOf( '/' ) );
598			if ( isNaN( tempNext ) === false ) {
599				nextpage = parseInt( tempNext ) + 1;
600			}
601		}
602
603		window.UploadView = Backbone.View.extend( {
604			events: {
605				'click #rtMedia-start-upload': 'uploadFiles'
606			},
607			initialize: function( config ) {
608				this.uploader = new plupload.Uploader( config );
609				/*
610				* 'ext_enabled' will get value of enabled media types if nothing is enabled,
611				* then an error message will be displayed.
612				*/
613				var ext_enabled = config.filters[0].extensions.length;
614				if ( ext_enabled === 0 ) {
615						this.uploader.bind( 'Browse', function( up ) {
616							rtmedia_gallery_action_alert_message( rtmedia_media_disabled_error_message, 'warning' );
617						} );
618				}
619			},
620			render: function() {
621
622			},
623			initUploader: function( a ) {
624				if ( typeof ( a ) !== 'undefined' ) {
625					a = false;// If rtmediapro widget calls the function, dont show max size note.
626				}			this.uploader.init();
627				//The plupload HTML5 code gives a negative z-index making add files button unclickable
628				$( '.plupload.html5' ).css( {
629					zIndex: 0
630				} );
631				$( '#rtMedia-upload-button' ).css( {
632					zIndex: 2
633				} );
634				if ( a !== false ) {
635					window.file_size_info = rtmedia_max_file_msg + this.uploader.settings.max_file_size_msg;
636					if ( rtmedia_version_compare( rtm_wp_version, '3.9' ) ) { // Plupload getting updated in 3.9
637						file_extn = this.uploader.settings.filters.mime_types[0].extensions;
638					} else {
639						file_extn = this.uploader.settings.filters[0].extensions;
640					}
641					window.file_extn_info = rtmedia_allowed_file_formats + ' : ' + file_extn.split( ',' ).join( ', ' );
642
643					var info = window.file_size_info + '\n' + window.file_extn_info;
644					$( '.rtm-file-size-limit' ).attr( 'title', info );
645					//$("#rtMedia-upload-button").after("<span>( <strong>" + rtmedia_max_file_msg + "</strong> "+ this.uploader.settings.max_file_size_msg + ")</span>");
646				}
647
648				return this;
649			},
650			uploadFiles: function( e ) {
651				if ( e != undefined ) {
652					e.preventDefault();
653				}
654				this.uploader.start();
655				return false;
656			}
657
658		} );
659
660		if ( $( '#rtMedia-upload-button' ).length > 0 ) {
661			if ( typeof rtmedia_upload_type_filter == 'object' && rtmedia_upload_type_filter.length > 0 ) {
662				rtMedia_plupload_config.filters[0].extensions = rtmedia_upload_type_filter.join();
663			}
664			uploaderObj = new UploadView( rtMedia_plupload_config );
665			uploaderObj.initUploader();
666
667			var rtnObj = '';
668			var redirect_request = false;
669
670			jQuery( document ).ajaxComplete(function() {
671				if( redirect_request ) {
672					redirect_request = false;
673					window.location = rtnObj.redirect_url;
674				}
675			});
676
677			uploaderObj.uploader.bind( 'UploadComplete', function( up, files ) {
678
679				activity_id = -1;
680				var hook_respo = rtMediaHook.call( 'rtmedia_js_after_files_uploaded' );
681				if ( typeof rtmedia_gallery_reload_on_upload != 'undefined' && rtmedia_gallery_reload_on_upload == '1' ) { //Reload gallery view when upload completes if enabled( by default enabled)
682					if ( hook_respo != false ) {
683						galleryObj.reloadView();
684					}
685				}
686				jQuery( '#rtmedia_uploader_filelist li.plupload_queue_li' ).remove();
687				jQuery( '.start-media-upload' ).hide();
688				apply_rtMagnificPopup( jQuery( '.rtmedia-list-media, .rtmedia-activity-container ul.rtmedia-list, #bp-media-list,.widget-item-listing,.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' ) );
689
690				var redirection = $( '#rt_upload_hf_redirect' );
691
692				if( '' !== rtnObj && 'undefined' !== typeof( rtnObj.redirect_url ) && null !== rtnObj.redirect_url ) {
693					if ( uploaderObj.upload_count === up.files.length
694						&& 0 < redirection.length
695						&& 'true' === redirection.val()
696						&& 0 === rtnObj.redirect_url.indexOf( 'http' ) ) {
697						redirect_request = true;
698					}
699				}
700
701				window.onbeforeunload = null;
702			} );
703
704			uploaderObj.uploader.bind( 'FilesAdded', function( up, files ) {
705				var upload_size_error = false;
706				var upload_error = '';
707				var upload_error_sep = '';
708				var upload_remove_array = [ ];
709
710				var select_btn = jQuery( '.rtmedia-upload-input' );
711				var upload_start_btn = jQuery('.start-media-upload');
712
713				$.each( files, function( i, file ) {
714					//Set file title along with file
715					rtm_file_name_array = file.name.split( '.' );
716					file.title = rtm_file_name_array[0];
717
718					var hook_respo = rtMediaHook.call( 'rtmedia_js_file_added', [ up, file, '#rtmedia_uploader_filelist' ] );
719
720					if ( hook_respo == false ) {
721						file.status = -1;
722						upload_remove_array.push( file.id );
723						return true;
724					}
725
726					select_btn.attr( 'value', rtmedia_add_more_files_msg );
727					if ( typeof rtmedia_direct_upload_enabled != 'undefined' && rtmedia_direct_upload_enabled == '1' ) {
728						upload_start_btn.hide();
729					} else {
730						upload_start_btn.show();
731					}
732					if ( uploaderObj.uploader.settings.max_file_size < file.size ) {
733						return true;
734					}
735					var tmp_array = file.name.split( '.' );
736					if ( rtmedia_version_compare( rtm_wp_version, '3.9' ) ) { // Plupload getting updated in 3.9
737						var ext_array = uploaderObj.uploader.settings.filters.mime_types[0].extensions.split( ',' );
738					} else {
739						var ext_array = uploaderObj.uploader.settings.filters[0].extensions.split( ',' );
740					}
741					if ( tmp_array.length > 1 ) {
742						var ext = tmp_array[tmp_array.length - 1];
743						ext = ext.toLowerCase();
744						if ( jQuery.inArray( ext, ext_array ) === -1 ) {
745							return true;
746						}
747					} else {
748						return true;
749					}
750
751					if ( rtmedia_version_compare( rtm_wp_version, '3.9' ) ) { // Plupload getting updated in 3.9
752						uploaderObj.uploader.settings.filters.mime_types[0].title;
753					} else {
754						uploaderObj.uploader.settings.filters[0].title;
755					}
756
757					// Creating list of media to preview selected files
758					rtmedia_selected_file_list( plupload, file, '', '' );
759
760					//Delete Function
761					$( '#' + file.id + ' .plupload_delete .remove-from-queue' ).click( function( e ) {
762						e.preventDefault();
763						uploaderObj.uploader.removeFile( up.getFile( file.id ) );
764						$( '#' + file.id ).remove();
765						rtMediaHook.call( 'rtmedia_js_file_remove', [ up, file ] );
766						return false;
767					} );
768
769					// To change the name of the uploading file
770					$( '#label_' + file.id ).click( function( e ) {
771						e.preventDefault();
772
773						rtm_file_label = this;
774
775						rtm_file_title_id = 'text_' + file.id;
776						rtm_file_title_input = '#' + rtm_file_title_id;
777						rtm_file_title_wrapper_id = 'rtm_title_wp_' + file.id;
778						rtm_file_title_wrapper = '#' + rtm_file_title_wrapper_id;
779
780						rtm_file_desc_id = 'rtm_desc_' + file.id;
781						rtm_file_desc_input = '#' + rtm_file_desc_id;
782						rtm_file_desc_wrapper_id = 'rtm_desc_wp_' + file.id;
783						rtm_file_desc_wrapper = '#' + rtm_file_desc_wrapper_id;
784
785						rtm_file_save_id = 'save_' + file.id;
786						rtm_file_save_el = '#' + rtm_file_save_id;
787
788						jQuery( rtm_file_label ).hide();
789						jQuery( rtm_file_label ).siblings( '.plupload_file_name_wrapper' ).hide();
790
791						// Show/create text box to edit media title
792						if ( jQuery( rtm_file_title_input ).length === 0 ) {
793							jQuery( rtm_file_label ).parent( '.plupload_file_name' ).prepend( '<div id="' + rtm_file_title_wrapper_id + '" class="rtm-upload-edit-title-wrapper"><label>' + rtmedia_edit_media_info_upload.title + '</label><input type="text" class="rtm-upload-edit-title" id="' + rtm_file_title_id + '" value="' + file.title + '" style="width: 75%;" /></div><div id="' + rtm_file_desc_wrapper_id + '" class="rtm-upload-edit-desc-wrapper"><label>' + rtmedia_edit_media_info_upload.description + '</label><textarea class="rtm-upload-edit-desc" id="' + rtm_file_desc_id + '"></textarea></div><span id="' + rtm_file_save_id + '" title="Save Change" class="dashicons dashicons-yes"></span>' );
794						} else {
795							jQuery( rtm_file_title_wrapper ).show();
796							jQuery( rtm_file_desc_wrapper ).show();
797							jQuery( rtm_file_save_el ).show();
798						}
799
800						jQuery( rtm_file_title_input ).focus();
801
802						// Set media title and description in file object
803						$( '#save_' + file.id ).click( function( e ) {
804						    e.preventDefault();
805
806						    rtm_file_label = this;
807
808						    rtm_file_title_id = 'text_' + file.id;
809						    rtm_file_title_input = '#' + rtm_file_title_id;
810						    rtm_file_title_wrapper_id = 'rtm_title_wp_' + file.id;
811						    rtm_file_title_wrapper = '#' + rtm_file_title_wrapper_id;
812
813						    rtm_file_desc_id = 'rtm_desc_' + file.id;
814						    rtm_file_desc_input = '#' + rtm_file_desc_id;
815						    rtm_file_desc_wrapper_id = 'rtm_desc_wp_' + file.id;
816						    rtm_file_desc_wrapper = '#' + rtm_file_desc_wrapper_id;
817
818						    rtm_file_save_id = 'save_' + file.id;
819						    rtm_file_save_el = '#' + rtm_file_save_id;
820
821						    var file_title_val = jQuery( rtm_file_title_input ).val();
822						    var file_desc_val = jQuery( rtm_file_desc_input ).val();
823						    var file_name_wrapper_el = jQuery( rtm_file_label ).siblings( '.plupload_file_name_wrapper' );
824
825							if ( '' !== file_title_val.trim() ) {
826								var extension = file.name.split( '.' )[1];
827								file_name_wrapper_el.text( file_title_val + '.' + extension );
828								file.title = file_title_val;
829							}
830
831						    if ( file_desc_val != '' ) {
832						        file.description = file_desc_val;
833						    }
834
835						    jQuery( rtm_file_title_wrapper ).hide();
836						    jQuery( rtm_file_desc_wrapper ).hide();
837
838						    file_name_wrapper_el.show();
839						    jQuery( rtm_file_label ).siblings( '#label_' + file.id ).show();
840						    jQuery( this ).hide();
841						} );
842					} );
843				} );
844
845				$.each( upload_remove_array, function( i, rfile ) {
846					if ( up.getFile( rfile ) ) {
847						up.removeFile( up.getFile( rfile ) );
848					}
849				} );
850
851				rtMediaHook.call( 'rtmedia_js_after_files_added', [ up, files ] );
852
853				if ( typeof rtmedia_direct_upload_enabled != 'undefined' && rtmedia_direct_upload_enabled == '1' ) {
854					var allow_upload = rtMediaHook.call( 'rtmedia_js_upload_file', { src: 'uploader' } );
855					if ( allow_upload == false ) {
856						return false;
857					}
858					uploaderObj.uploadFiles();
859				}
860
861				upload_start_btn.focus();
862
863			} );
864
865			uploaderObj.uploader.bind( 'Error', function( up, err ) {
866
867				if ( err.code == -600 ) { //File size error // if file size is greater than server's max allowed size
868					var tmp_array;
869					var ext = tr = '';
870					tmp_array = err.file.name.split( '.' );
871					if ( tmp_array.length > 1 ) {
872						ext = tmp_array[tmp_array.length - 1];
873						if ( ! ( typeof ( up.settings.upload_size ) != 'undefined' && typeof ( up.settings.upload_size[ext] ) != 'undefined' && typeof ( up.settings.upload_size[ext]['size'] ) ) ) {
874							rtmedia_selected_file_list( plupload, err.file, up, err );
875						}
876					}
877				} else {
878
879					if ( err.code == -601 ) { // File extension error
880						err.message = rtmedia_file_extension_error_msg;
881					}
882
883					rtmedia_selected_file_list( plupload, err.file, '', err );
884				}
885
886				jQuery( '.plupload_delete' ).on( 'click', function( e ) {
887					e.preventDefault();
888					jQuery( this ).parent().parent( 'li' ).remove();
889				} );
890				return false;
891
892			} );
893
894			jQuery( '.start-media-upload' ).on( 'click', function( e ) {
895				e.preventDefault();
896				// Make search box blank while uploading a media. So that newly uploaded media can be shown after upload.
897				var search_box = jQuery( '#media_search_input' );
898				if ( search_box.length > 0 ) {
899					search_box.val('');
900				}
901
902				/**
903				* To check if any media file is selected or not for uploading
904				*/
905				if ( jQuery( '#rtmedia_uploader_filelist' ).children( 'li' ).length > 0 ) {
906					var allow_upload = rtMediaHook.call( 'rtmedia_js_upload_file', { src: 'uploader' } );
907
908					if ( allow_upload == false ) {
909						return false;
910					}
911					uploaderObj.uploadFiles();
912				}
913			} );
914
915			uploaderObj.uploader.bind( 'UploadProgress', function( up, file ) {
916				//$("#" + file.id + " .plupload_file_status").html(file.percent + "%");
917				//$( "#" + file.id + " .plupload_file_status" ).html( rtmedia_uploading_msg + '( ' + file.percent + '% )' );
918				// creates a progress bar to display file upload status
919				var progressBar = jQuery( '<div/>', {
920					'class': 'plupload_file_progress ui-widget-header',
921				});
922				progressBar.css( 'width', file.percent + '%' );
923				$( '#' + file.id + ' .plupload_file_status' ).html( progressBar );
924				// filter to customize existing progress bar can be used to display
925				// '%' of upload completed.
926				rtMediaHook.call( 'rtm_custom_progress_bar_content', [ file ] );
927				$( '#' + file.id ).addClass( 'upload-progress' );
928				if ( file.percent == 100 ) {
929					$( '#' + file.id ).toggleClass( 'upload-success' );
930				}
931
932				window.onbeforeunload = function( evt ) {
933					var message = rtmedia_upload_progress_error_message;
934					return message;
935				};
936			} );
937
938			uploaderObj.uploader.bind( 'BeforeUpload', function( up, file ) {
939				// We send terms conditions data on backend to validate this on server side.
940				rtMediaHook.call( 'rtmedia_js_before_upload', { uploader: up, file: file, src: 'uploader' } );
941
942				up.settings.multipart_params.title = file.title.split( '.' )[ 0 ];
943
944				if ( typeof file.description != 'undefined' ) {
945					up.settings.multipart_params.description = file.description;
946				} else {
947					up.settings.multipart_params.description = '';
948				}
949
950				var privacy = $( '#rtm-file_upload-ui select.privacy' ).val();
951				if ( privacy !== undefined ) {
952					up.settings.multipart_params.privacy = $( '#rtm-file_upload-ui select.privacy' ).val();
953				}
954
955				var redirection = $( '#rt_upload_hf_redirect' );
956
957				if ( 0 < redirection.length ) {
958					up.settings.multipart_params.redirect    = up.files.length;
959					up.settings.multipart_params.redirection = redirection.val();
960				}
961				jQuery( '#rtmedia-uploader-form input[type=hidden]' ).each( function() {
962					up.settings.multipart_params[$( this ).attr( 'name' )] = $( this ).val();
963				} );
964				up.settings.multipart_params.activity_id = activity_id;
965				if ( $( '#rtmedia-uploader-form .rtmedia-user-album-list' ).length > 0 ) {
966					up.settings.multipart_params.album_id = $( '#rtmedia-uploader-form .rtmedia-user-album-list' ).find( ':selected' ).val();
967				} else if ( $( '#rtmedia-uploader-form .rtmedia-current-album' ).length > 0 ) {
968					up.settings.multipart_params.album_id = $( '#rtmedia-uploader-form .rtmedia-current-album' ).val();
969				}
970
971					rtMediaHook.call( 'rtmedia_js_before_file_upload', [up, file] );
972			} );
973
974			uploaderObj.uploader.bind( 'FileUploaded', function( up, file, res ) {
975				if ( /MSIE (\d+\.\d+);/.test( navigator.userAgent ) ) { //Test for MSIE x.x;
976					var ieversion = new Number( RegExp.$1 ); // Capture x.x portion and store as a number
977
978					if ( ieversion < 10 ) {
979						if ( typeof res.response !== 'undefined' ) {
980							res.status = 200;
981 						}
982					}
983				}
984
985				try {
986
987					rtnObj = JSON.parse( res.response );
988					uploaderObj.uploader.settings.multipart_params.activity_id = rtnObj.activity_id;
989					activity_id = rtnObj.activity_id;
990					if ( rtnObj.permalink != '' ) {
991						$( "#" + file.id + " .plupload_file_name" ).html( "<a href='" + rtnObj.permalink + "' target='_blank' title='" + rtnObj.permalink + "'>" + file.title.substring( 0, 40 ).replace( /(<([^>]+)>)/ig, "" ) + "</a>" );
992						$( "#" + file.id + " .plupload_media_edit" ).html( "<a href='" + rtnObj.permalink + "edit' target='_blank'><span title='" + rtmedia_edit_media + "'><i class='dashicons dashicons-edit'></i> " + rtmedia_edit + "</span></a>" );
993						$( "#" + file.id + " .plupload_delete" ).html( "<span id='" + rtnObj.media_id + "' class='rtmedia-delete-uploaded-media dashicons dashicons-dismiss' title='" + rtmedia_delete + "'></span>" );
994					}
995
996				} catch ( e ) {
997					// Console.log('Invalid Activity ID');
998				}
999				if ( res.status == 200 || res.status == 302 ) {
1000					if ( uploaderObj.upload_count == undefined ) {
1001						uploaderObj.upload_count = 1;
1002					} else {
1003						uploaderObj.upload_count++;
1004					}
1005
1006					rtMediaHook.call( 'rtmedia_js_after_file_upload', [ up, file, res.response ] );
1007				} else {
1008					$( '#' + file.id + ' .plupload_file_status' ).html( rtmedia_upload_failed_msg );
1009				}
1010
1011				files = up.files;
1012				lastfile = files[files.length - 1];
1013
1014			} );
1015
1016			uploaderObj.uploader.refresh();//Refresh the uploader for opera/IE fix on media page
1017
1018			$( '#rtMedia-start-upload' ).click( function( e ) {
1019				uploaderObj.uploadFiles( e );
1020			} );
1021			$( '#rtMedia-start-upload' ).hide();
1022
1023			jQuery( document ).on( 'click', '#rtm_show_upload_ui', function() {
1024				jQuery( '#rtm-media-gallery-uploader' ).slideToggle();
1025				uploaderObj.uploader.refresh();//Refresh the uploader for opera/IE fix on media page
1026				jQuery( '#rtm_show_upload_ui' ).toggleClass( 'primary' );
1027			} );
1028		} else {
1029			jQuery( document ).on( 'click', '#rtm_show_upload_ui', function() {
1030				/*
1031				* 'enabled_ext' will get value of enabled media types if nothing is enabled,
1032				* then an error message will be displayed.
1033				*/
1034				if ( 'object' === typeof rtMedia_plupload_config ) {
1035					var enabled_ext = rtMedia_plupload_config.filters[0].extensions.length;
1036					if ( 0 === enabled_ext ) {
1037						// If no media type is enabled error message will be displayed.
1038						rtmedia_gallery_action_alert_message( rtmedia_media_disabled_error_message, 'warning' );
1039					}
1040				}
1041
1042				jQuery( '#rtm-media-gallery-uploader' ).slideToggle();
1043				jQuery( '#rtm_show_upload_ui' ).toggleClass( 'primary' );
1044			} );
1045		}
1046
1047		jQuery( document ).on( 'click', '.plupload_delete .rtmedia-delete-uploaded-media', function() {
1048			var that = $( this );
1049			if ( confirm( rtmedia_delete_uploaded_media ) ) {
1050				var nonce = $( '#rtmedia-upload-container #rtmedia_media_delete_nonce' ).val();
1051				var media_id = $( this ).attr( 'id' );
1052				var data = {
1053					action: 'delete_uploaded_media',
1054					nonce: nonce,
1055					media_id: media_id
1056				};
1057
1058				$.post( ajaxurl, data, function( response ) {
1059					if ( response == '1' ) {
1060						that.closest( 'tr' ).remove();
1061						$( '#' + media_id ).remove();
1062					}
1063				} );
1064			}
1065		} );
1066
1067} );
1068
1069/** Activity Update Js **/
1070
1071jQuery( document ).ready( function( $ ) {
1072
1073
1074	/**
1075	 * Uploader improper enter behavior issue(124) fixed
1076	 *
1077	 * @param e
1078	 */
1079	var submit_function = function (e) {
1080		/**
1081		 * Execute code only on enter key
1082		 */
1083		if (e.keyCode === 13) {
1084			/**
1085			 * Prevent default behavior and fire custom click
1086			 */
1087			e.preventDefault();
1088			$(this).trigger('click');
1089			/**
1090			 * stop textarea from disabling
1091			 * @type {*|jQuery|HTMLElement}
1092			 */
1093			var textarea = $('#whats-new');
1094			textarea.removeAttr('disabled');
1095			/**
1096			 * set focus to textarea after buddypress timeout code
1097			 */
1098			setTimeout(function () {
1099				textarea.focus();
1100			}, 200);
1101		}
1102	};
1103	/**
1104	 * End of issue 124 fix
1105	 */
1106
1107	/**
1108	 * UI changes for buddypress nouveau theme on activity page
1109	 */
1110	if ( bp_template_pack && 'legacy' !== bp_template_pack ) {
1111
1112		var whats_new_form = jQuery( '#whats-new-form' );
1113
1114		jQuery( '#whats-new' ).on( 'focus', function () {
1115
1116			var rt_uploader_div = whats_new_form.find( '.rtmedia-uploader-div' );
1117			var rt_uploader_filelist = whats_new_form.find( '#rtmedia_uploader_filelist' );
1118			var whats_new_option = whats_new_form.find( '#whats-new-options' );
1119
1120			rt_uploader_div.show();
1121
1122			if ( 0 !== whats_new_option.length ) {
1123				whats_new_option.show();
1124
1125				whats_new_option.css( {
1126					'opacity': '1'
1127				} );
1128			}
1129
1130			rt_uploader_div.addClass( 'clearfix' );
1131
1132			whats_new_form.find( '#rtmedia-action-update' ).removeClass( 'clearfix' );
1133
1134			rt_uploader_filelist.addClass( 'clear-both' );
1135			rt_uploader_filelist.removeClass( 'clearfix' );
1136		} );
1137
1138		whats_new_form.bind( 'reset', function () {
1139			whats_new_form.find( '.rtmedia-uploader-div' ).hide();
1140		} );
1141
1142		whats_new_form.bind( 'submit', function () {
1143			window.onbeforeunload = null;
1144			setTimeout( function () {
1145				whats_new_form.find( '.rtmedia-uploader-div' ).hide();
1146			}, 2000 );
1147		} );
1148	}
1149	/**
1150	 * End of UI changes
1151	 */
1152
1153	/*
1154	 * Fix for file selector does not open in Safari browser in IOS.
1155	 * In Safari in IOS, Plupload don't click on it's input(type=file), so file selector dialog won't open.
1156	 * In order to fix this, when rtMedia's attach media button is clicked,
1157	 * we check if Plupload's input(type=file) is clicked or not, if it's not clicked, then we click it manually
1158	 * to open file selector.
1159	 */
1160
1161	// Initially, select file dialog is close.
1162	var file_dialog_open = false;
1163
1164	var button = '#rtmedia-upload-container #rtMedia-upload-button';
1165
1166	var input_file_el = '#rtmedia-upload-container input[type=file]:first';
1167
1168	// Bind callback on Plupload's input element.
1169	jQuery( document.body ).on( 'click', input_file_el, function() {
1170		file_dialog_open = true;
1171	} );
1172
1173	// Bind callback on rtMedia's attach media button.
1174	jQuery( document.body ).on( 'click', button, function() {
1175		if ( false === file_dialog_open ) {
1176			jQuery( input_file_el ).click();
1177			file_dialog_open = false;
1178		}
1179	} );
1180
1181	// Handling the "post update: button on activity page
1182	/**
1183	 * Commented by : Naveen giri
1184	 * Reason : Commenting this code because its overriding buddypress functionality
1185	 * 			and introducing issue Duplicate activity generation  Issue #108.
1186	 */
1187	/*JQuery( '#aw-whats-new-submit' ).removeAttr( 'disabled' );
1188	jQuery( document ).on( 'blur', '#whats-new', function() {
1189		setTimeout( function() {
1190			jQuery( '#aw-whats-new-submit' ).removeAttr( 'disabled' );
1191		}, 100 );
1192	} );
1193	jQuery( '#aw-whats-new-submit' ).on( 'click', function( e ) {
1194		setTimeout( function() {
1195			jQuery( '#aw-whats-new-submit' ).removeAttr( 'disabled' );
1196		}, 100 );
1197	} );*/
1198
1199	// When user changes the value in activity "post in" dropdown, hide the privacy dropdown and show when posting in profile.
1200	jQuery( '#whats-new-post-in' ).on( 'change', function( e ) {
1201		if ( jQuery( this ).val() == '0' ) {
1202			jQuery( '#whats-new-form #rtmedia-action-update .privacy' ).prop( 'disabled', false ).show();
1203		} else {
1204			jQuery( '#whats-new-form #rtmedia-action-update .privacy' ).prop( 'disabled', true ).hide();
1205		}
1206	} );
1207
1208	// change color of what's new if content is &nbsp;
1209	let whatsNew = jQuery( '#whats-new' );
1210	whatsNew.on( 'keyup', function( e ) {
1211		if ( '&nbsp;' === whatsNew.val() ) {
1212			whatsNew.css( 'color', 'transparent' );
1213		} else {
1214			let replaceNbsp = whatsNew.val().replace( '&nbsp;', '' );
1215			whatsNew.val( replaceNbsp );
1216			whatsNew.css( 'color', 'inherit' );
1217		}
1218	} );
1219
1220	if ( typeof rtMedia_update_plupload_config == 'undefined' ) {
1221		return false;
1222	}
1223	var activity_attachemnt_ids = [ ];
1224
1225	if ( ! rtmedia_add_media_button_post_update ) {
1226		rtmedia_add_media_button_post_update = $( '#rtmedia-add-media-button-post-update' );
1227	}
1228
1229	if ( rtmedia_add_media_button_post_update.length > 0 ) {
1230		objUploadView = new UploadView( rtMedia_update_plupload_config );
1231		objUploadView.initUploader();
1232
1233		setTimeout( function() {
1234			if ( rtmedia_add_media_button_post_update.length > 0 ) {
1235				$( '#whats-new-options' ).prepend( $( '#whats-new-form .rtmedia-plupload-container' ) );
1236				if ( $( '#whats-new-form #rtm-file_upload-ui .privacy' ).length > 0 ) {
1237					$( '#whats-new-form .rtmedia-plupload-container' ).append( $( '#whats-new-form #rtm-file_upload-ui .privacy' ) );
1238				}
1239				$( '#whats-new-form #rtmedia-whts-new-upload-container > div' ).css( 'top', '0' );
1240				$( '#whats-new-form #rtmedia-whts-new-upload-container > div' ).css( 'left', '0' );
1241			}
1242		}, 100 );
1243
1244		/**
1245		 * Appends rtMedia Uploader option below form content section
1246		 */
1247		if ( bp_template_pack && 'legacy' !== bp_template_pack ) {
1248
1249			var form_ref        = jQuery( '#whats-new-form' );
1250			var rt_uploader_div = jQuery( '.rtmedia-uploader-div' );
1251
1252			if ( 0 < jQuery( '.activity-update-form' ).length && 0 < form_ref.length && 0 < rt_uploader_div.length ) {
1253				jQuery( form_ref ).append( rt_uploader_div );
1254				rt_uploader_div.hide();
1255			}
1256
1257		} else {
1258
1259			var new_options = jQuery( '#whats-new-options' );
1260			var rt_uploader_div = jQuery( '#whats-new-form .rtmedia-uploader-div' );
1261
1262			if ( 0 < new_options.length && 0 < rt_uploader_div.length ) {
1263				new_options.append( rt_uploader_div );
1264			}
1265		}
1266
1267		if ( ! rtmedia_add_media_button_post_update ) {
1268			rtmedia_add_media_button_post_update = $( '#rtmedia-add-media-button-post-update' );
1269		}
1270		$( '#whats-new-form' ).on( 'click', rtmedia_add_media_button_post_update, function( e ) {
1271			objUploadView.uploader.refresh();
1272			$( '#rtmedia-whts-new-upload-container > div' ).css( 'top', '0' );
1273			$( '#rtmedia-whts-new-upload-container > div' ).css( 'left', '0' );
1274
1275			/**
1276			 * NOTE: Do not change.
1277			 * ISSUE: BuddyPress activity upload issue with Microsoft Edge
1278			 * GL: 132 [ http://git.rtcamp.com/rtmedia/rtMedia/issues/132 ]
1279			 * Reason: Trigger event not working for hidden element in Microsoft Edge browser
1280			 * Condition to check current browser.
1281			 */
1282			if ( /Edge/.test( navigator.userAgent ) ) {
1283				jQuery( this ).closest( '.rtm-upload-button-wrapper' ).find( 'input[type=file]' ).click();
1284			}
1285
1286			//Enable 'post update' button when media get select
1287			$( '#aw-whats-new-submit' ).prop( 'disabled', false );
1288		} );
1289		//Whats-new-post-in
1290
1291		objUploadView.upload_remove_array = [ ];
1292
1293		objUploadView.uploader.bind( 'FilesAdded', function( upl, rfiles ) {
1294			//$("#aw-whats-new-submit").attr('disabled', 'disabled');
1295
1296			//Remove focusout when media is added in activity post.
1297			jQuery( '#whats-new-form' ).unbind( 'focusout' );
1298
1299			$.each( rfiles, function( i, file ) {
1300
1301				//Set file title along with file
1302				file.title = file.name.substring(0,file.name.lastIndexOf("."));
1303
1304				rtm_file_name_array = file.name.split( '.' );
1305
1306				var hook_respo = rtMediaHook.call( 'rtmedia_js_file_added', [ upl, file, '#rtmedia_uploader_filelist' ] );
1307
1308				if ( hook_respo == false ) {
1309					file.status = -1;
1310					objUploadView.upload_remove_array.push( file.id );
1311					return true;
1312				}
1313
1314				if ( objUploadView.uploader.settings.max_file_size < file.size ) {
1315					return true;
1316				}
1317
1318				var tmp_array = file.name.split( '.' );
1319
1320				if ( rtmedia_version_compare( rtm_wp_version, '3.9' ) ) { // Plupload getting updated in 3.9
1321					var ext_array = objUploadView.uploader.settings.filters.mime_types[0].extensions.split( ',' );
1322				} else {
1323					var ext_array = objUploadView.uploader.settings.filters[0].extensions.split( ',' );
1324				}
1325				if ( tmp_array.length > 1 ) {
1326					var ext = tmp_array[tmp_array.length - 1];
1327					ext = ext.toLowerCase();
1328					if ( jQuery.inArray( ext, ext_array ) === -1 ) {
1329						return true;
1330					}
1331				} else {
1332					return true;
1333				}
1334
1335				rtmedia_selected_file_list( plupload, file, '', '' );
1336
1337				jQuery( '#whats-new-content' ).css( 'padding-bottom', '0px' );
1338
1339				$( '#' + file.id + ' .plupload_delete' ).click( function( e ) {
1340					e.preventDefault();
1341					objUploadView.uploader.removeFile( upl.getFile( file.id ) );
1342					$( '#' + file.id ).remove();
1343					return false;
1344				} );
1345
1346				// To change the name of the uploading file
1347				$( '#label_' + file.id ).click( function( e ) {
1348					e.preventDefault();
1349
1350					rtm_file_label = this;
1351
1352					rtm_file_title_id = 'text_' + file.id;
1353					rtm_file_title_input = '#' + rtm_file_title_id;
1354
1355					rtm_file_title_wrapper_id = 'rtm_title_wp_' + file.id;
1356					rtm_file_title_wrapper = '#' + rtm_file_title_wrapper_id;
1357
1358					rtm_file_desc_id = 'rtm_desc_' + file.id;
1359					rtm_file_desc_input = '#' + rtm_file_desc_id;
1360
1361					rtm_file_desc_wrapper_id = 'rtm_desc_wp_' + file.id;
1362					rtm_file_desc_wrapper = '#' + rtm_file_desc_wrapper_id;
1363
1364					rtm_file_save_id = 'save_' + file.id;
1365					rtm_file_save_el = '#' + rtm_file_save_id;
1366
1367					jQuery( rtm_file_label ).hide();
1368					jQuery( rtm_file_label ).siblings( '.plupload_file_name_wrapper' ).hide();
1369
1370					// Show/create text box to edit media title
1371					if ( jQuery( rtm_file_title_input ).length === 0 ) {
1372						jQuery( rtm_file_label ).parent( '.plupload_file_name' ).prepend( '<div id="' + rtm_file_title_wrapper_id + '" class="rtm-upload-edit-title-wrapper"><label>' + rtmedia_edit_media_info_upload.title + '</label><input type="text" class="rtm-upload-edit-title" id="' + rtm_file_title_id + '" value="' + file.title + '" style="width: 75%;" /></div><div id="' + rtm_file_desc_wrapper_id + '" class="rtm-upload-edit-desc-wrapper"><label>' + rtmedia_edit_media_info_upload.description + '</label><textarea class="rtm-upload-edit-desc" id="' + rtm_file_desc_id + '"></textarea></div><span id="' + rtm_file_save_id + '" title="Save Change" class="dashicons dashicons-yes"></span>' );
1373					} else {
1374						jQuery( rtm_file_title_wrapper ).show();
1375						jQuery( rtm_file_desc_wrapper ).show();
1376						jQuery( rtm_file_save_el ).show();
1377					}
1378
1379					jQuery( rtm_file_title_input ).focus();
1380
1381				} );
1382
1383				rtm_file_save_id = 'save_' + file.id;
1384				rtm_file_save_el = '#' + rtm_file_save_id;
1385				jQuery( document.body ).on('click', rtm_file_save_el , function( e ) {
1386					e.preventDefault();
1387					rtm_file_title_id = 'text_' + file.id;
1388					rtm_file_title_input = '#' + rtm_file_title_id;
1389
1390					rtm_file_desc_id = 'rtm_desc_' + file.id;
1391					rtm_file_desc_input = '#' + rtm_file_desc_id;
1392
1393					rtm_file_title_wrapper_id = 'rtm_title_wp_' + file.id;
1394					rtm_file_title_wrapper = '#' + rtm_file_title_wrapper_id;
1395
1396					rtm_file_desc_wrapper_id = 'rtm_desc_wp_' + file.id;
1397					rtm_file_desc_wrapper = '#' + rtm_file_desc_wrapper_id;
1398
1399					var file_title_val = jQuery( rtm_file_title_input ).val();
1400					var file_desc_val = jQuery( rtm_file_desc_input ).val();
1401
1402					rtm_file_label = '#label_' + file.id;
1403
1404					var file_name_wrapper_el = jQuery( rtm_file_label ).siblings( '.plupload_file_name_wrapper' );
1405
1406					if ( '' !== file_title_val.trim() ) {
1407						var extension = file.name.split( '.' )[1];
1408						file_name_wrapper_el.text( file_title_val + '.' + extension );
1409						file.title = file_title_val;
1410					}
1411
1412					if ( file_desc_val != '' ) {
1413						file.description = file_desc_val;
1414					}
1415
1416					jQuery( rtm_file_title_wrapper ).hide();
1417					jQuery( rtm_file_desc_wrapper ).hide();
1418					file_name_wrapper_el.show();
1419					jQuery( rtm_file_label ).siblings( '.plupload_file_name_wrapper' );
1420					jQuery( rtm_file_label ).show();
1421					jQuery( this ).hide();
1422				} );
1423			} );
1424
1425			$.each( objUploadView.upload_remove_array, function( i, rfile ) {
1426				if ( upl.getFile( rfile ) ) {
1427					upl.removeFile( upl.getFile( rfile ) );
1428				}
1429			} );
1430
1431			/*
1432			 * add rtmedia_activity_text_with_attachment condition to filter
1433			 * if user want media and activity_text both require
1434			 * By: Yahil
1435			 */
1436			if ( '' === jQuery( '#whats-new' ).val().trim() ) {
1437				if ( rtmedia_activity_text_with_attachment == 'disable' ) {
1438					if ( 'legacy' === bp_template_pack ) {
1439						$('#whats-new').css('color', 'transparent');
1440						$('#whats-new').val('&nbsp;');
1441					}
1442				} else {
1443					jQuery('#whats-new-form').prepend('<div id="message" class="error bp-ajax-message" style="display: block;"><p> ' + rtmedia_empty_activity_msg + ' </p></div>')
1444					jQuery( '#whats-new' ).removeAttr( 'disabled' );
1445					return false;
1446				}
1447			}
1448
1449			if ( typeof rtmedia_direct_upload_enabled != 'undefined' && rtmedia_direct_upload_enabled == '1' ) {
1450				//Call upload event direct when direct upload is enabled (removed UPLOAD button and its triggered event)
1451				var allow_upload = rtMediaHook.call( 'rtmedia_js_upload_file', { src: 'activity' } );
1452
1453				if ( allow_upload == false ) {
1454					return false;
1455				}
1456				objUploadView.uploadFiles();
1457			}
1458
1459			/**
1460			 * Uploader improper enter behavior issue(124) fixed
1461			 */
1462			$('#aw-whats-new-submit').focus();
1463			$(document).off('keydown', '#aw-whats-new-submit', submit_function);
1464			$(document).on('keydown', '#aw-whats-new-submit', submit_function);
1465			/**
1466			 * End issue 124
1467			 */
1468
1469		} );
1470
1471		objUploadView.uploader.bind( 'FileUploaded', function( up, file, res ) {
1472			if ( /MSIE (\d+\.\d+);/.test( navigator.userAgent ) ) { //Test for MSIE x.x;
1473				var ieversion = new Number( RegExp.$1 ); // Capture x.x portion and store as a number
1474
1475				if ( ieversion < 10 ) {
1476					try {
1477						if ( typeof JSON.parse( res.response ) !== 'undefined' ) {
1478							res.status = 200;
1479						}
1480					} catch ( e ) {
1481					}
1482				}
1483			}
1484
1485			if ( res.status == 200 ) {
1486				try {
1487					var objIds = JSON.parse( res.response );
1488					$.each( objIds, function( key, val ) {
1489						activity_attachemnt_ids.push( val );
1490						if ( $( '#whats-new-form' ).find( '#rtmedia_attached_id_' + val ).length < 1 ) {
1491							$( '#whats-new-form' ).append( '<input type=\'hidden\' name=\'rtMedia_attached_files[]\' data-mode=\'rtMedia-update\' id=\'rtmedia_attached_id_' + val + '\' value=\'' +
1492							val + '\' />' );
1493						}
1494					} );
1495				} catch ( e ) {
1496
1497				}
1498				rtMediaHook.call( 'rtmedia_js_after_file_upload', [ up, file, res.response ] );
1499			}
1500		} );
1501
1502		objUploadView.uploader.bind( 'Error', function( up, err ) {
1503
1504			if ( err.code == -600 ) { //File size error // if file size is greater than server's max allowed size
1505				var tmp_array;
1506				var ext = tr = '';
1507				tmp_array = err.file.name.split( '.' );
1508				if ( tmp_array.length > 1 ) {
1509
1510					ext = tmp_array[tmp_array.length - 1];
1511					if ( ! ( typeof ( up.settings.upload_size ) != 'undefined' && typeof ( up.settings.upload_size[ext] ) != 'undefined' && ( up.settings.upload_size[ext]['size'] < 1 || ( up.settings.upload_size[ext]['size'] * 1024 * 1024 ) >= err.file.size ) ) ) {
1512						rtmedia_selected_file_list( plupload, err.file, up, err );
1513					}
1514				}
1515			} else {
1516				if ( err.code == -601 ) { // File extension error
1517					err.message = rtmedia_file_extension_error_msg;
1518				}
1519
1520				rtmedia_selected_file_list( plupload, err.file, '', err );
1521			}
1522
1523			jQuery( '.plupload_delete' ).on( 'click', function( e ) {
1524				e.preventDefault();
1525				jQuery( this ).parent().parent( 'li' ).remove();
1526			} );
1527
1528			return false;
1529
1530		} );
1531
1532		objUploadView.uploader.bind( 'BeforeUpload', function( up, files ) {
1533			// We send terms conditions data on backend to validate this on server side.
1534			rtMediaHook.call( 'rtmedia_js_before_upload', { uploader: up, file: files, src: 'activity' } );
1535
1536			$.each( objUploadView.upload_remove_array, function( i, rfile ) {
1537				if ( up.getFile( rfile ) ) {
1538					up.removeFile( up.getFile( rfile ) );
1539 				}
1540			} );
1541
1542			var object  = 'profile';
1543			var item_id = 0;
1544
1545			if ( 'legacy' === bp_template_pack ) {
1546				if ( jQuery( '#whats-new-post-in' ).length > 0 ) {
1547					item_id = jQuery('#whats-new-post-in').val();
1548				}
1549
1550				/* Set object for non-profile posts */
1551				if ( item_id > 0 && jQuery('#whats-new-post-object').length > 0 ) {
1552					object = jQuery('#whats-new-post-object').val();
1553				}
1554			} else {
1555				if ( 'undefined' !== typeof BP_Nouveau?.activity?.params?.object ) {
1556					object = BP_Nouveau.activity.params.object;
1557				}
1558
1559				if ( 'undefined' !== typeof BP_Nouveau?.activity?.params?.item_id ) {
1560					item_id = BP_Nouveau.activity.params.item_id;
1561				} else if ( ( 'profile' === object || 'user' === object ) && 'undefined' !== typeof BP_Nouveau?.activity?.params?.user_id ) {
1562					item_id = BP_Nouveau.activity.params.user_id;
1563				}
1564			}
1565
1566			if ( 'groups' === object ) {
1567				object = 'group';
1568			} else if ( 'user' === object ) {
1569				object = 'profile';
1570			}
1571
1572			up.settings.multipart_params.context = object;
1573			up.settings.multipart_params.context_id = item_id;
1574			up.settings.multipart_params.title = files.title;
1575
1576			if ( typeof files.description != 'undefined' ) {
1577				up.settings.multipart_params.description = files.description;
1578			} else {
1579				up.settings.multipart_params.description = '';
1580			}
1581
1582			// If privacy dropdown is not disabled, then get the privacy value of the update
1583			if ( jQuery( '#whats-new-form select.privacy' ).prop( 'disabled' ) === false ) {
1584				up.settings.multipart_params.privacy = jQuery( '#whats-new-form select.privacy' ).val();
1585			}
1586		} );
1587
1588		objUploadView.uploader.bind( 'UploadComplete', function( up, files ) {
1589			media_uploading = true;
1590
1591			/**
1592			 * Blank error display issue resolved
1593			 */
1594			if ( bp_template_pack && 'legacy' !== bp_template_pack ) {
1595
1596				if ( 'legacy' === bp_template_pack && 'disable' === rtmedia_activity_text_with_attachment &&  '' === jQuery.trim( jQuery( '#whats-new' ).val() ) ) {
1597					let textarea = jQuery( '#whats-new' );
1598					textarea.css( 'color', 'transparent' );
1599					textarea.val( ' ' );
1600				}
1601
1602				jQuery( '#whats-new-form' ).submit();
1603			} else {
1604				jQuery( '#aw-whats-new-submit' ).click();
1605			}
1606
1607			jQuery( '#whats-new-form #rtmedia_uploader_filelist li.plupload_queue_li' ).remove();
1608			window.onbeforeunload = null;
1609		} );
1610
1611		objUploadView.uploader.bind( 'UploadProgress', function( up, file ) {
1612			//$( "#" + file.id + " .plupload_file_status" ).html( rtmedia_uploading_msg + '( ' + file.percent + '% )' );
1613			// creates a progress bar to display file upload status
1614			var progressBar = jQuery( '<div/>', {
1615				'class': 'plupload_file_progress ui-widget-header',
1616			});
1617			progressBar.css( 'width', file.percent + '%' );
1618			$( '#' + file.id + ' .plupload_file_status' ).html( progressBar );
1619			// filter to customize existing progress bar can be used to display
1620			// '%' of upload completed.
1621			rtMediaHook.call( 'rtm_custom_progress_bar_content', [ file ] );
1622			$( '#' + file.id ).addClass( 'upload-progress' );
1623			if ( file.percent == 100 ) {
1624				$( '#' + file.id ).toggleClass( 'upload-success' );
1625			}
1626
1627			window.onbeforeunload = function( evt ) {
1628				var message = rtmedia_upload_progress_error_message;
1629				return message;
1630			};
1631		} );
1632
1633		$( '#rtMedia-start-upload' ).hide();
1634
1635		var change_flag = false;
1636		var media_uploading = false;
1637
1638		$.ajaxPrefilter( function( options, originalOptions, jqXHR ) {
1639			// Modify options, control originalOptions, store jqXHR, etc
1640			try {
1641				if ( originalOptions.data == null || typeof ( originalOptions.data ) == 'undefined' || typeof ( originalOptions.data.action ) == 'undefined' ) {
1642					return true;
1643				}
1644			} catch ( e ) {
1645				return true;
1646			}
1647
1648			if ( originalOptions.data.action == 'post_update' || originalOptions.data.action == 'activity_widget_filter' ) {
1649				var temp = activity_attachemnt_ids;
1650				while ( activity_attachemnt_ids.length > 0 ) {
1651					options.data += '&rtMedia_attached_files[]=' + activity_attachemnt_ids.pop();
1652				}
1653
1654				var dynamic_privacy = '';
1655
1656				var privacy_select = jQuery( '#rtSelectPrivacy' );
1657				var whats_new_form = jQuery( '#whats-new-form' );
1658				if ( whats_new_form.length > 0 && privacy_select.length > 0 ) {
1659					dynamic_privacy = privacy_select.val();
1660				}
1661
1662				options.data += '&rtmedia-privacy=' + dynamic_privacy;
1663				activity_attachemnt_ids = temp;
1664
1665				var orignalSuccess = originalOptions.success;
1666				options.beforeSend = function() {
1667					/**
1668					 * This hook is added for rtMedia Upload Terms plugin to check if it is checked or not for activity
1669					 */
1670					var allowActivityPost = rtMediaHook.call( 'rtmedia_js_before_activity_added', { src: 'activity' } );
1671
1672					if ( ! allowActivityPost ) {
1673						$( '#whats-new-form #rtmedia-whts-new-upload-container' ).find( 'input' ).removeAttr( 'disabled' );
1674
1675						/**
1676						 * Issue fixed: 1056(rtmedia-upload-terms) - Not allowing to upload
1677						 */
1678						var activity_textarea = $( '#whats-new' );
1679						activity_textarea.removeAttr('disabled');
1680						/**
1681						 * End of issue 1056 fix
1682						 */
1683
1684						return false;
1685					}
1686
1687					if ( originalOptions.data.action == 'post_update' ) {
1688						if ( $.trim( $( '#whats-new' ).val() ) == '' && objUploadView.uploader.files.length > 0 ) {
1689							/*
1690							 * Added $nbsp; as activity text to post activity without TEXT
1691							 * Disabled TextBox color(transparent)
1692							 * ELSE
1693							 * Required Activity text with media
1694							 * add rtmedia_activity_text_with_attachment condition to filter
1695		 					 * if user want media and activity_text both require
1696		 					 * By: Yahil
1697							 */
1698
1699							if ( rtmedia_activity_text_with_attachment == 'disable') {
1700								if ( 'legacy' === bp_template_pack ) {
1701									$( '#whats-new' ).css( 'color', 'transparent' );
1702									$( '#whats-new' ).val( '&nbsp;' );
1703								}
1704							} else {
1705								jQuery('#whats-new-form').prepend('<div id="message" class="error bp-ajax-message" style="display: block;"><p> ' + rtmedia_empty_activity_msg + ' </p></div>')
1706								jQuery( '#whats-new' ).removeAttr( 'disabled' );
1707								return false;
1708							}
1709						}
1710					}
1711					if ( ! media_uploading && objUploadView.uploader.files.length > 0 ) {
1712						$( '#whats-new-post-in' ).attr( 'disabled', 'disabled' );
1713						if ( ! rtmedia_add_media_button_post_update ) {
1714							rtmedia_add_media_button_post_update = $( '#rtmedia-add-media-button-post-update' );
1715						}
1716						rtmedia_add_media_button_post_update.attr( 'disabled', 'disabled' );
1717
1718						var terms_condition_cb = $( '#rtmedia_upload_terms_conditions' );
1719						if ( terms_condition_cb.prop( 'checked' ) ) {
1720							terms_condition_cb.prop( 'disabled', true );
1721						}
1722
1723						objUploadView.uploadFiles();
1724						media_uploading = true;
1725						return false;
1726					} else {
1727						media_uploading = false;
1728						return true;
1729					}
1730
1731				};
1732				options.success = function( response ) {
1733                                        // For BuddyPress Nouveau Template.
1734					if ( orignalSuccess && 'function' === typeof orignalSuccess ) {
1735                                            orignalSuccess( response );
1736                                        }
1737
1738					if ( response[0] + response[1] == '-1' ) {
1739						//Error
1740
1741					} else {
1742						if ( originalOptions.data.action == 'activity_widget_filter' ) {
1743							$( 'div.activity' ).bind( 'fadeIn', function() {
1744								apply_rtMagnificPopup( jQuery( '.rtmedia-list-media, .rtmedia-activity-container ul.rtmedia-list, #bp-media-list,.widget-item-listing,.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' ) );
1745								rtMediaHook.call( 'rtmedia_js_after_activity_added', [ ] );
1746								if ( ! rtmedia_add_media_button_post_update ) {
1747									rtmedia_add_media_button_post_update = jQuery( '#rtmedia-add-media-button-post-update' );
1748								}
1749
1750								rtmedia_add_media_button_post_update.removeAttr( 'disabled' );
1751							} );
1752							$( 'div.activity' ).fadeIn( 100 );
1753						}
1754						jQuery( 'input[data-mode=rtMedia-update]' ).remove();
1755						while ( objUploadView.uploader.files.pop() != undefined ) {
1756						}
1757						objUploadView.uploader.refresh();
1758						$( '#rtmedia-whts-new-upload-container > div' ).css( { 'top': '0', 'left': '0' } );
1759						$( '#whats-new-form #rtMedia-update-queue-list' ).html( '' );
1760
1761						apply_rtMagnificPopup( jQuery( '.rtmedia-list-media, .rtmedia-activity-container ul.rtmedia-list, #bp-media-list,.widget-item-listing,.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' ) );
1762
1763						// For BuddyPress New Template hacks
1764						jQuery( '.plupload_filelist_content.rtm-plupload-list' ).html('');
1765
1766						rtMediaHook.call( 'rtmedia_js_after_activity_added', [ ] );
1767						if ( ! rtmedia_add_media_button_post_update ) {
1768							rtmedia_add_media_button_post_update = jQuery( '#rtmedia-add-media-button-post-update' );
1769						}
1770						rtmedia_add_media_button_post_update.removeAttr( 'disabled' );
1771					}
1772
1773					// rtmedia_on_activity_add();
1774
1775					$( '#whats-new-post-in' ).removeAttr( 'disabled' );
1776					if ( ! rtmedia_add_media_button_post_update ) {
1777						rtmedia_add_media_button_post_update = $( '#rtmedia-add-media-button-post-update' );
1778					}
1779					rtmedia_add_media_button_post_update.removeAttr( 'disabled' );
1780					// Enabled TextBox color back to normal
1781					$( '#whats-new' ).val( '' );
1782					$( '#whats-new' ).css( 'color', '' );
1783
1784				};
1785			}
1786		} );
1787	} else {
1788		$.ajaxPrefilter( function( options, originalOptions, jqXHR ) {
1789			// Modify options, control originalOptions, store jqXHR, etc
1790			try {
1791				if ( originalOptions.data == null || typeof ( originalOptions.data ) == 'undefined' || typeof ( originalOptions.data.action ) == 'undefined' ) {
1792					return true;
1793				}
1794			} catch ( e ) {
1795				return true;
1796			}
1797
1798			if ( originalOptions.data.action == 'post_update' || originalOptions.data.action == 'activity_widget_filter' ) {
1799				var dynamic_privacy = '';
1800
1801				if ( jQuery( 'select.privacy' ).not( '.rtm-activity-privacy-opt' ).length > 0 ) {
1802					dynamic_privacy = jQuery( 'select.privacy' ).not( '.rtm-activity-privacy-opt' ).val();
1803				} else if ( jQuery( 'input[name="privacy"]' ).length > 0 ) {
1804					dynamic_privacy = jQuery( 'input[name="privacy"]' ).val();
1805				}
1806
1807				options.data += '&rtmedia-privacy=' + dynamic_privacy;
1808				var orignalSuccess = originalOptions.done;
1809				options.done = function( response ) {
1810					orignalSuccess( response );
1811					if ( response[0] + response[1] == '-1' ) {
1812						//Error
1813					} else {
1814						if ( originalOptions.data.action == 'activity_widget_filter' ) {
1815							$( 'div.activity' ).fadeIn( 100 );
1816						}
1817					}
1818
1819					$( '#whats-new-post-in' ).removeAttr( 'disabled' );
1820					// Enabled TextBox color back to normal
1821					$( '#whats-new' ).css( 'color', '' );
1822
1823				};
1824			}
1825		} );
1826	}
1827} );
1828
1829
1830
1831/**
1832 * RtMedia Comment Js
1833 */
1834jQuery( document ).ready( function( $ ) {
1835	jQuery( document ).on( 'click', '#rt_media_comment_form #rt_media_comment_submit', function( e ) {
1836		var that = this;
1837		var widget_id = jQuery( this ).attr( 'widget_id' );
1838		var comment_form_el = jQuery( this ).closest('form');
1839		var comment_content_el = comment_form_el.find( '#comment_content' );
1840
1841		var show_error = false;
1842		var content = jQuery.trim( comment_content_el.val() );
1843
1844		comment_attached_id = comment_form_el.find( 'input[name="rtMedia_attached_files[]"]' ).val();
1845		if ( typeof comment_attached_id == 'undefined' && content == '' ) {
1846			show_error = 1;
1847		}else{
1848			if( comment_attached_id == ''  && content == '' ){
1849				show_error = 2;
1850			}
1851		}
1852
1853		if( show_error ){
1854
1855			rtmedia_single_media_alert_message( rtmedia_empty_comment_msg, 'warning', true );
1856
1857			if ( widget_id ) {
1858				rtmedia_comment_media_input_button( widget_id, false );
1859			} else {
1860				rtmedia_comment_submit_button_disable( false );
1861			}
1862
1863			return false;
1864		}
1865
1866
1867		$( this ).attr( 'disabled', 'disabled' );
1868		//If string has only &nbsp; then set value as empty.
1869		if ( '' === comment_content_el.val().replace(/\&nbsp;/g, '' ) ) {
1870			comment_content_el.val( '' );
1871		}
1872		$.ajax( {
1873			url: comment_form_el.attr( 'action' ),
1874			type: 'post',
1875			data: comment_form_el.serialize() + '&rtajax=true',
1876			success: function( data ) {
1877				$( '#rtmedia-no-comments' ).remove();
1878
1879				$( '#rtmedia_comment_ul' ).append( data );
1880
1881				
1882				comment_content_el.val( '' );
1883
1884				if ( widget_id ) {
1885					rtmedia_comment_media_remove_hidden_media_id( widget_id );
1886					rtmedia_comment_media_textbox_val( widget_id, false );
1887					rtmedia_comment_media_input_button( widget_id, false );
1888				} else {
1889					rtmedia_comment_submit_button_disable( false );
1890				}
1891
1892				rtmedia_apply_popup_to_media();
1893
1894				rtmedia_reset_video_and_audio_for_popup();
1895
1896				rtMediaHook.call( 'rtmedia_js_after_comment_added', [ ] );
1897
1898				/** Scroll function called */
1899				rtMediaScrollComments();
1900
1901				/** refreshing fragments */
1902				if ( false == $( 'body' ).hasClass( 'activity' ) && false == $( 'body' ).hasClass( 'groups' ) ) {
1903                    galleryObj.reloadView();
1904                }
1905			},
1906			error: function( data ) {
1907				if ( widget_id ) {
1908					rtmedia_comment_media_input_button( widget_id, false );
1909					rtmedia_comment_media_remove_hidden_media_id( widget_id );
1910				} else {
1911					rtmedia_comment_submit_button_disable( false );
1912				}
1913			}
1914		} );
1915
1916		return false;
1917	} );
1918
1919	//Delete comment
1920	jQuery( document ).on( 'click', '.rtmedia-delete-comment', function( e ) {
1921		e.preventDefault();
1922		var ask_confirmation = true;
1923		ask_confirmation = rtMediaHook.call( 'rtmedia_js_delete_comment_confirmation', [ ask_confirmation ] );
1924		if ( ask_confirmation && ! confirm( rtmedia_media_comment_delete_confirmation ) ) {
1925			return false;
1926		}
1927		var current_comment = jQuery( this );
1928		var current_comment_parent = current_comment.parent();
1929		var comment_id = current_comment.data( 'id' );
1930		current_comment_parent.css( 'opacity', '0.4' );
1931		if ( comment_id == '' || isNaN( comment_id ) ) {
1932			return false;
1933		}
1934		var action = current_comment.closest( 'ul' ).data( 'action' );
1935
1936		jQuery.ajax( {
1937			url: action,
1938			type: 'post',
1939			data: { comment_id: comment_id },
1940			success: function( res ) {
1941				if ( res != 'undefined' && res == 1 ) {
1942					current_comment.closest( 'li' ).hide( 1000, function() {
1943						current_comment.closest( 'li' ).remove();
1944					} );
1945				} else {
1946					current_comment_parent.css( 'opacity', '1' );
1947				}
1948				rtMediaHook.call( 'rtmedia_js_after_comment_deleted', [ ] );
1949			}
1950		} );
1951
1952	} );
1953
1954	$( document ).on( 'click', '.rtmedia-like', function( e ) {
1955		e.preventDefault();
1956		var that = this;
1957		var like_nonce = $( '#rtm_media_like_nonce' ).val();
1958		$( this ).attr( 'disabled', 'disabled' );
1959		var url = $( this ).parent().attr( 'action' );
1960		$( that ).prepend( '<img class=\'rtm-like-loading\' src=\'' + rMedia_loading_file + '\' style=\'width:10px\' />' );
1961		$.ajax( {
1962			url: url,
1963			type: 'post',
1964			data: { json: true, like_nonce: like_nonce },
1965			success: function( data ) {
1966				try {
1967					data = JSON.parse( data );
1968				} catch ( e ) {
1969
1970				}
1971
1972				$( '.rtmedia-like span' ).html( data.next );
1973				$( '.rtmedia-like' ).attr( 'title', data.next );
1974				$( '.rtmedia-like-counter-wrap' ).html( data.person_text );
1975				$( '.rtm-like-loading' ).remove();
1976				$( that ).removeAttr( 'disabled' );
1977				var comments_container = $( '.rtmedia-comments-container' ).length;
1978
1979				//Update the like counter
1980				// $( '.rtmedia-like-counter' ).html( data.count );
1981				if ( data.count > 0 ) {
1982					$( '.rtmedia-like-info, .rtm-like-comments-info' ).removeClass( 'hide' );
1983				} else {
1984					$( '.rtmedia-like-info' ).addClass( 'hide' );
1985
1986					// Add hide class to this element when "comment on media" is not enabled.
1987					if ( 0 === comments_container ) {
1988						$( '.rtm-like-comments-info' ).addClass( 'hide' );
1989					}
1990				}
1991			}
1992		} );
1993
1994	} );
1995	$( document ).on( 'click', '.rtmedia-featured, .rtmedia-group-featured', function( e ) {
1996		e.preventDefault();
1997		var that = this;
1998		$( this ).attr( 'disabled', 'disabled' );
1999		var featured_nonce = $( this ).siblings( '#rtm_media_featured_nonce' ).val();
2000		var url = $( this ).parent().attr( 'action' );
2001		$( that ).prepend( '<img class=\'rtm-featured-loading\' src=\'' + rMedia_loading_file + '\' />' );
2002		$.ajax( {
2003			url: url,
2004			type: 'post',
2005			data:  { json:true, featured_nonce:featured_nonce },
2006			success: function( data ) {
2007				try {
2008					data = JSON.parse( data );
2009				} catch ( e ) {
2010
2011				}
2012
2013				if ( data.nonce ) {
2014					rtmedia_single_media_alert_message( rtmedia_something_wrong_msg, 'warning' );
2015				} else {
2016					if ( data.action ) {
2017						rtmedia_single_media_alert_message( rtmedia_set_featured_image_msg, 'success' );
2018					} else {
2019						rtmedia_single_media_alert_message( rtmedia_unset_featured_image_msg, 'success' );
2020					}
2021				}
2022				$( that ).find( 'span' ).html( data.next );
2023				$( '.rtm-featured-loading' ).remove();
2024				$( that ).removeAttr( 'disabled' );
2025			}
2026		} );
2027
2028	} );
2029	jQuery( '#div-attache-rtmedia' ).find( 'input[type=file]' ).each( function() {
2030		//$(this).attr("capture", "camera");
2031		// $(this).attr("accept", $(this).attr("accept") + ';capture=camera');
2032
2033	} );
2034
2035	// Manually trigger fadein event so that we can bind some function on this event. It is used in activity when content getting load via ajax
2036	var _old_fadein = $.fn.fadeIn;
2037	jQuery.fn.fadeIn = function() {
2038		return _old_fadein.apply( this, arguments ).trigger( 'fadeIn' );
2039	};
2040} );
2041
2042
2043function rtmedia_selected_file_list( plupload, file, uploader, error, comment_media_id ) {
2044	var icon = '', err_msg = '', upload_progress = '', title = '';
2045
2046	/**
2047	 * Blank error display issue resolved
2048	 */
2049	if ( bp_template_pack && 'legacy' !== bp_template_pack ) {
2050
2051		var new_submit_btn = jQuery( '#aw-whats-new-submit' );
2052		if ( 0 < new_submit_btn.length ) {
2053
2054			var new_button = jQuery( '<input>', {
2055				type  : 'button',
2056				class : 'button',
2057				name  : 'aw-whats-new-submit',
2058				id    : 'aw-whats-new-submit',
2059				value : new_submit_btn.val()
2060			} );
2061
2062			new_submit_btn.replaceWith( new_button );
2063
2064			new_button.on( 'click', function ( e ) {
2065
2066				if ( ! rtmedia_add_media_button_post_update ) {
2067					rtmedia_add_media_button_post_update = jQuery( '#rtmedia-add-media-button-post-update' );
2068				}
2069				rtmedia_add_media_button_post_update.prop( 'disabled', true );
2070				if ( rtMediaHook.call( 'rtmedia_js_before_activity_added', { src: 'activity' } ) ) {
2071					objUploadView.uploadFiles( e );
2072				}
2073			} );
2074		}
2075	}
2076
2077	rtmedia_uploader_filelist = (typeof comment_media_id === "undefined") ? "#rtmedia_uploader_filelist" : "#rtmedia_uploader_filelist-"+comment_media_id;
2078	plupload_delete = (typeof comment_media_id === "undefined") ? "plupload_delete" : "plupload_delete-"+comment_media_id;
2079
2080	if ( error == '' ) {
2081		upload_progress = '<div class="plupload_file_progress ui-widget-header" style="width: 0%;">';
2082		upload_progress += '</div>';
2083		icon = '<span id="label_' + file.id + '" class="dashicons dashicons-edit" title="' + rtmedia_backbone_strings.rtm_edit_file_name + '"></span>';
2084	} else if ( error.code == -600 ) {
2085		alert( rtmedia_max_file_msg + uploader.settings.max_file_size );
2086		err_msg = ( uploader != '' ) ? rtmedia_max_file_msg + uploader.settings.max_file_size :  window.file_size_info;
2087		title = 'title=\'' + err_msg + '\'';
2088		icon = '<i class="dashicons dashicons-info" ' + title + '></i>';
2089	} else if ( error.code == -601 ) {
2090		alert( error.message + '. ' + window.file_extn_info );
2091		err_msg = error.message + '. ' + window.file_extn_info;
2092		title = 'title=\'' + err_msg + '\'';
2093		icon = '<i class="dashicons dashicons-info" ' + title + '></i>';
2094	}
2095
2096	var rtmedia_plupload_file = '<li class="plupload_file ui-state-default plupload_queue_li" id="' + file.id + '" ' + title + '>';
2097	rtmedia_plupload_file += '<div id="file_thumb_' + file.id + '" class="plupload_file_thumb">';
2098	rtmedia_plupload_file += '</div>';
2099	rtmedia_plupload_file += '<div class="plupload_file_status">';
2100	rtmedia_plupload_file += upload_progress;
2101	rtmedia_plupload_file += '</div>';
2102	rtmedia_plupload_file += '<div class="plupload_file_name" title="' + ( f
2102ile.name ? file.name : '' ) + '">';
2103	rtmedia_plupload_file += '<span class="plupload_file_name_wrapper">';
2104	rtmedia_plupload_file += ( file.name ? file.name : '' );
2105	rtmedia_plupload_file += '</span>';
2106	rtmedia_plupload_file += icon;
2107	rtmedia_plupload_file += '</div>';
2108	rtmedia_plupload_file += '<div class="plupload_file_action">';
2109	rtmedia_plupload_file += '<div class="plupload_action_icon ui-icon '+plupload_delete+'">';
2110	rtmedia_plupload_file += '<span class="remove-from-queue dashicons dashicons-dismiss"></span>';
2111	rtmedia_plupload_file += '</div>';
2112	rtmedia_plupload_file += '</div>';
2113	rtmedia_plupload_file += '<div class="plupload_file_size">';
2114	rtmedia_plupload_file += plupload.formatSize( file.size ).toUpperCase();
2115	rtmedia_plupload_file += '</div>';
2116	rtmedia_plupload_file += '<div class="plupload_file_fields">';
2117	rtmedia_plupload_file += '</div>';
2118	rtmedia_plupload_file += '</li>';
2119
2120	if ( error.code !== -601 && error.code !== -600 ) {
2121		jQuery( rtmedia_plupload_file ).appendTo( rtmedia_uploader_filelist );
2122	}
2123
2124	if ( comment_media_id ) {
2125		jQuery( '#rtmedia-comment-media-upload-' + comment_media_id ).focus();
2126	} else {
2127		jQuery( '#whats-new' ).focus();
2128	}
2129
2130	var type = file.type;
2131	var media_title = file.name;
2132	var ext = media_title.substring( media_title.lastIndexOf( '.' ) + 1, media_title.length );
2133
2134	if ( /image/i.test( type ) ) {
2135		if ( ext === 'gif' ) {
2136			jQuery( '<img src="' + rtmedia_media_thumbs[ 'photo' ] + '" />' ).appendTo( '#file_thumb_' + file.id );
2137		} else {
2138			var img = new mOxie.Image();
2139
2140			img.onload = function() {
2141				this.embed( jQuery( '#file_thumb_' + file.id ).get( 0 ), {
2142					width: 100,
2143					height: 60,
2144					crop: true
2145				} );
2146			};
2147
2148			img.onembedded = function() {
2149				this.destroy();
2150			};
2151
2152			img.onerror = function() {
2153				this.destroy();
2154			};
2155
2156			img.load( file.getSource() );
2157		}
2158	} else {
2159		jQuery.each( rtmedia_exteansions, function( key, value ) {
2160			if ( value.indexOf( ext ) >= 0 ) {
2161
2162				var media_thumbnail = '';
2163
2164				// Below condition is to show docs and files addon thumbnail.
2165				if ( rtmedia_media_thumbs[ ext ] ) {
2166					media_thumbnail = rtmedia_media_thumbs[ ext ];
2167				} else {
2168					media_thumbnail = rtmedia_media_thumbs[ key ];
2169				}
2170
2171				jQuery( '<img />', { src: media_thumbnail } ).appendTo( '#file_thumb_' + file.id );
2172
2173				return false;
2174			}
2175		} );
2176	}
2177
2178}
2179
2180/* Change URLin browser without reloading the page */
2181function change_rtBrowserAddressUrl( url, page ) {
2182	if ( typeof ( history.pushState ) != 'undefined' ) {
2183		var obj = { Page: page, Url: url };
2184		history.pushState( obj, obj.Page, obj.Url );
2185	}
2186}
2187
2188
2189/**
2190 * Get query string value
2191 * ref: http://stackoverflow.com/questions/9870512/how-to-obtaining-the-querystring-from-the-current-url-with-javascript
2192 * return string
2193 */
2194function getQueryStringValue (key) {
2195  return decodeURIComponent(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + encodeURIComponent(key).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1"));
2196}
2197
2198/**
2199 * Check paramater are available or not in url
2200 * return bool
2201 */
2202function check_condition( key ) {
2203	if( window.location.href.indexOf(key) > 0 ) {
2204		return true;
2205	} else {
2206		return false;
2207	}
2208}
2209
2210/**
2211 * Check paramater are available or not in URL parameters
2212 * Ref: https://www.kevinleary.net/jquery-parse-url
2213 * return bool
2214 */
2215function check_url( query ) {
2216	query = query.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
2217    var expr = "[\\?&]"+query+"=([^&#]*)";
2218    var regex = new RegExp( expr );
2219    var results = regex.exec( window.location.href );
2220    if( null !== results ) {
2221        return results[1];
2222    } else {
2223        return false;
2224    }
2225}
2226
2227/*
2228 * To change this template, choose Tools | Templates
2229 * and open the template in the editor.
2230 */
2231var 	commentObj = {};
2232var 	plupload_comment_main = {};
2233var 	comment_media_wrapper = 'comment-media-wrapper-';
2234var 	rtmedia_comment_media_submit = 'rtmedia-comment-media-submit-';
2235var 	comment_media_add_button = 'rtmedia-comment-media-upload-';
2236var 	comment_media_uplaod_media = 'rtMedia-start-upload-';
2237
2238
2239jQuery(document).ready(function($) {
2240
2241    rtMediaHook.register( 'rtmedia_js_popup_after_content_added', function() {
2242		var popup_upload_comment = jQuery( '.rtmedia-single-container .rtmedia-single-meta .rtm-media-single-comments form' );
2243		rtmedia_comment_media_upload( popup_upload_comment );
2244		rtmedia_apply_popup_to_media();
2245		return true;
2246	} );
2247
2248    rtmedia_apply_popup_to_media();
2249	rtmedia_comment_media_single_page();
2250	rtmedia_activity_comment_js_add_media_id();
2251	rtmedia_activity_stream_comment_media();
2252	rtmedia_buddypress_load_newest_button_click();
2253});
2254
2255
2256function rtmedia_reset_video_and_audio(){
2257	jQuery( 'ul.activity-list li.activity-item div.rtmedia-item-thumbnail > audio.wp-audio-shortcode, ul.activity-list li.activity-item div.rtmedia-item-thumbnail > video.wp-video-shortcode' ).mediaelementplayer( {
2258		// This is required to work with new MediaElement version.
2259                classPrefix: 'mejs-',
2260                // If the <video width> is not specified, this is the default
2261		defaultVideoWidth: 480,
2262		// If the <video height> is not specified, this is the default
2263		defaultVideoHeight: 270
2264	} );
2265}
2266
2267
2268function rtmedia_on_activity_add(){
2269	rtmedia_activity_stream_comment_media();
2270
2271	rtmedia_reset_video_and_audio();
2272
2273	rtmedia_apply_popup_to_media();
2274}
2275
2276
2277function rtmedia_single_page_popup_close(){
2278  	/* on close of popup resize the video height */
2279    if( typeof rtmedia_media_size_config != 'undefined' ){
2280        if( typeof rtmedia_media_size_config.video.activity_media != 'undefined' ){
2281            jQuery( '.rtmedia-single-container .rtmedia-comment-media-container .mejs-container.mejs-video' ).css({
2282                'height': rtmedia_media_size_config.video.activity_media.height,
2283                'width': rtmedia_media_size_config.video.activity_media.width
2284            });
2285        }
2286    }
2287}
2288
2289function rtmedia_reset_video_and_audio_for_popup(){
2290	jQuery( '.rtm-lightbox-container .rtmedia-comments-container ul.rtm-comment-list li.rtmedia-comment div.rtmedia-item-thumbnail > audio.wp-audio-shortcode, .rtm-lightbox-container .rtmedia-comments-container ul.rtm-comment-list li.rtmedia-comment div.rtmedia-item-thumbnail > video.wp-video-shortcode' ).mediaelementplayer( {
2291		// This is required to work with new MediaElement version.
2292                classPrefix: 'mejs-',
2293                // If the <video width> is not specified, this is the default
2294		defaultVideoWidth: 200,
2295		// If the <video height> is not specified, this is the default
2296		defaultVideoHeight: 200
2297	} );
2298}
2299
2300
2301function rtmedia_comment_media_uplaod_button_disble( widget_id, $value ){
2302	if( typeof $value != 'undefined' ){
2303		jQuery( '#'+comment_media_add_button+widget_id ).prop( 'disabled', $value );
2304	}
2305}
2306
2307function rtmedia_apply_popup_to_media(){
2308	if ( typeof( rtmedia_lightbox_enabled ) != 'undefined' && rtmedia_lightbox_enabled == '1' ) {
2309		apply_rtMagnificPopup( '.rtmedia-comment-media-container ul.rtmedia-comment-media-list, .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' );
2310	}
2311}
2312
2313
2314function rtmedia_comment_media_enable_diable_media_comment( that ){
2315	var widget_id = jQuery( that ).attr( 'widget_id' );
2316	if( typeof widget_id != 'undefined' ){
2317		rtmedia_comment_media_uplaod_button_disble( widget_id, false );
2318	}else{
2319		jQuery( '.rt_media_comment_form_with_media .rtmedia-comment-media-upload' ).prop( 'disabled', false );
2320	}
2321}
2322
2323
2324function rtmedia_add_comment_media_button_click( widget_id ){
2325	jQuery( '.'+rtmedia_comment_media_submit+widget_id ).on( 'click', function( e ){
2326		e.preventDefault();
2327		var media = jQuery( this ).attr( 'media' );
2328		if( typeof media != 'undefined'  && media == 1 ){
2329
2330			rtmedia_comment_media_input_button( widget_id, true );
2331
2332			rtmedia_comment_media_textbox_val( widget_id, true );
2333
2334			jQuery( this ).attr( 'media', 0 );
2335
2336			commentObj[ widget_id ].uploadFiles();
2337			return false;
2338		}
2339	});
2340}
2341
2342/**
2343 * Enable/Disable submit comment button.
2344 *
2345 * @since 4.3.2
2346 * @param {boolean} value Disable or Enable button.
2347 */
2348function rtmedia_comment_submit_button_disable( value ) {
2349	if ( 'boolean' === typeof value ) {
2350		jQuery( '#rt_media_comment_form #rt_media_comment_submit' ).prop( 'disabled', value );
2351	}
2352}
2353
2354function rtmedia_comment_media_input_button( widget_id, $value ){
2355
2356	rtmedia_comment_media_upload_button_post_disable( widget_id, $value );
2357
2358	rtmedia_comment_media_uplaod_button_disble( widget_id, $value );
2359
2360	rtmedia_uploaded_media_edit_disable( widget_id, $value );
2361}
2362
2363
2364
2365function rtmedia_uploaded_media_edit_disable( widget_id, $value ){
2366	if( $value ){
2367		jQuery( '.'+comment_media_wrapper+widget_id ).find( '.plupload_filelist_content .dashicons' ).hide()
2368		jQuery( '.'+comment_media_wrapper+widget_id ).find( '.plupload_file_action' ).hide()
2369	}else{
2370		jQuery( '.'+comment_media_wrapper+widget_id ).find( '.plupload_file_action' ).show()
2371		jQuery( '.'+comment_media_wrapper+widget_id ).find( '.plupload_filelist_content .dashicons' ).show()
2372	}
2373}
2374
2375function rtmedia_disable_comment_textbox( widget_id, value ){
2376	var form_class = '.'+comment_media_wrapper+widget_id;
2377	if( jQuery( form_class ).length > 0 ){
2378		comment_string = jQuery( form_class ).find( 'textarea' ).val();
2379		if( comment_string.includes( '&nbsp;' ) ){
2380			jQuery( form_class ).find('textarea.ac-input').val( '' );
2381		}
2382
2383		jQuery( form_class ).find( 'textarea' ).prop('disabled', value );
2384		jQuery( form_class ).find( 'textarea' ).css( 'color', '' );
2385	}
2386}
2387
2388
2389function rtmedia_comment_media_textbox_val( widget_id, $value ){
2390	var form_class = '.'+comment_media_wrapper+widget_id;
2391	if( jQuery( form_class ).length > 0 ){
2392		if( jQuery( form_class ).find('textarea.ac-input').length > 0 ){
2393			if( $value == true ){
2394				var textarea = jQuery( form_class ).find('textarea.ac-input').val();
2395				if( textarea == "" ){
2396					jQuery( form_class ).find('textarea.ac-input').val( '&nbsp;' );
2397					jQuery( form_class ).find( 'textarea' ).css( 'color', 'transparent' );
2398				}
2399			}else{
2400				jQuery( form_class ).find('textarea.ac-input').val( '' );
2401				jQuery( form_class ).find( 'textarea' ).css( 'color', '' );
2402			}
2403		}
2404	}
2405}
2406
2407
2408function rtmedia_comment_media_upload_button_post_disable( widget_id, $value ){
2409	if( typeof $value != 'undefined' ){
2410		jQuery( '.'+rtmedia_comment_media_submit+widget_id ).prop( 'disabled', $value );
2411		if( $value == true ){
2412			jQuery( '.'+rtmedia_comment_media_submit+widget_id ).closest( 'div.ac-reply-content' ).find( 'a.ac-reply-cancel' ).attr("disabled", "disabled");
2413		}else{
2414			jQuery( '.'+rtmedia_comment_media_submit+widget_id ).closest( 'div.ac-reply-content' ).find( 'a.ac-reply-cancel' ).removeAttr("disabled");
2415		}
2416	}
2417}
2418
2419
2420
2421function rtmedia_comment_media_remove_hidden_media_id( widget_id ){
2422	jQuery( '.'+comment_media_wrapper+widget_id ).find( 'input[name="rtMedia_attached_files[]"]' ).remove();
2423}
2424
2425
2426
2427function rtmedia_activity_comment_js_add_media_id(){
2428	jQuery.ajaxPrefilter( function( options, originalOptions, jqXHR ) {
2429		// Modify options, control originalOptions, store jqXHR, etc
2430		try {
2431			if ( originalOptions.data == null || typeof ( originalOptions.data ) == 'undefined' || typeof ( originalOptions.data.action ) == 'undefined' ) {
2432				return true;
2433			}
2434		} catch ( e ) {
2435			return true;
2436		}
2437
2438		if ( originalOptions.data.action == 'new_activity_comment' ) {
2439			widget_id = 'activity-'+originalOptions.data.form_id
2440
2441			var rtmedia_disable_media = 1;
2442			if( typeof rtmedia_disable_media_in_commented_media != 'undefined' ){
2443				rtmedia_disable_media = rtmedia_disable_media_in_commented_media;
2444			}
2445
2446			var temp = jQuery( '.'+comment_media_wrapper+widget_id ).find( 'input[name="rtMedia_attached_files[]"]' ).val();
2447
2448			if( typeof temp == 'undefined' ){
2449				temp = 0;
2450			}
2451
2452			if( typeof temp == '' ){
2453				temp = 0;
2454			}
2455			options.data += '&rtMedia_attached_files[]=' + temp;
2456			options.data += '&rtmedia_disable_media_in_commented_media=' + rtmedia_disable_media;
2457
2458			activity_attachemnt_ids = temp;
2459
2460			var orignalSuccess = originalOptions.success;
2461
2462			options.beforeSend = function() {
2463				if ( originalOptions.data.action == 'new_activity_comment' ) {
2464
2465					if( rtmedia_disable_media == 1 ){
2466						if( originalOptions.data.form_id != originalOptions.data.comment_id && temp > 0 ){
2467							jQuery( '.'+comment_media_wrapper+widget_id ).append('<div id="message" class="error bp-ajax-message" style="display: block;"><p> ' + rtmedia_disable_media_in_commented_media_text + ' </p></div>')
2468							jQuery( '.'+comment_media_wrapper+widget_id ).removeAttr( 'disabled' );
2469
2470							rtmedia_comment_media_input_button( widget_id, false );
2471
2472							rtmedia_disable_comment_textbox( widget_id, false );
2473
2474							return false;
2475						}
2476					}
2477				}
2478			};
2479			options.success = function( response ) {
2480                                if ( orignalSuccess && 'function' === typeof orignalSuccess ) {
2481                                    orignalSuccess( response );
2482                                }
2483				if ( response[0] + response[1] == '-1' ) {
2484					//Error
2485
2486				} else {
2487					if ( originalOptions.data.action == 'new_activity_comment' ) {
2488
2489						rtmedia_comment_media_remove_hidden_media_id( widget_id );
2490
2491						rtmedia_comment_media_textbox_val( widget_id, false );
2492
2493						rtmedia_comment_media_input_button( widget_id, false );
2494
2495						setTimeout( function() {
2496							rtmedia_apply_popup_to_media();
2497
2498							rtmedia_reset_video_and_audio();
2499
2500						}, 500 );
2501
2502						rtMediaHook.call( 'rtmedia_js_after_comment_added', [ ] );
2503					}
2504				}
2505
2506			};
2507			options.error = function() {
2508				if ( originalOptions.data.action == 'new_activity_comment' ) {
2509
2510					rtmedia_comment_media_remove_hidden_media_id( widget_id );
2511
2512					rtmedia_comment_media_textbox_val( widget_id, false );
2513
2514					rtmedia_comment_media_input_button( widget_id, false );
2515				}
2516			};
2517		}
2518	} );
2519}
2520
2521
2522function rtmedia_buddypress_load_newest_button_click(){
2523	jQuery( 'body #buddypress' ).on('click', 'ul.activity-list li.load-newest a', function(e) {
2524		e.preventDefault();
2525		/* add the popup to the images */
2526		rtmedia_apply_popup_to_media();
2527		/* add the uplaod button to the new activity */
2528		rtmedia_activity_stream_comment_media();
2529	});
2530}
2531
2532
2533function rtmedia_comment_media_upload_button_class( widget_id ){
2534	jQuery( 'form.'+comment_media_wrapper+widget_id ).find( 'input[type="submit"].rt_media_comment_submit' ).addClass( rtmedia_comment_media_submit+widget_id );
2535	jQuery( 'form.'+comment_media_wrapper+widget_id ).find( 'input[name="ac_form_submit"]' ).addClass( rtmedia_comment_media_submit+widget_id );
2536	rtmedia_add_widget_id_in_submit_button( widget_id );
2537}
2538
2539function rtmedia_add_widget_id_in_submit_button( widget_id ){
2540	jQuery( '.'+rtmedia_comment_media_submit+widget_id ).attr( 'widget_id', widget_id );
2541}
2542
2543
2544
2545function rtmedia_comment_media_upload_button_has_media( widget_id ,$value ){
2546	if( typeof $value != 'undefined' ){
2547		jQuery( '.'+rtmedia_comment_media_submit+widget_id ).attr( 'media', $value );
2548	}
2549}
2550
2551function rtmedia_comment_media_media_id( widget_id, media_id ){
2552	if ( jQuery( '.'+comment_media_wrapper+widget_id ).find( '#rtmedia_attached_id_' + media_id ).length < 1 ) {
2553
2554		rtmedia_comment_media_remove_hidden_media_id( widget_id );
2555
2556		jQuery( '.'+comment_media_wrapper+widget_id ).append( '<input type=\'hidden\' name=\'rtMedia_attached_files[]\' data-mode=\'rtmedia-update\' id=\'rtmedia_attached_id_' + media_id + '\' value=\'' +
2557		media_id + '\' />' );
2558	}
2559}
2560
2561function rtmedia_add_comment_media_button_trigger( widget_id ){
2562	if( jQuery( '.'+rtmedia_comment_media_submit+widget_id ).length > 0 ){
2563		jQuery( '.'+rtmedia_comment_media_submit+widget_id ).trigger('click');
2564	}
2565}
2566
2567
2568function renderUploadercomment_media( widget_id, parent_id_type ) {
2569   	var button = comment_media_add_button+widget_id;
2570
2571    //sidebar widget uploader config script
2572    if ( jQuery( '#'+button ).length > 0 && jQuery( "#"+button ).closest( 'form' ).find( 'input[type="file"]' ).length == 0 ) {
2573
2574    	jQuery( '#'+button ).closest('form').addClass( comment_media_wrapper+widget_id );
2575
2576
2577    	rtmedia_comment_media_upload_button_class( widget_id );
2578
2579    	if ( typeof rtMedia_update_plupload_comment == 'undefined' ) {
2580			return false;
2581		}
2582
2583		var plupload_comment = rtMedia_update_plupload_comment
2584		plupload_comment.browse_button = button;
2585		plupload_comment.container = 'rtmedia-comment-media-upload-container-'+widget_id;
2586
2587
2588		plupload_comment_main[ widget_id ] = plupload_comment;
2589
2590        commentObj[widget_id] = new UploadView(eval( plupload_comment_main[ widget_id ] ));
2591
2592        commentObj[widget_id].initUploader(false);
2593
2594		/*
2595		 * Fix for file selector does not open in Safari browser in IOS.
2596		 * In Safari in IOS, Plupload don't click on it's input(type=file), so file selector dialog won't open.
2597		 * In order to fix this, when rtMedia's attach media button is clicked,
2598		 * we check if Plupload's input(type=file) is clicked or not, if it's not clicked, then we click it manually
2599		 * to open file selector.
2600		 */
2601
2602		// Initially, select file dialog is close.
2603		var file_dialog_open = false;
2604
2605		// Plupload will click on this input when user click on rtMedia's attach media button.
2606		var input_file_el = '#' + plupload_comment.container + ' input[type=file]:first';
2607
2608		// Bind callback on Plupload's input element.
2609		jQuery( document.body ).on( 'click', input_file_el, function() {
2610			file_dialog_open = true;
2611		} );
2612
2613		// Bind callback on rtMedia's attach media button.
2614		jQuery( document.body ).on( 'click', '#' + button, function() {
2615			if ( false === file_dialog_open ) {
2616				jQuery( input_file_el ).click();
2617				file_dialog_open = false;
2618			}
2619			jQuery(this).blur();
2620		} );
2621
2622		var form_html = jQuery( "."+comment_media_wrapper+widget_id );
2623		if( jQuery( form_html ).find('div.rtmedia-plupload-container').length ){
2624			if( parent_id_type == "activity" ){
2625				form_html.find('.ac-reply-content .ac-textarea').after( form_html.find('div.rtmedia-plupload-container .rtmedia-comment-media-upload') );
2626			}
2627
2628			if( parent_id_type == "rtmedia" ){
2629				form_html.find('textarea').after( form_html.find('div.rtmedia-plupload-container .rtmedia-comment-media-upload') );
2630			}
2631		}
2632
2633
2634        jQuery("#"+comment_media_uplaod_media+widget_id).hide();
2635
2636        jQuery("#"+comment_media_uplaod_media+widget_id).click(function(e) {
2637
2638			//Enable 'post update' button when media get select
2639			rtmedia_comment_media_upload_button_post_disable( widget_id, true );
2640
2641            commentObj[widget_id].uploadFiles(e);
2642            commentObj[ widget_id ].uploader.refresh();
2643        });
2644
2645        rtmedia_add_comment_media_button_click( widget_id );
2646
2647
2648        commentObj[widget_id].uploader.bind('FilesAdded', function(upl, rfiles) {
2649
2650        	/* doest not allow multipal uplaod in comment media */
2651        	while (upl.files.length > 1) {
2652		        upl.removeFile(upl.files[0]);
2653		    }
2654			/* remove the last file that has being added to the comment media */
2655			commentObj[ widget_id ].upload_remove_array = [ ];
2656			jQuery( '#rtmedia_uploader_filelist-'+widget_id+' li.plupload_queue_li' ).remove();
2657
2658			rtmedia_comment_media_upload_button_has_media( widget_id, 1 );
2659
2660			jQuery.each( rfiles, function( i, file ) {
2661
2662				//Set file title along with file
2663				rtm_file_name_array = file.name.split( '.' );
2664				file.title = rtm_file_name_array[0];
2665
2666				var hook_respo = rtMediaHook.call( 'rtmedia_js_file_added', [ upl, file, '#rtmedia_uploader_filelist-'+widget_id ] );
2667
2668				if ( hook_respo == false ) {
2669					file.status = -1;
2670					commentObj[ widget_id ].upload_remove_array.push( file.id );
2671					return true;
2672				}
2673
2674				if ( commentObj[ widget_id ].uploader.settings.max_file_size < file.size ) {
2675					return true;
2676				}
2677
2678				var tmp_array = file.name.split( '.' );
2679
2680				if ( rtmedia_version_compare( rtm_wp_version, '3.9' ) ) { // Plupload getting updated in 3.9
2681					var ext_array = commentObj[ widget_id ].uploader.settings.filters.mime_types[0].extensions.split( ',' );
2682				} else {
2683					var ext_array = commentObj[ widget_id ].uploader.settings.filters[0].extensions.split( ',' );
2684				}
2685				if ( tmp_array.length > 1 ) {
2686					var ext = tmp_array[tmp_array.length - 1];
2687					ext = ext.toLowerCase();
2688					if ( jQuery.inArray( ext, ext_array ) === -1 ) {
2689						return true;
2690					}
2691				} else {
2692					return true;
2693				}
2694
2695				rtmedia_selected_file_list( plupload, file, '', '', widget_id );
2696
2697				 //Delete Function
2698                jQuery( "#" + file.id + " .plupload_delete-" + widget_id + " .remove-from-queue" ).click( function ( e ) {
2699                    e.preventDefault();
2700
2701                    /* submit button with no media */
2702					jQuery( "."+rtmedia_comment_media_submit+widget_id ).attr( 'media', '0' );
2703
2704                    commentObj[widget_id].uploader.removeFile(upl.getFile(file.id));
2705                    jQuery("#" + file.id).remove();
2706                    return false;
2707                });
2708
2709				// To change the name of the uploading file
2710				jQuery( '#label_' + file.id ).click( function( e ) {
2711					e.preventDefault();
2712
2713					rtm_file_label = this;
2714
2715					rtm_file_title_id = 'text_' + file.id;
2716					rtm_file_title_input = '#' + rtm_file_title_id;
2717
2718					rtm_file_title_wrapper_id = 'rtm_title_wp_' + file.id;
2719					rtm_file_title_wrapper = '#' + rtm_file_title_wrapper_id;
2720
2721					rtm_file_desc_id = 'rtm_desc_' + file.id;
2722					rtm_file_desc_input = '#' + rtm_file_desc_id;
2723
2724					rtm_file_desc_wrapper_id = 'rtm_desc_wp_' + file.id;
2725					rtm_file_desc_wrapper = '#' + rtm_file_desc_wrapper_id;
2726
2727					rtm_file_save_id = 'save_' + file.id;
2728					rtm_file_save_el = '#' + rtm_file_save_id;
2729
2730					jQuery( rtm_file_label ).hide();
2731					jQuery( rtm_file_label ).siblings( '.plupload_file_name_wrapper' ).hide();
2732
2733					// Show/create text box to edit media title
2734					if ( jQuery( rtm_file_title_input ).length === 0 ) {
2735						jQuery( rtm_file_label ).parent( '.plupload_file_name' ).prepend( '<div id="' + rtm_file_title_wrapper_id + '" class="rtm-upload-edit-title-wrapper"><label>' + rtmedia_edit_media_info_upload.title + '</label><input type="text" class="rtm-upload-edit-title" id="' + rtm_file_title_id + '" value="' + file.title + '" style="width: 75%;" /></div><div id="' + rtm_file_desc_wrapper_id + '" class="rtm-upload-edit-desc-wrapper"><label>' + rtmedia_edit_media_info_upload.description + '</label><textarea class="rtm-upload-edit-desc" id="' + rtm_file_desc_id + '"></textarea></div><span id="' + rtm_file_save_id + '" title="Save Change" class="dashicons dashicons-yes"></span>' );
2736					} else {
2737						jQuery( rtm_file_title_wrapper ).show();
2738						jQuery( rtm_file_desc_wrapper ).show();
2739						jQuery( rtm_file_save_el ).show();
2740					}
2741
2742					jQuery( rtm_file_title_input ).focus();
2743
2744				} );
2745
2746				rtm_file_save_id = 'save_' + file.id;
2747				rtm_file_save_el = '#' + rtm_file_save_id;
2748				jQuery( document.body ).on('click', rtm_file_save_el , function( e ) {
2749					e.preventDefault();
2750					rtm_file_title_id = 'text_' + file.id;
2751					rtm_file_title_input = '#' + rtm_file_title_id;
2752
2753					rtm_file_desc_id = 'rtm_desc_' + file.id;
2754					rtm_file_desc_input = '#' + rtm_file_desc_id;
2755
2756					rtm_file_title_wrapper_id = 'rtm_title_wp_' + file.id;
2757					rtm_file_title_wrapper = '#' + rtm_file_title_wrapper_id;
2758
2759					rtm_file_desc_wrapper_id = 'rtm_desc_wp_' + file.id;
2760					rtm_file_desc_wrapper = '#' + rtm_file_desc_wrapper_id;
2761
2762					var file_title_val = jQuery( rtm_file_title_input ).val();
2763					var file_desc_val = jQuery( rtm_file_desc_input ).val();
2764
2765					rtm_file_label = '#label_' + file.id;
2766
2767					var file_name_wrapper_el = jQuery( rtm_file_label ).siblings( '.plupload_file_name_wrapper' );
2768
2769					if ( '' !== file_title_val.trim() ) {
2770						var extension = file.name.split( '.' )[1];
2771						file_name_wrapper_el.text( file_title_val + '.' + extension );
2772						file.title = file_title_val;
2773					}
2774
2775					if ( file_desc_val != '' ) {
2776						file.description = file_desc_val;
2777					}
2778
2779					jQuery( rtm_file_title_wrapper ).hide();
2780					jQuery( rtm_file_desc_wrapper ).hide();
2781					file_name_wrapper_el.show();
2782					jQuery( rtm_file_label ).siblings( '.plupload_file_name_wrapper' );
2783					jQuery( rtm_file_label ).show();
2784					jQuery( this ).hide();
2785				} );
2786			} );
2787
2788            jQuery.each( commentObj[ widget_id ].upload_remove_array, function( i, rfile ) {
2789				if ( upl.getFile( rfile ) ) {
2790					upl.removeFile( upl.getFile( rfile ) );
2791				}
2792			} );
2793
2794			rtMediaHook.call( 'rtmedia_js_after_files_added', [ upl, rfiles ] );
2795
2796			if ( 'undefined' != typeof rtmedia_direct_upload_enabled && '1' == rtmedia_direct_upload_enabled ) {
2797
2798				jQuery( '.rtmedia-comment-media-submit-' + widget_id ).focus();
2799				/* when direct upload is enable */
2800				jQuery( '.'+rtmedia_comment_media_submit+widget_id ).trigger( 'click' );
2801			}
2802
2803			/**
2804			 * Uploader improper enter behavior issue(124) fixed
2805			 */
2806			jQuery('.rtmedia-comment-media-submit-'+widget_id).focus();
2807			/**
2808			 * End of issue 124
2809			 */
2810
2811        });
2812
2813
2814        commentObj[ widget_id ].uploader.bind( 'FileUploaded', function( up, file, res ) {
2815			if ( /MSIE (\d+\.\d+);/.test( navigator.userAgent ) ) { //Test for MSIE x.x;
2816				var ieversion = new Number( RegExp.jQuery1 ); // Capture x.x portion and store as a number
2817
2818				if ( ieversion < 10 ) {
2819					try {
2820						if ( typeof JSON.parse( res.response ) !== 'undefined' ) {
2821							res.status = 200;
2822						}
2823					} catch ( e ) {
2824					}
2825				}
2826			}
2827
2828			if ( res.status == 200 ) {
2829				try {
2830					var objIds = JSON.parse( res.response );
2831					jQuery.each( objIds, function( key, val ) {
2832						/* after id of the images get */
2833						rtmedia_comment_media_upload_button_post_disable( widget_id, false );
2834						rtmedia_comment_media_media_id( widget_id, val );
2835						rtmedia_add_comment_media_button_trigger( widget_id );
2836					} );
2837				} catch ( e ) {
2838
2839				}
2840				rtMediaHook.call( 'rtmedia_js_after_file_upload', [ up, file, res.response ] );
2841			}
2842		} );
2843
2844
2845        commentObj[ widget_id ].uploader.bind( 'Error', function( up, err ) {
2846
2847        	rtmedia_comment_media_upload_button_post_disable( widget_id, false );
2848
2849			if ( err.code == -600 ) { //File size error // if file size is greater than server's max allowed size
2850				var tmp_array;
2851				var ext = tr = '';
2852				tmp_array = err.file.name.split( '.' );
2853				if ( tmp_array.length > 1 ) {
2854
2855					ext = tmp_array[tmp_array.length - 1];
2856					if ( ! ( typeof ( up.settings.upload_size ) != 'undefined' && typeof ( up.settings.upload_size[ext] ) != 'undefined' && ( up.settings.upload_size[ext]['size'] < 1 || ( up.settings.upload_size[ext]['size'] * 1024 * 1024 ) >= err.file.size ) ) ) {
2857						rtmedia_selected_file_list( plupload, err.file, up, err, widget_id );
2858					}
2859				}
2860			} else {
2861				if ( err.code == -601 ) { // File extension error
2862					err.message = rtmedia_file_extension_error_msg;
2863				}
2864
2865				rtmedia_selected_file_list( plupload, err.file, '', err, widget_id );
2866			}
2867			jQuery( '.plupload_delete-'+widget_id ).on( 'click', function( e ) {
2868				e.preventDefault();
2869
2870				/* submit button with no media */
2871				jQuery( "."+rtmedia_comment_media_submit+widget_id ).attr( 'media', '0' );
2872
2873				jQuery( this ).parent().parent( 'li' ).remove();
2874			} );
2875
2876			return false;
2877		} );
2878
2879
2880        commentObj[ widget_id ].uploader.bind( 'BeforeUpload', function( up, files ) {
2881			jQuery.each( commentObj[ widget_id ].upload_remove_array, function( i, rfile ) {
2882				if ( up.getFile( rfile ) ) {
2883					up.removeFile( up.getFile( rfile ) );
2884				}
2885			} );
2886
2887			item_id = 0;
2888			object = 'profile';
2889
2890			up.settings.multipart_params.context = object;
2891			up.settings.multipart_params.comment_media_activity_id = widget_id;
2892			up.settings.multipart_params.context_id = item_id;
2893			up.settings.multipart_params.rtmedia_update = true;
2894			up.settings.multipart_params.activity_id = 'null';
2895			up.settings.multipart_params.title = files.title.split( '.' )[ 0 ];
2896			if ( typeof files.description != 'undefined' ) {
2897				up.settings.multipart_params.description = files.description;
2898			} else {
2899				up.settings.multipart_params.description = '';
2900			}
2901		} );
2902
2903        commentObj[ widget_id ].uploader.bind( 'UploadComplete', function( up, files ) {
2904
2905			jQuery( '#rtmedia_uploader_filelist-'+widget_id+' li').remove();
2906
2907			window.onbeforeunload = null;
2908		} );
2909
2910        commentObj[ widget_id ].uploader.bind( 'UploadProgress', function( up, file ) {
2911			// creates a progress bar to display file upload status
2912			var progressBar = jQuery( '<div/>', {
2913				'class': 'plupload_file_progress ui-widget-header',
2914			});
2915			progressBar.css( 'width', file.percent + '%' );
2916			jQuery( '#' + file.id + ' .plupload_file_status' ).html( progressBar );
2917			// filter to customize existing progress bar can be used to display
2918			// '%' of upload completed.
2919			rtMediaHook.call( 'rtm_custom_progress_bar_content', [ file ] );
2920			jQuery( '#' + file.id ).addClass( 'upload-progress' );
2921			if ( file.percent == 100 ) {
2922				jQuery( '#' + file.id ).toggleClass( 'upload-success' );
2923			}
2924
2925			window.onbeforeunload = function( evt ) {
2926				var message = rtmedia_upload_progress_error_message;
2927				return message;
2928			};
2929		} );
2930
2931        commentObj[widget_id].uploader.refresh();//refresh the uploader for opera/IE fix on media page
2932    }
2933}
2934
2935function rtmedia_comment_media_upload( upload_comment ){
2936	if( typeof upload_comment != 'undefined' ){
2937		if( jQuery( upload_comment ).find( '.rt_upload_hf_upload_parent_id' ).length > 0 ){
2938			var parent_id = jQuery( upload_comment ).find( '.rt_upload_hf_upload_parent_id' ).val();
2939			var parent_id_type = jQuery( upload_comment ).find( '.rt_upload_hf_upload_parent_id_type' ).val();
2940			if( typeof parent_id != 'undefined'  && typeof parent_id_type != 'undefined'  ){
2941				var widget_id = parent_id_type+ '-' +parent_id;
2942
2943		        renderUploadercomment_media( widget_id , parent_id_type );
2944			}
2945		}
2946	}
2947}
2948
2949
2950function rtmedia_activity_stream_comment_media(){
2951
2952    // For Buddypress new template nouveau
2953    if ( bp_template_pack && 'legacy' !== bp_template_pack ) {
2954		jQuery('#buddypress div#activity-stream ul.activity-list li.activity-item, #buddypress ul#activity-stream ul.activity-list li.activity-item').each(function () {
2955            if( jQuery( this ).find( '.rt_upload_hf_upload_parent_id' ).length  && jQuery( this ).find( '.rt_upload_hf_upload_parent_id_type' ).length ){
2956                if ( jQuery( this ).find( "input[type=file]" ).length == 0 ) {
2957                    // Please remove this in future when buddypress's nouveau tmeplate add some hook into comment form. Currently there is no hook into comment form so this is pretty hook.
2958                    var container = jQuery( this ).find( '.rtmedia-uploader-div' );
2959                    jQuery( this ).find('.ac-form').append( container.html() );
2960                    container.remove();
2961                    rtmedia_comment_media_upload( this );
2962                }
2963            }
2964        });
2965    }
2966    else {
2967        jQuery('#buddypress ul#activity-stream li.activity-item').each(function () {
2968            if( jQuery( this ).find( '.rt_upload_hf_upload_parent_id' ).length  && jQuery( this ).find( '.rt_upload_hf_upload_parent_id_type' ).length ){
2969	        rtmedia_comment_media_upload( this );
2970            }
2971        });
2972    }
2973}
2974
2975
2976
2977
2978function rtmedia_comment_media_single_page(){
2979	var single_upload_comment = jQuery( '.rtmedia-single-container .rtmedia-single-meta .rtmedia-item-comments form' );
2980	rtmedia_comment_media_upload( single_upload_comment );
2981}
2982
2983
2984function rtmedia_disable_popup_navigation_comment_media_focus() {
2985	rtmedia_disable_popup_navigation( '.plupload_filelist_content li input.rtm-upload-edit-title' );
2986	rtmedia_disable_popup_navigation( '.plupload_filelist_content li textarea.rtm-upload-edit-desc' );
2987}
2988
2989
2990function rtmedia_disable_popup_navigation( $selector ){
2991	jQuery( document ).on( 'focusin', $selector, function() {
2992		jQuery( document ).unbind( 'keydown' );
2993	} );
2994
2995	jQuery( document ).on( 'focusout', $selector, function() {
2996		var rtm_mfp = jQuery.magnificPopup.instance;
2997		jQuery( document ).on( 'keydown', function( e ) {
2998			if ( e.keyCode === 37 ) {
2999				rtm_mfp.prev();
3000			} else if ( e.keyCode === 39 ) {
3001				rtm_mfp.next();
3002			}
3003		} );
3004	} );
3005}
3006
3007/**
3008 * Function that smooth scrolls to the latest comment in rtMedia.
3009 *  Created on 23-Nov-2020 by Vipin Kumar Dinkar <[email protected]>
3010 */
3011const rtMediaScrollComments = () => {
3012	const commentBox       = document.getElementById( 'rtmedia_comment_ul' );
3013
3014	if ( commentBox !== null ) {
3015		const commentsToScroll = ( commentBox.offsetHeight ) * 1000;
3016		commentBox.scrollTo( { top: commentsToScroll, behavior: 'smooth' } );
3017	}
3018}
3019
3020/* Add max size limit message beside upload button */
3021const rtMediaMaxSizeMessage = () => {
3022	const buttonContainer = document.getElementById( 'rtmedia-action-update' );
3023	if ( buttonContainer ) {
3024		const msg = document.createElement('span');
3025		msg.textContent = 'Max. File Size: ' + rtMedia_update_plupload_config.max_file_size;
3026		msg.style.fontSize = '12px';
3027		msg.style.opacity = '0.7'; 
3028		buttonContainer.appendChild(msg);
3029	}
3030}
3031
3032rtMediaMaxSizeMessage();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.