Drupal coder

jQuery

Drupal 6 JavaScript and jQuery

Drupal is getting a hotter and hotter topic by the day. This is proven by the amount and the diversity of books being published about it. There are beginner books, advanced books, the ones with a more hands-on approach. There are books about module development, theming, ... But the most significant proof that Drupal is hot is that some books are available already that cover only a small topic of Drupal like security, views and now also JavaScript and jQuery. And it are those latest few that are the most appealing from my point of view.

In particular I've been really looking forward to Matt Butcher's Drupal 6 Javascript and jQuery. This book covers JavaScript and jQuery from a Drupal point of view. Drupal already opted very early for jQuery as its preferred JavaScript framework. In time, Drupal added another library on top of jQuery (Drupal.js) that gives Drupal themers and module developers a range of tools on the JavaScript layer to translate strings, use some kind of theming (like the "PHP one"), easier work with AJAX, ... These things aren't covered very well (yet) in the Drupal handbook and API. This book fills this gap.

Cross browser sticky footer with fluid height using jQuery

I recently needed a sticky footer. Having a sticky footer means your footer sticks to the bottom of your browser window if your document (content) is not as heigh as your browser window.

There's a few options to do this using CSS. But they all assume you know the height (fixed) of your footer. I didn't. The footer was managed in the CSS, so I could expand or shrink over time.

I decided to write something myself. CSS only didn't seem too cut the chase. So I headed over to my jQuery toolbox and came up with the following code. You can see an example of it here. You can see it in action on a production (Drupal) site on www.encantar.be.

October 19, 2009JavaScript, jQuery

Disabling password check in Drupal 6

I've had some clients not wanting the uber cool password strength checking in Drupal 6. Well, here's a very short tip how to disable this.

Just add the following in some javascript (your theme, your module, ...)

<script language="javascript">
// disabling password security check
Drupal.behaviors.password = function(context) {
  return;
}
</script>

Hooray for behaviors!

disable-password-check.png

March 14, 2009Drupal, JavaScript, jQuery

Automatically open all external links in a new window using jQuery

We all know that to open a link in a new window, you have to specify the target attribute as '_blank' in your HTML link tag.

But this process is boring and it's very easy to forget this when typing an article, page, blog post, ... because you want to focus on your content.

Did you even know that in Strict HTML it isn't even allowed to use the target attribute? Personally I hate it when links open up in a new window but your client my argue that his visitors want this behaviour.

To make your and your webmaster/editor's life easier, I have written a few lines of jQuery code that will convert all external links (i.e. links that begin with http) to links opening up in a new window by injecting the target="_blank" behind the screens. So you never have to specify the target attribute again. This way your code is ready if you ever want to convert to the Strict flavour.

$(document).ready(function() {
  $("a[@href^=http]").each(
    function(){
	    if(this.href.indexOf(location.hostname) == -1) { 
        $(this).attr('target', '_blank');
      }
    }
  )
});
February 07, 2008Drupal, JavaScript, jQuery