Author: jablko
Date: Mon Oct 25 12:01:26 2010
New Revision: 8474

Log:
Cosmetic changes

Modified:
   trunk/js/multiInput.js

Modified: trunk/js/multiInput.js
==============================================================================
--- trunk/js/multiInput.js      Mon Oct 25 11:27:31 2010        (r8473)
+++ trunk/js/multiInput.js      Mon Oct 25 12:01:26 2010        (r8474)
@@ -19,7 +19,8 @@
 
           $('input.multiInput', context).each(function ()
             {
-              var name = this.name;
+              var index = 0;
+              var name = this.name.replace('[new]', '');
 
               $(this)
 
@@ -29,12 +30,6 @@
                 // Bind blur, click, or keydown events
                 .bind('blur click keydown', function (event)
                   {
-                    if (undefined === $(this).data('counter'))
-                    {
-                      $(this).data('counter', 0);
-                    }
-                    var counter = $(this).data('counter');
-
                     // Don't fire on keydown other than tab (9) or enter (13)
                     if ($(this).val()
                         && ('keydown' !== event.type
@@ -47,38 +42,33 @@
                         event.preventDefault();
                       }
 
-                      // Add input value to multInput
-                      var stem = name.replace('[new]', '');
-                      var $li = $('<li><input id="' + stem + '_new_' + counter 
+ '" name="' + stem + '[new' + counter + ']" value="' + this.value + 
'"/></li>');
-
-                      // Bind click event to new list item
-                      $li.click(function (event)
-                        {
-                          if (event.target === this)
-                          {
-                            // On click, remove <li/>
-                            $(this).hide('fast', function ()
-                              {
-                                $(this).remove();
-                              });
-                          }
-                        });
-
-                      // Create <ul/> if it doesn't exist
-                      if (!$(this).prev('ul.multInput').length)
+                      var $ul = $(this).prev('ul.multInput');
+                      if (!$ul.length)
                       {
                         // Add <ul/> element, if it doesn't exist already (new
                         // object)
-                        $('<ul class="multInput" name="' + stem + 
'"/>').insertBefore(this);
+                        $ul = $('<ul class="multInput"/>').insertBefore(this);
                       }
 
-                      // Add <li/> to <ul/>
-                      $(this).prev('ul.multInput').append($li);
+                      // Add input value to multInput
+                      var $li = $('<li><input name="' + name + '[new' + 
index++ + ']" value="' + this.value + '"/></li>')
+
+                        // Bind click event to new list item
+                        .click(function (event)
+                          {
+                            if (event.target === this)
+                            {
+                              // On click, remove <li/>
+                              $(this).hide('fast', function ()
+                                {
+                                  $(this).remove();
+                                });
+                            }
+                          })
+                        .appendTo($ul);
 
                       // Clear <input/>
                       this.value = '';
-
-                      $(this).data('counter', ++counter);
                     }
                   });
             });

-- 
You received this message because you are subscribed to the Google Groups 
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/qubit-commits?hl=en.

Reply via email to