Monday, August 8, 2011

Disabling a button/link with JQuery

As you probably know, if you want to make a sexy button, you need to implement it with a link.

Here is a simple search I did with Google, and an example for it I found right away

Note - that the post does not explain how to disable/enable the button... And who wants a button that cannot be disabled?

Disabling a button can be very useful if you want to make sure the form is filled properly. Simply enable it once all the details are ok.


However, disabling a link is impossible.
Instead - you need to implement "onclick" with "return false".


At first, I thought about using blockUI - a cool JQuery plugin I recently discovered.
But it seems it does not block anchors - I could still click the anchors.


Solution step #1
A really good solution would be to change the opacity to 0.4 and add "onclick" as required.
This works great.

And at first I used this technic in a Utils function... cool ain't it?

However, soon enough, I had to have it as a JQuery prototype function (method).

Solution step #2
Adding this solution to JQuery was easier than it looks
/** Adding "disable" on expand button**/
$.fn.extend({

    disableButton:function(){
            $(this).fadeTo(1,0.3);
            $(this).click(function(event){event.preventDefault()});
    },

    enableButton:function(){
            $(this).fadeTo(1,1);
            $(this).attr('onclick','').unbind('click');
    }
});

As you can probably see, it's quite easy to add "isButtonDisabled" method to the deal.

Troubleshooting
What I really wanted was to modify only the Anchor tags.
So I tried to do something like

$.fn.extend(AnchorHTMLElement.prototype, { ... } )

But it didn't work. If anyone has any idea why, please let me know. 
This is also the reason why I have such specific names for the methods, and not just "enable"/"disable"

Wednesday, August 3, 2011

Blogger wants to track my physical location?

We all know the well familiar "App wants to use your location" from Apple's devices such as iPod and iPhone and such..

Today, I noticed the same from Chrome browser.



Weird..
It seems a new feature is available for geo tagging.


I must also comment on the new Blogger layout. Amazing!
I especially liked the editing view for a post.
You should really try it out.

What I don't understand, is the "upload image" dialogs..
When I edit the HTML directly, I get the old style.
But when I compose, I get the new cool dialog (which allows you to add multiple pictures by the way...).




Without a doubt.. Blogger is on the right track.
When my sister thought about which blog engine she should use, I recommended Blogger.
Glad to see it is backed up with actions.