Wednesday Afternoon Open Thread

• Views: 1,027

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 Cause of the Rain Here? dryad, in Greek mythology, a nymph or nature spirit who lives in trees and takes the form of a beautiful young woman. Dryads were originally the spirits of oak trees (drys: “oak”), but the name was later applied to ...
William Lewis
Yesterday
Views: 96 • Comments: 0 • Rating: 4
The Good Liars at Miami Trump Rally [VIDEO] Jason and Davram talk with Trump supporters about art, Mike Lindell, who is really president and more! SUPPORT US: herohero.co SEE THE GOOD LIARS LIVE!LOS ANGELES, CA squadup.com SUBSCRIBE TO OUR AUDIO PODCAST:Apple Podcasts: podcasts.apple.comSpotify: open.spotify.comJoin this channel to ...
teleskiguy
2 weeks ago
Views: 538 • Comments: 0 • Rating: 0
Ranked-Choice Voting Has Challenged the Status Quo. Its Popularity Will Be Tested in November. JUNEAU — Alaska’s new election system — with open primaries and ranked voting — has been a model for those in other states who are frustrated by political polarization and a sense that voters lack real choice at the ...
Cheechako
4 weeks ago
Views: 407 • Comments: 0 • Rating: 2