Ajaxifying

Generally, I feel bad when I see my own code. Especially, when the code has been written some time ago. But the code below is a real junk: it simply does not work(always) and it is meant to handle click on links; it replaces default links’ behavior by my own: meaning by calling “Ext.Ajax.Request”.

<script>
. . .
    // post click universal handler
    var maskClick = function(e){
        // find the "a" element that was clicked
        var a = e.getTarget(‘a’);
        if (a) {
            if( a.rel != ‘noajax’
                && cleanUrl.indexOf(Wp.bloginfo.url) == 0
                && cleanUrl.indexOf(‘wp-admin’) == -1
                && cleanUrl.indexOf(‘wp-login’) == -1
                && cleanUrl.indexOf(‘feed’) == -1
              ){
                e.preventDefault();
                Wp.theme.loadPosts(a.href);
            }
 
        }
    };
. . .
</script>

I have made the function private of Wp.theme. The concept was to make universal click handler for links, but I have realised that not every link should be handled. Especially not blog URL (Wp.bloginfo.ur), all links that go to admin interface should not be handled also, neither feed links, and so on and so on…. As you can see the condition can be easily break. (the real maskClick is even more messy because it tries to handle links with #). Now it cannot be applied everywhere because Ext uses “A” tags very often. This is because some elements need focus and in some browsers there is no focus without “A” tag.

Please help me to find a better alternative!