Skip to content

Commit

Permalink
Adding in the readmore js for the descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
krugazul committed Nov 8, 2024
1 parent f74db85 commit 030ae71
Showing 1 changed file with 46 additions and 28 deletions.
74 changes: 46 additions & 28 deletions assets/js/src/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,38 +47,56 @@ if ( window.location.hash ) {
* @subpackage scripts
*/
lsx_to.set_read_more = function() {
$( '.lsx-to-review-content .more-link, .lsx-to-team-content .more-link, .entry-content .more-link, .archive-description .more-link' ).each( function() {
if ( 'Read More' === $( this ).html() || 'Lees verder' === $( this ).html() ) {
$( this ).closest( '.lsx-to-review-content, .lsx-to-team-content, .entry-content, .archive-description' ).each( function() {
var visible = true;

$( this ).children().each( function() {
if ( 'Read More' === $( this ).find( '.more-link' ).html() ) {
visible = false;
} else if ( ! visible && this.id !== 'sharing' ) {
$( this ).hide();
}
} );
} );

$( this ).click( function( event ) {
event.preventDefault();
$( this ).hide();
$( '.single-tour-operator .wp-block-read-more' ).each( function() {
lsx_to.readMoreSet( $(this) );
} );

if ($( this ).hasClass( 'more-link-remove-p' ) ) {
var html = '';
$( '.single-tour-operator .wp-block-read-more' ).on( 'click', function( event ) {
event.preventDefault();
$( this ).hide();

$( this ).closest( '.lsx-to-review-content, .lsx-to-team-content, .entry-content, .archive-description' ).children().each( function() {
$( this ).show();
} );
} else {
$( this ).closest( '.lsx-to-review-content, .lsx-to-team-content, .entry-content, .archive-description' ).children().show();
}
} );
if ( $( this ).hasClass( 'less-link' ) ) {
lsx_to.readMoreSet($( this ));
} else {
lsx_to.readMoreOpen($( this ));
}

$( this ).show();
} );
};

lsx_to.readMoreSet = function( button ) {
let contentWrapper = button.closest( '.wp-block-group' ).find('.wp-block-post-content');
if ( 0 < contentWrapper.length ) {
if ( 1 < contentWrapper.find('p').length ) {

var limit = 1;
let counter = 0;

contentWrapper.find('p').each( function() {
if ( limit <= counter ) {
$(this).hide();
}
counter++;
});
} else {
button.hide();
}
button.removeClass('less-link');
}
}

lsx_to.readMoreOpen = function( button ) {
let contentWrapper = button.closest( '.wp-block-group' ).find('.wp-block-post-content p');
if ( 0 < contentWrapper.length ) {
contentWrapper.each( function() {
$(this).show();
});
button.addClass( 'less-link' );
button.show();
}
}

/**
* Read more (travel info) effect.
*
Expand Down Expand Up @@ -294,8 +312,8 @@ if ( window.location.hash ) {
*/
$document.ready( function() {
lsx_to.set_read_more();
lsx_to.set_read_more_travel_info();
lsx_to.set_read_more_itinerary();
//lsx_to.set_read_more_travel_info();
//lsx_to.set_read_more_itinerary();
lsx_to.build_slider( window_width );
} );

Expand Down

0 comments on commit 030ae71

Please sign in to comment.