Archive for category javascript

A Simple jQuery Print Page Plugin

The other day I was after a really simple way to add a print page link to a page to, well, er, print it.  So I came up with my jQuery Print Page plugin and stuck it on GitHub with a demo page: http://github.com/ianoxley/jqueryprintpage

This really is nothing fancy: it’s just a convenient way of adding an <a> tag plus an event-handler to a page to print it. Using it is as simple as, well, using File -> Print. But you can’t style the File menu with CSS so this is much more fun :-)

, ,

No Comments

Stack Overflow Tag Cloud Greasemonkey Script

Stack Overflow is great and I’m a big fan of the site. However, I’m not such a big fan of their tags page:

screenshot-tags-stack-overflow

Because the tags are ordered solely by popularity and not alphabetically, I find it a bit awkward trying to find a tag I am interested in e.g. if you want to find JavaScript it could be located anywhere in the list.

Admittedly there is a search function to help you find tags but I wanted to be able to scan the list more easily and pick out the tags that interest me most. So, to scratch my own itch, I created a Greasemonkey script to transform the current tags page into a tag cloud:

screenshot-tags-stack-overflow-greasemonkey

Because the tags are in alphabetical order with their font size weighted according to popularity, I find it much easier to find tags I am interested in.

Try it out for yourself and see what you think:

And if you have any suggestions for improvements, please leave a comment.

,

No Comments

Greasemonkey Script to Bypass the Add to Google Homepage or Google Reader page

I have just created a quick Greasemonkey script to bypass the Add to Google page and add feeds straight to Google Reader.

The Add to Google page offers you the choice of adding a feed to your Google homepage or Google Reader and, seeing as I don’t really use my iGoogle page, adding them straight to Google Reader makes more sense and elimates that extra click.

Now, I know Google make a Subscribe… bookmarklet available to “subscribe as you surf” (via Manage Subscriptions -> Goodies in Google Reader). But since I have been using the NoScript Firefox extension this bookmarklet often does not work for me, as the site I am on typically will not be on my NoScript whitelist.

So instead of using the bookmarklet I started subscribing to feeds directly through Firefox:

  1. Click the feed icon in the address bar
  2. Select Google on the Firefox subscribe page and click the button
  3. Select Add to Reader on the Add to Google page

After a while though, clicking Add to Reader everytime was causing some friction. So I came up with my Straight to Reader Greasemonkey script: the Add to Google page loads before you are redirected straight to Google Reader and subscribed to the feed.

If you want to give it a try you can install it here: straighttoreader.user.js.

Alternatively you can view the script and install it from userscripts.org.

UPDATE: I have fixed a bug in the original version so that, if you are not currently logged in to your Google Account, you still get forwarded on to the Add to Reader page (via the Google Account sign in page).

No Comments

jQuery fadeOut() Then slideUp()

After hastily answering a question on stackoverflow.com regarding calling jQuery’s slideUp() method after fadeOut(), what I thought to be a good answer turned out to be not quite so good afterall.  After reading the comments on my answer I decided to investigate to see what was wrong with my original solution. Now, the problem that needed to be solved was the element below the faded-out element jumping up during the slide up: a nice smooth slide up was required. I initially thought you could accomplish this by calling fadeOut() with a callback function as the second parameter which would handle the slideUp(). Something like this:

$('elementAbove').fadeOut(500, function() {
    $('elementBelow').slideUp();
});

But you still get the jump up, rather than the nice smooth slide up that is desired. In the comments to my answer it was suggested fading the element out to an opacity of 1%, then doing the slide up, would work. After checking the documentation, jQuery has a fadeTo( speed, opacity, [callback] ) method which lets us do exactly this, then execute the slide up in our callback function. So, given the following HTML:

<ul id="menu">
    <li><a href="#">Home</a></li>
    <li><a href="#">About</a></li>
    <li><a href="#">News &amp; Events</a></li>
    <li><a href="#">Downloads</a></li>
    <li><a href="#">Contact Us</a></li>
</ul>

We can achieve our desired effect like this:

$(document).ready(function() {
    $('#menu a').click(function() {
        var $theParent = $(this).parent();
        $(this).fadeTo(500, 0.1, function() {
            $theParent.slideUp(750);
        });
 	return false;
    });
});

You can see this in action here.

1 Comment

jQuery Form Focus Plugin Released

I have released the first version of my jQuery Form Focus plugin. This lets you set the initial focus on any form element but is careful not to set the focus if the user has already started filling in the form. To use it you call something like:

$('#username').formFocus();
$('form input:first').formFocus();
$('form#options input[type="checkbox"]:first').formFocus();

Hope you find it useful.

, ,

No Comments

OpenSearch Added to Unobtrusive JavaScript Google Co-op Search

I have added OpenSearch to my Google Co-op Search Engine Unobtrusive JavaScript. Now you use the search engine in OpenSearch aware browsers you can add it to the browser’s search box.

,

No Comments

Unobtrusive JavaScript

I have been playing around with Google Co-op recently and have created Unobtrusive JavaScript: a custom search engine that focuses on unobtrusive JavaScript knowledge and tips from leading JavaScript experts. Please give it a try and let me know what you think.

,

No Comments