Saturday, January 28, 2012

That jquery click event and moving viewport problem

Sometimes certain combinations of attributes and values on a DOM element conspire to make you look stupid. In this case, a jQuery click function attached to an anchor tag with a href attribute.
<a href="#" class="reply-action">  
      <span>  
         <i></i>  
             Reply  
         </span>  
      </a>  
</span> 
And the jQuery is pretty straight-forward. The anchor tag when clicked will just toggle a div.replies to show or hide.
$('.reply-action').click(function () {
 $('.replies').toggle();
})
At this point, all things work. The replies div slide up and down as described by the jQuery toggle function. Normally this isn't a problem when you run this code at very top of the browser viewport. "Top of the browser viewport" simply means that the page hasn't scrolled down. The "moving viewport" problem happens when you run the click function when you're at bottom of the page. The click function keeps forcing the viewport to move to the top. Its annoying as hell. Fortunately the solution is simple. So simple in fact it made me go *FACE PALM*. The root of the problem is the the anchor href attribute set to "#". So by just changing the href attribute to something else like javascript:void(0) or just simply delete it, you fix the problem.
<a href="javascript:void(0)" class="reply-action">  
      <span>  
         <i></i>  
             Reply  
         </span>  
      </a>  
</span> 
It took me about a day to figure it out after trying to use overly complex jQuery like event and mouse APIs. Talk about being given the runaround.

Wednesday, January 18, 2012

Going dark

I'm a freelance web developer and web administrator. I am able to do this because the Internet is free and open. But redneck, technology ignorant American congressmen and senators are sponsoring a pair of bills that will kill that freedom and openness. All in the name of stopping online piracy.

These bills (SOPA and PIPA) are moving through the American political system and even though I'm not American and I have an interest in this. So in about 4 hours (from this post) I'm going to shutdown all the sites that I'm currently the administrator for 12 hours in protest. Just like what reddit.com and wikipedia.org will be doing in protest.

You can read up here on how these two bills are written and will affect the whole Internet if passed and signed into law.

I'm going dark because if SOPA and/or PIPA pass, it wouldn't matter much because my sites will be going dark PERMANENTLY.

If you are a citizen of the Internets, show your support here.


Thursday, January 5, 2012

Learning Scala is screwing up my head

After learning Groovy, I decided to learn Scala. I'm in my 2nd week of learning it and its screwing up my head. I think its has more to do with the programming paradigm that Scala is in. Scala is a multi-paradigm programming language designed to integrate features of object-oriented programming and functional programming. 

Scala 2.9.1 in Netbeans
So to get started, I download and install Scala and got Netbeans to work with in. Scala in Netbeans is pretty sweet. You can follow all the Scala tutorials using the interactive shell and then try your hands on writing Scala scripts. 

The object-oriented part is cake but the functional programming part that what's screwing up my head. All this reminds me of what I had to go through learning object oriented programming coming from a procedural programming language. I'm expecting to go half-mad, a nervous breakdown and then suddenly just get it. 

This is going to be wild ride.