Comment Toggle

I mentioned in the previous entry the "semi-functional comment-toggling that I started to work on quite a while ago and promptly forgot about". Well evidently I’ve remembered it (for some reason I typed that originally as "un-forgotten about it"; 1984 was 20 years ago). I’ve played around a bit and the following changes are of note:

  • It now works in Opera as well as Gecko, after I eliminated the need for the addEventListener() function. It occurs as I write this that Opera claims support for this function so the problem probably lay in my use of window.addEventListener() as opposed to, I assume, document.addEventListener().
  • It now only toggles the visibility of comments relating to the entry in which the toggle button was pressed, where it previously toggled all comments on the page.
  • It’s possible to navigate to the toggle with the keyboard. I’ve made it an actual link so that it takes a place in the browser’s tab order. Previously it was an image with a javascript onclick attribute and some CSS making it look clickable.
  • Since the code now works properly in the browsers it works in and fails gracefully in those it fails in—ie. it isn’t visible at all to browsers that can’t handle it, like Internet Explorer—I have made coments invisible by default. The new comment icon will only appear if there are comments on the entry. Clicking on it will display them immediately since they’re already downloaded. Comments remain visible at all times on browsers that can’t handle this code.

Personally I think this is a pretty good example of additional functionality made available to those who can support it without any side-effects for those who can’t.