DRY and Pythonic jQuery?

Apparently, groovy:spring:java as jabs:jquery:javascript. As if jQuery wasn’t short enough already.

Jabs lets you write this jQuery code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
jQuery(function() {
  var $ = jQuery;
 
  $("[default_value]")
    .blur(function() {
      var self = $(this);
      if(self.val() === "") {
        self.val(self.attr("default_value"));
      }
    })
    .focus(function() {
      var self = $(this);
      if(self.val === self.attr("default_value")) {
        self.val("");
      }
    })
    .blur(); 
});

By typing this:

1
2
3
4
5
6
7
8
$ [default_value]
  :blur
    if @value === ""
      @value = @default_value
  :focus
    if @value === @default_value
      @value = ""
  .blur

HAML tactics FTW.

2 FEEDBACKS

  1. Hey, I've noticed, thanks to your post, that the Jabs readme file is showing those two examples incorrectly. I've updated the text at http://github.com/collin/jabs

  2. Thanks man! I updated my post.

    Great stuff, btw. I love it. Idk if i'll use it, but it's really awesome.

LEAVE A COMMENT

Additional comments powered by BackType