[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 /* global wp, BP_Nouveau, JSON */ 2 /* jshint devel: true */ 3 /* jshint browser: true */ 4 /* @since 3.0.0 */ 5 /* @version 8.0.0 */ 6 window.wp = window.wp || {}; 7 window.bp = window.bp || {}; 8 9 ( function( bp, $ ) { 10 11 // Bail if not set. 12 if ( typeof BP_Nouveau === 'undefined' ) { 13 return; 14 } 15 16 /** 17 * [Nouveau description] 18 * @type {Object} 19 */ 20 bp.Nouveau = { 21 /** 22 * [start description] 23 * @return {[type]} [description] 24 */ 25 start: function() { 26 27 // Setup globals. 28 this.setupGlobals(); 29 30 // Adjust Document/Forms properties. 31 this.prepareDocument(); 32 33 // Init the BuddyPress objects. 34 this.initObjects(); 35 36 // Set BuddyPress HeartBeat. 37 this.setHeartBeat(); 38 39 // Listen to events ("Add hooks!"). 40 this.addListeners(); 41 }, 42 43 /** 44 * [setupGlobals description] 45 * @return {[type]} [description] 46 */ 47 setupGlobals: function() { 48 this.ajax_request = null; 49 50 // Object Globals. 51 this.objects = $.map( BP_Nouveau.objects, function( value ) { return value; } ); 52 this.objectNavParent = BP_Nouveau.object_nav_parent; 53 54 // HeartBeat Global. 55 this.heartbeat = wp.heartbeat || {}; 56 57 // An object containing each query var. 58 this.querystring = this.getLinkParams(); 59 }, 60 61 /** 62 * [prepareDocument description] 63 * @return {[type]} [description] 64 */ 65 prepareDocument: function() { 66 67 // Remove the no-js class and add the js one. 68 if ( $( 'body' ).hasClass( 'no-js' ) ) { 69 $('body').removeClass( 'no-js' ).addClass( 'js' ); 70 } 71 72 // Log Warnings into the console instead of the screen. 73 if ( BP_Nouveau.warnings && 'undefined' !== typeof console && console.warn ) { 74 $.each( BP_Nouveau.warnings, function( w, warning ) { 75 console.warn( warning ); 76 } ); 77 } 78 79 // Remove the directory title if there's a widget containing it. 80 if ( $( '.buddypress_object_nav .widget-title' ).length ) { 81 var text = $( '.buddypress_object_nav .widget-title' ).html(); 82 83 $( 'body' ).find( '*:contains("' + text + '")' ).each( function( e, element ) { 84 if ( ! $( element ).hasClass( 'widget-title' ) && text === $( element ).html() && ! $( element ).is( 'a' ) ) { 85 $( element ).remove(); 86 } 87 } ); 88 } 89 }, 90 91 /** Helpers *******************************************************************/ 92 93 /** 94 * [getStorage description] 95 * @param {[type]} type [description] 96 * @param {[type]} property [description] 97 * @return {[type]} [description] 98 */ 99 getStorage: function( type, property ) { 100 var store = sessionStorage.getItem( type ); 101 102 if ( store ) { 103 store = JSON.parse( store ); 104 } else { 105 store = {}; 106 } 107 108 if ( undefined !== property ) { 109 return store[property] || false; 110 } 111 112 return store; 113 }, 114 115 /** 116 * [setStorage description] 117 * @param {[type]} type [description] 118 * @param {[type]} property [description] 119 * @param {[type]} value [description] 120 */ 121 setStorage: function( type, property, value ) { 122 var store = this.getStorage( type ); 123 124 if ( undefined === value && undefined !== store[ property ] ) { 125 delete store[ property ]; 126 } else { 127 // Set property. 128 store[ property ] = value; 129 } 130 131 sessionStorage.setItem( type, JSON.stringify( store ) ); 132 133 return sessionStorage.getItem( type ) !== null; 134 }, 135 136 /** 137 * [getLinkParams description] 138 * @param {[type]} url [description] 139 * @param {[type]} param [description] 140 * @return {[type]} [description] 141 */ 142 getLinkParams: function( url, param ) { 143 var qs; 144 if ( url ) { 145 qs = ( -1 !== url.indexOf( '?' ) ) ? '?' + url.split( '?' )[1] : ''; 146 } else { 147 qs = document.location.search; 148 } 149 150 if ( ! qs ) { 151 return null; 152 } 153 154 var params = qs.replace( /(^\?)/, '' ).split( '&' ).map( function( n ) { 155 return n = n.split( '=' ), this[n[0]] = n[1], this; 156 }.bind( {} ) )[0]; 157 158 if ( param ) { 159 return params[param]; 160 } 161 162 return params; 163 }, 164 165 /** 166 * URL Decode a query variable. 167 * 168 * @param {string} qv The query variable to decode. 169 * @param {object} chars The specific characters to use. Optional. 170 * @return {string} The URL decoded variable. 171 */ 172 urlDecode: function( qv, chars ) { 173 var specialChars = chars || { 174 amp: '&', 175 lt: '<', 176 gt: '>', 177 quot: '"', 178 '#039': '\'' 179 }; 180 181 return decodeURIComponent( qv.replace( /\+/g, ' ' ) ).replace( /&([^;]+);/g, function( v, q ) { 182 return specialChars[q] || ''; 183 } ); 184 }, 185 186 /** 187 * [ajax description] 188 * @param {[type]} post_data [description] 189 * @param {[type]} object [description] 190 * @return {[type]} [description] 191 */ 192 ajax: function( post_data, object ) { 193 if ( this.ajax_request ) { 194 this.ajax_request.abort(); 195 } 196 197 // Extend posted data with stored data and object nonce. 198 var postData = $.extend( {}, bp.Nouveau.getStorage( 'bp-' + object ), { nonce: BP_Nouveau.nonces[object] }, post_data ); 199 200 if ( undefined !== BP_Nouveau.customizer_settings ) { 201 postData.customized = BP_Nouveau.customizer_settings; 202 } 203 204 this.ajax_request = $.post( BP_Nouveau.ajaxurl, postData, 'json' ); 205 206 return this.ajax_request; 207 }, 208 209 inject: function( selector, content, method ) { 210 if ( ! $( selector ).length || ! content ) { 211 return; 212 } 213 214 /** 215 * How the content should be injected in the selector 216 * 217 * possible methods are 218 * - reset: the selector will be reset with the content 219 * - append: the content will be added after selector's content 220 * - prepend: the content will be added before selector's content 221 */ 222 method = method || 'reset'; 223 224 if ( 'append' === method ) { 225 $( selector ).append( content ); 226 } else if ( 'prepend' === method ) { 227 $( selector ).prepend( content ); 228 } else { 229 $( selector ).html( content ); 230 } 231 232 if ( 'undefined' !== typeof bp_mentions || 'undefined' !== typeof bp.mentions ) { 233 $( '.bp-suggestions' ).bp_mentions( bp.mentions.users ); 234 } 235 }, 236 237 /** 238 * [objectRequest description] 239 * @param {[type]} data [description] 240 * @return {[type]} [description] 241 */ 242 objectRequest: function( data ) { 243 var postdata = {}, self = this; 244 245 data = $.extend( { 246 object : '', 247 scope : null, 248 filter : null, 249 target : '#buddypress [data-bp-list]', 250 search_terms : '', 251 page : 1, 252 extras : null, 253 caller : null, 254 template : null, 255 method : 'reset' 256 }, data ); 257 258 // Do not request if we don't have the object or the target to inject results into. 259 if ( ! data.object || ! data.target ) { 260 return; 261 } 262 263 // Prepare the search terms for the request. 264 if ( data.search_terms ) { 265 data.search_terms = data.search_terms.replace( /</g, '<' ).replace( />/g, '>' ); 266 } 267 268 // Set session's data. 269 if ( null !== data.scope ) { 270 this.setStorage( 'bp-' + data.object, 'scope', data.scope ); 271 } 272 273 if ( null !== data.filter ) { 274 this.setStorage( 'bp-' + data.object, 'filter', data.filter ); 275 } 276 277 if ( null !== data.extras ) { 278 this.setStorage( 'bp-' + data.object, 'extras', data.extras ); 279 } 280 281 /* Set the correct selected nav and filter */ 282 $( this.objectNavParent + ' [data-bp-object]' ).each( function() { 283 $( this ).removeClass( 'selected loading' ); 284 } ); 285 286 $( this.objectNavParent + ' [data-bp-scope="' + data.scope + '"], #object-nav li.current' ).addClass( 'selected loading' ); 287 $( '#buddypress [data-bp-filter="' + data.object + '"] option[value="' + data.filter + '"]' ).prop( 'selected', true ); 288 289 if ( 'friends' === data.object || 'friend_requests' === data.object || 'group_members' === data.object ) { 290 data.template = data.object; 291 data.object = 'members'; 292 } else if ( 'group_requests' === data.object ) { 293 data.object = 'groups'; 294 data.template = 'group_requests'; 295 } else if ( 'notifications' === data.object ) { 296 data.object = 'members'; 297 data.template = 'member_notifications'; 298 } 299 300 postdata = $.extend( { 301 action: data.object + '_filter' 302 }, data ); 303 304 return this.ajax( postdata, data.object ).done( function( response ) { 305 if ( false === response.success ) { 306 return; 307 } 308 309 $( self.objectNavParent + ' [data-bp-scope="' + data.scope + '"]' ).removeClass( 'loading' ); 310 311 if ( 'reset' !== data.method ) { 312 self.inject( data.target, response.data.contents, data.method ); 313 314 $( data.target ).trigger( 'bp_ajax_' + data.method, $.extend( data, { response: response.data } ) ); 315 } else { 316 /* animate to top if called from bottom pagination */ 317 if ( data.caller === 'pag-bottom' && $( '#subnav' ).length ) { 318 var top = $('#subnav').parent(); 319 $( 'html,body' ).animate( { scrollTop: top.offset().top }, 'slow', function() { 320 $( data.target ).fadeOut( 100, function() { 321 self.inject( this, response.data.contents, data.method ); 322 $( this ).fadeIn( 100, 'swing', function(){ 323 // Inform other scripts the list of objects has been refreshed. 324 $( data.target ).trigger( 'bp_ajax_request', $.extend( data, { response: response.data } ) ); 325 } ); 326 } ); 327 } ); 328 329 } else { 330 $( data.target ).fadeOut( 100, function() { 331 self.inject( this, response.data.contents, data.method ); 332 $( this ).fadeIn( 100, 'swing', function(){ 333 // Inform other scripts the list of objects has been refreshed. 334 $( data.target ).trigger( 'bp_ajax_request', $.extend( data, { response: response.data } ) ); 335 } ); 336 } ); 337 } 338 } 339 } ); 340 }, 341 342 /** 343 * [initObjects description] 344 * @return {[type]} [description] 345 */ 346 initObjects: function() { 347 var self = this, objectData = {}, queryData = {}, scope = 'all', search_terms = '', extras = null, filter = null; 348 349 $.each( this.objects, function( o, object ) { 350 objectData = self.getStorage( 'bp-' + object ); 351 352 if ( undefined !== objectData.scope ) { 353 scope = objectData.scope; 354 } 355 356 // Notifications always need to start with Newest ones. 357 if ( undefined !== objectData.extras && 'notifications' !== object ) { 358 extras = objectData.extras; 359 } 360 361 if ( $( '#buddypress [data-bp-filter="' + object + '"]' ).length ) { 362 if ( '-1' !== $( '#buddypress [data-bp-filter="' + object + '"]' ).val() && '0' !== $( '#buddypress [data-bp-filter="' + object + '"]' ).val() ) { 363 filter = $( '#buddypress [data-bp-filter="' + object + '"]' ).val(); 364 } else if ( undefined !== objectData.filter ) { 365 filter = objectData.filter, 366 $( '#buddypress [data-bp-filter="' + object + '"] option[value="' + filter + '"]' ).prop( 'selected', true ); 367 } 368 } 369 370 if ( $( this.objectNavParent + ' [data-bp-object="' + object + '"]' ).length ) { 371 $( this.objectNavParent + ' [data-bp-object="' + object + '"]' ).each( function() { 372 $( this ).removeClass( 'selected' ); 373 } ); 374 375 $( this.objectNavParent + ' [data-bp-scope="' + object + '"], #object-nav li.current' ).addClass( 'selected' ); 376 } 377 378 // Check the querystring to eventually include the search terms. 379 if ( null !== self.querystring ) { 380 if ( undefined !== self.querystring[ object + '_search'] ) { 381 search_terms = self.querystring[ object + '_search']; 382 } else if ( undefined !== self.querystring.s ) { 383 search_terms = self.querystring.s; 384 } 385 386 if ( search_terms ) { 387 search_terms = self.urlDecode( search_terms ); 388 $( '#buddypress [data-bp-search="' + object + '"] input[type=search]' ).val( search_terms ); 389 } 390 } 391 392 if ( $( '#buddypress [data-bp-list="' + object + '"]' ).length ) { 393 queryData = { 394 object : object, 395 scope : scope, 396 filter : filter, 397 search_terms : search_terms, 398 extras : extras 399 }; 400 401 // Populate the object list. 402 self.objectRequest( queryData ); 403 } 404 } ); 405 }, 406 407 /** 408 * [setHeartBeat description] 409 */ 410 setHeartBeat: function() { 411 if ( typeof BP_Nouveau.pulse === 'undefined' || ! this.heartbeat ) { 412 return; 413 } 414 415 this.heartbeat.interval( Number( BP_Nouveau.pulse ) ); 416 417 // Extend "send" with BuddyPress namespace. 418 $.fn.extend( { 419 'heartbeat-send': function() { 420 return this.bind( 'heartbeat-send.buddypress' ); 421 } 422 } ); 423 424 // Extend "tick" with BuddyPress namespace. 425 $.fn.extend( { 426 'heartbeat-tick': function() { 427 return this.bind( 'heartbeat-tick.buddypress' ); 428 } 429 } ); 430 }, 431 432 /** Event Listeners ***********************************************************/ 433 434 /** 435 * [addListeners description] 436 */ 437 addListeners: function() { 438 // Disabled inputs. 439 $( '[data-bp-disable-input]' ).on( 'change', this.toggleDisabledInput ); 440 441 // HeartBeat Send and Receive. 442 $( document ).on( 'heartbeat-send.buddypress', this.heartbeatSend ); 443 $( document ).on( 'heartbeat-tick.buddypress', this.heartbeatTick ); 444 445 // Refreshing. 446 $( this.objectNavParent + ' .bp-navs' ).on( 'click', 'a', this, this.scopeQuery ); 447 448 // Filtering. 449 $( '#buddypress [data-bp-filter]' ).on( 'change', this, this.filterQuery ); 450 451 // Searching. 452 $( '#buddypress [data-bp-search]' ).on( 'submit', 'form', this, this.searchQuery ); 453 $( '#buddypress [data-bp-search] form' ).on( 'search', 'input[type=search]', this.resetSearch ); 454 455 // Buttons. 456 $( '#buddypress [data-bp-list], #buddypress #item-header' ).on( 'click', '[data-bp-btn-action]', this, this.buttonAction ); 457 458 // Close notice. 459 $( '#buddypress [data-bp-close]' ).on( 'click', this, this.closeNotice ); 460 461 // Pagination. 462 $( '#buddypress [data-bp-list]' ).on( 'click', '[data-bp-pagination] a', this, this.paginateAction ); 463 }, 464 465 /** Event Callbacks ***********************************************************/ 466 467 /** 468 * Toggle the availability of Delete My account button. 469 * 470 * @param {Object} event The change event. 471 */ 472 toggleDisabledInput: function( event ) { 473 var target = $( event.currentTarget ), disabledControl = '#' + target.data( 'bp-disable-input' ), 474 isChecked = target.prop( 'checked' ); 475 476 target.removeClass( 'enabled disabled' ); 477 478 if ( isChecked ) { 479 target.addClass( 'enabled' ); 480 $( disabledControl ).prop( 'disabled', false ); 481 } else { 482 $( disabledControl ).prop( 'disabled', true ); 483 target.addClass( 'disabled' ); 484 } 485 }, 486 487 /** 488 * [heartbeatSend description] 489 * @param {[type]} event [description] 490 * @param {[type]} data [description] 491 * @return {[type]} [description] 492 */ 493 heartbeatSend: function( event, data ) { 494 // Add an heartbeat send event to possibly any BuddyPress pages. 495 $( '#buddypress' ).trigger( 'bp_heartbeat_send', data ); 496 }, 497 498 /** 499 * [heartbeatTick description] 500 * @param {[type]} event [description] 501 * @param {[type]} data [description] 502 * @return {[type]} [description] 503 */ 504 heartbeatTick: function( event, data ) { 505 // Add an heartbeat send event to possibly any BuddyPress pages. 506 $( '#buddypress' ).trigger( 'bp_heartbeat_tick', data ); 507 }, 508 509 /** 510 * [queryScope description] 511 * @param {[type]} event [description] 512 * @return {[type]} [description] 513 */ 514 scopeQuery: function( event ) { 515 var self = event.data, target = $( event.currentTarget ).parent(), 516 scope = 'all', object, filter = null, search_terms = ''; 517 518 if ( target.hasClass( 'no-ajax' ) || $( event.currentTarget ).hasClass( 'no-ajax' ) || ! target.attr( 'data-bp-scope' ) ) { 519 return event; 520 } 521 522 scope = target.data( 'bp-scope' ); 523 object = target.data( 'bp-object' ); 524 525 if ( ! scope || ! object ) { 526 return event; 527 } 528 529 // Stop event propagation. 530 event.preventDefault(); 531 532 filter = $( '#buddypress' ).find( '[data-bp-filter="' + object + '"]' ).first().val(); 533 534 if ( $( '#buddypress [data-bp-search="' + object + '"] input[type=search]' ).length ) { 535 search_terms = $( '#buddypress [data-bp-search="' + object + '"] input[type=search]' ).val(); 536 } 537 538 // Remove the New count on dynamic tabs. 539 if ( target.hasClass( 'dynamic' ) ) { 540 target.find( 'a span' ).html(''); 541 } 542 543 self.objectRequest( { 544 object : object, 545 scope : scope, 546 filter : filter, 547 search_terms : search_terms, 548 page : 1 549 } ); 550 }, 551 552 /** 553 * [filterQuery description] 554 * @param {[type]} event [description] 555 * @return {[type]} [description] 556 */ 557 filterQuery: function( event ) { 558 var self = event.data, object = $( event.target ).data( 'bp-filter' ), 559 scope = 'all', filter = $( event.target ).val(), 560 search_terms = '', template = null; 561 562 if ( ! object ) { 563 return event; 564 } 565 566 if ( $( self.objectNavParent + ' [data-bp-object].selected' ).length ) { 567 scope = $( self.objectNavParent + ' [data-bp-object].selected' ).data( 'bp-scope' ); 568 } 569 570 if ( $( '#buddypress [data-bp-search="' + object + '"] input[type=search]' ).length ) { 571 search_terms = $( '#buddypress [data-bp-search="' + object + '"] input[type=search]' ).val(); 572 } 573 574 self.objectRequest( { 575 object : object, 576 scope : scope, 577 filter : filter, 578 search_terms : search_terms, 579 page : 1, 580 template : template 581 } ); 582 }, 583 584 /** 585 * [searchQuery description] 586 * @param {[type]} event [description] 587 * @return {[type]} [description] 588 */ 589 searchQuery: function( event ) { 590 var self = event.data, object, scope = 'all', filter = null, template = null, search_terms = ''; 591 592 if ( $( event.delegateTarget ).hasClass( 'no-ajax' ) || undefined === $( event.delegateTarget ).data( 'bp-search' ) ) { 593 return event; 594 } 595 596 // Stop event propagation. 597 event.preventDefault(); 598 599 object = $( event.delegateTarget ).data( 'bp-search' ); 600 filter = $( '#buddypress' ).find( '[data-bp-filter="' + object + '"]' ).first().val(); 601 search_terms = $( event.delegateTarget ).find( 'input[type=search]' ).first().val(); 602 603 if ( $( self.objectNavParent + ' [data-bp-object]' ).length ) { 604 scope = $( self.objectNavParent + ' [data-bp-object="' + object + '"].selected' ).data( 'bp-scope' ); 605 } 606 607 self.objectRequest( { 608 object : object, 609 scope : scope, 610 filter : filter, 611 search_terms : search_terms, 612 page : 1, 613 template : template 614 } ); 615 }, 616 617 /** 618 * [showSearchSubmit description] 619 * @param {[type]} event [description] 620 * @return {[type]} [description] 621 */ 622 showSearchSubmit: function( event ) { 623 $( event.delegateTarget ).find( '[type=submit]' ).addClass( 'bp-show' ); 624 if( $('[type=submit]').hasClass( 'bp-hide' ) ) { 625 $( '[type=submit]' ).removeClass( 'bp-hide' ); 626 } 627 }, 628 629 /** 630 * [resetSearch description] 631 * @param {[type]} event [description] 632 * @return {[type]} [description] 633 */ 634 resetSearch: function( event ) { 635 if ( ! $( event.target ).val() ) { 636 $( event.delegateTarget ).submit(); 637 } else { 638 $( event.delegateTarget ).find( '[type=submit]' ).show(); 639 } 640 }, 641 642 /** 643 * [buttonAction description] 644 * @param {[type]} event [description] 645 * @return {[type]} [description] 646 */ 647 buttonAction: function( event ) { 648 var self = event.data, target = $( event.currentTarget ), action = target.data( 'bp-btn-action' ), nonceUrl = target.data( 'bp-nonce' ), 649 item = target.closest( '[data-bp-item-id]' ), item_id = item.data( 'bp-item-id' ), item_inner = target.closest('.list-wrap'), 650 object = item.data( 'bp-item-component' ), nonce = ''; 651 652 // Simply let the event fire if we don't have needed values. 653 if ( ! action || ! item_id || ! object ) { 654 return event; 655 } 656 657 // Stop event propagation. 658 event.preventDefault(); 659 660 if ( ( undefined !== BP_Nouveau[ action + '_confirm'] && false === window.confirm( BP_Nouveau[ action + '_confirm'] ) ) || target.hasClass( 'pending' ) ) { 661 return false; 662 } 663 664 // Find the required wpnonce string. 665 // if button element set we'll have our nonce set on a data attr 666 // Check the value & if exists split the string to obtain the nonce string 667 // if no value, i.e false, null then the href attr is used. 668 if ( nonceUrl ) { 669 nonce = nonceUrl.split('?_wpnonce='); 670 nonce = nonce[1]; 671 } else { 672 nonce = self.getLinkParams( target.prop( 'href' ), '_wpnonce' ); 673 } 674 675 // Unfortunately unlike groups 676 // Friends actions does not match the wpnonce 677 var friends_actions_map = { 678 is_friend : 'remove_friend', 679 not_friends : 'add_friend', 680 pending : 'withdraw_friendship', 681 accept_friendship : 'accept_friendship', 682 reject_friendship : 'reject_friendship' 683 }; 684 685 if ( 'members' === object && undefined !== friends_actions_map[ action ] ) { 686 action = friends_actions_map[ action ]; 687 object = 'friends'; 688 } 689 690 // Add a pending class to prevent queries while we're processing the action. 691 target.addClass( 'pending loading' ); 692 693 self.ajax( { 694 action : object + '_' + action, 695 item_id : item_id, 696 _wpnonce : nonce 697 }, object ).done( function( response ) { 698 if ( false === response.success ) { 699 item_inner.prepend( response.data.feedback ); 700 target.removeClass( 'pending loading' ); 701 item.find( '.bp-feedback' ).fadeOut( 6000 ); 702 } else { 703 // Specific cases for groups. 704 if ( 'groups' === object ) { 705 706 // Group's header button. 707 if ( undefined !== response.data.is_group && response.data.is_group ) { 708 return window.location.reload(); 709 } 710 } 711 712 // User's groups invitations screen & User's friend screens. 713 if ( undefined !== response.data.is_user && response.data.is_user ) { 714 target.parent().html( response.data.feedback ); 715 item.fadeOut( 1500 ); 716 return; 717 } 718 719 // Update count. 720 if ( $( self.objectNavParent + ' [data-bp-scope="personal"]' ).length ) { 721 var personal_count = Number( $( self.objectNavParent + ' [data-bp-scope="personal"] span' ).html() ) || 0; 722 723 if ( -1 !== $.inArray( action, ['leave_group', 'remove_friend'] ) ) { 724 personal_count -= 1; 725 } else if ( -1 !== $.inArray( action, ['join_group'] ) ) { 726 personal_count += 1; 727 } 728 729 if ( personal_count < 0 ) { 730 personal_count = 0; 731 } 732 733 $( self.objectNavParent + ' [data-bp-scope="personal"] span' ).html( personal_count ); 734 } 735 736 target.parent().replaceWith( response.data.contents ); 737 } 738 } ); 739 }, 740 741 /** 742 * [closeNotice description] 743 * @param {[type]} event [description] 744 * @return {[type]} [description] 745 */ 746 closeNotice: function( event ) { 747 var closeBtn = $( event.currentTarget ); 748 749 event.preventDefault(); 750 751 // Make sure cookies are removed. 752 if ( 'clear' === closeBtn.data( 'bp-close' ) ) { 753 if ( undefined !== $.cookie( 'bp-message' ) ) { 754 $.removeCookie( 'bp-message' ); 755 } 756 757 if ( undefined !== $.cookie( 'bp-message-type' ) ) { 758 $.removeCookie( 'bp-message-type' ); 759 } 760 } 761 762 // @todo other cases... 763 // Dismissing site-wide notices. 764 if ( closeBtn.closest( '.bp-feedback' ).hasClass( 'bp-sitewide-notice' ) ) { 765 bp.Nouveau.ajax( { 766 action : 'messages_dismiss_sitewide_notice' 767 }, 'messages' ); 768 } 769 770 // Remove the notice. 771 closeBtn.closest( '.bp-feedback' ).remove(); 772 }, 773 774 paginateAction: function( event ) { 775 var self = event.data, navLink = $( event.currentTarget ), pagArg, 776 scope = null, object, objectData, filter = null, search_terms = null, extras = null; 777 778 pagArg = navLink.closest( '[data-bp-pagination]' ).data( 'bp-pagination' ) || null; 779 780 if ( null === pagArg ) { 781 return event; 782 } 783 784 event.preventDefault(); 785 786 object = $( event.delegateTarget ).data( 'bp-list' ) || null; 787 788 // Set the scope & filter. 789 if ( null !== object ) { 790 objectData = self.getStorage( 'bp-' + object ); 791 792 if ( undefined !== objectData.scope ) { 793 scope = objectData.scope; 794 } 795 796 if ( undefined !== objectData.filter ) { 797 filter = objectData.filter; 798 } 799 800 if ( undefined !== objectData.extras ) { 801 extras = objectData.extras; 802 } 803 } 804 805 // Set the search terms. 806 if ( $( '#buddypress [data-bp-search="' + object + '"] input[type=search]' ).length ) { 807 search_terms = $( '#buddypress [data-bp-search="' + object + '"] input[type=search]' ).val(); 808 } 809 810 var queryData = { 811 object : object, 812 scope : scope, 813 filter : filter, 814 search_terms : search_terms, 815 extras : extras, 816 page : self.getLinkParams( navLink.prop( 'href' ), pagArg ) || 1 817 }; 818 819 // Request the page. 820 self.objectRequest( queryData ); 821 } 822 }; 823 824 // Launch BP Nouveau. 825 bp.Nouveau.start(); 826 827 } )( window.bp, jQuery );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sat Mar 6 01:01:37 2021 | Cross-referenced by PHPXref 0.7.1 |