jQuery: Link override with search box

Posted: November 26th, 2008 | Author: Rob Searles | Filed under: JavaScript | Tags: | Comments


Just been working on a little something for a client involving Google Custom Search Engines.

The app we’re building uses 4 different search engines which are all specialised in a certain area. There is a central “Overview” page that gets the top results for the search from each of the search engines, plus there are normal links above the search box that, when clicked on should take the user directly to the Custom Search Engine results page for the string in the search box.

Sounds quite straightforward, but the links also save the current search (which may be different to the search box if the user has just entered a search into the box) so in this case, the old search needs to be stripped and the new search carried forward to the Custom Search Engine.

So it’s a little more tricky, but fortunately using jQuery and the URL Parser plugin by Mark Perkins I was able to cut out most of the tricky stuff.

Below is a little demo to illustrate the main part of the jQuery usage. Before you conduct a search, you should be able to click on the links to go and search Google for those keywords (jQuery, CakePHP, Ruby On Rails and No Search conducted). If you enter a string in the box and hit the “Search” button, you’ll go to Google and search for the string. However, if you enter a string in the search box but then click on a link, you’ll be taken to Google and search for the string.

This isn’t quite how it works on the client site, but is enough to show how the jQuery is being used.

Search Google

 

Javascript code in the <head> tags is:

<script src="/javascript/jquery.1.2.6.js" type="text/javascript"></script> 
<script src="/javascript/jquery.url.js" type="text/javascript"></script>
<script type="text/javascript"><!--
$(function(){
	$("#jQuerySearchExample a").click(function () {
		var path = "http://www.google.co.uk/";
		path += jQuery.url.setUrl($(this).attr("href")).attr("path");
		path += "?"+$("#jQuerySearchExampleInput").serialize();
		$(this).attr("href", path);
	});
});
// --></script>

And the HTML is as follows:

<ul id="jQuerySearchExample">
	<li><a href="http://www.google.co.uk/search" target="_blank">No Search</a></li>
	<li><a href="http://www.google.co.uk/search?q=jquery" target="_blank">jQuery</a></li>
	<li><a href="http://www.google.co.uk/search?q=CakePHP" target="_blank">CakePHP</a></li>
	<li><a href="http://www.google.co.uk/search?q=ruby+on+rails" target="_blank">Ruby On Rail</a></li>
</ul>
Search Google
<form action="http://www.google.com/search" method="get"> 
<input id="jQuerySearchExampleInput" name="q" type="text" /> 
<input type="submit" value="Search" />
</form>

As you can see, I use

jQuery.url.setUrl($(this).attr("href")).attr("path");

To strip out the current query string from the hard coded URL and then

"?"+$("#jQuerySearchExampleInput").serialize();

To replace it with the string within the search box.

Took a bit of faffing about, but works quite well


Xubuntu: Nautilus overtakes XFCE on startup

Posted: November 25th, 2008 | Author: Rob Searles | Filed under: Linux | Tags: , | Comments

Just had a nightmare hour trying to get my lovely clean Xubuntu desktop back to normal.

For some strange reason it was loading in the Gnome desktop over the top. All very odd, loaded up as XFCE for a second or two, but then flashed into Gnome – very irritating.

Finally managed to track down the problem which was Nautilus was automatically loading, which was then replacing the desktop. After about an hour of Googling and 15 minutes of going through all the session config variables to try and work out where it was loading, I finally came across this thread in the brilliant Ubuntu Forums which mali2297 recommended removing the .cache directory. I did, and it worked!

For example’s sake, I did this:

$ rm /home/rob/.cache -Rf

I just thought I’d share this in case someone else is having a similar problem.


Welcome to the Blog of Rob Searles

Posted: November 20th, 2008 | Author: Rob Searles | Filed under: General | Comments

Hi, and welcome to the new Blog by me, Rob Searles

I’ll be writing a brief “about me” soon, but for the time being, I’ll just let you know what to expect from me and when to expect it.

I’m a web developer, in fact I run my own web development company based on Berlin and London, you can have a look and see what we do at ibrow.com. Yes, I know what you’re thinking: the what kind of a rubbish site is that for a web development company to have. And you’re right. But this is one of the things we are going to be sorting out over Christmas and New Year, ready for 2009.

This year has been pretty hectic, we’ve been up to our eyeballs in work and trying to set up the office in Berlin, but that’s all coming to an end now which means I’ll be making sure I dedicate some time to writing this blog. In fact, I’m going to set aside at least 2 days a month that I can focus on this blog, and I’m hoping to make it up to 4 – but I am not the world’s best at getting “me stuff” done when there is client work to do!

So what can you expect to see on this blog? I’m a web developer and to be honest I love it! Some may call me a geek, and I don’t really want to admit they are right! As such, you can expect to see quite a few articles on here about web development and general geekyness. I’ve been using PHP for ever and I have a couple of things I know I want to right about. I’m playing with rails, so expect something or other on that to crop up. I’m quickly falling in love with Ubuntu (in fact Xubuntu, but there you go) so I want to scream from the roof tops that it is just so lovely. I’m a big advocate of Open Source, and will hopefully be talking about moving the TimesheetNG forward over the next year and beyond. And of course, I’ll be talking about the business of the web, and my particular views on it.

So if you like the sound of that, please bookmark me, or whack me in your RSS Reader and tune in

Have Fun