Skip to content

Commit

Permalink
Fix 695: show hide lists in profile (#705)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mte90 committed Oct 12, 2021
1 parent 637e16f commit 2a6d6e3
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 37 deletions.
68 changes: 50 additions & 18 deletions buddypress/members/single/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
require "{$theme_directory}/countries.php";
require "{$theme_directory}/pronouns.php";
$current_translation = mozilla_get_current_translation();
$show_minimum_items = 3;

$event_countries = em_get_countries();

Expand Down Expand Up @@ -165,8 +166,12 @@
<?php
$group = new BP_Groups_Group( $gid );
$group_meta = groups_get_groupmeta( $gid, 'meta' );
$group_hidden = '';
if ( $group_count >= $show_minimum_items ) {
$group_hidden = ' hidden';
}
?>
<a class="profile__group" href=" <?php echo esc_attr( get_home_url( null, 'groups/' . $group->slug ) ); ?>">
<a class="profile__group<?php echo $group_hidden; ?>" href="<?php echo esc_attr( get_home_url( null, 'groups/' . $group->slug ) ); ?>">
<h2 class="profile__group-title"><?php echo esc_html( str_replace( '\\', '', stripslashes( $group->name ) ) ); ?></h2>
<?php
if ( ( isset( $group_meta['group_city'] ) && strlen( trim( $group_meta['group_city'] ) ) > 0 ) || ( isset( $group_meta['group_country'] ) && strlen( trim( $group_meta['group_country'] ) ) > 1 ) || isset( $group_meta['group_type'] ) ) :
Expand Down Expand Up @@ -220,10 +225,13 @@
</div>
</a>
<?php $group_count++; ?>
<?php if ( $group_count > 0 && $group_count < $groups['total'] ) : ?>
<hr class="profile__group-line" />
<?php endif; ?>
<?php endforeach; ?>
<hr class="profile__group-line<?php echo $group_hidden; ?>" />
<?php endforeach; ?>
<?php if ( $group_count >= $show_minimum_items ) : ?>
<a href="#" class="group__events-link show-more">
<?php _e('View All', 'community-portal') . ' (' . $group_count . ')'; ?><svg width="8" height="10" viewBox="0 0 8 10" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M2.33301 8.66634L5.99967 4.99967L2.33301 1.33301" stroke="#0060DF" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>
</a>
<?php endif; ?>
</div>
<?php endif; ?>
<?php endif; ?>
Expand All @@ -245,8 +253,13 @@
$date_format = 'en' === $current_translation ? 'M d' : 'd M';
$event_date = mozilla_localize_date( $event->event_start_date, $date_format );
$location = em_get_location( $event->location_id );

$event_hidden = '';
if ( $events_attended_count >= $show_minimum_items ) {
$event_hidden = ' hidden';
}
?>
<a class="profile__event" href="<?php echo esc_attr( get_home_url( null, 'events/' . $event->slug ) ); ?>">
<a class="profile__event<?php echo $event_hidden; ?>" href="<?php echo esc_attr( get_home_url( null, 'events/' . $event->slug ) ); ?>">
<div class="profile__event-date">
<?php echo esc_html( $event_date ); ?>
</div>
Expand Down Expand Up @@ -283,10 +296,13 @@
</div>
</a>
<?php $events_attended_count++; ?>
<?php if ( $events_attended_count < count( $events ) ) : ?>
<hr class="profile__group-line" />
<?php endif; ?>
<hr class="profile__group-line<?php echo $event_hidden; ?>" />
<?php endforeach; ?>
<?php if ( $events_attended_count >= $show_minimum_items ) : ?>
<a href="#" class="group__events-link show-more">
<?php echo __('View All', 'community-portal') . '(' . $events_attended_count . ')'; ?><svg width="8" height="10" viewBox="0 0 8 10" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M2.33301 8.66634L5.99967 4.99967L2.33301 1.33301" stroke="#0060DF" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>
</a>
<?php endif; ?>
</div>
<?php endif; ?>
<?php endif; ?>
Expand Down Expand Up @@ -324,8 +340,13 @@
$date_format = 'en' === $current_translation ? 'M d' : 'd M';
$event_date = mozilla_localize_date( $event->event_start_date, $date_format );
$location = em_get_location( $event->location_id );

$event_hidden = '';
if ( $events_organized_count >= $show_minimum_items ) {
$event_hidden = ' hidden';
}
?>
<a class="profile__event" href="<?php echo esc_attr( get_home_url( null, 'events/' . $event->slug ) ); ?>">
<a class="profile__event<?php echo $event_hidden ?>" href="<?php echo esc_attr( get_home_url( null, 'events/' . $event->slug ) ); ?>">
<div class="profile__event-date">
<?php echo esc_html( $event_date ); ?>
</div>
Expand Down Expand Up @@ -364,10 +385,13 @@
<?php
$events_organized_count++;
?>
<?php if ( $events_organized_count < count( $events_organized ) ) : ?>
<hr class="profile__group-line" />
<?php endif; ?>
<hr class="profile__group-line<?php echo $event_hidden; ?>" />
<?php endforeach; ?>
<?php if ( $events_organized_count >= $show_minimum_items ) : ?>
<a href="#" class="group__events-link show-more">
<?php echo __('View All', 'community-portal') . ' (' . $events_organized_count . ')'; ?><svg width="8" height="10" viewBox="0 0 8 10" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M2.33301 8.66634L5.99967 4.99967L2.33301 1.33301" stroke="#0060DF" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>
</a>
<?php endif; ?>
</div>
<?php endif; ?>
<?php endif; ?>
Expand Down Expand Up @@ -399,8 +423,13 @@
$start = get_field( 'campaign_start_date', $campaign->ID );
$end = get_field( 'campaign_end_date', $campaign->ID );
$campaign_tags = get_the_terms( $campaign, 'post_tag' );

$campaign_hidden = '';
if ( $campaign_count >= $show_minimum_items ) {
$campaign_hidden = ' hidden';
}
?>
<a class="profile__campaign" href="<?php echo esc_attr( get_home_url( null, 'campaigns/' . $campaign->post_name ) ); ?>">
<a class="profile__campaign<?php echo $campaign_hidden ?>" href="<?php echo esc_attr( get_home_url( null, 'campaigns/' . $campaign->post_name ) ); ?>">
<h3 class="profile__campaign-title"><?php echo esc_html( $campaign->post_title ); ?></h3>
<div class="profile__campaign-dates">
<?php
Expand Down Expand Up @@ -431,11 +460,14 @@
<?php endif; ?>
</a>
<?php $campaign_count++; ?>
<?php if ( $campaign_count < count( $campaign_objects ) ) : ?>
<hr class="profile__group-line" />
<?php endif; ?>
<hr class="profile__group-line<?php echo $campaign_hidden; ?>" />
<?php endif; ?>
<?php endforeach; ?>
<?php if ( $campaign_count >= $show_minimum_items ) : ?>
<a href="#" class="group__events-link show-more">
<?php echo __('View All', 'community-portal') . ' (' . $campaign_count . ')'; ?><svg width="8" height="10" viewBox="0 0 8 10" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M2.33301 8.66634L5.99967 4.99967L2.33301 1.33301" stroke="#0060DF" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>
</a>
<?php endif; ?>
</div>
<?php endif; ?>
<?php endif; ?>
Expand Down Expand Up @@ -655,7 +687,7 @@ class="st1"
<?php esc_html_e( 'Tags', 'community-portal' ); ?>
<div class="profile__tags-container">
<?php $tags = array_filter( explode( ',', $info['tags']->value ) ); ?>
<?php $system_tags = get_tags( array( 'hide_empty' => false ) ); ?>
<?php $system_tags = get_tags( array( 'hidden_empty' => false ) ); ?>
<?php foreach ( $tags as $loop_tag ) : ?>
<?php
foreach ( $system_tags as $t ) {
Expand Down
49 changes: 30 additions & 19 deletions js/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jQuery(function(){
if (!validMatrixId) {
formErrorState(this);
return
}
}
}
formClearError(this);
}
Expand Down Expand Up @@ -74,7 +74,7 @@ jQuery(function(){

if (language){
params += '&lang=' + language;
}
}
if (country) {
params += '&country=' + country;
}
Expand Down Expand Up @@ -125,7 +125,7 @@ jQuery(function(){
if (re.test($this.val())=== false) {
$this.addClass('error');
return false;
}
}
$this.removeClass('error');
return true
}
Expand All @@ -138,7 +138,7 @@ jQuery(function(){
const verified = verifyEmail(email);
if (!verified) {
return false;
}
}
const country = jQuery('#newsletter-country').val();
const language = jQuery('#newsletter-language').val();
return handleSignUpSubmit(email.val(), country, language);
Expand All @@ -158,7 +158,7 @@ jQuery(function(){

var $ele = jQuery(ele);
var user = $ele.data('username');

var avatar = new Identicon(btoa(user + 'mozilla-community-portal'), { format: 'svg' }).toString();
$ele.css({'background-image': "url('data:image/svg+xml;base64," + avatar + "')"});

Expand Down Expand Up @@ -192,13 +192,13 @@ jQuery(function(){
formErrorState($matrixInput);
}
}

jQuery(':input[required]').each(function(index, element) {
var $ele = jQuery(element);
var $errorMsg = $ele.next('.form__error-container');

if($ele.val() == "" || $ele.val() == "0" || ($ele.is(':checkbox') && $ele.prop("checked") === false)) {
error = true;
error = true;
$ele.addClass("profile__input--error");
$errorMsg.addClass('form__error-container--visible');
}
Expand Down Expand Up @@ -305,7 +305,7 @@ jQuery(function(){
});

jQuery('.profile__remove-language').click(function(e) {

e.preventDefault();

var $element = jQuery(this).parent().parent();
Expand Down Expand Up @@ -333,9 +333,9 @@ jQuery(function(){
}

});

const getCurrentTags = function(tagsInput) {
let currentValue = tagsInput.val();
let currentValue = tagsInput.val();
currentValue = currentValue.length > 0 ? currentValue.split(/,\s?/) : [];
return currentValue;
}
Expand All @@ -344,7 +344,7 @@ jQuery(function(){
let newValues = currentValue;
if (currentValue.length > 1) {
newValues = currentValue.join(',');
}
}
$tagsInput.val(`${newValues}`);
}

Expand Down Expand Up @@ -376,10 +376,10 @@ jQuery(function(){

if(!$label.hasClass('profile__tag--active')) {
addNewTag($tagsInput, currentValue, tag);
}
}
if($label.hasClass('profile__tag--active')){
removeExistingTag($tagsInput, currentValue, tag);
}
}
$label.toggleClass('profile__tag--active');
return false;
});
Expand All @@ -393,7 +393,7 @@ jQuery(function(){
.removeClass('form__error-container--secondary')
.removeClass('form__error-container--tertiary');
}

function handleMultipleErrorStates(input, secondary = false, tertiary = false) {
const $this = jQuery(input);
var $errorContainer = $this.next('.form__error-container');
Expand Down Expand Up @@ -458,7 +458,7 @@ jQuery(function(){
const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if (re.test(value.toLowerCase()) === false) {
handleMultipleErrorStates($this, false, true);
}
}
const get = {};
get.u = value;

Expand Down Expand Up @@ -562,17 +562,17 @@ jQuery(function(){
jQuery('input[name="language"]').val(language);

jQuery('#members-search-form').submit();

});

jQuery('.members__tag-select').change(function(e){
var tag = jQuery(this).val();
jQuery('input[name="tag"]').val(tag);
jQuery('#members-search-form').submit();


});

jQuery('.members__toggle-filter').click(function(e) {
const $this = jQuery(this);

Expand All @@ -594,4 +594,15 @@ jQuery(function(){
return false;
});

});
jQuery('.show-more').click(function(e) {
const $this = jQuery(this);
e.preventDefault();
var items = $this.parent().find('a');
jQuery(items).each(function( index ) {
jQuery(this).removeClass('hidden');
$this.addClass('hidden');
});
return false;
});

});
4 changes: 4 additions & 0 deletions scss/_profile.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
position: relative;
width: 100%;

.hidden {
display: none;
}

a {

&.profile__languages-link {
Expand Down

0 comments on commit 2a6d6e3

Please sign in to comment.