Author: jablko
Date: Sun Oct 24 18:49:05 2010
New Revision: 8450

Log:
Refactor

Modified:
   trunk/js/date.js

Modified: trunk/js/date.js
==============================================================================
--- trunk/js/date.js    Sun Oct 24 18:28:40 2010        (r8449)
+++ trunk/js/date.js    Sun Oct 24 18:49:05 2010        (r8450)
@@ -5,109 +5,72 @@
     Drupal.behaviors.date = {
       attach: function (context)
         {
-          $('.date', context).each(function ()
+          function parse(value)
+          {
+            var min = [];
+            var max = [];
+
+            var matches = 
value.match(/\d+(?:[-/]0*(?:1[0-2]|\d)(?:[-/]0*(?:3[01]|[12]?\d))?(?!\d))?/g);
+            if (matches)
             {
-              var $start = $('[id$=startDate]', this);
-              var $end = $('[id$=endDate]', this);
+              jQuery.each(matches, function (index)
+                {
+                  var matches = this.match(/\d+/g);
+                  if (0 === index)
+                  {
+                    min = max = matches;
 
-              var min = [];
-              var max = [];
+                    return;
+                  }
 
-              var matches = $('[id$=dateDisplay]', this)
-                .change(function ()
-                  {
-                    if (min === $start.val() && max === $end.val())
+                  jQuery.each(min, function (index)
                     {
-                      min = max = [];
+                      if (this - 0 < matches[index] - 0)
+                      {
+                        return false;
+                      }
 
-                      var matches = 
$(this).val().match(/\d+(?:[-/]0*(?:1[0-2]|\d)(?:[-/]0*(?:3[01]|[12]?\d))?(?!\d))?/g);
-                      if (matches)
+                      if (this - 0 != matches[index] - 0)
                       {
-                        jQuery.each(matches, function (index)
-                          {
-                            var matches = this.match(/\d+/g);
-                            if (0 === index)
-                            {
-                              min = max = matches;
-
-                              return;
-                            }
-
-                            jQuery.each(min, function (index)
-                              {
-                                if (this - 0 < matches[index] - 0)
-                                {
-                                  return false;
-                                }
-
-                                if (this - 0 != matches[index] - 0)
-                                {
-                                  min = matches;
-                                }
-                              });
-
-                            jQuery.each(max, function (index)
-                              {
-                                if (this - 0 > matches[index] - 0)
-                                {
-                                  return false;
-                                }
-
-                                if (this - 0 != matches[index] - 0)
-                                {
-                                  max = matches;
-                                }
-                              });
-                          });
+                        min = matches;
                       }
+                    });
 
-                      $start.val(min = min.join('-'));
-                      $end.val(max = max.join('-'));
-                    }
-                  })
-                
.val().match(/\d+(?:[-/]0*(?:1[0-2]|\d)(?:[-/]0*(?:3[01]|[12]?\d))?(?!\d))?/g);
-              if (matches)
-              {
-                jQuery.each(matches, function (index)
-                  {
-                    var matches = this.match(/\d+/g);
-                    if (0 === index)
+                  jQuery.each(max, function (index)
                     {
-                      min = max = matches;
-
-                      return;
-                    }
-
-                    jQuery.each(min, function (index)
+                      if (this - 0 > matches[index] - 0)
                       {
-                        if (this - 0 < matches[index] - 0)
-                        {
-                          return false;
-                        }
-
-                        if (this - 0 != matches[index] - 0)
-                        {
-                          min = matches;
-                        }
-                      });
+                        return false;
+                      }
 
-                    jQuery.each(max, function (index)
+                      if (this - 0 != matches[index] - 0)
                       {
-                        if (this - 0 > matches[index] - 0)
-                        {
-                          return false;
-                        }
-
-                        if (this - 0 != matches[index] - 0)
-                        {
-                          max = matches;
-                        }
-                      });
-                  });
-              }
+                        max = matches;
+                      }
+                    });
+                });
+            }
+
+            return [min.join('-'), max.join('-')];
+          }
+
+          $('.date', context).each(function ()
+            {
+              var $start = $('[id$=startDate]', this);
+              var $end = $('[id$=endDate]', this);
 
-              min = min.join('-');
-              max = max.join('-');
+              var components = parse($('[id$=dateDisplay]', this)
+                .change(function ()
+                  {
+                    if (components[0] === $start.val() && components[1] === 
$end.val())
+                    {
+                      components = parse($(this).val());
+
+                      $start.val(components[0]);
+                      $end.val(components[1]);
+                    }
+                  })
+                .val());
             });
         } };
   })(jQuery);

-- 
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