[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 /** 2 * WordPress dependencies. 3 */ 4 const { 5 i18n: { 6 __, 7 sprintf, 8 }, 9 } = wp; 10 11 /** 12 * BuddyPress dependencies. 13 */ 14 const { 15 dynamicWidgetBlock, 16 } = bp; 17 18 /** 19 * Front-end Friends block class. 20 */ 21 class bpFriendsWidgetBlock extends dynamicWidgetBlock { 22 loop( friends = [], container = '', type = 'active' ) { 23 const tmpl = super.useTemplate( 'bp-friends-item' ); 24 const selector = document.querySelector( '#' + container ); 25 let output = ''; 26 27 if ( friends && friends.length ) { 28 friends.forEach( ( friend ) => { 29 if ( 'active' === type && friend.last_activity ) { 30 /* translators: %s: last activity timestamp (e.g. "Active 1 hour ago") */ 31 friend.extra = sprintf( __( 'Active %s', 'buddypress' ), friend.last_activity.timediff ); 32 } else if ( 'popular' === type && friend.total_friend_count ) { 33 const friendsCount = parseInt( friend.total_friend_count, 10 ); 34 35 if ( 0 === friendsCount ) { 36 friend.extra = __( 'No friends', 'buddypress' ); 37 } else if ( 1 === friendsCount ) { 38 friend.extra = __( '1 friend', 'buddypress' ); 39 } else { 40 /* translators: %s: total friend count (more than 1). */ 41 friend.extra = sprintf( __( '%s friends', 'buddypress' ), friend.total_friend_count ); 42 } 43 } else if ( 'newest' === type && friend.registered_since ) { 44 /* translators: %s is time elapsed since the registration date happened */ 45 friend.extra = sprintf( __( 'Registered %s', 'buddypress' ), friend.registered_since ); 46 } 47 48 /* translators: %s: member name */ 49 friend.avatar_alt = sprintf( __( 'Profile picture of %s', 'buddypress' ), friend.name ); 50 51 output += tmpl( friend ); 52 } ); 53 } else { 54 output = '<div class="widget-error">' + __( 'Sorry, no members were found.', 'buddypress' ) + '</div>'; 55 } 56 57 selector.innerHTML = output; 58 } 59 60 start() { 61 this.blocks.forEach( ( block, i ) => { 62 const { selector } = block; 63 const { type } = block.query_args; 64 const list = document.querySelector( '#' + selector ).closest( '.bp-dynamic-block-container' ); 65 66 // Get default Block's type friends. 67 super.getItems( type, i ); 68 69 // Listen to Block's Nav item clics 70 list.querySelectorAll( '.item-options a' ).forEach( ( navItem ) => { 71 navItem.addEventListener( 'click', ( event ) => { 72 event.preventDefault(); 73 74 // Changes the displayed filter. 75 event.target.closest( '.item-options' ).querySelector( '.selected' ).classList.remove( 'selected' ); 76 event.target.classList.add( 'selected' ); 77 78 const newType = event.target.getAttribute( 'data-bp-sort' ); 79 80 if ( newType !== this.blocks[ i ].query_args.type ) { 81 super.getItems( newType, i ); 82 } 83 } ); 84 } ); 85 } ); 86 } 87 } 88 89 const settings = window.bpFriendsSettings || {}; 90 const blocks = window.bpFriendsBlocks || {}; 91 const bpFriends = new bpFriendsWidgetBlock( settings, blocks ); 92 93 if ( 'loading' === document.readyState ) { 94 document.addEventListener( 'DOMContentLoaded', bpFriends.start() ); 95 } else { 96 bpFriends.start(); 97 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri May 5 01:01:24 2023 | Cross-referenced by PHPXref 0.7.1 |