SHOW:
|
|
- or go back to the newest paste.
1 | // AJAX Functions | |
2 | var jq = jQuery; | |
3 | ||
4 | // Global variable to prevent multiple AJAX requests | |
5 | var bp_ajax_request = null; | |
6 | ||
7 | jq(document).ready( function() { | |
8 | /**** Page Load Actions *******************************************************/ | |
9 | ||
10 | /* Hide Forums Post Form */ | |
11 | if ( '-1' == window.location.search.indexOf('new') && jq('div.forums').length ) | |
12 | jq('div#new-topic-post').hide(); | |
13 | else | |
14 | jq('div#new-topic-post').show(); | |
15 | ||
16 | /* Activity filter and scope set */ | |
17 | bp_init_activity(); | |
18 | ||
19 | /* Object filter and scope set. */ | |
20 | var objects = [ 'members', 'groups', 'blogs', 'forums' ]; | |
21 | bp_init_objects( objects ); | |
22 | ||
23 | /* @mention Compose Scrolling */ | |
24 | if ( jq.query.get('r') && jq('textarea#whats-new').length ) { | |
25 | jq('#whats-new-options').animate({height:'40px'}); | |
26 | jq("form#whats-new-form textarea").animate({height:'50px'}); | |
27 | jq.scrollTo( jq('textarea#whats-new'), 500, { offset:-125, easing:'easeOutQuad' } ); | |
28 | jq('textarea#whats-new').focus(); | |
29 | } | |
30 | ||
31 | /**** Activity Posting ********************************************************/ | |
32 | ||
33 | /* Textarea focus */ | |
34 | jq('#whats-new').focus( function(){ | |
35 | jq("#whats-new-options").animate({height:'40px'}); | |
36 | jq("form#whats-new-form textarea").animate({height:'50px'}); | |
37 | jq("#aw-whats-new-submit").prop("disabled", false); | |
38 | }); | |
39 | ||
40 | /* New posts */ | |
41 | jq("input#aw-whats-new-submit").click( function() { | |
42 | var button = jq(this); | |
43 | var form = button.parent().parent().parent().parent(); | |
44 | ||
45 | form.children().each( function() { | |
46 | if ( jq.nodeName(this, "textarea") || jq.nodeName(this, "input") ) | |
47 | jq(this).prop( 'disabled', true ); | |
48 | }); | |
49 | ||
50 | /* Remove any errors */ | |
51 | jq('div.error').remove(); | |
52 | button.addClass('loading'); | |
53 | button.prop('disabled', true); | |
54 | ||
55 | /* Default POST values */ | |
56 | var object = ''; | |
57 | var item_id = jq("#whats-new-post-in").val(); | |
58 | var content = jq("textarea#whats-new").val(); | |
59 | ||
60 | /* Set object for non-profile posts */ | |
61 | if ( item_id > 0 ) { | |
62 | object = jq("#whats-new-post-object").val(); | |
63 | } | |
64 | ||
65 | jq.post( ajaxurl, { | |
66 | action: 'post_update', | |
67 | 'cookie': encodeURIComponent(document.cookie), | |
68 | '_wpnonce_post_update': jq("input#_wpnonce_post_update").val(), | |
69 | 'content': content, | |
70 | 'object': object, | |
71 | 'item_id': item_id | |
72 | }, | |
73 | function(response) { | |
74 | ||
75 | form.children().each( function() { | |
76 | if ( jq.nodeName(this, "textarea") || jq.nodeName(this, "input") ) { | |
77 | jq(this).prop( 'disabled', false ); | |
78 | } | |
79 | }); | |
80 | ||
81 | /* Check for errors and append if found. */ | |
82 | if ( response[0] + response[1] == '-1' ) { | |
83 | form.prepend( response.substr( 2, response.length ) ); | |
84 | jq( 'form#' + form.attr('id') + ' div.error').hide().fadeIn( 200 ); | |
85 | } else { | |
86 | if ( 0 == jq("ul.activity-list").length ) { | |
87 | jq("div.error").slideUp(100).remove(); | |
88 | jq("div#message").slideUp(100).remove(); | |
89 | jq("div.activity").append( '<ul id="activity-stream" class="activity-list item-list">' ); | |
90 | } | |
91 | ||
92 | jq("ul#activity-stream").prepend(response); | |
93 | jq("ul#activity-stream li:first").addClass('new-update'); | |
94 | ||
95 | if ( 0 != jq("div#latest-update").length ) { | |
96 | var l = jq("ul#activity-stream li.new-update .activity-content .activity-inner p").html(); | |
97 | var v = jq("ul#activity-stream li.new-update .activity-content .activity-header p a.view").attr('href'); | |
98 | ||
99 | var ltext = jq("ul#activity-stream li.new-update .activity-content .activity-inner p").text(); | |
100 | ||
101 | var u = ''; | |
102 | if ( ltext != '' ) | |
103 | u = '"' + l + '" '; | |
104 | ||
105 | u += '<a href="' + v + '" rel="nofollow">' + BP_DTheme.view + '</a>'; | |
106 | ||
107 | jq("div#latest-update").slideUp(300,function(){ | |
108 | jq("div#latest-update").html( u ); | |
109 | jq("div#latest-update").slideDown(300); | |
110 | }); | |
111 | } | |
112 | ||
113 | jq("li.new-update").hide().slideDown( 300 ); | |
114 | jq("li.new-update").removeClass( 'new-update' ); | |
115 | jq("textarea#whats-new").val(''); | |
116 | } | |
117 | ||
118 | jq("#whats-new-options").animate({height:'0px'}); | |
119 | jq("form#whats-new-form textarea").animate({height:'20px'}); | |
120 | jq("#aw-whats-new-submit").prop("disabled", true).removeClass('loading'); | |
121 | }); | |
122 | ||
123 | return false; | |
124 | }); | |
125 | ||
126 | /* List tabs event delegation */ | |
127 | jq('div.activity-type-tabs').click( function(event) { | |
128 | var target = jq(event.target).parent(); | |
129 | ||
130 | if ( event.target.nodeName == 'STRONG' || event.target.nodeName == 'SPAN' ) | |
131 | target = target.parent(); | |
132 | else if ( event.target.nodeName != 'A' ) | |
133 | return false; | |
134 | ||
135 | /* Reset the page */ | |
136 | jq.cookie( 'bp-activity-oldestpage', 1, {path: '/'} ); | |
137 | ||
138 | /* Activity Stream Tabs */ | |
139 | var scope = target.attr('id').substr( 9, target.attr('id').length ); | |
140 | var filter = jq("#activity-filter-select select").val(); | |
141 | ||
142 | if ( scope == 'mentions' ) | |
143 | jq( 'li#' + target.attr('id') + ' a strong' ).remove(); | |
144 | ||
145 | bp_activity_request(scope, filter); | |
146 | ||
147 | return false; | |
148 | }); | |
149 | ||
150 | /* Activity filter select */ | |
151 | jq('#activity-filter-select select').change( function() { | |
152 | var selected_tab = jq( 'div.activity-type-tabs li.selected' ); | |
153 | ||
154 | if ( !selected_tab.length ) | |
155 | var scope = null; | |
156 | else | |
157 | var scope = selected_tab.attr('id').substr( 9, selected_tab.attr('id').length ); | |
158 | ||
159 | var filter = jq(this).val(); | |
160 | ||
161 | bp_activity_request(scope, filter); | |
162 | ||
163 | return false; | |
164 | }); | |
165 | ||
166 | /* Stream event delegation */ | |
167 | jq('div.activity').click( function(event) { | |
168 | var target = jq(event.target); | |
169 | ||
170 | /* Favoriting activity stream items */ | |
171 | if ( target.hasClass('fav') || target.hasClass('unfav') ) { | |
172 | var type = target.hasClass('fav') ? 'fav' : 'unfav'; | |
173 | var parent = target.parent().parent().parent(); | |
174 | var parent_id = parent.attr('id').substr( 9, parent.attr('id').length ); | |
175 | ||
176 | target.addClass('loading'); | |
177 | ||
178 | jq.post( ajaxurl, { | |
179 | action: 'activity_mark_' + type, | |
180 | 'cookie': encodeURIComponent(document.cookie), | |
181 | 'id': parent_id | |
182 | }, | |
183 | function(response) { | |
184 | target.removeClass('loading'); | |
185 | ||
186 | target.fadeOut( 100, function() { | |
187 | jq(this).html(response); | |
188 | jq(this).attr('title', 'fav' == type ? BP_DTheme.remove_fav : BP_DTheme.mark_as_fav); | |
189 | jq(this).fadeIn(100); | |
190 | }); | |
191 | ||
192 | if ( 'fav' == type ) { | |
193 | if ( !jq('div.item-list-tabs li#activity-favorites').length ) | |
194 | jq('div.item-list-tabs ul li#activity-mentions').before( '<li id="activity-favorites"><a href="#">' + BP_DTheme.my_favs + ' <span>0</span></a></li>'); | |
195 | ||
196 | target.removeClass('fav'); | |
197 | target.addClass('unfav'); | |
198 | ||
199 | jq('div.item-list-tabs ul li#activity-favorites span').html( Number( jq('div.item-list-tabs ul li#activity-favorites span').html() ) + 1 ); | |
200 | } else { | |
201 | target.removeClass('unfav'); | |
202 | target.addClass('fav'); | |
203 | ||
204 | jq('div.item-list-tabs ul li#activity-favorites span').html( Number( jq('div.item-list-tabs ul li#activity-favorites span').html() ) - 1 ); | |
205 | ||
206 | if ( !Number( jq('div.item-list-tabs ul li#activity-favorites span').html() ) ) { | |
207 | if ( jq('div.item-list-tabs ul li#activity-favorites').hasClass('selected') ) | |
208 | bp_activity_request( null, null ); | |
209 | ||
210 | jq('div.item-list-tabs ul li#activity-favorites').remove(); | |
211 | } | |
212 | } | |
213 | ||
214 | if ( 'activity-favorites' == jq( 'div.item-list-tabs li.selected').attr('id') ) | |
215 | target.parent().parent().parent().slideUp(100); | |
216 | }); | |
217 | ||
218 | return false; | |
219 | } | |
220 | ||
221 | /* Delete activity stream items */ | |
222 | if ( target.hasClass('delete-activity') ) { | |
223 | var li = target.parents('div.activity ul li'); | |
224 | var id = li.attr('id').substr( 9, li.attr('id').length ); | |
225 | var link_href = target.attr('href'); | |
226 | var nonce = link_href.split('_wpnonce='); | |
227 | ||
228 | nonce = nonce[1]; | |
229 | ||
230 | target.addClass('loading'); | |
231 | ||
232 | jq.post( ajaxurl, { | |
233 | action: 'delete_activity', | |
234 | 'cookie': encodeURIComponent(document.cookie), | |
235 | 'id': id, | |
236 | '_wpnonce': nonce | |
237 | }, | |
238 | function(response) { | |
239 | ||
240 | if ( response[0] + response[1] == '-1' ) { | |
241 | li.prepend( response.substr( 2, response.length ) ); | |
242 | li.children('div#message').hide().fadeIn(300); | |
243 | } else { | |
244 | li.slideUp(300); | |
245 | } | |
246 | }); | |
247 | ||
248 | return false; | |
249 | } | |
250 | ||
251 | /* Load more updates at the end of the page */ | |
252 | if ( target.parent().hasClass('load-more') ) { | |
253 | jq("#content li.load-more").addClass('loading'); | |
254 | ||
255 | if ( null == jq.cookie('bp-activity-oldestpage') ) | |
256 | jq.cookie('bp-activity-oldestpage', 1, {path: '/'} ); | |
257 | ||
258 | var oldest_page = ( jq.cookie('bp-activity-oldestpage') * 1 ) + 1; | |
259 | var search_terms=jq("#search-terms").val(); | |
260 | search_terms=search_terms?search_terms:''; | |
261 | ||
262 | jq.post( ajaxurl, { | |
263 | - | 'page': oldest_page |
263 | + | |
264 | 'cookie': encodeURIComponent(document.cookie), | |
265 | 'page': oldest_page, | |
266 | 'search_terms':search_terms | |
267 | } | |
268 | , | |
269 | function(response) | |
270 | { | |
271 | jq("#content li.load-more").removeClass('loading'); | |
272 | jq.cookie( 'bp-activity-oldestpage', oldest_page, {path: '/'} ); | |
273 | jq("#content ul.activity-list").append(response.contents); | |
274 | ||
275 | target.parent().hide(); | |
276 | }, 'json' ); | |
277 | ||
278 | return false; | |
279 | } | |
280 | }); | |
281 | ||
282 | // Activity "Read More" links | |
283 | jq('.activity-read-more a').live('click', function(event) { | |
284 | var target = jq(event.target); | |
285 | var link_id = target.parent().attr('id').split('-'); | |
286 | var a_id = link_id[3]; | |
287 | var type = link_id[0]; /* activity or acomment */ | |
288 | ||
289 | var inner_class = type == 'acomment' ? 'acomment-content' : 'activity-inner'; | |
290 | var a_inner = jq('li#' + type + '-' + a_id + ' .' + inner_class + ':first' ); | |
291 | jq(target).addClass('loading'); | |
292 | ||
293 | jq.post( ajaxurl, { | |
294 | action: 'get_single_activity_content', | |
295 | 'activity_id': a_id | |
296 | }, | |
297 | function(response) { | |
298 | jq(a_inner).slideUp(300).html(response).slideDown(300); | |
299 | }); | |
300 | ||
301 | return false; | |
302 | }); | |
303 | ||
304 | /**** Activity Comments *******************************************************/ | |
305 | ||
306 | /* Hide all activity comment forms */ | |
307 | jq('form.ac-form').hide(); | |
308 | ||
309 | /* Hide excess comments */ | |
310 | if ( jq('div.activity-comments').length ) | |
311 | bp_dtheme_hide_comments(); | |
312 | ||
313 | /* Activity list event delegation */ | |
314 | jq('div.activity').click( function(event) { | |
315 | var target = jq(event.target); | |
316 | ||
317 | /* Comment / comment reply links */ | |
318 | if ( target.hasClass('acomment-reply') || target.parent().hasClass('acomment-reply') ) { | |
319 | if ( target.parent().hasClass('acomment-reply') ) | |
320 | target = target.parent(); | |
321 | ||
322 | var id = target.attr('id'); | |
323 | ids = id.split('-'); | |
324 | ||
325 | var a_id = ids[2] | |
326 | var c_id = target.attr('href').substr( 10, target.attr('href').length ); | |
327 | var form = jq( '#ac-form-' + a_id ); | |
328 | ||
329 | form.css( 'display', 'none' ); | |
330 | form.removeClass('root'); | |
331 | jq('.ac-form').hide(); | |
332 | ||
333 | /* Hide any error messages */ | |
334 | form.children('div').each( function() { | |
335 | if ( jq(this).hasClass( 'error' ) ) | |
336 | jq(this).hide(); | |
337 | }); | |
338 | ||
339 | if ( ids[1] != 'comment' ) { | |
340 | jq('div.activity-comments li#acomment-' + c_id).append( form ); | |
341 | } else { | |
342 | jq('li#activity-' + a_id + ' div.activity-comments').append( form ); | |
343 | } | |
344 | ||
345 | if ( form.parent().hasClass( 'activity-comments' ) ) | |
346 | form.addClass('root'); | |
347 | ||
348 | form.slideDown( 200 ); | |
349 | jq.scrollTo( form, 500, { offset:-100, easing:'easeOutQuad' } ); | |
350 | jq('#ac-form-' + ids[2] + ' textarea').focus(); | |
351 | ||
352 | return false; | |
353 | } | |
354 | ||
355 | /* Activity comment posting */ | |
356 | if ( target.attr('name') == 'ac_form_submit' ) { | |
357 | var form = target.parent().parent(); | |
358 | var form_parent = form.parent(); | |
359 | var form_id = form.attr('id').split('-'); | |
360 | ||
361 | if ( !form_parent.hasClass('activity-comments') ) { | |
362 | var tmp_id = form_parent.attr('id').split('-'); | |
363 | var comment_id = tmp_id[1]; | |
364 | } else { | |
365 | var comment_id = form_id[2]; | |
366 | } | |
367 | ||
368 | /* Hide any error messages */ | |
369 | jq( 'form#' + form + ' div.error').hide(); | |
370 | target.addClass('loading').prop('disabled', true); | |
371 | ||
372 | jq.post( ajaxurl, { | |
373 | action: 'new_activity_comment', | |
374 | 'cookie': encodeURIComponent(document.cookie), | |
375 | '_wpnonce_new_activity_comment': jq("input#_wpnonce_new_activity_comment").val(), | |
376 | 'comment_id': comment_id, | |
377 | 'form_id': form_id[2], | |
378 | 'content': jq('form#' + form.attr('id') + ' textarea').val() | |
379 | }, | |
380 | function(response) | |
381 | { | |
382 | target.removeClass('loading'); | |
383 | ||
384 | /* Check for errors and append if found. */ | |
385 | if ( response[0] + response[1] == '-1' ) { | |
386 | form.append( response.substr( 2, response.length ) ).hide().fadeIn( 200 ); | |
387 | } else { | |
388 | form.fadeOut( 200, | |
389 | function() { | |
390 | if ( 0 == form.parent().children('ul').length ) { | |
391 | if ( form.parent().hasClass('activity-comments') ) | |
392 | form.parent().prepend('<ul></ul>'); | |
393 | else | |
394 | form.parent().append('<ul></ul>'); | |
395 | } | |
396 | ||
397 | form.parent().children('ul').append(response).hide().fadeIn( 200 ); | |
398 | form.children('textarea').val(''); | |
399 | form.parent().parent().addClass('has-comments'); | |
400 | } | |
401 | ); | |
402 | jq( 'form#' + form + ' textarea').val(''); | |
403 | ||
404 | /* Increase the "Reply (X)" button count */ | |
405 | jq('li#activity-' + form_id[2] + ' a.acomment-reply span').html( Number( jq('li#activity-' + form_id[2] + ' a.acomment-reply span').html() ) + 1 ); | |
406 | } | |
407 | ||
408 | jq(target).prop("disabled", false); | |
409 | }); | |
410 | ||
411 | return false; | |
412 | } | |
413 | ||
414 | /* Deleting an activity comment */ | |
415 | if ( target.hasClass('acomment-delete') ) { | |
416 | var link_href = target.attr('href'); | |
417 | var comment_li = target.parent().parent(); | |
418 | var form = comment_li.parents('div.activity-comments').children('form'); | |
419 | ||
420 | var nonce = link_href.split('_wpnonce='); | |
421 | nonce = nonce[1]; | |
422 | ||
423 | var comment_id = link_href.split('cid='); | |
424 | comment_id = comment_id[1].split('&'); | |
425 | comment_id = comment_id[0]; | |
426 | ||
427 | target.addClass('loading'); | |
428 | ||
429 | /* Remove any error messages */ | |
430 | jq('div.activity-comments ul div.error').remove(); | |
431 | ||
432 | /* Reset the form position */ | |
433 | comment_li.parents('div.activity-comments').append(form); | |
434 | ||
435 | jq.post( ajaxurl, { | |
436 | action: 'delete_activity_comment', | |
437 | 'cookie': encodeURIComponent(document.cookie), | |
438 | '_wpnonce': nonce, | |
439 | 'id': comment_id | |
440 | }, | |
441 | function(response) | |
442 | { | |
443 | /* Check for errors and append if found. */ | |
444 | if ( response[0] + response[1] == '-1' ) { | |
445 | comment_li.prepend( response.substr( 2, response.length ) ).hide().fadeIn( 200 ); | |
446 | } else { | |
447 | var children = jq( 'li#' + comment_li.attr('id') + ' ul' ).children('li'); | |
448 | var child_count = 0; | |
449 | jq(children).each( function() { | |
450 | if ( !jq(this).is(':hidden') ) | |
451 | child_count++; | |
452 | }); | |
453 | comment_li.fadeOut(200); | |
454 | ||
455 | /* Decrease the "Reply (X)" button count */ | |
456 | var parent_li = comment_li.parents('ul#activity-stream > li'); | |
457 | jq('li#' + parent_li.attr('id') + ' a.acomment-reply span').html( jq('li#' + parent_li.attr('id') + ' a.acomment-reply span').html() - ( 1 + child_count ) ); | |
458 | } | |
459 | }); | |
460 | ||
461 | return false; | |
462 | } | |
463 | ||
464 | /* Showing hidden comments - pause for half a second */ | |
465 | if ( target.parent().hasClass('show-all') ) { | |
466 | target.parent().addClass('loading'); | |
467 | ||
468 | setTimeout( function() { | |
469 | target.parent().parent().children('li').fadeIn(200, function() { | |
470 | target.parent().remove(); | |
471 | }); | |
472 | }, 600 ); | |
473 | ||
474 | return false; | |
475 | } | |
476 | }); | |
477 | ||
478 | /* Escape Key Press for cancelling comment forms */ | |
479 | jq(document).keydown( function(e) { | |
480 | e = e || window.event; | |
481 | if (e.target) | |
482 | element = e.target; | |
483 | else if (e.srcElement) | |
484 | element = e.srcElement; | |
485 | ||
486 | if( element.nodeType == 3) | |
487 | element = element.parentNode; | |
488 | ||
489 | if( e.ctrlKey == true || e.altKey == true || e.metaKey == true ) | |
490 | return; | |
491 | ||
492 | var keyCode = (e.keyCode) ? e.keyCode : e.which; | |
493 | ||
494 | if ( keyCode == 27 ) { | |
495 | if (element.tagName == 'TEXTAREA') { | |
496 | if ( jq(element).hasClass('ac-input') ) | |
497 | jq(element).parent().parent().parent().slideUp( 200 ); | |
498 | } | |
499 | } | |
500 | }); | |
501 | ||
502 | /**** Directory Search ****************************************************/ | |
503 | ||
504 | /* The search form on all directory pages */ | |
505 | jq('div.dir-search').click( function(event) { | |
506 | if ( jq(this).hasClass('no-ajax') ) | |
507 | return; | |
508 | ||
509 | var target = jq(event.target); | |
510 | ||
511 | if ( target.attr('type') == 'submit' ) { | |
512 | var css_id = jq('div.item-list-tabs li.selected').attr('id').split( '-' ); | |
513 | var object = css_id[0]; | |
514 | ||
515 | bp_filter_request( object, jq.cookie('bp-' + object + '-filter'), jq.cookie('bp-' + object + '-scope') , 'div.' + object, target.parent().children('label').children('input').val(), 1, jq.cookie('bp-' + object + '-extras') ); | |
516 | ||
517 | return false; | |
518 | } | |
519 | }); | |
520 | ||
521 | /**** Tabs and Filters ****************************************************/ | |
522 | ||
523 | /* When a navigation tab is clicked - e.g. | All Groups | My Groups | */ | |
524 | jq('div.item-list-tabs').click( function(event) { | |
525 | if ( jq(this).hasClass('no-ajax') ) | |
526 | return; | |
527 | ||
528 | var target = jq(event.target).parent(); | |
529 | ||
530 | if ( 'LI' == event.target.parentNode.nodeName && !target.hasClass('last') ) { | |
531 | var css_id = target.attr('id').split( '-' ); | |
532 | var object = css_id[0]; | |
533 | ||
534 | if ( 'activity' == object ) | |
535 | return false; | |
536 | ||
537 | var scope = css_id[1]; | |
538 | var filter = jq("#" + object + "-order-select select").val(); | |
539 | var search_terms = jq("#" + object + "_search").val(); | |
540 | ||
541 | bp_filter_request( object, filter, scope, 'div.' + object, search_terms, 1, jq.cookie('bp-' + object + '-extras') ); | |
542 | ||
543 | return false; | |
544 | } | |
545 | }); | |
546 | ||
547 | /* When the filter select box is changed re-query */ | |
548 | jq('li.filter select').change( function() { | |
549 | if ( jq('div.item-list-tabs li.selected').length ) | |
550 | var el = jq('div.item-list-tabs li.selected'); | |
551 | else | |
552 | var el = jq(this); | |
553 | ||
554 | var css_id = el.attr('id').split('-'); | |
555 | var object = css_id[0]; | |
556 | var scope = css_id[1]; | |
557 | var filter = jq(this).val(); | |
558 | var search_terms = false; | |
559 | ||
560 | if ( jq('div.dir-search input').length ) | |
561 | search_terms = jq('div.dir-search input').val(); | |
562 | ||
563 | if ( 'friends' == object ) | |
564 | object = 'members'; | |
565 | ||
566 | bp_filter_request( object, filter, scope, 'div.' + object, search_terms, 1, jq.cookie('bp-' + object + '-extras') ); | |
567 | ||
568 | return false; | |
569 | }); | |
570 | ||
571 | /* All pagination links run through this function */ | |
572 | jq('div#content').click( function(event) { | |
573 | var target = jq(event.target); | |
574 | ||
575 | if ( target.hasClass('button') ) | |
576 | return true; | |
577 | ||
578 | if ( target.parent().parent().hasClass('pagination') && !target.parent().parent().hasClass('no-ajax') ) { | |
579 | if ( target.hasClass('dots') || target.hasClass('current') ) | |
580 | return false; | |
581 | ||
582 | if ( jq('div.item-list-tabs li.selected').length ) | |
583 | var el = jq('div.item-list-tabs li.selected'); | |
584 | else | |
585 | var el = jq('li.filter select'); | |
586 | ||
587 | var page_number = 1; | |
588 | var css_id = el.attr('id').split( '-' ); | |
589 | var object = css_id[0]; | |
590 | var search_terms = false; | |
591 | ||
592 | if ( jq('div.dir-search input').length ) | |
593 | search_terms = jq('div.dir-search input').val(); | |
594 | ||
595 | if ( jq(target).hasClass('next') ) | |
596 | var page_number = Number( jq('div.pagination span.current').html() ) + 1; | |
597 | else if ( jq(target).hasClass('prev') ) | |
598 | var page_number = Number( jq('div.pagination span.current').html() ) - 1; | |
599 | else | |
600 | var page_number = Number( jq(target).html() ); | |
601 | ||
602 | bp_filter_request( object, jq.cookie('bp-' + object + '-filter'), jq.cookie('bp-' + object + '-scope'), 'div.' + object, search_terms, page_number, jq.cookie('bp-' + object + '-extras') ); | |
603 | ||
604 | return false; | |
605 | } | |
606 | ||
607 | }); | |
608 | ||
609 | /**** New Forum Directory Post **************************************/ | |
610 | ||
611 | /* Hit the "New Topic" button on the forums directory page */ | |
612 | jq('a.show-hide-new').click( function() { | |
613 | if ( !jq('div#new-topic-post').length ) | |
614 | return false; | |
615 | ||
616 | if ( jq('div#new-topic-post').is(":visible") ) | |
617 | jq('div#new-topic-post').slideUp(200); | |
618 | else | |
619 | jq('div#new-topic-post').slideDown(200, function() { jq('#topic_title').focus(); } ); | |
620 | ||
621 | return false; | |
622 | }); | |
623 | ||
624 | /* Cancel the posting of a new forum topic */ | |
625 | jq('input#submit_topic_cancel').click( function() { | |
626 | if ( !jq('div#new-topic-post').length ) | |
627 | return false; | |
628 | ||
629 | jq('div#new-topic-post').slideUp(200); | |
630 | return false; | |
631 | }); | |
632 | ||
633 | /* Clicking a forum tag */ | |
634 | jq('div#forum-directory-tags a').click( function() { | |
635 | bp_filter_request( 'forums', 'tags', jq.cookie('bp-forums-scope'), 'div.forums', jq(this).html().replace( / /g, '-' ), 1, jq.cookie('bp-forums-extras') ); | |
636 | return false; | |
637 | }); | |
638 | ||
639 | /** Invite Friends Interface ****************************************/ | |
640 | ||
641 | /* Select a user from the list of friends and add them to the invite list */ | |
642 | jq("div#invite-list input").click( function() { | |
643 | jq('.ajax-loader').toggle(); | |
644 | ||
645 | var friend_id = jq(this).val(); | |
646 | ||
647 | if ( jq(this).prop('checked') == true ) | |
648 | var friend_action = 'invite'; | |
649 | else | |
650 | var friend_action = 'uninvite'; | |
651 | ||
652 | jq('div.item-list-tabs li.selected').addClass('loading'); | |
653 | ||
654 | jq.post( ajaxurl, { | |
655 | action: 'groups_invite_user', | |
656 | 'friend_action': friend_action, | |
657 | 'cookie': encodeURIComponent(document.cookie), | |
658 | '_wpnonce': jq("input#_wpnonce_invite_uninvite_user").val(), | |
659 | 'friend_id': friend_id, | |
660 | 'group_id': jq("input#group_id").val() | |
661 | }, | |
662 | function(response) | |
663 | { | |
664 | if ( jq("#message") ) | |
665 | jq("#message").hide(); | |
666 | ||
667 | jq('.ajax-loader').toggle(); | |
668 | ||
669 | if ( friend_action == 'invite' ) { | |
670 | jq('#friend-list').append(response); | |
671 | } else if ( friend_action == 'uninvite' ) { | |
672 | jq('#friend-list li#uid-' + friend_id).remove(); | |
673 | } | |
674 | ||
675 | jq('div.item-list-tabs li.selected').removeClass('loading'); | |
676 | }); | |
677 | }); | |
678 | ||
679 | /* Remove a user from the list of users to invite to a group */ | |
680 | jq("#friend-list li a.remove").live('click', function() { | |
681 | jq('.ajax-loader').toggle(); | |
682 | ||
683 | var friend_id = jq(this).attr('id'); | |
684 | friend_id = friend_id.split('-'); | |
685 | friend_id = friend_id[1]; | |
686 | ||
687 | jq.post( ajaxurl, { | |
688 | action: 'groups_invite_user', | |
689 | 'friend_action': 'uninvite', | |
690 | 'cookie': encodeURIComponent(document.cookie), | |
691 | '_wpnonce': jq("input#_wpnonce_invite_uninvite_user").val(), | |
692 | 'friend_id': friend_id, | |
693 | 'group_id': jq("input#group_id").val() | |
694 | }, | |
695 | function(response) | |
696 | { | |
697 | jq('.ajax-loader').toggle(); | |
698 | jq('#friend-list li#uid-' + friend_id).remove(); | |
699 | jq('#invite-list input#f-' + friend_id).prop('checked', false); | |
700 | }); | |
701 | ||
702 | return false; | |
703 | }); | |
704 | ||
705 | /** Friendship Requests **************************************/ | |
706 | ||
707 | /* Accept and Reject friendship request buttons */ | |
708 | jq("ul#friend-list a.accept, ul#friend-list a.reject").click( function() { | |
709 | var button = jq(this); | |
710 | var li = jq(this).parents('ul#friend-list li'); | |
711 | var action_div = jq(this).parents('li div.action'); | |
712 | ||
713 | var id = li.attr('id').substr( 11, li.attr('id').length ); | |
714 | var link_href = button.attr('href'); | |
715 | ||
716 | var nonce = link_href.split('_wpnonce='); | |
717 | nonce = nonce[1]; | |
718 | ||
719 | if ( jq(this).hasClass('accepted') || jq(this).hasClass('rejected') ) | |
720 | return false; | |
721 | ||
722 | if ( jq(this).hasClass('accept') ) { | |
723 | var action = 'accept_friendship'; | |
724 | action_div.children('a.reject').css( 'visibility', 'hidden' ); | |
725 | } else { | |
726 | var action = 'reject_friendship'; | |
727 | action_div.children('a.accept').css( 'visibility', 'hidden' ); | |
728 | } | |
729 | ||
730 | button.addClass('loading'); | |
731 | ||
732 | jq.post( ajaxurl, { | |
733 | action: action, | |
734 | 'cookie': encodeURIComponent(document.cookie), | |
735 | 'id': id, | |
736 | '_wpnonce': nonce | |
737 | }, | |
738 | function(response) { | |
739 | button.removeClass('loading'); | |
740 | ||
741 | if ( response[0] + response[1] == '-1' ) { | |
742 | li.prepend( response.substr( 2, response.length ) ); | |
743 | li.children('div#message').hide().fadeIn(200); | |
744 | } else { | |
745 | button.fadeOut( 100, function() { | |
746 | if ( jq(this).hasClass('accept') ) { | |
747 | action_div.children('a.reject').hide(); | |
748 | jq(this).html( BP_DTheme.accepted ).fadeIn(50); | |
749 | jq(this).addClass('accepted'); | |
750 | } else { | |
751 | action_div.children('a.accept').hide(); | |
752 | jq(this).html( BP_DTheme.rejected ).fadeIn(50); | |
753 | jq(this).addClass('rejected'); | |
754 | } | |
755 | }); | |
756 | } | |
757 | }); | |
758 | ||
759 | return false; | |
760 | }); | |
761 | ||
762 | /* Add / Remove friendship buttons */ | |
763 | jq("div.friendship-button a").live('click', function() { | |
764 | jq(this).parent().addClass('loading'); | |
765 | var fid = jq(this).attr('id'); | |
766 | fid = fid.split('-'); | |
767 | fid = fid[1]; | |
768 | ||
769 | var nonce = jq(this).attr('href'); | |
770 | nonce = nonce.split('?_wpnonce='); | |
771 | nonce = nonce[1].split('&'); | |
772 | nonce = nonce[0]; | |
773 | ||
774 | var thelink = jq(this); | |
775 | ||
776 | jq.post( ajaxurl, { | |
777 | action: 'addremove_friend', | |
778 | 'cookie': encodeURIComponent(document.cookie), | |
779 | 'fid': fid, | |
780 | '_wpnonce': nonce | |
781 | }, | |
782 | function(response) | |
783 | { | |
784 | var action = thelink.attr('rel'); | |
785 | var parentdiv = thelink.parent(); | |
786 | ||
787 | if ( action == 'add' ) { | |
788 | jq(parentdiv).fadeOut(200, | |
789 | function() { | |
790 | parentdiv.removeClass('add_friend'); | |
791 | parentdiv.removeClass('loading'); | |
792 | parentdiv.addClass('pending'); | |
793 | parentdiv.fadeIn(200).html(response); | |
794 | } | |
795 | ); | |
796 | ||
797 | } else if ( action == 'remove' ) { | |
798 | jq(parentdiv).fadeOut(200, | |
799 | function() { | |
800 | parentdiv.removeClass('remove_friend'); | |
801 | parentdiv.removeClass('loading'); | |
802 | parentdiv.addClass('add'); | |
803 | parentdiv.fadeIn(200).html(response); | |
804 | } | |
805 | ); | |
806 | } | |
807 | }); | |
808 | return false; | |
809 | } ); | |
810 | ||
811 | /** Group Join / Leave Buttons **************************************/ | |
812 | ||
813 | jq("div.group-button a").live('click', function() { | |
814 | var gid = jq(this).parent().attr('id'); | |
815 | gid = gid.split('-'); | |
816 | gid = gid[1]; | |
817 | ||
818 | var nonce = jq(this).attr('href'); | |
819 | nonce = nonce.split('?_wpnonce='); | |
820 | nonce = nonce[1].split('&'); | |
821 | nonce = nonce[0]; | |
822 | ||
823 | var thelink = jq(this); | |
824 | ||
825 | jq.post( ajaxurl, { | |
826 | action: 'joinleave_group', | |
827 | 'cookie': encodeURIComponent(document.cookie), | |
828 | 'gid': gid, | |
829 | '_wpnonce': nonce | |
830 | }, | |
831 | function(response) | |
832 | { | |
833 | var parentdiv = thelink.parent(); | |
834 | ||
835 | if ( !jq('body.directory').length ) | |
836 | location.href = location.href; | |
837 | else { | |
838 | jq(parentdiv).fadeOut(200, | |
839 | function() { | |
840 | parentdiv.fadeIn(200).html(response); | |
841 | } | |
842 | ); | |
843 | } | |
844 | }); | |
845 | return false; | |
846 | } ); | |
847 | ||
848 | /** Button disabling ************************************************/ | |
849 | ||
850 | jq('div.pending').click(function() { | |
851 | return false; | |
852 | }); | |
853 | ||
854 | /** Private Messaging ******************************************/ | |
855 | ||
856 | /* AJAX send reply functionality */ | |
857 | jq("input#send_reply_button").click( | |
858 | function() { | |
859 | var order = jq('#messages_order').val() || 'ASC', | |
860 | offset = jq('#message-recipients').offset(); | |
861 | ||
862 | var button = jq("input#send_reply_button"); | |
863 | jq(button).addClass('loading'); | |
864 | ||
865 | jq.post( ajaxurl, { | |
866 | action: 'messages_send_reply', | |
867 | 'cookie': encodeURIComponent(document.cookie), | |
868 | '_wpnonce': jq("input#send_message_nonce").val(), | |
869 | ||
870 | 'content': jq("#message_content").val(), | |
871 | 'send_to': jq("input#send_to").val(), | |
872 | 'subject': jq("input#subject").val(), | |
873 | 'thread_id': jq("input#thread_id").val() | |
874 | }, | |
875 | function(response) | |
876 | { | |
877 | if ( response[0] + response[1] == "-1" ) { | |
878 | jq('form#send-reply').prepend( response.substr( 2, response.length ) ); | |
879 | } else { | |
880 | jq('form#send-reply div#message').remove(); | |
881 | jq("#message_content").val(''); | |
882 | ||
883 | if ( 'ASC' == order ) { | |
884 | jq('form#send-reply').before( response ); | |
885 | } else { | |
886 | jq('#message-recipients').after( response ); | |
887 | jq(window).scrollTop(offset.top); | |
888 | } | |
889 | ||
890 | jq("div.new-message").hide().slideDown( 200, function() { | |
891 | jq('div.new-message').removeClass('new-message'); | |
892 | }); | |
893 | } | |
894 | jq(button).removeClass('loading'); | |
895 | }); | |
896 | ||
897 | return false; | |
898 | } | |
899 | ); | |
900 | ||
901 | /* Marking private messages as read and unread */ | |
902 | jq("a#mark_as_read, a#mark_as_unread").click(function() { | |
903 | var checkboxes_tosend = ''; | |
904 | var checkboxes = jq("#message-threads tr td input[type='checkbox']"); | |
905 | ||
906 | if ( 'mark_as_unread' == jq(this).attr('id') ) { | |
907 | var currentClass = 'read' | |
908 | var newClass = 'unread' | |
909 | var unreadCount = 1; | |
910 | var inboxCount = 0; | |
911 | var unreadCountDisplay = 'inline'; | |
912 | var action = 'messages_markunread'; | |
913 | } else { | |
914 | var currentClass = 'unread' | |
915 | var newClass = 'read' | |
916 | var unreadCount = 0; | |
917 | var inboxCount = 1; | |
918 | var unreadCountDisplay = 'none'; | |
919 | var action = 'messages_markread'; | |
920 | } | |
921 | ||
922 | checkboxes.each( function(i) { | |
923 | if(jq(this).is(':checked')) { | |
924 | if ( jq('tr#m-' + jq(this).attr('value')).hasClass(currentClass) ) { | |
925 | checkboxes_tosend += jq(this).attr('value'); | |
926 | jq('tr#m-' + jq(this).attr('value')).removeClass(currentClass); | |
927 | jq('tr#m-' + jq(this).attr('value')).addClass(newClass); | |
928 | var thread_count = jq('tr#m-' + jq(this).attr('value') + ' td span.unread-count').html(); | |
929 | ||
930 | jq('tr#m-' + jq(this).attr('value') + ' td span.unread-count').html(unreadCount); | |
931 | jq('tr#m-' + jq(this).attr('value') + ' td span.unread-count').css('display', unreadCountDisplay); | |
932 | ||
933 | var inboxcount = jq('tr.unread').length; | |
934 | ||
935 | jq('a#user-messages span').html( inboxcount ); | |
936 | ||
937 | if ( i != checkboxes.length - 1 ) { | |
938 | checkboxes_tosend += ',' | |
939 | } | |
940 | } | |
941 | } | |
942 | }); | |
943 | jq.post( ajaxurl, { | |
944 | action: action, | |
945 | 'thread_ids': checkboxes_tosend | |
946 | }); | |
947 | return false; | |
948 | }); | |
949 | ||
950 | /* Selecting unread and read messages in inbox */ | |
951 | jq("select#message-type-select").change( | |
952 | function() { | |
953 | var selection = jq("select#message-type-select").val(); | |
954 | var checkboxes = jq("td input[type='checkbox']"); | |
955 | checkboxes.each( function(i) { | |
956 | checkboxes[i].checked = ""; | |
957 | }); | |
958 | ||
959 | switch(selection) { | |
960 | case 'unread': | |
961 | var checkboxes = jq("tr.unread td input[type='checkbox']"); | |
962 | break; | |
963 | case 'read': | |
964 | var checkboxes = jq("tr.read td input[type='checkbox']"); | |
965 | break; | |
966 | } | |
967 | if ( selection != '' ) { | |
968 | checkboxes.each( function(i) { | |
969 | checkboxes[i].checked = "checked"; | |
970 | }); | |
971 | } else { | |
972 | checkboxes.each( function(i) { | |
973 | checkboxes[i].checked = ""; | |
974 | }); | |
975 | } | |
976 | } | |
977 | ); | |
978 | ||
979 | /* Bulk delete messages */ | |
980 | jq("a#delete_inbox_messages, a#delete_sentbox_messages").click( function() { | |
981 | checkboxes_tosend = ''; | |
982 | checkboxes = jq("#message-threads tr td input[type='checkbox']"); | |
983 | ||
984 | jq('div#message').remove(); | |
985 | jq(this).addClass('loading'); | |
986 | ||
987 | jq(checkboxes).each( function(i) { | |
988 | if( jq(this).is(':checked') ) | |
989 | checkboxes_tosend += jq(this).attr('value') + ','; | |
990 | }); | |
991 | ||
992 | if ( '' == checkboxes_tosend ) { | |
993 | jq(this).removeClass('loading'); | |
994 | return false; | |
995 | } | |
996 | ||
997 | jq.post( ajaxurl, { | |
998 | action: 'messages_delete', | |
999 | 'thread_ids': checkboxes_tosend | |
1000 | }, function(response) { | |
1001 | if ( response[0] + response[1] == "-1" ) { | |
1002 | jq('#message-threads').prepend( response.substr( 2, response.length ) ); | |
1003 | } else { | |
1004 | jq('#message-threads').before( '<div id="message" class="updated"><p>' + response + '</p></div>' ); | |
1005 | ||
1006 | jq(checkboxes).each( function(i) { | |
1007 | if( jq(this).is(':checked') ) | |
1008 | jq(this).parent().parent().fadeOut(150); | |
1009 | }); | |
1010 | } | |
1011 | ||
1012 | jq('div#message').hide().slideDown(150); | |
1013 | jq("a#delete_inbox_messages, a#delete_sentbox_messages").removeClass('loading'); | |
1014 | }); | |
1015 | return false; | |
1016 | }); | |
1017 | ||
1018 | /* Close site wide notices in the sidebar */ | |
1019 | jq("a#close-notice").click( function() { | |
1020 | jq(this).addClass('loading'); | |
1021 | jq('div#sidebar div.error').remove(); | |
1022 | ||
1023 | jq.post( ajaxurl, { | |
1024 | action: 'messages_close_notice', | |
1025 | 'notice_id': jq('.notice').attr('rel').substr( 2, jq('.notice').attr('rel').length ) | |
1026 | }, | |
1027 | function(response) { | |
1028 | jq("a#close-notice").removeClass('loading'); | |
1029 | ||
1030 | if ( response[0] + response[1] == '-1' ) { | |
1031 | jq('.notice').prepend( response.substr( 2, response.length ) ); | |
1032 | jq( 'div#sidebar div.error').hide().fadeIn( 200 ); | |
1033 | } else { | |
1034 | jq('.notice').slideUp( 100 ); | |
1035 | } | |
1036 | }); | |
1037 | return false; | |
1038 | }); | |
1039 | ||
1040 | /* Admin Bar & wp_list_pages Javascript IE6 hover class */ | |
1041 | jq("#wp-admin-bar ul.main-nav li, #nav li").mouseover( function() { | |
1042 | jq(this).addClass('sfhover'); | |
1043 | }); | |
1044 | ||
1045 | jq("#wp-admin-bar ul.main-nav li, #nav li").mouseout( function() { | |
1046 | jq(this).removeClass('sfhover'); | |
1047 | }); | |
1048 | ||
1049 | /* Clear BP cookies on logout */ | |
1050 | jq('a.logout').click( function() { | |
1051 | jq.cookie('bp-activity-scope', null, {path: '/'}); | |
1052 | jq.cookie('bp-activity-filter', null, {path: '/'}); | |
1053 | jq.cookie('bp-activity-oldestpage', null, {path: '/'}); | |
1054 | ||
1055 | var objects = [ 'members', 'groups', 'blogs', 'forums' ]; | |
1056 | jq(objects).each( function(i) { | |
1057 | jq.cookie('bp-' + objects[i] + '-scope', null, {path: '/'} ); | |
1058 | jq.cookie('bp-' + objects[i] + '-filter', null, {path: '/'} ); | |
1059 | jq.cookie('bp-' + objects[i] + '-extras', null, {path: '/'} ); | |
1060 | }); | |
1061 | }); | |
1062 | }); | |
1063 | ||
1064 | /* Setup activity scope and filter based on the current cookie settings. */ | |
1065 | function bp_init_activity() { | |
1066 | /* Reset the page */ | |
1067 | jq.cookie( 'bp-activity-oldestpage', 1, {path: '/'} ); | |
1068 | ||
1069 | if ( null != jq.cookie('bp-activity-filter') && jq('#activity-filter-select').length ) | |
1070 | jq('#activity-filter-select select option[value="' + jq.cookie('bp-activity-filter') + '"]').prop( 'selected', true ); | |
1071 | ||
1072 | /* Activity Tab Set */ | |
1073 | if ( null != jq.cookie('bp-activity-scope') && jq('div.activity-type-tabs').length ) { | |
1074 | jq('div.activity-type-tabs li').each( function() { | |
1075 | jq(this).removeClass('selected'); | |
1076 | }); | |
1077 | jq('li#activity-' + jq.cookie('bp-activity-scope') + ', div.item-list-tabs li.current').addClass('selected'); | |
1078 | } | |
1079 | } | |
1080 | ||
1081 | /* Setup object scope and filter based on the current cookie settings for the object. */ | |
1082 | function bp_init_objects(objects) { | |
1083 | jq(objects).each( function(i) { | |
1084 | if ( null != jq.cookie('bp-' + objects[i] + '-filter') && jq('li#' + objects[i] + '-order-select select').length ) | |
1085 | jq('li#' + objects[i] + '-order-select select option[value="' + jq.cookie('bp-' + objects[i] + '-filter') + '"]').prop( 'selected', true ); | |
1086 | ||
1087 | if ( null != jq.cookie('bp-' + objects[i] + '-scope') && jq('div.' + objects[i]).length ) { | |
1088 | jq('div.item-list-tabs li').each( function() { | |
1089 | jq(this).removeClass('selected'); | |
1090 | }); | |
1091 | jq('div.item-list-tabs li#' + objects[i] + '-' + jq.cookie('bp-' + objects[i] + '-scope') + ', div.item-list-tabs#object-nav li.current').addClass('selected'); | |
1092 | } | |
1093 | }); | |
1094 | } | |
1095 | ||
1096 | /* Filter the current content list (groups/members/blogs/topics) */ | |
1097 | function bp_filter_request( object, filter, scope, target, search_terms, page, extras ) { | |
1098 | if ( 'activity' == object ) | |
1099 | return false; | |
1100 | ||
1101 | if ( jq.query.get('s') && !search_terms ) | |
1102 | search_terms = jq.query.get('s'); | |
1103 | ||
1104 | if ( null == scope ) | |
1105 | scope = 'all'; | |
1106 | ||
1107 | /* Save the settings we want to remain persistent to a cookie */ | |
1108 | jq.cookie( 'bp-' + object + '-scope', scope, {path: '/'} ); | |
1109 | jq.cookie( 'bp-' + object + '-filter', filter, {path: '/'} ); | |
1110 | jq.cookie( 'bp-' + object + '-extras', extras, {path: '/'} ); | |
1111 | ||
1112 | /* Set the correct selected nav and filter */ | |
1113 | jq('div.item-list-tabs li').each( function() { | |
1114 | jq(this).removeClass('selected'); | |
1115 | }); | |
1116 | jq('div.item-list-tabs li#' + object + '-' + scope + ', div.item-list-tabs#object-nav li.current').addClass('selected'); | |
1117 | jq('div.item-list-tabs li.selected').addClass('loading'); | |
1118 | jq('div.item-list-tabs select option[value="' + filter + '"]').prop( 'selected', true ); | |
1119 | ||
1120 | if ( 'friends' == object ) | |
1121 | object = 'members'; | |
1122 | ||
1123 | if ( bp_ajax_request ) | |
1124 | bp_ajax_request.abort(); | |
1125 | ||
1126 | bp_ajax_request = jq.post( ajaxurl, { | |
1127 | action: object + '_filter', | |
1128 | 'cookie': encodeURIComponent(document.cookie), | |
1129 | 'object': object, | |
1130 | 'filter': filter, | |
1131 | 'search_terms': search_terms, | |
1132 | 'scope': scope, | |
1133 | 'page': page, | |
1134 | 'extras': extras | |
1135 | }, | |
1136 | function(response) | |
1137 | { | |
1138 | jq(target).fadeOut( 100, function() { | |
1139 | jq(this).html(response); | |
1140 | jq(this).fadeIn(100); | |
1141 | }); | |
1142 | jq('div.item-list-tabs li.selected').removeClass('loading'); | |
1143 | }); | |
1144 | } | |
1145 | ||
1146 | /* Activity Loop Requesting */ | |
1147 | function bp_activity_request(scope, filter) { | |
1148 | /* Save the type and filter to a session cookie */ | |
1149 | jq.cookie( 'bp-activity-scope', scope, {path: '/'} ); | |
1150 | jq.cookie( 'bp-activity-filter', filter, {path: '/'} ); | |
1151 | jq.cookie( 'bp-activity-oldestpage', 1, {path: '/'} ); | |
1152 | ||
1153 | /* Remove selected and loading classes from tabs */ | |
1154 | jq('div.item-list-tabs li').each( function() { | |
1155 | jq(this).removeClass('selected loading'); | |
1156 | }); | |
1157 | /* Set the correct selected nav and filter */ | |
1158 | jq('li#activity-' + scope + ', div.item-list-tabs li.current').addClass('selected'); | |
1159 | jq('div#object-nav.item-list-tabs li.selected, div.activity-type-tabs li.selected').addClass('loading'); | |
1160 | jq('#activity-filter-select select option[value="' + filter + '"]').prop( 'selected', true ); | |
1161 | ||
1162 | /* Reload the activity stream based on the selection */ | |
1163 | jq('.widget_bp_activity_widget h2 span.ajax-loader').show(); | |
1164 | ||
1165 | if ( bp_ajax_request ) | |
1166 | bp_ajax_request.abort(); | |
1167 | ||
1168 | bp_ajax_request = jq.post( ajaxurl, { | |
1169 | action: 'activity_widget_filter', | |
1170 | 'cookie': encodeURIComponent(document.cookie), | |
1171 | '_wpnonce_activity_filter': jq("input#_wpnonce_activity_filter").val(), | |
1172 | 'scope': scope, | |
1173 | 'filter': filter | |
1174 | }, | |
1175 | function(response) | |
1176 | { | |
1177 | jq('.widget_bp_activity_widget h2 span.ajax-loader').hide(); | |
1178 | ||
1179 | jq('div.activity').fadeOut( 100, function() { | |
1180 | jq(this).html(response.contents); | |
1181 | jq(this).fadeIn(100); | |
1182 | ||
1183 | /* Selectively hide comments */ | |
1184 | bp_dtheme_hide_comments(); | |
1185 | }); | |
1186 | ||
1187 | /* Update the feed link */ | |
1188 | if ( null != response.feed_url ) | |
1189 | jq('.directory div#subnav li.feed a, .home-page div#subnav li.feed a').attr('href', response.feed_url); | |
1190 | ||
1191 | jq('div.item-list-tabs li.selected').removeClass('loading'); | |
1192 | ||
1193 | }, 'json' ); | |
1194 | } | |
1195 | ||
1196 | /* Hide long lists of activity comments, only show the latest five root comments. */ | |
1197 | function bp_dtheme_hide_comments() { | |
1198 | var comments_divs = jq('div.activity-comments'); | |
1199 | ||
1200 | if ( !comments_divs.length ) | |
1201 | return false; | |
1202 | ||
1203 | comments_divs.each( function() { | |
1204 | if ( jq(this).children('ul').children('li').length < 5 ) return; | |
1205 | ||
1206 | var comments_div = jq(this); | |
1207 | var parent_li = comments_div.parents('ul#activity-stream > li'); | |
1208 | var comment_lis = jq(this).children('ul').children('li'); | |
1209 | var comment_count = ' '; | |
1210 | ||
1211 | if ( jq('li#' + parent_li.attr('id') + ' a.acomment-reply span').length ) | |
1212 | var comment_count = jq('li#' + parent_li.attr('id') + ' a.acomment-reply span').html(); | |
1213 | ||
1214 | comment_lis.each( function(i) { | |
1215 | /* Show the latest 5 root comments */ | |
1216 | if ( i < comment_lis.length - 5 ) { | |
1217 | jq(this).addClass('hidden'); | |
1218 | jq(this).toggle(); | |
1219 | ||
1220 | if ( !i ) | |
1221 | jq(this).before( '<li class="show-all"><a href="#' + parent_li.attr('id') + '/show-all/" title="' + BP_DTheme.show_all_comments + '">' + BP_DTheme.show_all + ' ' + comment_count + ' ' + BP_DTheme.comments + '</a></li>' ); | |
1222 | } | |
1223 | }); | |
1224 | ||
1225 | }); | |
1226 | } | |
1227 | ||
1228 | /* Helper Functions */ | |
1229 | ||
1230 | function checkAll() { | |
1231 | var checkboxes = document.getElementsByTagName("input"); | |
1232 | for(var i=0; i<checkboxes.length; i++) { | |
1233 | if(checkboxes[i].type == "checkbox") { | |
1234 | if($("check_all").checked == "") { | |
1235 | checkboxes[i].checked = ""; | |
1236 | } | |
1237 | else { | |
1238 | checkboxes[i].checked = "checked"; | |
1239 | } | |
1240 | } | |
1241 | } | |
1242 | } | |
1243 | ||
1244 | function clear(container) { | |
1245 | if( !document.getElementById(container) ) return; | |
1246 | ||
1247 | var container = document.getElementById(container); | |
1248 | ||
1249 | if ( radioButtons = container.getElementsByTagName('INPUT') ) { | |
1250 | for(var i=0; i<radioButtons.length; i++) { | |
1251 | radioButtons[i].checked = ''; | |
1252 | } | |
1253 | } | |
1254 | ||
1255 | if ( options = container.getElementsByTagName('OPTION') ) { | |
1256 | for(var i=0; i<options.length; i++) { | |
1257 | options[i].selected = false; | |
1258 | } | |
1259 | } | |
1260 | ||
1261 | return; | |
1262 | } | |
1263 | ||
1264 | /* ScrollTo plugin - just inline and minified */ | |
1265 | ;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery); | |
1266 | ||
1267 | /* jQuery Easing Plugin, v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/ */ | |
1268 | jQuery.easing.jswing=jQuery.easing.swing;jQuery.extend(jQuery.easing,{def:"easeOutQuad",swing:function(e,f,a,h,g){return jQuery.easing[jQuery.easing.def](e,f,a,h,g)},easeInQuad:function(e,f,a,h,g){return h*(f/=g)*f+a},easeOutQuad:function(e,f,a,h,g){return -h*(f/=g)*(f-2)+a},easeInOutQuad:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f+a}return -h/2*((--f)*(f-2)-1)+a},easeInCubic:function(e,f,a,h,g){return h*(f/=g)*f*f+a},easeOutCubic:function(e,f,a,h,g){return h*((f=f/g-1)*f*f+1)+a},easeInOutCubic:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f*f+a}return h/2*((f-=2)*f*f+2)+a},easeInQuart:function(e,f,a,h,g){return h*(f/=g)*f*f*f+a},easeOutQuart:function(e,f,a,h,g){return -h*((f=f/g-1)*f*f*f-1)+a},easeInOutQuart:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f*f*f+a}return -h/2*((f-=2)*f*f*f-2)+a},easeInQuint:function(e,f,a,h,g){return h*(f/=g)*f*f*f*f+a},easeOutQuint:function(e,f,a,h,g){return h*((f=f/g-1)*f*f*f*f+1)+a},easeInOutQuint:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f*f*f*f+a}return h/2*((f-=2)*f*f*f*f+2)+a},easeInSine:function(e,f,a,h,g){return -h*Math.cos(f/g*(Math.PI/2))+h+a},easeOutSine:function(e,f,a,h,g){return h*Math.sin(f/g*(Math.PI/2))+a},easeInOutSine:function(e,f,a,h,g){return -h/2*(Math.cos(Math.PI*f/g)-1)+a},easeInExpo:function(e,f,a,h,g){return(f==0)?a:h*Math.pow(2,10*(f/g-1))+a},easeOutExpo:function(e,f,a,h,g){return(f==g)?a+h:h*(-Math.pow(2,-10*f/g)+1)+a},easeInOutExpo:function(e,f,a,h,g){if(f==0){return a}if(f==g){return a+h}if((f/=g/2)<1){return h/2*Math.pow(2,10*(f-1))+a}return h/2*(-Math.pow(2,-10*--f)+2)+a},easeInCirc:function(e,f,a,h,g){return -h*(Math.sqrt(1-(f/=g)*f)-1)+a},easeOutCirc:function(e,f,a,h,g){return h*Math.sqrt(1-(f=f/g-1)*f)+a},easeInOutCirc:function(e,f,a,h,g){if((f/=g/2)<1){return -h/2*(Math.sqrt(1-f*f)-1)+a}return h/2*(Math.sqrt(1-(f-=2)*f)+1)+a},easeInElastic:function(f,h,e,l,k){var i=1.70158;var j=0;var g=l;if(h==0){return e}if((h/=k)==1){return e+l}if(!j){j=k*0.3}if(g<Math.abs(l)){g=l;var i=j/4}else{var i=j/(2*Math.PI)*Math.asin(l/g)}return -(g*Math.pow(2,10*(h-=1))*Math.sin((h*k-i)*(2*Math.PI)/j))+e},easeOutElastic:function(f,h,e,l,k){var i=1.70158;var j=0;var g=l;if(h==0){return e}if((h/=k)==1){return e+l}if(!j){j=k*0.3}if(g<Math.abs(l)){g=l;var i=j/4}else{var i=j/(2*Math.PI)*Math.asin(l/g)}return g*Math.pow(2,-10*h)*Math.sin((h*k-i)*(2*Math.PI)/j)+l+e},easeInOutElastic:function(f,h,e,l,k){var i=1.70158;var j=0;var g=l;if(h==0){return e}if((h/=k/2)==2){return e+l}if(!j){j=k*(0.3*1.5)}if(g<Math.abs(l)){g=l;var i=j/4}else{var i=j/(2*Math.PI)*Math.asin(l/g)}if(h<1){return -0.5*(g*Math.pow(2,10*(h-=1))*Math.sin((h*k-i)*(2*Math.PI)/j))+e}return g*Math.pow(2,-10*(h-=1))*Math.sin((h*k-i)*(2*Math.PI)/j)*0.5+l+e},easeInBack:function(e,f,a,i,h,g){if(g==undefined){g=1.70158}return i*(f/=h)*f*((g+1)*f-g)+a},easeOutBack:function(e,f,a,i,h,g){if(g==undefined){g=1.70158}return i*((f=f/h-1)*f*((g+1)*f+g)+1)+a},easeInOutBack:function(e,f,a,i,h,g){if(g==undefined){g=1.70158}if((f/=h/2)<1){return i/2*(f*f*(((g*=(1.525))+1)*f-g))+a}return i/2*((f-=2)*f*(((g*=(1.525))+1)*f+g)+2)+a},easeInBounce:function(e,f,a,h,g){return h-jQuery.easing.easeOutBounce(e,g-f,0,h,g)+a},easeOutBounce:function(e,f,a,h,g){if((f/=g)<(1/2.75)){return h*(7.5625*f*f)+a}else{if(f<(2/2.75)){return h*(7.5625*(f-=(1.5/2.75))*f+0.75)+a}else{if(f<(2.5/2.75)){return h*(7.5625*(f-=(2.25/2.75))*f+0.9375)+a}else{return h*(7.5625*(f-=(2.625/2.75))*f+0.984375)+a}}}},easeInOutBounce:function(e,f,a,h,g){if(f<g/2){return jQuery.easing.easeInBounce(e,f*2,0,h,g)*0.5+a}return jQuery.easing.easeOutBounce(e,f*2-g,0,h,g)*0.5+h*0.5+a}}); | |
1269 | ||
1270 | /* jQuery Cookie plugin */ | |
1271 | jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1;}var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000));}else{date=options.expires;}expires='; expires='+date.toUTCString();}var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('');}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break;}}}return cookieValue;}}; | |
1272 | ||
1273 | /* jQuery querystring plugin */ | |
1274 | eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('M 6(A){4 $11=A.11||\'&\';4 $V=A.V===r?r:j;4 $1p=A.1p===r?\'\':\'[]\';4 $13=A.13===r?r:j;4 $D=$13?A.D===j?"#":"?":"";4 $15=A.15===r?r:j;v.1o=M 6(){4 f=6(o,t){8 o!=1v&&o!==x&&(!!t?o.1t==t:j)};4 14=6(1m){4 m,1l=/\\[([^[]*)\\]/g,T=/^([^[]+)(\\[.*\\])?$/.1r(1m),k=T[1],e=[];19(m=1l.1r(T[2]))e.u(m[1]);8[k,e]};4 w=6(3,e,7){4 o,y=e.1b();b(I 3!=\'X\')3=x;b(y===""){b(!3)3=[];b(f(3,L)){3.u(e.h==0?7:w(x,e.z(0),7))}n b(f(3,1a)){4 i=0;19(3[i++]!=x);3[--i]=e.h==0?7:w(3[i],e.z(0),7)}n{3=[];3.u(e.h==0?7:w(x,e.z(0),7))}}n b(y&&y.T(/^\\s*[0-9]+\\s*$/)){4 H=1c(y,10);b(!3)3=[];3[H]=e.h==0?7:w(3[H],e.z(0),7)}n b(y){4 H=y.B(/^\\s*|\\s*$/g,"");b(!3)3={};b(f(3,L)){4 18={};1w(4 i=0;i<3.h;++i){18[i]=3[i]}3=18}3[H]=e.h==0?7:w(3[H],e.z(0),7)}n{8 7}8 3};4 C=6(a){4 p=d;p.l={};b(a.C){v.J(a.Z(),6(5,c){p.O(5,c)})}n{v.J(1u,6(){4 q=""+d;q=q.B(/^[?#]/,\'\');q=q.B(/[;&]$/,\'\');b($V)q=q.B(/[+]/g,\' \');v.J(q.Y(/[&;]/),6(){4 5=1e(d.Y(\'=\')[0]||"");4 c=1e(d.Y(\'=\')[1]||"");b(!5)8;b($15){b(/^[+-]?[0-9]+\\.[0-9]*$/.1d(c))c=1A(c);n b(/^[+-]?[0-9]+$/.1d(c))c=1c(c,10)}c=(!c&&c!==0)?j:c;b(c!==r&&c!==j&&I c!=\'1g\')c=c;p.O(5,c)})})}8 p};C.1H={C:j,1G:6(5,1f){4 7=d.Z(5);8 f(7,1f)},1h:6(5){b(!f(5))8 d.l;4 K=14(5),k=K[0],e=K[1];4 3=d.l[k];19(3!=x&&e.h!=0){3=3[e.1b()]}8 I 3==\'1g\'?3:3||""},Z:6(5){4 3=d.1h(5);b(f(3,1a))8 v.1E(j,{},3);n b(f(3,L))8 3.z(0);8 3},O:6(5,c){4 7=!f(c)?x:c;4 K=14(5),k=K[0],e=K[1];4 3=d.l[k];d.l[k]=w(3,e.z(0),7);8 d},w:6(5,c){8 d.N().O(5,c)},1s:6(5){8 d.O(5,x).17()},1z:6(5){8 d.N().1s(5)},1j:6(){4 p=d;v.J(p.l,6(5,7){1y p.l[5]});8 p},1F:6(Q){4 D=Q.B(/^.*?[#](.+?)(?:\\?.+)?$/,"$1");4 S=Q.B(/^.*?[?](.+?)(?:#.+)?$/,"$1");8 M C(Q.h==S.h?\'\':S,Q.h==D.h?\'\':D)},1x:6(){8 d.N().1j()},N:6(){8 M C(d)},17:6(){6 F(G){4 R=I G=="X"?f(G,L)?[]:{}:G;b(I G==\'X\'){6 1k(o,5,7){b(f(o,L))o.u(7);n o[5]=7}v.J(G,6(5,7){b(!f(7))8 j;1k(R,5,F(7))})}8 R}d.l=F(d.l);8 d},1B:6(){8 d.N().17()},1D:6(){4 i=0,U=[],W=[],p=d;4 16=6(E){E=E+"";b($V)E=E.B(/ /g,"+");8 1C(E)};4 1n=6(1i,5,7){b(!f(7)||7===r)8;4 o=[16(5)];b(7!==j){o.u("=");o.u(16(7))}1i.u(o.P(""))};4 F=6(R,k){4 12=6(5){8!k||k==""?[5].P(""):[k,"[",5,"]"].P("")};v.J(R,6(5,7){b(I 7==\'X\')F(7,12(5));n 1n(W,12(5),7)})};F(d.l);b(W.h>0)U.u($D);U.u(W.P($11));8 U.P("")}};8 M C(1q.S,1q.D)}}(v.1o||{});',62,106,'|||target|var|key|function|value|return|||if|val|this|tokens|is||length||true|base|keys||else||self||false|||push|jQuery|set|null|token|slice|settings|replace|queryObject|hash|str|build|orig|index|typeof|each|parsed|Array|new|copy|SET|join|url|obj|search|match|queryString|spaces|chunks|object|split|get||separator|newKey|prefix|parse|numbers|encode|COMPACT|temp|while|Object|shift|parseInt|test|decodeURIComponent|type|number|GET|arr|EMPTY|add|rx|path|addFields|query|suffix|location|exec|REMOVE|constructor|arguments|undefined|for|empty|delete|remove|parseFloat|compact|encodeURIComponent|toString|extend|load|has|prototype'.split('|'),0,{})) |