3 ms·
Yep. They're simply <a> tags. The code inside `onclick` is very primitive: if (u.pathname == '/vote') { vote(p.get('id'), p.get('how'), p.get('auth')
by colejohnson66 5y ago
Yep. They're simply <a> tags. The code inside `onclick` is very primitive:
if (u.pathname == '/vote') {
vote(p.get('id'), p.get('how'), p.get('auth'), p.get('goto'));
}
`vote` just sees if it's an up or a down, set's the unvote link's `innerHTML`, then, curiously, uses an `Image` object to make the request:
new Image().src = vurl(id, how, auth, _goto);
The code is only 152 lines and is very easy to read: https://news.ycombinator.com/hn.js https://news.ycombinator.com/hn.js
- zarzavat 5y agoThe Image makes sense as a way to make HTTP requests before XMLHttpRequest was widely supported.
- matt_kantor 5y agoHacker News isn't that old. It launched in 2007 at which point XMLHttpRequest had been implemented in all major browsers for several years.
- zarzavat 5y agoOn the desktop yes, but it was on the cusp of the smartphone era so there were many weird mobile browsers around.
- colejohnson66 5y agoThe advantage of XMLHttpRequest is that you get feedback through a callback. When the user clicks the vote arrows, they could turn into something else (such as a spinner) that would disappear when the API request finishes. If my internet is spotty, having some feedback (so I know my votes didn't timeout) would be nice.
- deleted 5y ago[deleted]