/[drupal]/contributions/modules/compact_forms/compact_forms.js
ViewVC logotype

Diff of /contributions/modules/compact_forms/compact_forms.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.2, Fri May 1 23:10:11 2009 UTC revision 1.2.2.1, Wed May 6 23:43:47 2009 UTC
# Line 1  Line 1 
1  // $Id: compact_forms.js,v 1.1 2007/07/29 17:20:58 tomsun Exp $  // $Id: compact_forms.js,v 1.2 2009/05/01 23:10:11 sun Exp $
2    
3  (function ($) {  (function ($) {
4    
# Line 12  $.fn.compactForm = function (stars, colo Line 12  $.fn.compactForm = function (stars, colo
12    var colons = colons || 0;    var colons = colons || 0;
13    
14    this.each(function (index) {    this.each(function (index) {
15      $(this).addClass('compact-form').find("label").each(function () {      $(this).addClass('compact-form').find('label').each(function () {
16        var label = $(this);        var $label = $(this);
17        var field = $('#' + label.attr('for'));        var $field = $('#' + $label.attr('for'));
18        if (field.attr('type') != 'text' && field.attr('type') != 'password') {        if ($field.attr('type') != 'text' && $field.attr('type') != 'password') {
19          return;          return;
20        }        }
21    
22        if ($(field).val() != '') {        if ($field.val() != '') {
23          $(label).fadeOut(1);          $label.fadeOut(1);
24        }        }
25    
26        $(label).parent().addClass('compact-form-wrapper');        $label.parent().addClass('compact-form-wrapper');
27        label.addClass('compact-form-label');        $label.addClass('compact-form-label');
28        field.addClass('compact-form-field');        $field.addClass('compact-form-field');
29    
30        if (stars === 0) {        if (stars === 0) {
31          $(label).find('.form-required').hide();          $label.find('.form-required').hide();
32        }        }
33        else if (stars === 2) {        else if (stars === 2) {
34          $(label).find('.form-required').insertAfter(field).prepend(' ');          $label.find('.form-required').insertAfter($field).prepend(' ');
35        }        }
36    
37        if (colons === 0) {        if (colons === 0) {
38          var lbl = $(label).html();          var lbl = $label.html();
39          lbl = lbl.replace(/:/,' ');          lbl = lbl.replace(/:/,' ');
40          $(label).html(lbl);          $label.html(lbl);
41        }        }
42    
43        $(field).focus(function () {        $field.focus(function () {
44          if($(this).val() === '') {          if($(this).val() === '') {
45            $(label).fadeOut('fast');            $label.fadeOut('fast');
46          }          }
47        });        });
48    
49        $(field).blur(function () {        $field.blur(function () {
50          if($(this).val() === '') {          if($(this).val() === '') {
51            $(label).fadeIn('slow');            $label.fadeIn('slow');
52          }          }
53        });        });
54      });      });
55    });    });
56  }  };
57    
58  Drupal.behaviors.compactForms = function (context) {  Drupal.behaviors.compactForms = function (context) {
59    if (!Drupal.settings || !Drupal.settings.compactForms) {    if (!Drupal.settings || !Drupal.settings.compactForms) {
# Line 62  Drupal.behaviors.compactForms = function Line 62  Drupal.behaviors.compactForms = function
62    $.each(Drupal.settings.compactForms.forms, function () {    $.each(Drupal.settings.compactForms.forms, function () {
63      $('#' + this, context).compactForm(Drupal.settings.compactForms.stars, Drupal.settings.compactForms.colons);      $('#' + this, context).compactForm(Drupal.settings.compactForms.stars, Drupal.settings.compactForms.colons);
64    });    });
65  }  };
66    
67  // D5 only.  // D5 only.
68  $(document).ready(function () {  $(document).ready(function () {

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.2.2.1

  ViewVC Help
Powered by ViewVC 1.1.2