PageSourceSearch

https://aprenderfotografia.online/wp-content/plugins/mediapress/assets/js/activity.js?ver=6.0.16

js aprenderfotografia.online collected 2026-09-24 09:04:02 UTC 20,269 bytes, 675 lines download raw bytes

1//this file mostly contains the modified version of functions 
2//taken from buddypress.js to add/delete activity and other activity related action
3
4jQuery( document ).ready( function(){
5var jq = jQuery;
6/**
7 * For Allowing User to post first comment to a media Item when the media item has no entry in the activity table
8 * Thanks to @apeatling, this function is taken from bp-default/_inc/global.js but slightly modified to use prefix mpp-
9 */
10
11	/* Textarea focus */
12	jq(document).on('focus', '#mpp-whats-new', function() {
13		jq("#mpp-whats-new-options").animate({
14			height:'50px'
15		});
16		/*jq("form#mpp-whats-new-form textarea").animate({
17			height:'50px'
18		});
19		*/
20		jq("#mpp-aw-whats-new-submit").prop("disabled", false);
21
22		var $whats_new_form = jq("form#mpp-whats-new-form");
23		if ( $whats_new_form.hasClass("submitted") ) {
24			$whats_new_form.removeClass("submitted");	
25		}
26	});
27
28	/* On blur, shrink if it's empty */
29	jq(document).on('blur', '#mpp-whats-new',  function(){
30		if (!this.value.match(/\S+/)) {
31			this.value = "";
32			jq("#mpp-whats-new-options").animate({
33				height:'0'
34			});
35			/*
36			jq("form#mpp-whats-new-form textarea").animate({
37				height:'20px'
38			});*/
39			jq("#mpp-aw-whats-new-submit").prop("disabled", true);
40		}
41	});
42
43
44	/* New posts Activity comment(not the replies to comment) on media/gallery */
45	jq(document).on('click', 'input#mpp-aw-whats-new-submit', function() {
46		var activity_list = '';
47		var button = jq(this);
48		var form = button.closest("form#mpp-whats-new-form");
49
50		form.children().each( function() {
51			if ( jq.nodeName(this, "textarea") || jq.nodeName(this, "input") )
52				jq(this).prop( 'disabled', true );
53		});
54
55		/* Remove any errors */
56		jq('div.error').remove();
57		
58		button.addClass('loading');
59		button.prop('disabled', true);
60		form.addClass("submitted");
61		
62		/* Default POST values */
63		var object = '';
64		var item_id = form.find("#mpp-whats-new-post-in").val();
65		var content = form.find("textarea#mpp-whats-new").val();
66
67		/* Set object for non-profile posts */
68		if ( item_id > 0 ) {
69			object = form.find("#mpp-whats-new-post-object").val();
70		}
71
72		var mpp_type = jq(form).find('#mpp-activity-type').val();
73		var mpp_id = jq(form).find('#mpp-item-id').val();
74		jq.post( ajaxurl, {
75			action: 'mpp_add_comment',
76			'cookie': mpp_get_cookies(),
77			'_wpnonce_post_update': form.find("input#_wpnonce_post_update").val(),
78			'content': content,
79			'object': object,
80			'item_id': item_id,
81			'mpp-id': mpp_id,
82			'mpp-type'	: mpp_type, //media or gallery
83			'_bp_as_nonce': jq('#_bp_as_nonce').val() || ''
84		},
85		function(response) {
86
87			form.children().each( function() {
88				if ( jq.nodeName(this, "textarea") || jq.nodeName(this, "input") ) {
89					jq(this).prop( 'disabled', false );
90				}
91			});
92			button.prop('disabled', false);
93			/* Check for errors and append if found. */
94			if ( response[0] + response[1] == '-1' ) {
95				form.prepend( response.substr( 2, response.length ) );
96				jq( 'form#' + form.attr('id') + ' div.error').hide().fadeIn( 200 );
97			} else {
98				activity_list = jq(form.parents('.mpp-activity').get(0) );
99				if ( 0 == (activity_list.find("ul.mpp-activity-list")).length ) {
100					jq("div.error").slideUp(100).remove();
101					jq("div#message").slideUp(100).remove();
102					activity_list.append( '<ul id="mpp-activity-stream" class="mpp-activity-list item-list">' );
103				}
104
105				activity_list.find("ul#mpp-activity-stream").prepend(response);
106				activity_list.find("ul#mpp-activity-stream li:first").addClass('new-update just-posted');
107
108				
109				form.find("textarea#mpp-whats-new").val('');
110			}
111
112			form.find("#mpp-whats-new-options").animate({
113				height:'0px'
114			});
115			form.find("textarea").animate({
116				height:'20px'
117			});
118			form.find("#mpp-whats-new-submit").prop("disabled", false).removeClass('loading');
119		});
120
121		return false;
122	});
123	
124	/* Stream event delegation */
125	jq(document).on('click', 'div.mpp-activity', function(event) {
126		var target = jq(event.target),
127			type, parent, parent_id,
128			li, id, link_href, nonce, timestamp,
129			oldest_page, just_posted;
130
131		/* Favoriting activity stream items */
132		if ( target.hasClass('fav') || target.hasClass('unfav') ) {
133			type      = target.hasClass('fav') ? 'fav' : 'unfav';
134			parent    = target.closest('.activity-item');
135			parent_id = parent.attr('id').substr( 9, parent.attr('id').length );
136
137			target.addClass('loading');
138
139			jq.post( ajaxurl, {
140				action: 'activity_mark_' + type,
141				'cookie': mpp_get_cookies(),
142				'id': parent_id
143			},
144			function(response) {
145				target.removeClass('loading');
146
147				target.fadeOut( 200, function() {
148					jq(this).html(response);
149					jq(this).attr('title', 'fav' === type ? _mppStrings.remove_fav : _mppStrings.mark_as_fav);
150					jq(this).fadeIn(200);
151				});
152
153				if ( 'fav' === type ) {
154					if ( !jq('.item-list-tabs #activity-favs-personal-li').length ) {
155						if ( !jq('.item-list-tabs #activity-favorites').length ) {
156							jq('.item-list-tabs ul #activity-mentions').before( '<li id="activity-favorites"><a href="#">' + _mppStrings.my_favs + ' <span>0</span></a></li>');
157						}
158
159						jq('.item-list-tabs ul #activity-favorites span').html( Number( jq('.item-list-tabs ul #activity-favorites span').html() ) + 1 );
160					}
161
162					target.removeClass('fav');
163					target.addClass('unfav');
164
165				} else {
166					
167				}
168
169				
170			});
171
172			return false;
173		}
174
175		/* Delete activity stream items */
176		if ( target.hasClass('delete-activity') ) {
177			li        = target.parents('div.mpp-activity ul li');
178			id        = li.attr('id').substr( 9, li.attr('id').length );
179			link_href = target.attr('href');
180			nonce     = link_href.split('_wpnonce=');
181			timestamp = li.prop( 'class' ).match( /date-recorded-([0-9]+)/ );
182			nonce     = nonce[1];
183
184			target.addClass('loading');
185
186			jq.post( ajaxurl, {
187				action: 'delete_activity',
188				'cookie': mpp_get_cookies(),
189				'id': id,
190				'_wpnonce': nonce
191			},
192			function(response) {
193
194				if ( response[0] + response[1] === '-1' ) {
195					li.prepend( response.substr( 2, response.length ) );
196					li.children('#message').hide().fadeIn(300);
197				} else {
198					li.slideUp(300);
199
200					// reset vars to get newest activities
201					if ( timestamp && activity_last_recorded === timestamp[1] ) {
202						newest_activities = '';
203						activity_last_recorded  = 0;
204					}
205				}
206			});
207
208			return false;
209		}
210
211		// Spam activity stream items
212		if ( target.hasClass( 'spam-activity' ) ) {
213			li        = target.parents( 'div.mpp-activity ul li' );
214			timestamp = li.prop( 'class' ).match( /date-recorded-([0-9]+)/ );
215			target.addClass( 'loading' );
216
217			jq.post( ajaxurl, {
218				action: 'bp_spam_activity',
219				'cookie': encodeURIComponent( document.cookie ),
220				'id': li.attr( 'id' ).substr( 9, li.attr( 'id' ).length ),
221				'_wpnonce': target.attr( 'href' ).split( '_wpnonce=' )[1]
222			},
223
224			function(response) {
225				if ( response[0] + response[1] === '-1' ) {
226					li.prepend( response.substr( 2, response.length ) );
227					li.children( '#message' ).hide().fadeIn(300);
228				} else {
229					li.slideUp( 300 );
230					// reset vars to get newest activities
231					if ( timestamp && activity_last_recorded === timestamp[1] ) {
232						newest_activities = '';
233						activity_last_recorded  = 0;
234					}
235				}
236			});
237
238			return false;
239		}
240
241		/* Load more updates at the end of the page */
242		if ( target.parent().hasClass('mpp-load-more') ) {
243			if ( bp_ajax_request ) {
244				bp_ajax_request.abort();
245			}
246
247			target.parent().find('.mpp-load-more').addClass('loading');
248
249			if ( null === jq.cookie('bp-activity-oldestpage') ) {
250				jq.cookie('bp-activity-oldestpage', 1, {
251					path: '/'
252				} );
253			}
254
255			oldest_page = ( jq.cookie('bp-activity-oldestpage') * 1 ) + 1;
256			just_posted = [];
257
258			jq('.mpp-activity-list li.just-posted').each( function(){
259				just_posted.push( jq(this).attr('id').replace( 'mpp-activity-','' ) );
260			});
261
262			load_more_args = {
263				action: 'activity_get_older_updates',
264				'cookie': mpp_get_cookies(),
265				'page': oldest_page,
266				'exclude_just_posted': just_posted.join(',')
267			};
268
269			load_more_search = mpp_get_querystring('s');
270
271			if ( load_more_search ) {
272				load_more_args.search_terms = load_more_search;
273			}
274
275			bp_ajax_request = jq.post( ajaxurl, load_more_args,
276			function(response)
277			{
278				target.parent().find('.mpp-load-more').removeClass('loading');
279				jq.cookie( 'bp-activity-oldestpage', oldest_page, {
280					path: '/'
281				} );
282				jq('ul.mpp-activity-list').append(response.contents);
283
284				target.parent().hide();
285			}, 'json' );
286
287			return false;
288		}
289
290		/* Load newest updates at the top of the list */
291		if ( target.parent().hasClass('load-newest') ) {
292
293			event.preventDefault();
294
295			target.parent().hide();
296
297			/**
298			 * If a plugin is updating the recorded_date of an activity
299			 * it will be loaded as a new one. We need to look in the
300			 * stream and eventually remove similar ids to avoid "double".
301			 */
302			activity_html = jq.parseHTML( newest_activities );
303
304			jq.each( activity_html, function( i, el ){
305				if( 'LI' === el.nodeName && jq(el).hasClass( 'just-posted' ) ) {
306					if( jq( '#' + jq(el).attr( 'id' ) ).length ) {
307						jq( '#' + jq(el).attr( 'id' ) ).remove();
308					}
309				}
310			} );
311
312			// Now the stream is cleaned, prepend newest
313			jq( 'ul.mpp-activity-list' ).prepend( newest_activities );
314
315			// reset the newest activities now they're displayed
316			newest_activities = '';
317		}
318	});
319
320	// Activity "Read More" links inside the gallery/media activity
321	jq(document).on('click', 'div.mpp-activity .activity-read-more a', function(event) {
322		
323		var target = jq(event.target),
324			link_id = target.parent().attr('id').split('-'),
325			a_id    = link_id[4],
326			type    = link_id[1], /* activity or acomment */
327			inner_class, a_inner;
328
329		inner_class = type === 'acomment' ? 'mpp-acomment-content' : 'mpp-activity-inner';
330		a_inner = jq('#' + type + '-' + a_id + ' .' + inner_class + ':first' );
331		jq(target).addClass('loading');
332
333		jq.post( ajaxurl, {
334			action: 'get_single_activity_content',//should we override it too?
335			'activity_id': a_id
336		},
337		function(response) {
338			jq(a_inner).slideUp(300).html(response).slideDown(300);
339		});
340
341		return false;
342	});
343
344	/**** Activity Comments *******************************************************/
345
346	/* Hide all activity comment forms */
347	jq('form.mpp-ac-form').hide();
348	
349	/* Activity list event delegation */
350	jq(document).on( 'click', '.mpp-activity', function(event) {
351		
352	var target = jq(event.target),
353			id, ids, a_id, c_id, form,
354			form_parent, form_id,
355			tmp_id, comment_id, comment,content,
356			ajaxdata,
357			ak_nonce,
358			show_all_a, new_count,
359			link_href, comment_li, nonce;
360
361		/* Comment / comment reply links */
362		if ( target.hasClass('mpp-acomment-reply') || target.parent().hasClass('mpp-acomment-reply') ) {
363			if ( target.parent().hasClass('mpp-acomment-reply') ) {
364				target = target.parent();
365			}
366			
367			var id = target.attr('id');
368			ids = id.split('-');
369
370			var a_id = ids[3]
371			var c_id = target.attr('href').substr( 10, target.attr('href').length );
372			
373			var form = jq( '#mpp-ac-form-' + a_id );
374
375			form.css( 'display', 'none' );
376			form.removeClass('root');
377			jq('.mpp-ac-form').hide();
378
379			/* Hide any error messages */
380			form.children('div').each( function() {
381				if ( jq(this).hasClass( 'error' ) )
382					jq(this).hide();
383			});
384
385			if ( ids[2] !== 'comment' ) {
386				jq('#mpp-acomment-' + c_id).append( form );
387			} else {
388				jq('#mpp-activity-' + a_id + ' .mpp-activity-comments').append( form );
389			}
390
391			if ( form.parent().hasClass( 'mpp-activity-comments' ) ) {
392				form.addClass('root');
393			}
394
395			form.slideDown( 200 );
396			jq.scrollTo( form, 500, {
397				offset:-100,
398				easing:'swing'
399			} );
400			jq('#mpp-ac-form-' + ids[3] + ' textarea').focus();
401
402			return false;
403		}
404
405		/* Activity comment posting */
406		if ( target.attr('name') == 'mpp_ac_form_submit' ) {
407			var form        = target.parents( 'form' );
408			var form_parent = form.parent();
409			var form_id     = form.attr('id').split('-');
410
411			if ( !form_parent.hasClass('mpp-activity-comments') ) {
412				var tmp_id = form_parent.attr('id').split('-');
413				var comment_id = tmp_id[2];
414			} else {
415				var comment_id = form_id[3];
416			}
417			content = jq( '#' + form.attr('id') + ' textarea' );
418			
419			/* Hide any error messages */
420			jq( '#' + form.attr('id') + ' div.error').hide();
421			target.addClass('loading').prop('disabled', true);
422			content.addClass('loading').prop('disabled', true);
423
424			var ajaxdata = {
425				action: 'mpp_add_reply',
426				'cookie': mpp_get_cookies(),
427				'_wpnonce_new_activity_comment': jq("input#_wpnonce_new_activity_comment").val(),
428				'comment_id': comment_id,
429				'form_id': form_id[3],
430				'content': content.val()
431			};
432
433			// Akismet
434			ak_nonce = jq('#_bp_as_nonce_' + comment_id).val();
435			if ( ak_nonce ) {
436				ajaxdata['_bp_as_nonce_' + comment_id] = ak_nonce;
437			}
438
439			jq.post( ajaxurl, ajaxdata, function(response) {
440				target.removeClass('loading');
441				content.removeClass('loading');
442				/* Check for errors and append if found. */
443				if ( response[0] + response[1] == '-1' ) {
444					form.append( jq( response.substr( 2, response.length ) ).hide().fadeIn( 200 ) );
445				} else {
446					var activity_comments = form.parent();
447					form.fadeOut( 200, function() {
448						if ( 0 == activity_comments.children('ul').length ) {
449							if ( activity_comments.hasClass('mpp-activity-comments') ) {
450								activity_comments.prepend('<ul></ul>');
451							} else {
452								activity_comments.append('<ul></ul>');
453							}
454						}
455
456						/* Preceeding whitespace breaks output with jQuery 1.9.0 */
457						var the_comment = jq.trim( response );
458
459						activity_comments.children('ul').append( jq( the_comment ).hide().fadeIn( 200 ) );
460						form.children('textarea').val('');
461						activity_comments.parent().addClass('has-comments');
462					} );
463
464					jq( '#' + form.attr('id') + ' textarea').val('');
465
466					/* Increase the "Reply (X)" button count */
467					jq('#mpp-activity-' + form_id[3] + ' a.mpp-acomment-reply span').html( Number( jq('#mpp-activity-' + form_id[3] + ' a.mpp-acomment-reply span').html() ) + 1 );
468
469					// Increment the 'Show all x comments' string, if present
470					var show_all_a = activity_comments.find('.show-all').find('a');
471					if ( show_all_a ) {
472						new_count = jq('li#mpp-activity-' + form_id[3] + ' a.mpp-acomment-reply span').html();
473						show_all_a.html( _mppStrings.show_x_comments.replace( '%d', new_count ) );
474					}
475				}
476				jq(target).prop('disabled', false);
477				jq(content).prop('disabled', false);
478			});
479
480			return false;
481		}
482
483		/* Deleting an activity comment */
484		if ( target.hasClass('mpp-acomment-delete') ) {
485			var link_href = target.attr('href');
486			var comment_li = target.parent().parent();
487			var form = comment_li.parents('div.mpp-activity-comments').children('form');
488
489			var nonce = link_href.split('_wpnonce=');
490			nonce = nonce[1];
491
492			var comment_id = link_href.split('cid=');
493			comment_id = comment_id[1].split('&');
494			comment_id = comment_id[0];
495
496			target.addClass('loading');
497
498			/* Remove any error messages */
499			jq('.mpp-activity-comments ul .error').remove();
500
501			/* Reset the form position */
502			comment_li.parents('.mpp-activity-comments').append(form);
503
504			jq.post( ajaxurl, {
505				action: 'delete_activity_comment',
506				'cookie': mpp_get_cookies(),
507				'_wpnonce': nonce,
508				'id': comment_id
509			},
510			function(response) {
511				/* Check for errors and append if found. */
512				if ( response[0] + response[1] === '-1' ) {
513					comment_li.prepend( jq( response.substr( 2, response.length ) ).hide().fadeIn( 200 ) );
514				} else {
515					var children  = jq( '#' + comment_li.attr('id') + ' ul' ).children('li'),
516						child_count = 0,
517						count_span, new_count, show_all_a;
518
519					jq(children).each( function() {
520						if ( !jq(this).is(':hidden') ) {
521							child_count++;
522						}
523					});
524					comment_li.fadeOut(200, function() {
525						comment_li.remove();
526					});
527
528					/* Decrease the "Reply (X)" button count */
529					count_span = jq('#' + comment_li.parents('#mpp-activity-stream > li').attr('id') + ' a.mpp-acomment-reply span');
530					new_count = count_span.html() - ( 1 + child_count );
531					count_span.html(new_count);
532
533					// Change the 'Show all x comments' text
534					show_all_a = comment_li.siblings('.show-all').find('a');
535					if ( show_all_a ) {
536						show_all_a.html( _mppStrings.show_x_comments.replace( '%d', new_count ) );
537					}
538
539					/* If that was the last comment for the item, remove the has-comments class to clean up the styling */
540					if ( 0 === new_count ) {
541						jq(comment_li.parents('#mpp-activity-stream > li')).removeClass('has-comments');
542					}
543				}
544			});
545
546
547			return false;
548		}
549
550				// Spam an activity stream comment
551		if ( target.hasClass( 'spam-activity-comment' ) ) {
552			link_href  = target.attr( 'href' );
553			comment_li = target.parent().parent();
554
555			target.addClass('loading');
556
557			// Remove any error messages
558			jq( '.mpp-activity-comments ul div.error' ).remove();
559
560			// Reset the form position
561			comment_li.parents( '.mpp-activity-comments' ).append( comment_li.parents( '.mpp-activity-comments' ).children( 'form' ) );
562
563			jq.post( ajaxurl, {
564				action: 'bp_spam_activity_comment',
565				'cookie': encodeURIComponent( document.cookie ),
566				'_wpnonce': link_href.split( '_wpnonce=' )[1],
567				'id': link_href.split( 'cid=' )[1].split( '&' )[0]
568			},
569
570			function ( response ) {
571				// Check for errors and append if found.
572				if ( response[0] + response[1] === '-1' ) {
573					comment_li.prepend( jq( response.substr( 2, response.length ) ).hide().fadeIn( 200 ) );
574
575				} else {
576					var children  = jq( '#' + comment_li.attr( 'id' ) + ' ul' ).children( 'li' ),
577						child_count = 0,
578						parent_li;
579
580					jq(children).each( function() {
581						if ( !jq( this ).is( ':hidden' ) ) {
582							child_count++;
583						}
584					});
585					comment_li.fadeOut( 200 );
586
587					// Decrease the "Reply (X)" button count
588					parent_li = comment_li.parents( '#mpp-activity-stream > li' );
589					jq( '#' + parent_li.attr( 'id' ) + ' a.mpp-acomment-reply span' ).html( jq( '#' + parent_li.attr( 'id' ) + ' a.mpp-acomment-reply span' ).html() - ( 1 + child_count ) );
590				}
591			});
592
593			return false;
594		}
595
596		/* Showing hidden comments - pause for half a second */
597		if ( target.parent().hasClass('show-all') ) {
598			target.parent().addClass('loading');
599
600			setTimeout( function() {
601				target.parent().parent().children('li').fadeIn(200, function() {
602					target.parent().remove();
603				});
604			}, 600 );
605
606			return false;
607		}
608
609		// Canceling an activity comment
610		if ( target.hasClass( 'mpp-ac-reply-cancel' ) ) {
611			jq(target).closest('.mpp-ac-form').slideUp( 200 );
612			return false;
613		}
614	});
615/* Escape Key Press for cancelling comment forms */
616	jq(document).keydown( function(e) {
617		e = e || window.event;
618		if (e.target) {
619			element = e.target;
620		} else if (e.srcElement) {
621			element = e.srcElement;
622		}
623
624		if( element.nodeType === 3) {
625			element = element.parentNode;
626		}
627
628		if( e.ctrlKey === true || e.altKey === true || e.metaKey === true ) {
629			return;
630		}
631
632		var keyCode = (e.keyCode) ? e.keyCode : e.which;
633
634		if ( keyCode === 27 ) {
635			if (element.tagName === 'TEXTAREA') {
636				if ( jq(element).hasClass('mpp-ac-input') ) {
637					jq(element).parent().parent().parent().slideUp( 200 );
638					return false;
639				}
640			}
641		}
642	});
643
644})	;
645//a replacement of bp_get_querystring for themes that does not have it
646function mpp_get_querystring( n ) {
647	var half = location.search.split( n + '=' )[1];
648	return half ? decodeURIComponent( half.split('&')[0] ) : null;
649}
650
651//copy of bp_get_cookies since some themes might not include that
652/* Returns a querystring of BP cookies (cookies beginning with 'bp-') */
653function mpp_get_cookies() {
654	// get all cookies and split into an array
655	var allCookies   = document.cookie.split(";");
656
657	var bpCookies    = {};
658	var cookiePrefix = 'bp-';
659
660	// loop through cookies
661	for (var i = 0; i < allCookies.length; i++) {
662		var cookie    = allCookies[i];
663		var delimiter = cookie.indexOf("=");
664		var name      = jq.trim( unescape( cookie.slice(0, delimiter) ) );
665		var value     = unescape( cookie.slice(delimiter + 1) );
666
667		// if BP cookie, store it
668		if ( name.indexOf(cookiePrefix) == 0 ) {
669			bpCookies[name] = value;
670		}
671	}
672
673	// returns BP cookies as querystring
674	return encodeURIComponent( jq.param(bpCookies) );
675}

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.