• Need help with jquery selectors

    I have a code:

    <ul class="gallery_demo_unstyled">
        <li class="active"><img src='001.jpg' /></li> 
        <li><img src='002.jpg' /></li> 
        <li><img src='003.jpg' /></li> 
        <li><img src='004.jpg' /></li> 
        <li><img src='005.jpg' /></li> 
        <li><img src='006.jpg' /></li> 
    </ul> 
    
    <div class="Paginator"> 
        <a href="../2/" class="Prev">&lt;&lt;</a> 
        <a href="../1/">1</a> 
        <a href="../2/">2</a> 
        <span class="this-page">3</span> 
        <a href="../4/">4</a> 
        <a href="../5/">5</a> 
        <a href="../4/" class="Next">&gt;&gt;</a> 
    </div> 
    
    <div class="Albums"><div class="AlbumsMenu">
    <p><b>ALBUMS</b></p>
        <p><a href="../../blackandwhite/1/" >blackandwhite</a></p>
        <p><a href="../../color/1/" class='this-page'>>>color</a></p>
        <p><a href="../../film/1/" >film</a></p>
        <p><a href="../../digital/1/" >digital</a></p>
        <p><a href="../../portraits/1/" >portraits</a></p>
    </div></div>  
    

    ... and some JavaScript / jQuery that allows you to cyclically move images (the topmost li elements), returning to the first image after the last:

    $$.nextSelector = function(selector) {
    return $(selector).is(':last-child') ?
           $(selector).siblings(':first-child') :
           $(selector).next();
    
    };
    

    The current page is always the class "this page" (range or p in my case, but I could change this if necessary).

    Question : what should I change in my code so that it goes after the last image to the next page, and not cyclically move around the page again and again, and the next album after the last page? And to the first image on the first page of the first album after the last last (or just stop there - anyway)?

    +3
    1

    - :

    function nextImage()
    {
        var li = $('#gallery_demo_unstyled li.active');
    
        if (li.is(':last-child')) {
            nextPage();
        } else {
            li.removeClass('active');
            li.next().addClass('active');
        }
    }
    
    function nextPage()
    {
        var next = $('div.Paginator a.Next');
    
        if (next.length == 0) {
            nextAlbum();
        } else {
            window.location = next.attr('href');
        }
    }
    
    function nextAlbum()
    {
        var this_album = $('div.AlbumsMenu p a.this-name');
        var p = this_album.parent();
    
        if (p.next().length == 0) {
            return;
        }
    
        window.location = p.next().children('a').attr('href');
    }
    
    +4

    Source: https://habr.com/ru/post/1739399/


    All Articles