Wednesday Afternoon Open Thread

• Views: 1,020

Here’s an open thread for a hump day afternoon.

And since tech threads always turn into open threads anyway, here’s another bit of info that might be interesting to Javascript geeks. I mentioned that I’ve been working with the jQuery Javascript library to do the ‘slide down’ special effects in our commenting engine; but it does a lot more than fancy eye candy. Here’s an example showing how much time and code the library can save.

If you’re not logged in, the little buttons that activate the ‘reply’ and ‘quote’ features on the top line of each comment are hidden. So if you’re on a page containing comments and you log in, the commenting engine needs to go through all the existing comments, and make the ‘reply’ and ‘quote’ links visible.

Before jQuery, this was the code that showed those links; to find them, each set of reply/quote links is wrapped in a tag that has the CSS class ‘replylink.’ First, since there’s no native Javascript function to find all elements with a certain class, we need a special function:

function getElementsByClass(searchClass, node, tag) {
  var classElements = new Array();
  if ( node == null )
    node = document;
  if ( tag == null )
    tag = ‘*’;
  var els = node.getElementsByTagName(tag);
  var elsLen = els.length;
  var pattern = new RegExp(‘(^|\s)’+searchClass+’(\s|$)’);
  for (i = 0, j = 0; i < elsLen; i++) {
    if ( pattern.test(els[i].className) ) {
      classElements[j] = els[i];
      j++;
    }
  }
  return classElements;
}

The code to actually show the elements calls this function, then loops through the results, setting the ‘display’ property for each one so that it becomes visible.

var theReplylinks = getElementsByClass(‘replylink’);
for (var i = 0; i < theReplylinks.length; i++) {
  theReplylinks[i].style.display = ‘inline’;
}

Now here’s the cool part. Using jQuery to show all the ‘replylink’ elements on the page reduces all this code down to one—count it, one—simple line:

$(‘.replylink’).show();

That ends our geek exploration of the day. The thread is now open…

Jump to top

Create a PageThis is the LGF Pages posting bookmarklet. To use it, drag this button to your browser's bookmark bar, and title it 'LGF Pages' (or whatever you like). Then browse to a site you want to post, select some text on the page to use for a quote, click the bookmarklet, and the Pages posting window will appear with the title, text, and any embedded video or audio files already filled in, ready to go.
Or... you can just click this button to open the Pages posting window right away.
Last updated: 2023-04-04 11:11 am PDT
LGF User's Guide RSS Feeds

Help support Little Green Footballs!

Subscribe now for ad-free access!Register and sign in to a free LGF account before subscribing, and your ad-free access will be automatically enabled.

Donate with
PayPal
Cash.app
Recent PagesClick to refresh
The Pandemic Cost 7 Million Lives, but Talks to Prevent a Repeat Stall In late 2021, as the world reeled from the arrival of the highly contagious omicron variant of the coronavirus, representatives of almost 200 countries met - some online, some in-person in Geneva - hoping to forestall a future worldwide ...
Cheechako
3 days ago
Views: 120 • Comments: 0 • Rating: 1
Texas County at Center of Border Fight Is Overwhelmed by Migrant Deaths EAGLE PASS, Tex. - The undertaker lighted a cigarette and held it between his latex-gloved fingers as he stood over the bloated body bag lying in the bed of his battered pickup truck. The woman had been fished out ...
Cheechako
2 weeks ago
Views: 280 • Comments: 0 • Rating: 1