'JavaScript' Category Results

jQuery Dropdown Menu

Tuesday, March 17th, 2009

In this short article we will use jQuery to produce this dropdown menu. Over the past six months I have been using a lot of jQuery and have fallen in love with it. For those not familiar with jQuery it is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. All this and for only 19KB! How nice is that? They claim that, “jQuery will change the way that you write JavaScript.” And they are right. Companies such as Google, Dell, Bank of America, Major League Baseball, Digg, NBC, CBS, Netflix, Technorati, WordPress, Drupal, Mozilla and many others use jQuery too. Ok, that’s enough of a plug, let’s look at the code:

(more…)

Nicely-Fitting Background Images

Tuesday, June 17th, 2008

In recent thread over at the SitePoint forums, someone asked how to have any sized image fit nicely into the viewport while maintaining its aspect ratio. The assumption is that all the content can fit in the viewport and no scrollbars are needed. While CSS is wonderful and magical, it doesn’t know the sizes of images and let us play with them to pixel perfection, so we must turn to good old JavaScript to maintain aspect ratio.

(more…)

Greasing Gmail

Monday, April 21st, 2008

Greasemonkey is a wonderful thing. I enjoy the little (or sometimes not so little) challenges posed by websites that I want to modify. One of the most difficult scripts to write for is Gmail, because of its dynamic nature and its reliance on very large helpings of obfuscated JavaScript and HTML. In addition, you can't use Firebug to debug scripts, which is a major annoyance, so alert and GM_log become one's best debugging friends. To make writing Greasemonkey scripts a bit easier, the chaps on the Gmail team supplied an API, which one commenter describes as "truly incredible, forward thinking". It really is quite nice.

Yesterday I decided to add a little bit of functionality to Gmail. I wanted to be able to isolate messages from a mailing list I subscribe to that nobody had replied to. This would require marking as read "conversations" or messages containing "Re:" at the start of the subject line. The obvious place to put links to do this is along with the other "selectors" above the thread list (Figure 1).

Figure 1
New selectors added

I call them "selectors" simply because Gmail has given each "link" (actually a span) a custom selector attribute. The original markup before adding the links after "Unstarred" looks like this (it isn't nicely indented in Gmail's code though):

HTML:
  1. <div class="bKmyId">Select:
  2.   <span class="bsABdf">
  3.     <span selector="all">All</span>,
  4.     <span selector="none">None</span>,
  5.     <span selector="read">Read</span>,
  6.     <span selector="unread">Unread</span>,
  7.     <span selector="starred">Starred</span>,
  8.     <span selector="unstarred">Unstarred</span>
  9.   </span>
  10. </div>

So, it looks pretty simple to add a couple of commas and two more spans. And it is, but how to access the containing div is what the Gmail API makes easier. This is the complete script, and we'll start off with the main loading business and the function that handles the adding of these two new links, addlinks:

(more...)

Popular Articles

Top 10 Commentators


Subscribe to this feed! Subscribe by Email!

Random Bits Podcast

You need to download the Flash player from Adobe

Blogs Worth Reading