scripts Archive

0

Tweaking Jquery AutoSuggest

I have been using the JQuery library for a long time now, and am still amazed at what people get it to do.  One feature that the base libaray was really lacking was a good Autosuggest for a text input.  It needed to be AJAX driven, and understand having multiple values.

I found a great example of what I wanted at Drew Wilson’s blog, complete with almost all the features I needed.

One thing his script is really lacking is a good way to show ALL the results.  We have a huge category list, and want to let someone browse them all.  In the base script, this isn’t going to work, since there isnt a way to make the look up fire off without input.  I didnt want my users to have to enter in, one by one, each letter of the alphabet looking for what they wanted, so I settled on using a double click event to force the display of the entire list.

And here is how to make that happen:

In the js file (jquery.autoSuggest.js) you will need to make some changes.

~line 149 add:

 }).dblclick(function(){
 if (timeout){ clearTimeout(timeout); }
 timeout = setTimeout(function(){ keyChange(); }, opts.keyDelay);

so it will look like:

 }).blur(function(){
 if($(this).val() == "" && values_input.val() == "" && prefill_value == ""){
 $(this).val(opts.startText);
 } else if(input_focus){
 $("li.as-selection-item", selections_holder).addClass("blur").removeClass("selected");
 results_holder.hide();
 }
 }).dblclick(function(){
 if (timeout){ clearTimeout(timeout); }
 timeout = setTimeout(function(){ keyChange(); }, opts.keyDelay);
 }).keydown(function(e) {

This will pull up a list on double click.  You can change dlbclick to just click for a single click response instead.

~line 226 comment out the lines:

if( lastKeyPressCode == 46 || (lastKeyPressCode > 8 && lastKeyPressCode < 32) ){ return results_holder.hide(); }

and

if (string == prev) return;

and

if (string.length >= opts.minChars) {

and then on ~line 252 comment out

 } else {
 selections_holder.removeClass("loading");
 results_holder.hide();
 }

You will also want to turn the option “resultsHighlight” false, when you create the instance.

Now, on double click it will present a full list of options.

Enhanced by Zemanta
Share
0

Types of Programming Bugs

In a recent project I have been working on, I took over another’s code base, based in Drupal, and have been working to both fix issues and add functionality.  It has been a lot of fun learning Drupal, and working with this interesting application.  And finding different types of bugs.  If you are a programmer, you know there are bugs that are different and behave oddly.   Here are some types of programming bugs I have come across recently.

Heisenbug
Named for the Heisenberg uncertainty principle, this type of bug is only appears when you aren’t looking.  You know the kind, the kind you swear you can’t replicate, but yet, the users day after day report them happening.  If you try to measure this type of bug, you will inevitably alter your results.  They are the worst to track down, because a lot of the time you end up making changes just to hope they go away, even though you still aren’t sure exactly what caused them.

Keyser Söze Bug
These actually arent even bugs, but they make you think they are, and are a complete pain in the neck.  Basically, it is a “bug” that is causing a huge problem for you, but as you learn, and dig and dig, you figure out it isnt a bug, just a “feature”.  It may be stupid, illogical, or incorrect, but the code itself is working just as design and written.  So, in essence, it isnt a bug, only made you think it was.

WTF Bug
This is one of those that you swear up and down you have fixed, several times, yet is still there.  The most common one of these is when a customer’s ISP or internal firewall have cached old versions, so the damn thing is still cropping up on you, but you know it isn’t there anymore.  Another time these happen is when you change one part of the code, only to figure out that those methods were depreciated 8 versions ago, and now all that logic is somewhere else.  Yes you changed it, yes you committed it, but the bug is still there.

Enhanced by Zemanta
Share
0

How to fix WP ECommerce

On front end pages with no ecommerce functionality, this plugin adds over 220+ database queries.  The more I messed with the code trying to make it behave, the more I understood just how horribly written this plugin is.

Now, as someone that has been doing development long enough to know, there are times that code just gets away from the development team and becomes a mess unto itself.  It happens, especially in the OSS world where code reviews are few if ever.  But, as I read the forums for this thing, the developers are just fooling themselves thinking the code is in good shape.

Here are a few basic suggestions:
1) Check to see if the page needs to execute the plugin.  If it doesnt, dont do it.  There is no reason to increase the number of queries by an order of magantuide when I am on a page that has no WP Ecommerce functionality.
2) Clean up the queries.  For example:
SELECT `id` FROM `wp_product_list` WHERE `active` IN(’1′)
should be
SELECT `id` FROM `wp_product_list` WHERE `active` = 1
It is more effiecent.

3) Index the tables!  The query above doesnt use an index.  That is right folks, the field “active” in product_list is not indexed.  This is easy and simple.

4) Use arrays or some other data structure for complex data.  Dont use the same basic query over and over again.  Example:

Share
0

phpMyAdmin over SSL

I get asked this question a lot: “How can I force phpMyAdmin to run over https ‘SSL’?” It is basically an issue to deal with security. Since phpMyAdmin deals with directly accessing your database, it only makes sense you want to make it as secure as you can. While running over SSL ‘HTTPS’ is not the total solution, it does help. So, here is how to make it run over SSL.

Read the rest of this entry »

Share
Tags: , ,
0

phpMyAdmin over SSL

I get asked this question a lot: “How can I force phpMyAdmin to run over https ‘SSL’?” It is basically an issue to deal with security. Since phpMyAdmin deals with directly accessing your database, it only makes sense you want to make it as secure as you can. While running over SSL ‘HTTPS’ is not the total solution, it does help. So, here is how to make it run over SSL.

Read the rest of this entry »

Share
Tags: , ,