-
Notifications
You must be signed in to change notification settings - Fork 12
/
global.js
1609 lines (1298 loc) · 45.8 KB
/
global.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// AJAX Functions
var jq = jQuery;
// Global variable to prevent multiple AJAX requests
var bp_ajax_request = null;
jq(document).ready( function() {
/**** Page Load Actions *******************************************************/
/* Hide Forums Post Form */
if ( '-1' == window.location.search.indexOf('new') && jq('div.forums').length )
jq('#new-topic-post').hide();
else
jq('#new-topic-post').show();
/* Activity filter and scope set */
bp_init_activity();
/* Object filter and scope set. */
var objects = [ 'members', 'groups', 'blogs', 'forums' ],
$whats_new = jq('#whats-new');
bp_init_objects( objects );
/* @mention Compose Scrolling */
if ( $whats_new.length && bp_get_querystring('r') ) {
var $member_nicename = $whats_new.val();
jq('#whats-new-options').animate({
height:'40px'
});
$whats_new.animate({
height:'50px'
});
jq.scrollTo( $whats_new, 500, {
offset:-125,
easing:'swing'
} );
$whats_new.val('').focus().val( $member_nicename );
}
/**** Activity Posting ********************************************************/
/* Textarea focus */
jq('#whats-new').focus( function(){
jq("#whats-new-options").animate({
height:'40px'
});
jq("form#whats-new-form textarea").animate({
height:'50px'
});
jq("#aw-whats-new-submit").prop("disabled", false);
var $whats_new_form = jq("form#whats-new-form");
if ( $whats_new_form.hasClass("submitted") ) {
$whats_new_form.removeClass("submitted");
}
});
/* On blur, shrink if it's empty */
jq('#whats-new').blur( function(){
if (!this.value.match(/\S+/)) {
this.value = "";
jq("#whats-new-options").animate({
height:'40px'
});
jq("form#whats-new-form textarea").animate({
height:'20px'
});
jq("#aw-whats-new-submit").prop("disabled", true);
}
});
/* New posts */
jq("input#aw-whats-new-submit").click( function() {
var button = jq(this);
var form = button.closest("form#whats-new-form");
form.children().each( function() {
if ( jq.nodeName(this, "textarea") || jq.nodeName(this, "input") )
jq(this).prop( 'disabled', true );
});
/* Remove any errors */
jq('div.error').remove();
button.addClass('loading');
button.prop('disabled', true);
form.addClass("submitted");
/* Default POST values */
var object = '';
var item_id = jq("#whats-new-post-in").val();
var content = jq("textarea#whats-new").val();
/* Set object for non-profile posts */
if ( item_id > 0 ) {
object = jq("#whats-new-post-object").val();
}
jq.post( ajaxurl, {
action: 'post_update',
'cookie': bp_get_cookies(),
'_wpnonce_post_update': jq("input#_wpnonce_post_update").val(),
'content': content,
'object': object,
'item_id': item_id,
'_bp_as_nonce': jq('#_bp_as_nonce').val() || ''
},
function(response) {
form.children().each( function() {
if ( jq.nodeName(this, "textarea") || jq.nodeName(this, "input") ) {
jq(this).prop( 'disabled', false );
}
});
/* Check for errors and append if found. */
if ( response[0] + response[1] == '-1' ) {
form.prepend( response.substr( 2, response.length ) );
jq( 'form#' + form.attr('id') + ' div.error').hide().fadeIn( 200 );
} else {
if ( 0 == jq("ul.activity-list").length ) {
jq("div.error").slideUp(100).remove();
jq("div#message").slideUp(100).remove();
jq("div.activity").append( '<ul id="activity-stream" class="activity-list item-list">' );
}
jq("ul#activity-stream").prepend(response);
jq("ul#activity-stream li:first").addClass('new-update just-posted');
if ( 0 != jq("#latest-update").length ) {
var l = jq("ul#activity-stream li.new-update .activity-content .activity-inner p").html();
var v = jq("ul#activity-stream li.new-update .activity-content .activity-header p a.view").attr('href');
var ltext = jq("ul#activity-stream li.new-update .activity-content .activity-inner p").text();
var u = '';
if ( ltext != '' )
u = l + ' ';
u += '<a href="' + v + '" rel="nofollow">' + BP_DTheme.view + '</a>';
jq("#latest-update").slideUp(300,function(){
jq("#latest-update").html( u );
jq("#latest-update").slideDown(300);
});
}
jq("li.new-update").hide().slideDown( 300 );
jq("li.new-update").removeClass( 'new-update' );
jq("textarea#whats-new").val('');
}
jq("#whats-new-options").animate({
height:'0px'
});
jq("form#whats-new-form textarea").animate({
height:'20px'
});
jq("#aw-whats-new-submit").prop("disabled", true).removeClass('loading');
});
return false;
});
/* List tabs event delegation */
jq('div.activity-type-tabs').click( function(event) {
var target = jq(event.target).parent();
if ( event.target.nodeName == 'STRONG' || event.target.nodeName == 'SPAN' )
target = target.parent();
else if ( event.target.nodeName != 'A' )
return false;
/* Reset the page */
jq.cookie( 'bp-activity-oldestpage', 1, {
path: '/'
} );
/* Activity Stream Tabs */
var scope = target.attr('id').substr( 9, target.attr('id').length );
var filter = jq("#activity-filter-select select").val();
if ( scope == 'mentions' )
jq( 'li#' + target.attr('id') + ' a strong' ).remove();
bp_activity_request(scope, filter);
return false;
});
/* Activity filter select */
jq('#activity-filter-select select').change( function() {
var selected_tab = jq( 'div.activity-type-tabs li.selected' );
if ( !selected_tab.length )
var scope = null;
else
var scope = selected_tab.attr('id').substr( 9, selected_tab.attr('id').length );
var filter = jq(this).val();
bp_activity_request(scope, filter);
return false;
});
/* Stream event delegation */
jq('div.activity').click( function(event) {
var target = jq(event.target);
/* Favoriting activity stream items */
if ( target.hasClass('fav') || target.hasClass('unfav') ) {
var type = target.hasClass('fav') ? 'fav' : 'unfav';
var parent = target.closest('.activity-item');
var parent_id = parent.attr('id').substr( 9, parent.attr('id').length );
var nonce = bp_get_query_var( '_wpnonce', target.attr( 'href' ) );
target.addClass('loading');
jq.post( ajaxurl, {
action: 'activity_mark_' + type,
'cookie': bp_get_cookies(),
'id': parent_id,
nonce: nonce
},
function(response) {
target.removeClass('loading');
target.fadeOut( 100, function() {
jq(this).html(response);
jq(this).attr('title', 'fav' == type ? BP_DTheme.remove_fav : BP_DTheme.mark_as_fav);
jq(this).fadeIn(100);
});
if ( 'fav' == type ) {
if ( !jq('.item-list-tabs li#activity-favorites').length )
jq('.item-list-tabs ul li#activity-mentions').before( '<li id="activity-favorites"><a href="#">' + BP_DTheme.my_favs + ' <span>0</span></a></li>');
target.removeClass('fav');
target.addClass('unfav');
jq('.item-list-tabs ul li#activity-favorites span').html( Number( jq('.item-list-tabs ul li#activity-favorites span').html() ) + 1 );
} else {
target.removeClass('unfav');
target.addClass('fav');
jq('.item-list-tabs ul li#activity-favorites span').html( Number( jq('.item-list-tabs ul li#activity-favorites span').html() ) - 1 );
if ( !Number( jq('.item-list-tabs ul li#activity-favorites span').html() ) ) {
if ( jq('.item-list-tabs ul li#activity-favorites').hasClass('selected') )
bp_activity_request( null, null );
jq('.item-list-tabs ul li#activity-favorites').remove();
}
}
if ( 'activity-favorites' == jq( '.item-list-tabs li.selected').attr('id') )
target.parent().parent().parent().slideUp(100);
});
return false;
}
/* Delete activity stream items */
if ( target.hasClass('delete-activity') ) {
var li = target.parents('div.activity ul li');
var id = li.attr('id').substr( 9, li.attr('id').length );
var link_href = target.attr('href');
var nonce = link_href.split('_wpnonce=');
nonce = nonce[1];
target.addClass('loading');
jq.post( ajaxurl, {
action: 'delete_activity',
'cookie': bp_get_cookies(),
'id': id,
'_wpnonce': nonce
},
function(response) {
if ( response[0] + response[1] == '-1' ) {
li.prepend( response.substr( 2, response.length ) );
li.children('div#message').hide().fadeIn(300);
} else {
li.slideUp(300);
}
});
return false;
}
// Spam activity stream items
if ( target.hasClass( 'spam-activity' ) ) {
var li = target.parents( 'div.activity ul li' );
target.addClass( 'loading' );
jq.post( ajaxurl, {
action: 'bp_spam_activity',
'cookie': encodeURIComponent( document.cookie ),
'id': li.attr( 'id' ).substr( 9, li.attr( 'id' ).length ),
'_wpnonce': target.attr( 'href' ).split( '_wpnonce=' )[1]
},
function(response) {
if ( response[0] + response[1] === '-1' ) {
li.prepend( response.substr( 2, response.length ) );
li.children( 'div#message' ).hide().fadeIn(300);
} else {
li.slideUp( 300 );
}
});
return false;
}
/* Load more updates at the end of the page */
if ( target.parent().hasClass('load-more') ) {
jq("#content li.load-more").addClass('loading');
if ( null == jq.cookie('bp-activity-oldestpage') )
jq.cookie('bp-activity-oldestpage', 1, {
path: '/'
} );
var oldest_page = ( jq.cookie('bp-activity-oldestpage') * 1 ) + 1;
var just_posted = [];
jq('.activity-list li.just-posted').each( function(){
just_posted.push( jq(this).attr('id').replace( 'activity-','' ) );
});
jq.post( ajaxurl, {
action: 'activity_get_older_updates',
'cookie': bp_get_cookies(),
'page': oldest_page,
'exclude_just_posted': just_posted.join(',')
},
function(response)
{
jq("#content li.load-more").removeClass('loading');
jq.cookie( 'bp-activity-oldestpage', oldest_page, {
path: '/'
} );
jq("#content ul.activity-list").append(response.contents);
target.parent().hide();
}, 'json' );
return false;
}
});
// Activity "Read More" links
jq('div.activity').on('click', '.activity-read-more a', function(event) {
var target = jq(event.target);
var link_id = target.parent().attr('id').split('-');
var a_id = link_id[3];
var type = link_id[0]; /* activity or acomment */
var inner_class = type == 'acomment' ? 'acomment-content' : 'activity-inner';
var a_inner = jq('li#' + type + '-' + a_id + ' .' + inner_class + ':first' );
jq(target).addClass('loading');
jq.post( ajaxurl, {
action: 'get_single_activity_content',
'activity_id': a_id
},
function(response) {
jq(a_inner).slideUp(300).html(response).slideDown(300);
});
return false;
});
/**** Activity Comments *******************************************************/
/* Hide all activity comment forms */
jq('form.ac-form').hide();
/* Hide excess comments */
if ( jq('.activity-comments').length )
bp_dtheme_hide_comments();
/* Activity list event delegation */
jq('div.activity').click( function(event) {
var target = jq(event.target);
/* Comment / comment reply links */
if ( target.hasClass('acomment-reply') || target.parent().hasClass('acomment-reply') ) {
if ( target.parent().hasClass('acomment-reply') )
target = target.parent();
var id = target.attr('id');
ids = id.split('-');
var a_id = ids[2]
var c_id = target.attr('href').substr( 10, target.attr('href').length );
var form = jq( '#ac-form-' + a_id );
form.css( 'display', 'none' );
form.removeClass('root');
jq('.ac-form').hide();
/* Hide any error messages */
form.children('div').each( function() {
if ( jq(this).hasClass( 'error' ) )
jq(this).hide();
});
if ( ids[1] != 'comment' ) {
jq('.activity-comments li#acomment-' + c_id).append( form );
} else {
jq('li#activity-' + a_id + ' .activity-comments').append( form );
}
if ( form.parent().hasClass( 'activity-comments' ) )
form.addClass('root');
form.slideDown( 200 );
jq.scrollTo( form, 500, {
offset:-100,
easing:'swing'
} );
jq('#ac-form-' + ids[2] + ' textarea').focus();
return false;
}
/* Activity comment posting */
if ( target.attr('name') == 'ac_form_submit' ) {
var form = target.parents( 'form' );
var form_parent = form.parent();
var form_id = form.attr('id').split('-');
if ( !form_parent.hasClass('activity-comments') ) {
var tmp_id = form_parent.attr('id').split('-');
var comment_id = tmp_id[1];
} else {
var comment_id = form_id[2];
}
/* Hide any error messages */
jq( 'form#' + form.attr('id') + ' div.error').hide();
target.addClass('loading').prop('disabled', true);
var ajaxdata = {
action: 'new_activity_comment',
'cookie': bp_get_cookies(),
'_wpnonce_new_activity_comment': jq("input#_wpnonce_new_activity_comment").val(),
'comment_id': comment_id,
'form_id': form_id[2],
'content': jq('form#' + form.attr('id') + ' textarea').val()
};
// Akismet
var ak_nonce = jq('#_bp_as_nonce_' + comment_id).val();
if ( ak_nonce ) {
ajaxdata['_bp_as_nonce_' + comment_id] = ak_nonce;
}
jq.post( ajaxurl, ajaxdata, function(response) {
target.removeClass('loading');
/* Check for errors and append if found. */
if ( response[0] + response[1] == '-1' ) {
form.append( jq( response.substr( 2, response.length ) ).hide().fadeIn( 200 ) );
} else {
var activity_comments = form.parent();
form.fadeOut( 200, function() {
if ( 0 == activity_comments.children('ul').length ) {
if ( activity_comments.hasClass('activity-comments') ) {
activity_comments.prepend('<ul></ul>');
} else {
activity_comments.append('<ul></ul>');
}
}
/* Preceeding whitespace breaks output with jQuery 1.9.0 */
var the_comment = jq.trim( response );
activity_comments.children('ul').append( jq( the_comment ).hide().fadeIn( 200 ) );
form.children('textarea').val('');
activity_comments.parent().addClass('has-comments');
} );
jq( 'form#' + form.attr('id') + ' textarea').val('');
/* Increase the "Reply (X)" button count */
jq('li#activity-' + form_id[2] + ' a.acomment-reply span').html( Number( jq('li#activity-' + form_id[2] + ' a.acomment-reply span').html() ) + 1 );
// Increment the 'Show all x comments' string, if present
var show_all_a = activity_comments.find('.show-all').find('a');
if ( show_all_a ) {
var new_count = jq('li#activity-' + form_id[2] + ' a.acomment-reply span').html();
show_all_a.html( BP_DTheme.show_x_comments.replace( '%d', new_count ) );
}
}
jq(target).prop("disabled", false);
});
return false;
}
/* Deleting an activity comment */
if ( target.hasClass('acomment-delete') ) {
var link_href = target.attr('href');
var comment_li = target.parent().parent();
var form = comment_li.parents('div.activity-comments').children('form');
var nonce = link_href.split('_wpnonce=');
nonce = nonce[1];
var comment_id = link_href.split('cid=');
comment_id = comment_id[1].split('&');
comment_id = comment_id[0];
target.addClass('loading');
/* Remove any error messages */
jq('.activity-comments ul .error').remove();
/* Reset the form position */
comment_li.parents('.activity-comments').append(form);
jq.post( ajaxurl, {
action: 'delete_activity_comment',
'cookie': bp_get_cookies(),
'_wpnonce': nonce,
'id': comment_id
},
function(response)
{
/* Check for errors and append if found. */
if ( response[0] + response[1] == '-1' ) {
comment_li.prepend( jq( response.substr( 2, response.length ) ).hide().fadeIn( 200 ) );
} else {
var children = jq( 'li#' + comment_li.attr('id') + ' ul' ).children('li');
var child_count = 0;
jq(children).each( function() {
if ( !jq(this).is(':hidden') )
child_count++;
});
comment_li.fadeOut(200, function() {
comment_li.remove();
});
/* Decrease the "Reply (X)" button count */
var count_span = jq('li#' + comment_li.parents('ul#activity-stream > li').attr('id') + ' a.acomment-reply span');
var new_count = count_span.html() - ( 1 + child_count );
count_span.html(new_count);
// Change the 'Show all x comments' text
var show_all_a = comment_li.siblings('.show-all').find('a');
if ( show_all_a ) {
show_all_a.html( BP_DTheme.show_x_comments.replace( '%d', new_count ) );
}
/* If that was the last comment for the item, remove the has-comments class to clean up the styling */
if ( 0 == new_count ) {
jq(comment_li.parents('ul#activity-stream > li')).removeClass('has-comments');
}
}
});
return false;
}
// Spam an activity stream comment
if ( target.hasClass( 'spam-activity-comment' ) ) {
var link_href = target.attr( 'href' );
var comment_li = target.parent().parent();
target.addClass('loading');
// Remove any error messages
jq( '.activity-comments ul div.error' ).remove();
// Reset the form position
comment_li.parents( '.activity-comments' ).append( comment_li.parents( '.activity-comments' ).children( 'form' ) );
jq.post( ajaxurl, {
action: 'bp_spam_activity_comment',
'cookie': encodeURIComponent( document.cookie ),
'_wpnonce': link_href.split( '_wpnonce=' )[1],
'id': link_href.split( 'cid=' )[1].split( '&' )[0]
},
function ( response ) {
// Check for errors and append if found.
if ( response[0] + response[1] == '-1' ) {
comment_li.prepend( jq( response.substr( 2, response.length ) ).hide().fadeIn( 200 ) );
} else {
var children = jq( 'li#' + comment_li.attr( 'id' ) + ' ul' ).children( 'li' );
var child_count = 0;
jq(children).each( function() {
if ( !jq( this ).is( ':hidden' ) ) {
child_count++;
}
});
comment_li.fadeOut( 200 );
// Decrease the "Reply (X)" button count
var parent_li = comment_li.parents( 'ul#activity-stream > li' );
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 ) );
}
});
return false;
}
/* Showing hidden comments - pause for half a second */
if ( target.parent().hasClass('show-all') ) {
target.parent().addClass('loading');
setTimeout( function() {
target.parent().parent().children('li').fadeIn(200, function() {
target.parent().remove();
});
}, 600 );
return false;
}
});
/* Escape Key Press for cancelling comment forms */
jq(document).keydown( function(e) {
e = e || window.event;
if (e.target)
element = e.target;
else if (e.srcElement)
element = e.srcElement;
if( element.nodeType == 3)
element = element.parentNode;
if( e.ctrlKey == true || e.altKey == true || e.metaKey == true )
return;
var keyCode = (e.keyCode) ? e.keyCode : e.which;
if ( keyCode == 27 ) {
if (element.tagName == 'TEXTAREA') {
if ( jq(element).hasClass('ac-input') )
jq(element).parent().parent().parent().slideUp( 200 );
}
}
});
/**** Directory Search ****************************************************/
/* The search form on all directory pages */
jq('.dir-search').click( function(event) {
if ( jq(this).hasClass('no-ajax') )
return;
var target = jq(event.target);
if ( target.attr('type') == 'submit' ) {
var css_id = jq('.item-list-tabs li.selected').attr('id').split( '-' );
var object = css_id[0];
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') );
return false;
}
});
/**** Tabs and Filters ****************************************************/
/* When a navigation tab is clicked - e.g. | All Groups | My Groups | */
jq('div.item-list-tabs').click( function(event) {
if ( jq(this).hasClass('no-ajax') )
return;
var targetElem = ( event.target.nodeName == 'SPAN' ) ? event.target.parentNode : event.target;
var target = jq( targetElem ).parent();
if ( 'LI' == target[0].nodeName && !target.hasClass('last') ) {
var css_id = target.attr('id').split( '-' );
var object = css_id[0];
if ( 'activity' == object )
return false;
var scope = css_id[1];
var filter = jq("#" + object + "-order-select select").val();
var search_terms = jq("#" + object + "_search").val();
bp_filter_request( object, filter, scope, 'div.' + object, search_terms, 1, jq.cookie('bp-' + object + '-extras') );
return false;
}
});
/* When the filter select box is changed re-query */
jq('li.filter select').change( function() {
if ( jq('.item-list-tabs li.selected').length )
var el = jq('.item-list-tabs li.selected');
else
var el = jq(this);
var css_id = el.attr('id').split('-');
var object = css_id[0];
var scope = css_id[1];
var filter = jq(this).val();
var search_terms = false;
if ( jq('.dir-search input').length )
search_terms = jq('.dir-search input').val();
if ( 'friends' == object )
object = 'members';
bp_filter_request( object, filter, scope, 'div.' + object, search_terms, 1, jq.cookie('bp-' + object + '-extras') );
return false;
});
/* All pagination links run through this function */
jq('div#content').click( function(event) {
var target = jq(event.target);
if ( target.hasClass('button') )
return true;
if ( target.parent().parent().hasClass('pagination') && !target.parent().parent().hasClass('no-ajax') ) {
if ( target.hasClass('dots') || target.hasClass('current') )
return false;
if ( jq('.item-list-tabs li.selected').length )
var el = jq('.item-list-tabs li.selected');
else
var el = jq('li.filter select');
var page_number = 1;
var css_id = el.attr('id').split( '-' );
var object = css_id[0];
var search_terms = false;
var pagination_id = jq(target).closest('.pagination-links').attr('id');
if ( jq('div.dir-search input').length )
search_terms = jq('.dir-search input').val();
if ( jq(target).hasClass('next') )
var page_number = Number( jq('.pagination span.current').html() ) + 1;
else if ( jq(target).hasClass('prev') )
var page_number = Number( jq('.pagination span.current').html() ) - 1;
else
var page_number = Number( jq(target).html() );
if ( pagination_id.indexOf( 'pag-bottom' ) !== -1 ) {
var caller = 'pag-bottom';
} else {
var caller = null;
}
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'), caller );
return false;
}
});
/**** New Forum Directory Post **************************************/
/* Hit the "New Topic" button on the forums directory page */
jq('a.show-hide-new').click( function() {
if ( !jq('#new-topic-post').length )
return false;
if ( jq('#new-topic-post').is(":visible") )
jq('#new-topic-post').slideUp(200);
else
jq('#new-topic-post').slideDown(200, function() {
jq('#topic_title').focus();
} );
return false;
});
/* Cancel the posting of a new forum topic */
jq('input#submit_topic_cancel').click( function() {
if ( !jq('#new-topic-post').length )
return false;
jq('#new-topic-post').slideUp(200);
return false;
});
/* Clicking a forum tag */
jq('#forum-directory-tags a').click( function() {
bp_filter_request( 'forums', 'tags', jq.cookie('bp-forums-scope'), 'div.forums', jq(this).html().replace( / /g, '-' ), 1, jq.cookie('bp-forums-extras') );
return false;
});
/** Invite Friends Interface ****************************************/
/* Select a user from the list of friends and add them to the invite list */
jq("div#invite-list input").click( function() {
jq('.ajax-loader').toggle();
var friend_id = jq(this).val();
if ( jq(this).prop('checked') == true )
var friend_action = 'invite';
else
var friend_action = 'uninvite';
jq('.item-list-tabs li.selected').addClass('loading');
jq.post( ajaxurl, {
action: 'groups_invite_user',
'friend_action': friend_action,
'cookie': bp_get_cookies(),
'_wpnonce': jq("input#_wpnonce_invite_uninvite_user").val(),
'friend_id': friend_id,
'group_id': jq("input#group_id").val()
},
function(response)
{
if ( jq("#message") )
jq("#message").hide();
jq('.ajax-loader').toggle();
if ( friend_action == 'invite' ) {
jq('#friend-list').append(response);
} else if ( friend_action == 'uninvite' ) {
jq('#friend-list li#uid-' + friend_id).remove();
}
jq('.item-list-tabs li.selected').removeClass('loading');
});
});
/* Remove a user from the list of users to invite to a group */
jq("#friend-list").on('click', 'li a.remove', function() {
jq('.ajax-loader').toggle();
var friend_id = jq(this).attr('id');
friend_id = friend_id.split('-');
friend_id = friend_id[1];
jq.post( ajaxurl, {
action: 'groups_invite_user',
'friend_action': 'uninvite',
'cookie': bp_get_cookies(),
'_wpnonce': jq("input#_wpnonce_invite_uninvite_user").val(),
'friend_id': friend_id,
'group_id': jq("input#group_id").val()
},
function(response)
{
jq('.ajax-loader').toggle();
jq('#friend-list li#uid-' + friend_id).remove();
jq('#invite-list input#f-' + friend_id).prop('checked', false);
});
return false;
});
/** Profile Visibility Settings *********************************/
jq('.field-visibility-settings').hide();
jq( '.visibility-toggle-link' ).on( 'click', function( event ) {
event.preventDefault();
jq( this ).parent().hide().addClass( 'field-visibility-settings-hide' )
.siblings( '.field-visibility-settings' ).show().addClass( 'field-visibility-settings-open' );
} );
jq( '.field-visibility-settings-close' ).on( 'click', function( event ) {
event.preventDefault();
var settings_div = jq( this ).parent(),
vis_setting_text = settings_div.find( 'input:checked' ).parent().text();
settings_div.hide().removeClass( 'field-visibility-settings-open' )
.siblings( '.field-visibility-settings-toggle' )
.children( '.current-visibility-level' ).text( vis_setting_text ).end()
.show().removeClass( 'field-visibility-settings-hide' );
} );
jq("#profile-edit-form input:not(:submit), #profile-edit-form textarea, #profile-edit-form select, #signup_form input:not(:submit), #signup_form textarea, #signup_form select").change( function() {
var shouldconfirm = true;
jq('#profile-edit-form input:submit, #signup_form input:submit').on( 'click', function() {
shouldconfirm = false;
});
window.onbeforeunload = function(e) {
if ( shouldconfirm ) {
return BP_DTheme.unsaved_changes;
}
};
});
/** Friendship Requests **************************************/
/* Accept and Reject friendship request buttons */
jq("ul#friend-list a.accept, ul#friend-list a.reject").click( function() {
var button = jq(this);
var li = jq(this).parents('ul#friend-list li');
var action_div = jq(this).parents('li div.action');
var id = li.attr('id').substr( 11, li.attr('id').length );
var link_href = button.attr('href');
var nonce = link_href.split('_wpnonce=');
nonce = nonce[1];
if ( jq(this).hasClass('accepted') || jq(this).hasClass('rejected') )
return false;
if ( jq(this).hasClass('accept') ) {
var action = 'accept_friendship';
action_div.children('a.reject').css( 'visibility', 'hidden' );
} else {
var action = 'reject_friendship';
action_div.children('a.accept').css( 'visibility', 'hidden' );
}
button.addClass('loading');
jq.post( ajaxurl, {
action: action,
'cookie': bp_get_cookies(),
'id': id,
'_wpnonce': nonce
},
function(response) {
button.removeClass('loading');
if ( response[0] + response[1] == '-1' ) {
li.prepend( response.substr( 2, response.length ) );
li.children('div#message').hide().fadeIn(200);
} else {
button.fadeOut( 100, function() {
if ( jq(this).hasClass('accept') ) {
action_div.children('a.reject').hide();
jq(this).html( BP_DTheme.accepted ).contents().unwrap();
} else {
action_div.children('a.accept').hide();
jq(this).html( BP_DTheme.rejected ).contents().unwrap();
}
});
}
});
return false;
});
/* Add / Remove friendship buttons */
jq('#members-dir-list').on('click', '.friendship-button a', function() {
jq(this).parent().addClass('loading');
var fid = jq(this).attr('id');
fid = fid.split('-');
fid = fid[1];
var nonce = jq(this).attr('href');
nonce = nonce.split('?_wpnonce=');
nonce = nonce[1].split('&');
nonce = nonce[0];
var thelink = jq(this);
jq.post( ajaxurl, {
action: 'addremove_friend',
'cookie': bp_get_cookies(),
'fid': fid,
'_wpnonce': nonce
},
function(response)
{
var action = thelink.attr('rel');
var parentdiv = thelink.parent();
if ( action == 'add' ) {
jq(parentdiv).fadeOut(200,
function() {
parentdiv.removeClass('add_friend');
parentdiv.removeClass('loading');
parentdiv.addClass('pending_friend');
parentdiv.fadeIn(200).html(response);
}
);
} else if ( action == 'remove' ) {
jq(parentdiv).fadeOut(200,
function() {
parentdiv.removeClass('remove_friend');
parentdiv.removeClass('loading');
parentdiv.addClass('add');