Code Monkey home page Code Monkey logo

Comments (1)

jevgenijs-jefimovs avatar jevgenijs-jefimovs commented on August 17, 2024

@exaline-ru

Add the "search-paging-wrapper" to search.njk:

...
<div id="info" class="text-center mb-5 mx-auto text-lg text-slate-600"></div>
<div id="wrapper" class="flex flex-wrap -mx-2"></div>
<div id="search-paging-wrapper" class="mt-3 flow-root"></div>

Add the "const pagingWrapperEl..." to search.js:

  render(query) {
    const wrapperEl = document.getElementById('wrapper');
    const searchBoxEl = document.getElementById('searchbox');
    const infoEl = document.getElementById('info');
    const pagingWrapperEl = document.getElementById('search-paging-wrapper');

Clear the content of pagingWrapperEl:

    searchBoxEl.value = query;
    wrapperEl.innerHTML = '';
    pagingWrapperEl.innerHTML = '';

Add the Previous and Next buttons to pagingWrapperEl:

    slicedPosts.forEach((post) => {
    ...
    });

    if (offset > 0) {
        const newStart = offset - size + 1 > 0 ? offset - size + 1 : 1;
        const newUrl = `?q=${query}&start=${newStart}&size=${size}`;
        pagingWrapperEl.innerHTML += `<a href="` + newUrl + `" class="float-left bg-white font-semibold py-2 px-4 border rounded shadow-md text-slate-800 cursor-pointer hover:bg-slate-100">Previous</a>`;
    } else {
        pagingWrapperEl.innerHTML += `<a href="javascript:void(0)" class="float-left bg-white font-semibold py-2 px-4 border rounded shadow-md text-slate-800 cursor-default text-opacity-50">Previous</a>`;
    }

    if (lastPostIndex < matchedPosts.length) {
        const newStart = offset + size + 1;
        const newUrl = `?q=${query}&start=${newStart}&size=${size}`;
        pagingWrapperEl.innerHTML += `<a href="` + newUrl + `" class="float-right bg-white font-semibold py-2 px-4 border rounded shadow-md text-slate-800 cursor-pointer hover:bg-slate-100">Next</a>`;
    } else {
        pagingWrapperEl.innerHTML += `<a href="javascript:void(0)" class="float-right bg-white font-semibold py-2 px-4 border rounded shadow-md text-slate-800 cursor-default text-opacity-50">Next</a>`;
    }

from vredeburg.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.