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

Contents of /contributions/modules/compact_forms/compact_forms.js

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


Revision 1.7 - (show annotations) (download) (as text)
Wed Sep 30 03:52:36 2009 UTC (8 weeks, 2 days ago) by sun
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +8 -13 lines
File MIME type: text/javascript
by sun: Ported to Drupal 7.
1 // $Id: compact_forms.js,v 1.6 2009/08/06 20:27:22 sun Exp $
2
3 (function ($) {
4
5 /**
6 * Compact Forms jQuery plugin.
7 */
8 $.fn.compactForm = function (stars) {
9 stars = stars || 0;
10
11 this.each(function () {
12 $(this).addClass('compact-form').find('label').each(function () {
13 var context = this.form;
14 var $label = $(this);
15 var $field = $('#' + $label.attr('for'), context);
16 if (!$field.is('input:text,input:password,textarea')) {
17 return;
18 }
19
20 if ($field.val() != '') {
21 $label.fadeOut(1);
22 }
23
24 $label.parent().addClass('compact-form-wrapper');
25 $label.addClass('compact-form-label');
26 $field.addClass('compact-form-field');
27
28 if (stars === 0) {
29 $label.find('.form-required').hide();
30 }
31 else if (stars === 2) {
32 $label.find('.form-required').insertAfter($field).prepend(' ');
33 }
34
35 $field.focus(function () {
36 if($(this).val() === '') {
37 $label.fadeOut('fast');
38 }
39 });
40
41 $field.blur(function () {
42 if($(this).val() === '') {
43 $label.fadeIn('slow');
44 }
45 });
46 });
47 });
48 };
49
50 Drupal.behaviors.compactForms = {
51 attach: function (context, settings) {
52 if (!settings || !settings.compactForms) {
53 return;
54 }
55 $('#' + settings.compactForms.forms.join(',#'), context).compactForm(settings.compactForms.stars);
56 }
57 };
58
59 })(jQuery);

  ViewVC Help
Powered by ViewVC 1.1.2