Painless Web 2.0 with jQuery

By Brian, November 28, 2008 1:04 pm

Allow me introduce you to my new favorite web tool: jQuery. jQuery is a handy java script that allows you to add AJAX functionality to your website without too much fuss at all.

After placing the jquery.js (obtained from jQuery.com) file in your website’s path (ex. yoursite.com/include/) you simply need to add two javascript references in your page header:

<script src='include/jquery.js'></script>
<script src='include/scripts.js'></script>

The scripts.js file is where all the custom functionality code goes. Here’s an example, where links clicked in a div named #nav will load the new content into the #content div without refreshing the whole page:

$(document).ready(function() {           // after page is loaded, this is called automagically $('#nav li a').click(function() {     var query = $(this).attr('href');                  // this is what appears in the href tag     $('#content').hide('slow',loadContent);            // hides the div, calls loadContent()

     function loadContent() {         $('#content').load(query,'',showNewContent()); // pull the request into the div     }                                                  // calls showNewContent()

     function showNewContent() {         $('#content').show('fast');                    // show the new page content     }     return false; // returning false indicates the event was processed });});

No change to the actual page markup was required to make this happen at all. A small hurdle I encountered working with jQuery was that having an event bound to content inside the div #content would cease to function once new content was brought in. The reason for this is that jQuery loads the event binding based on what is on the page at first load. The easy way to solve this is to add the Live Query plugin for jQuery. Put it in your include directory with the other two scripts, and reference the script after jQuery but before your site’s script:

<script src='include/jquery.js'></script>
<script src='include/jquery.livequery.js'></script>
<script src='include/scripts.js'></script>

You will need to perform the related event binding to use Live Query slightly different from a normal jQuery binding:

$(document).ready(function() {    // after page is loaded, this is called automagically $('#content a').livequery('click', function() {        // livequery auto-binds when tags change     var query = $(this).attr('href');                  // this is what appears in the href tag     alert('You clicked this link: ' + query);     return false; // returning false indicates the event was processed });});

Yup, it’s just that easy – and once again, no change was made to the page markup. There is no end to the applications of jQuery and it’s related plugins. Happy coding, and welcome to Web 2.0!

Missing Safely Remove Hardware in System Tray

By Brian, October 11, 2008 1:36 pm

So, I plug my USB flash drive into my computer and load some data to take with me. I look down to the bottom right of my screen and … where’s the icon gone?

I look through the menus and control panels and cannot find an entry for it. Next step, I check to see if the drive has an ‘Eject’ option. It doesn’t. Only two things I can do – pull the drive and hope it’s all written, or shutdown the PC and pull it out then. Since I was short on time, I yanked the USB drive and everything went OK – but where did that icon go?

Rebooting did not resolve the issue. I searched Google and there wasn’t too much help there at all – although I did find numerous sites with the following tip:

Create a new shortcut on your desktop – right click and slide down to “New” then click on “Shortcut”.

Copy this “%windir%\system32\RunDll32.exe shell32.dll,Control_RunDLL hotplug.dll” (excluding the quotes) and paste it in the field that comes up in the next dialog box, under where it says “Type the location of the item:”, then click “Next >”.

The screen that follows prompts you to give the shortcut a name and is already pre-filled with “rundll32.exe” which is not helpful at all. Name it something obvious, such as “Safely Remove Hardare” and click “Finish”.

Double clicking the shortcut should launch the Safetly Remove Hardware window with your list of devices.

A nice touch is to edit the shortcut’s properties and change the icon to the usual one by using the icon browser. The icon can be found in “c:\windows\system32\hotplug.dll”.

Letterman Makes The Point

By Brian, September 16, 2008 6:25 pm

I realize these clips are old, but I only just stumbled upon them today. I’ve caught a few of the Late Show episodes over the years and love the top ten list, but I’ve not really been a follower of it.

In these clips, David Letterman makes some very good points about the USA’s invasion of Iraq, and boils it down to what it’s all really about. Oil. It’s definately worth watching the whole thing.

Part 1: http://www.youtube.com/watch?v=wWOGMKQ1aHo
Part 2: http://www.youtube.com/watch?v=l_LO-BuhxW0

Panorama Theme by Themocracy