Live data from Hacker News

The Single Piece of JavaScript on HN

blog.watchandcode.com

51–60 of 195 posts

Re: The Single Piece of JavaScript on HN

#51
post #8

Not much to say, really. Just some simple code. What I'm curious is if someone can reiimplement this without and javascript.

Well there appear to be two things stopping this: - Hiding two elements on the page (one can be hidden with the CSS :visited selector) - Remaining with your position on the page whilst also sending a message to the server and without opening new windows. So the only way to do the task is to send a full request to the server which would return you to the page with the buttons correctly disabled. Extra load on the serv…

1. I think you could hide both with some adjacent sibling selector trickery. (Assuming you can select a sibling of a :visited)

2. Could you set a background image on a visited to a 1x1 gif of the tracking url? Not sure if CSS lets you do that.

I know there are some limitations around :visited specifically to stop privacy snooping, but out so I can't look up the specifics right now.

Re: The Single Piece of JavaScript on HN

#52

Earlier quoted context omitted.

Well there appear to be two things stopping this: - Hiding two elements on the page (one can be hidden with the CSS :visited selector) - Remaining with your position on the page whilst also sending a message to the server and without opening new windows. So the only way to do the task is to send a full request to the server which would return you to the page with the buttons correctly disabled. Extra load on the serv…

You could render the vote buttons in iframes, so just the iframe would reload. But you'd have to load N iframes for N vote buttons on page load. Not worth the performance hit.

> But you'd have to load N iframes for N vote buttons on page load.

No you don't. Use a FORM with a target of the iframe, make each arrow an

One form can cover all the arrows at once. Or you can have a form per set of arrows. Either way you only need one iframe.

Making it hide is a bit more complicated:

One way is have it hide on focus using visiblity, then set a very long transition in the CSS rules to unhide.

Re: The Single Piece of JavaScript on HN

#54

If we ever make it around to a second piece of javascript on here, can I request that it be a collapse comment function? I promise i won't ask for anything else.

I use this plugin, I don't think I'd visit as often if I didn't have it: https://chrome.google.com/webstore/detail/hacker-news-enhanc...

Re: The Single Piece of JavaScript on HN

#55
post #40
post #10

So without JS enabled you can't vote?

I'm getting clobbered with downvotes. I need to ask less stupid questions. The problem is that I don't really have a way to know they are stupid.

That was a legitimate question. I think the problem where the down-voters not you. To answer the question. Yes you could still vote, but you would need to refresh the page to show the current state. The JS is doing it on the fly.

Re: The Single Piece of JavaScript on HN

#56
post #53
post #40

Earlier quoted context omitted.

I'm getting clobbered with downvotes. I need to ask less stupid questions. The problem is that I don't really have a way to know they are stupid.

The downvotes are how you know.

It would be great if I could delete a post and get all the points back. (grin)

Re: The Single Piece of JavaScript on HN

#57

function hide(id) { var el = document.getElementById(id); if (el) { el.style.visibility = 'hidden'; } } function vote(node) { var v = node.id.split(/_/); var item = v[1]; hide('up_' + item); hide('down_' + item); var ping = new Image(); ping.src = node.href; return false; }

What's most fascinating to me about this isn't the simplicity, it's that this code has lived for so long with almost no changes. It's a great counter-example to all the recent articles about JavaScript fatigue. It's good for us to see real examples of sites that aren't caught up in the framework of the week hype. At the end of the day we're trying to make stuff that works. ES5 vs ES6, React vs Angular vs. Ember vs. A…

+1 times infinity

Re: The Single Piece of JavaScript on HN

#58
post #41

Earlier quoted context omitted.

For the majority of cases that I've seen, these arguments are simply excuses to avoid doing real work. It's way more fun to decide whether your amazingly awesome Unicorn startup is going to use React or Angular, or Express vs. Rails, or whatever than it is to actually go through the hard work of building a customer base and making money.

The problem (from my perspective) is that the job market follows . It's good at that--always following.

And so we use React in our project (even if it makes no sense to) because then we can put it in our resume. And thereby contribute to the problem.

Re: The Single Piece of JavaScript on HN

#59
post #8

Not much to say, really. Just some simple code. What I'm curious is if someone can reiimplement this without and javascript.

This should work:

  
  

  div {
    display: none;
  }

  input:checked + div {
    display: block;
  }
A background-image won't be requested unless it is visible. (This is why lots of peoples on-hover icons flicker if they don't spritemaps, SVGS or iconfonts).

Edit: Obviously you'd style it to make it pretty :p

Edit 2: For accessibility you'd probably want a visibly hidden - but visible to screen readers - anchor that votes.

Edit 3: Looks like chrome pre-fetches things even when they're not visible now. Presumably to fix all those flickery icons out there :(

Re: The Single Piece of JavaScript on HN

#60
post #56
post #53

Earlier quoted context omitted.

The downvotes are how you know.

It would be great if I could delete a post and get all the points back. (grin)

That would make the whole downvote system useless. Just post spam comments everywhere then delete them after a day and you’ll always have a positive karma.
Post reply on HN