Just a little less than a year ago I launched Better-Than-Live AJAX WordPress Search. I felt it was time to get back in the swing of things, so I’m now releasing version 2 of the script.

Download

You can download the files here.

The included files are: prototype.js, effects.js, search.js, search.php, and README.txt.

If you used the previous version of the script, you probably don’t need to read much further to figure it out, though I’d recommend that you do it anyway.

What’s new?

There are a few main changes:

  • Uses private variables instead of forcing you to search through the whole script to configure things.
  • Works around your already-built search form rather than making you code around the script.
  • Checks for multiple searches in a row and closes the previous results before starting the next search.

This makes it much easier to set up, and it’s quite easy to use with your own back-end (unlike what some thought with with the previous version, this script will work with any sort of custom back-end search. It is, however, configured for WordPress by default and comes with a pre-made search file.)

How to set it all up.

Lines 19-26 contain all the necessary variables and look something like this:


var form	= 'search'; // id of your search form
var input	= 'search_input'; // id of your search input field
var results	= 'searchresults'; // id of your results div/paragraph/whatever
var x		= 'closeresults'; // id of the button/link to close the results
var submit	= 'searchsubmit'; // id of the submit button
var sText	= 'Better-than-live search.'; // Default value for your search input field. This is for the automatic clearing of the field onClick.
var iUrl	= '/indicator.gif'; // url of indicator image
var file	= '/index.php'; // url of the backend file doing the actual searching. If using WordPress, there's a 99% chance you should this leave as-is. 

Should be fairly straight forward. This makes it much easier to set up, and unlike before, you can now integrate this script with your own search form by simply plugging the IDs into the script. (Note to those updating from version 1: The default values for the form are the same as was required in the previous version, so you should not need to change any of these unless you personally customized the script.)

If you’re using WordPress, I’d advise opening up search.php and replacing yourpath in line three with the path to your WordPress directory. If you already have a search.php in your current theme directory, save and/or rename it (in case you want it back) before uploading the search.php file that game with the Better-Than-Live download to the directory (Note to those updating from version 1: There has been no update to search.php, so there is no need to mess with or change your current file. You can skip this step.)

If you are using a back-end other than WordPress, you will need to create your own file to do the actual searching of the database(s) and return the results. Then simply define the file variable as the path to your search file, and you should be set.

When including the JavaScript files, make sure that prototpype.js is first, effects.js is second, and search.js is last. If you have them in the wrong order, the script will not work as some of these files are dependent on previous ones.

Also note that just like in the first version of this script, the activity indicator image will have an ID of indicator-safari in Safari and just indicator in non-Safari browsers. This is because in some versions of Safari the form elements cannot be altered as much, so you may want to position the indicator differently.

So enjoy, I’d love to see how you use it, and if you have any questions you can drop ‘em in the comments. swan