| 1 |
// $Id: compact_forms.js,v 1.5 2009/05/27 08:15:17 sun Exp $ |
// $Id: compact_forms.js,v 1.6 2009/08/06 20:27:22 sun Exp $ |
| 2 |
|
|
| 3 |
(function ($) { |
(function ($) { |
| 4 |
|
|
| 5 |
/** |
/** |
| 6 |
* Compact Forms jQuery plugin. |
* Compact Forms jQuery plugin. |
| 7 |
*/ |
*/ |
| 8 |
$.fn.compactForm = function (stars, colons) { |
$.fn.compactForm = function (stars) { |
| 9 |
stars = stars || 0; |
stars = stars || 0; |
|
colons = colons || 0; |
|
| 10 |
|
|
| 11 |
this.each(function () { |
this.each(function () { |
| 12 |
$(this).addClass('compact-form').find('label').each(function () { |
$(this).addClass('compact-form').find('label').each(function () { |
| 32 |
$label.find('.form-required').insertAfter($field).prepend(' '); |
$label.find('.form-required').insertAfter($field).prepend(' '); |
| 33 |
} |
} |
| 34 |
|
|
|
if (colons === 0) { |
|
|
var lbl = $label.html(); |
|
|
lbl = lbl.replace(/:/,' '); |
|
|
$label.html(lbl); |
|
|
} |
|
|
|
|
| 35 |
$field.focus(function () { |
$field.focus(function () { |
| 36 |
if($(this).val() === '') { |
if($(this).val() === '') { |
| 37 |
$label.fadeOut('fast'); |
$label.fadeOut('fast'); |
| 47 |
}); |
}); |
| 48 |
}; |
}; |
| 49 |
|
|
| 50 |
Drupal.behaviors.compactForms = function (context) { |
Drupal.behaviors.compactForms = { |
| 51 |
if (!Drupal.settings || !Drupal.settings.compactForms) { |
attach: function (context, settings) { |
| 52 |
return; |
if (!settings || !settings.compactForms) { |
| 53 |
|
return; |
| 54 |
|
} |
| 55 |
|
$('#' + settings.compactForms.forms.join(',#'), context).compactForm(settings.compactForms.stars); |
| 56 |
} |
} |
|
$('#' + Drupal.settings.compactForms.forms.join(',#'), context).compactForm(Drupal.settings.compactForms.stars, Drupal.settings.compactForms.colons); |
|
| 57 |
}; |
}; |
| 58 |
|
|
| 59 |
})(jQuery); |
})(jQuery); |