Okay
  Public Ticket #907052
JQuery on portfolio filter categories
Closed

Comments

  • Ricard started the conversation

    Hello Laborator team,

    My name is Ricard and I’m contacting you because I’m working with your theme
    Kalium and everything is going really all right. However, there is a small issue with a java script code that I’m trying to add to the portfolio filters.

    <script>
    // Terms category inside portfolio thumbnails
    jQuery( document ).ready( function( $ ) {
        jQuery( ".terms" ).click( function( ev ) {
            var $pir = jQuery( ".position1" );
            if ( jQuery( 'body' ).hasClass( 'home' ) && $pir.length > 0 ) {
                ev.preventDefault();
                jQuery( "html, body" ).animate( {scrollTop: $pir.offset().top } );
            }
        } );
    } );
    // Portfolio category filter
    jQuery( document ).ready( function( $ ) {
        jQuery( ".portfolio-root-categories" ).click( function( ev ) {
            var $pir = jQuery( ".position1" );
            if ( jQuery( 'body' ).hasClass( 'home' ) && $pir.length > 0 ) {
                ev.preventDefault();
                jQuery( "html, body" ).animate( {scrollTop: $pir.offset().top } );
            }
        } );
    } );
    </script>

    This jquery code is about to run a scroll to a particular section. In more detail, when someone clicks on the .terms class (located inside the portfolio thumbnails) and/or the .portfolio-root-categories class (located in the category filters for portfolio items), this code activates a scroll that takes you to a specific position indicated by me (position1 class).

    All seems to work perfectly fine, but when I click on the “show more” button, the code does not work over the new items loaded by this “show more”. In fact, it load the images of the specific category requested, but the scroll does not takes you to the position indicated (position1).

    Sorry to ask but, in that point, I’ve been working on this for two weeks and I don’t know if it is due to a bug in the theme or it’s because I’m doing something wrong.

    Thank you very much for your time,
    Kind regards,
    Ric

  • [deleted] replied

    Hi Ricard,

    Can you please give me the URL of this page so I can figure the solution for you?

  •   Ricard replied privately
  • [deleted] replied

    Hi Ricard,

    I've changed the nomral form of click event:

    jQuery( ".portfolio-root-categories" ).click( fn[...] );
    

    To delegated event:

    jQuery( 'body' ).on( 'click', '.portfolio-root-categories', fn[ ... ] );

    This solved the issue because it is applied for each element after its appended to the document.

  • Ricard replied

    Big thanks for your excellent support Arlind! The solution works perfectly also on the items appended to the document.

    Thank you so much again and have a great week for all the team!

    Kind regards,
    Ric

  • Ricard replied

    Hello Arlind,

    Sorry to bother you again, I just wanted to comment a couple of small bugs (I hope the last ones) regarding the portfolio categories. Specifically:

    1.- When you add a portfolio-category to the direction of the web, the web address you to the Blog instead to this portfolio-category. Just in case it could be useful, by the moment I’ve fixed this issue writing “portfolio” on the option of “custom portfolio category URL prefix” (maybe this is not the best solution, but perhaps it may give you some clue).
    E.g.: http://demo.kaliumtheme.com/photography/portfolio-category/ (We are on the blog, not on the portfolio-category)

    2.- I’ve seen a small bug related to the link (or web direction) that is created when someone wants to access to a specific category.
    In more details, when users go to the address bar of the browser and paste a direct link to any particular category, automatically the browser adds a slash symbol (/) at the end of this direction and then, instead to address the users to this particular category, users are addressed to the general portfolio (category “All”).
    E.g.: http://demo.kaliumtheme.com/photography/#animals (perfect)
    E.g2.:   http://demo.kaliumtheme.com/photography/#animals/ (on "All" category instead of "Animals" category)

    As always, thank you very much for your kind attention,

    Best regards,
    Ric

  • [deleted] replied

    Hi Ricard,

    I am happy that the previous fix worked for you. Here are my answers to your other questions:

    1. It is weird how that happens, I have to check why it redirects to Posts archive page!

    2. This has to do with canonical redirection, if you try it in our site you'll see it will not append the forward slash in the end:

    http://demo.kaliumtheme.com/photography/#macro

    So this plugin might help you in this case:

    https://wordpress.org/plugins/permalink-fix-disable-canonical-redirects-pack/

    Thanks for pointing out these issues, we are happy to fix as many as possible glitches that you can find.

  • Ricard replied

    I'm really grateful for your splendid support, Arlind. I'll try with the plugin you suggest right now :)

    Big thanks again and all the best for you and your team!

    Ric

  • [deleted] replied

    Glad to hear that Ricard : )