GithubHelp home page GithubHelp logo

versus-js's Introduction

Versus JS

There is a general conversation around jQuery that it is a "legacy" tool that has long since been replaced with ES6. This conversation seems to focus on features like document.querySelector() as "replacements" for what jQuery does. Many state that jQuery can be replaced by "four lines of utility code".

This project is currently in the process of being updated to document the outcome of the conversation.

You can see the original files for the conversation by visiting the Original folder here:

https://github.com/jbanes/versus-js/tree/main/Original

Stay tuned for the updated analysis!

versus-js's People

Contributors

jbanes avatar

Stargazers

Agustinus Nathaniel avatar jottr avatar Serhii Ponomarov avatar cocoonk1d avatar  avatar Julian Xhokaxhiu avatar Maxmillion McLaughlin avatar Andrii Chumak avatar  avatar Brenno Rodrigues avatar Tryston Perry avatar Tim Kersey avatar 姚文强 avatar Andrew Lim avatar Sung Jeon avatar  avatar Clément Barbaza avatar

Watchers

 avatar

versus-js's Issues

Alternate solution

Since we're dealing with the web:

  1. Include lang="en"
  2. Include charset
  3. Use <a href> for the pagination links
  4. Use aria-current="page" to indicate selection
  5. Content in <main>

And then tech upgrades / changes:

  1. type="module" so no more DOMContentLoaded needed.
  2. Use single click event listener instead of event handler per element.
  3. Using links added keyboard support for free.

The rest is just my own coding style balancing for a minimalistic but readable approach since this doesn't really need to go for full throttle on abstractions.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>ES6 Demonstration</title>
    <style>
    .pager { margin: 5px 10px; font-family: sans-serif; }
    .pager .page { color: inherit; display: inline-block; padding: 0px 5px; text-decoration: none; }
    .pager .page:active { color: red; }
    .page[aria-current="page" i] { font-weight: bold; color: red; }
    .paged-content { font: bold 250% sans-serif; padding: 25px 10px; }
    </style>
    <script type="module">
        let currentPage = 1;

        function renderPagers(pageCount) {
            const pagers = document.querySelectorAll('.pager');
            let html = `Page: `;
            for (let i = 1; i <= pageCount; i++) {
                const current = currentPage === i ? ` aria-current="page"` : '';
                html += `<a href="#content" class="page" data-page="${i}"${current}>${i}`;
            }
            pagers.forEach(pager => void (pager.innerHTML = html));
        }

        function updatePage(page) {
            const pageCount = 5;
            currentPage = Number(page) || currentPage;
            renderPagers(pageCount);
            document.querySelector('#content').textContent = `Page ${currentPage}`;
        }

        document.addEventListener('click', function(event) {
            const page = event.target.closest('[data-page]')?.dataset.page;
            if (page) updatePage(page);
        });

        updatePage();
    </script>
</head>
<body>
    <div id="top_pager" class="pager"></div>
    <main id="content" class="paged-content"></main>
    <div id="bottom_pager" class="pager"></div>
</body>
</html>

I guess you'll need a more complex / real lifey example because I don't feel like this code would need jQuerifying. It might get more interesting if you enforced some usability improvements like "focus must remain where it is" as focus is one of the things that gets lost when using innerHTML (or jQuery's .empty()). That single limitation would force a lot more complexity by the need of reusing existing DOM.

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.