couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cml...@apache.org
Subject svn commit: r734953 - /couchdb/trunk/share/www/script/jquery.form.js
Date Fri, 16 Jan 2009 10:04:20 GMT
Author: cmlenz
Date: Fri Jan 16 02:04:18 2009
New Revision: 734953

URL: http://svn.apache.org/viewvc?rev=734953&view=rev
Log:
Update jquery.form to 2.18 in order to fix compatibility issues with jQuery 1.3, in particular
COUCHDB-211.

Modified:
    couchdb/trunk/share/www/script/jquery.form.js

Modified: couchdb/trunk/share/www/script/jquery.form.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/jquery.form.js?rev=734953&r1=734952&r2=734953&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/jquery.form.js (original)
+++ couchdb/trunk/share/www/script/jquery.form.js Fri Jan 16 02:04:18 2009
@@ -1,6 +1,6 @@
 /*
  * jQuery Form Plugin
- * version: 2.12 (06/07/2008)
+ * version: 2.18 (06-JAN-2009)
  * @requires jQuery v1.2.2 or later
  *
  * Examples and documentation at: http://malsup.com/jquery/form/
@@ -10,7 +10,7 @@
  *
  * Revision: $Id$
  */
-(function($) {
+;(function($) {
 
 /*
     Usage Note:  
@@ -67,13 +67,25 @@
     if (veto.veto) {
         log('ajaxSubmit: submit vetoed via form-pre-serialize trigger');
         return this;
-   }
+    }
 
+    // provide opportunity to alter form data before it is serialized
+    if (options.beforeSerialize && options.beforeSerialize(this, options) === false)
{
+        log('ajaxSubmit: submit aborted via beforeSerialize callback');
+        return this;
+    }    
+   
     var a = this.formToArray(options.semantic);
     if (options.data) {
         options.extraData = options.data;
-        for (var n in options.data)
-            a.push( { name: n, value: options.data[n] } );
+        for (var n in options.data) {
+          if(options.data[n] instanceof Array) {
+            for (var k in options.data[n])
+              a.push( { name: n, value: options.data[n][k] } )
+          }  
+          else
+             a.push( { name: n, value: options.data[n] } );
+        }
     }
 
     // give pre-submit callback an opportunity to abort the submit
@@ -114,7 +126,7 @@
 
     options.success = function(data, status) {
         for (var i=0, max=callbacks.length; i < max; i++)
-            callbacks[i](data, status, $form);
+            callbacks[i].apply(options, [data, status, $form]);
     };
 
     // are there files to upload?
@@ -145,12 +157,13 @@
     function fileUpload() {
         var form = $form[0];
         
-        if ($(':input[@name=submit]', form).length) {
+        if ($(':input[name=submit]', form).length) {
             alert('Error: Form elements must not be named "submit".');
             return;
         }
         
         var opts = $.extend({}, $.ajaxSettings, options);
+		var s = jQuery.extend(true, {}, $.extend(true, {}, $.ajaxSettings), opts);
 
         var id = 'jqFormIO' + (new Date().getTime());
         var $io = $('<iframe id="' + id + '" name="' + id + '" />');
@@ -161,13 +174,18 @@
         $io.css({ position: 'absolute', top: '-1000px', left: '-1000px' });
 
         var xhr = { // mock object
+            aborted: 0,
             responseText: null,
             responseXML: null,
             status: 0,
             statusText: 'n/a',
             getAllResponseHeaders: function() {},
             getResponseHeader: function() {},
-            setRequestHeader: function() {}
+            setRequestHeader: function() {},
+            abort: function() { 
+                this.aborted = 1; 
+                $io.attr('src','about:blank'); // abort op in progress
+            }
         };
 
         var g = opts.global;
@@ -175,6 +193,13 @@
         if (g && ! $.active++) $.event.trigger("ajaxStart");
         if (g) $.event.trigger("ajaxSend", [xhr, opts]);
 
+		if (s.beforeSend && s.beforeSend(xhr, s) === false) {
+			s.global && jQuery.active--;
+			return;
+        }
+        if (xhr.aborted)
+            return;
+        
         var cbInvoked = 0;
         var timedOut = 0;
 
@@ -191,18 +216,24 @@
                 }
             }
         }
-        
+
         // take a breath so that pending repaints get some cpu time before the upload starts
         setTimeout(function() {
             // make sure form attrs are set
             var t = $form.attr('target'), a = $form.attr('action');
             $form.attr({
                 target:   id,
-                encoding: 'multipart/form-data',
-                enctype:  'multipart/form-data',
                 method:   'POST',
                 action:   opts.url
             });
+            
+            // ie borks in some cases when setting encoding
+            if (! options.skipEncodingOverride) {
+                $form.attr({
+                    encoding: 'multipart/form-data',
+                    enctype:  'multipart/form-data'
+                });
+            }
 
             // support timout
             if (opts.timeout)
@@ -325,23 +356,23 @@
     }).each(function() {
         // store options in hash
         $(":submit,input:image", this).bind('click.form-plugin',function(e) {
-            var $form = this.form;
-            $form.clk = this;
+            var form = this.form;
+            form.clk = this;
             if (this.type == 'image') {
                 if (e.offsetX != undefined) {
-                    $form.clk_x = e.offsetX;
-                    $form.clk_y = e.offsetY;
+                    form.clk_x = e.offsetX;
+                    form.clk_y = e.offsetY;
                 } else if (typeof $.fn.offset == 'function') { // try to use dimensions plugin
                     var offset = $(this).offset();
-                    $form.clk_x = e.pageX - offset.left;
-                    $form.clk_y = e.pageY - offset.top;
+                    form.clk_x = e.pageX - offset.left;
+                    form.clk_y = e.pageY - offset.top;
                 } else {
-                    $form.clk_x = e.pageX - this.offsetLeft;
-                    $form.clk_y = e.pageY - this.offsetTop;
+                    form.clk_x = e.pageX - this.offsetLeft;
+                    form.clk_y = e.pageY - this.offsetTop;
                 }
             }
             // clear form vars
-            setTimeout(function() { $form.clk = $form.clk_x = $form.clk_y = null; }, 10);
+            setTimeout(function() { form.clk = form.clk_x = form.clk_y = null; }, 10);
         });
     });
 };
@@ -574,7 +605,7 @@
  * Checks/unchecks any matching checkboxes or radio buttons and
  * selects/deselects and matching option elements.
  */
-$.fn.select = function(select) {
+$.fn.selected = function(select) {
     if (select == undefined) select = true;
     return this.each(function() { 
         var t = this.type;
@@ -584,7 +615,7 @@
             var $sel = $(this).parent('select');
             if (select && $sel[0] && $sel[0].type == 'select-one') {
                 // deselect all other options
-                $sel.find('option').select(false);
+                $sel.find('option').selected(false);
             }
             this.selected = select;
         }
@@ -598,4 +629,4 @@
         window.console.log('[jquery.form] ' + Array.prototype.join.call(arguments,''));
 };
 
-})(jQuery);
+})(jQuery);
\ No newline at end of file



Mime
View raw message