Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show links/quotes mixed in order with entries on mobile #165

Closed
simonw opened this issue Oct 21, 2020 · 5 comments
Closed

Show links/quotes mixed in order with entries on mobile #165

simonw opened this issue Oct 21, 2020 · 5 comments

Comments

@simonw
Copy link
Owner

simonw commented Oct 21, 2020

On mobile stuff in the "Elsewhere" column is only visible if you scroll most of the way down the page. I want to interleave this content in date order with the entries when the site is displayed in a single column.

@simonw
Copy link
Owner Author

simonw commented Oct 21, 2020

I was hoping this would be possible using clever CSS grid tricks but it looks like it needs some JavaScript after all.

simonw added a commit that referenced this issue Oct 21, 2020
@simonw
Copy link
Owner Author

simonw commented Oct 21, 2020

JavaScript prototype (to paste into devtools):

var items = Array.from(document.querySelectorAll('*[data-date]'));
items.sort((a, b) => {
    const aDate = a.getAttribute('data-date');
    const bDate = b.getAttribute('data-date');
    if (aDate < bDate) {
        return 1;
    }
    if (aDate > bDate) {
        return -1;
    }
    return 0;
});
primary = document.querySelector('#primary');
items.forEach(el => primary.appendChild(el));

@simonw
Copy link
Owner Author

simonw commented Oct 21, 2020

This version turns the <li> elements into <div>:

var items = Array.from(document.querySelectorAll('*[data-date]'));
items.sort((a, b) => {
    const aDate = a.getAttribute('data-date');
    const bDate = b.getAttribute('data-date');
    if (aDate < bDate) {
        return 1;
    }
    if (aDate > bDate) {
        return -1;
    }
    return 0;
});
var primary = document.querySelector('#primary');
items.forEach(el => {
    if (el.tagName == 'LI') {
        // Turn this into a <div>
        var div = document.createElement('div');
        div.classList.add('elsewhere-in-primary');
        div.innerHTML = el.innerHTML;
        primary.appendChild(div);
        el.parentNode.removeChild(el);
    } else {
        primary.appendChild(el);
    }
});

@simonw
Copy link
Owner Author

simonw commented Oct 21, 2020

I'm going to style it to look like the search results, with the date displayed on each item when they are shown in the primary navigation. https://simonwillison.net/search/?q=jupyter

@simonw simonw closed this as completed in 00ab271 Oct 21, 2020
@simonw
Copy link
Owner Author

simonw commented Oct 21, 2020

Shipped.
responsive

simonw added a commit that referenced this issue Oct 21, 2020
simonw added a commit that referenced this issue Oct 21, 2020
Things were not displaying correctly if the window was
resized in and out multiple times.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant