| 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 |
|
|
| 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) { |
| 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 () { |