(function ($) {
  $.fn.enable = function () {
    return this.removeAttr('disabled');
  };
  $.fn.disable = function () {
    return this.attr('disabled', 'disabled');
  };
})(jQuery);

$(document).ready(function () {
  $('#columns .tweets').empty();  // Remove dummy content.

  $('.not-signed-in #the-sign-in-menu').popover({
    placement: 'below',
    trigger: 'manual'
  }).popover('show');

  var update_character_count = function () {
    $('#character-count').text(140 - $(this).val().length);  // FIXME
  };
  $('#status')
    .keydown(update_character_count)
    .keyup(update_character_count);

  $('.not-signed-in #tweet-form :input').disable();
  $('#tweet-form').submit(function () {
    var indicate_requesting_status = function () {
      $('#tweet-form :input').disable();
      $('#tweet-form #status').twipsy({
        placement: 'below',
        trigger: 'manual'
      }).twipsy('show');
    };
    var restore_requesting_status = function () {
      $('#tweet-form :input').enable();
      $('#tweet-form #status').twipsy('hide');
    };
    indicate_requesting_status();
    $.post(
      '/api/1/statuses/update.json',
      {
        status: $('#status').val()
      },
      'json'
    )
    .success(function (data) {
      if (data.error == null) {
        alert(data);  // FIXME: Update view.
        $('#status').val('');
      } else {
        // FIXME: Alert gracefully.
        alert('Failed to tweet: ' + data.error);
      }
    })
    .error(function (_jqXHR, textStatus, errorThrown) {
      // FIXME: Alert gracefully.
      alert('Failed to tweet: ' + textStatus + ' / ' + errorThrown);
    })
    .complete(function (_jqXHR, _textStatus) {
      restore_requesting_status();
    });

    return false;
  });
});

// __END__  {{{1
// vim: expandtab shiftwidth=2 softtabstop=2
// vim: foldmethod=marker

@@ -398,34 +398,33 @@
   var update
-_c
+C
 haracter
 _count = fun
@@ -407,26 +407,25 @@
 ateCharacter
-_c
+C
 ount = funct
@@ -538,34 +538,33 @@
 ydown(update
-_c
+C
 haracter
 _count)%0A    
@@ -547,26 +547,25 @@
 ateCharacter
-_c
+C
 ount)%0A    .k
@@ -579,18 +579,17 @@
 date
-_c
+C
 haracter
 _cou
@@ -588,10 +588,9 @@
 cter
-_c
+C
 ount
@@ -693,34 +693,33 @@
     var indicate
-_r
+R
 equesting_status
@@ -703,34 +703,33 @@
 dicateRequesting
-_s
+S
 tatus = function
@@ -908,34 +908,33 @@
 %0A    var restore
-_r
+R
 equesting_status
@@ -922,26 +922,25 @@
 reRequesting
-_s
+S
 tatus = func
@@ -1055,18 +1055,17 @@
 indicate
-_r
+R
 equestin
@@ -1057,34 +1057,33 @@
 dicateRequesting
-_s
+S
 tatus();%0A    $.p
@@ -1678,10 +1678,9 @@
 tore
-_r
+R
 eque
@@ -1688,10 +1688,9 @@
 ting
-_s
+S
 tatu

Refactor - Unify naming in JavaScript