]> source.dussan.org Git - jquery.git/commitdiff
Moved plugins to the new plugin directory.
authorJohn Resig <jeresig@gmail.com>
Sun, 13 Aug 2006 14:52:14 +0000 (14:52 +0000)
committerJohn Resig <jeresig@gmail.com>
Sun, 13 Aug 2006 14:52:14 +0000 (14:52 +0000)
form/form.js [deleted file]
plugins/compat/compat.js [new file with mode: 0644]
plugins/form/form.js [new file with mode: 0644]

diff --git a/form/form.js b/form/form.js
deleted file mode 100644 (file)
index 13b513b..0000000
+++ /dev/null
@@ -1,200 +0,0 @@
-/**\r
- * A method for submitting an HTML form using AJAX, as opposed to the\r
- * standard page-load way.\r
- *\r
- * This method attempts to mimic the functionality of the original form\r
- * as best as possible (duplicating the method, action, and exact contents\r
- * of the form).\r
- *\r
- * There are three different resulting operations that can occur, after\r
- * your form has been submitted.\r
- *\r
- * 1. The form is submitted and a callback is fired, letting you know\r
- *    when it's done:\r
- *    $("form").ajaxSubmit(function(){\r
- *      alert("all done!");\r
- *    });\r
- *\r
- * 2. The form is submitted and the resulting HTML contents are injected\r
- *    into the page, at your specified location.\r
- *    $("form").ajaxSubmit("#destination");\r
- *\r
- * 3. The form is submitted and the results returned from the server are\r
- *    automatically executed (useful for having the server return more\r
- *    Javascript commands to execute).\r
- *    $("form").ajaxSubmit();\r
- *\r
- * Additionally, an optional pre-submit callback can be provided. If it,\r
- * when called with the contents of the form, returns false, the form will\r
- * not be submitted.\r
- *\r
- * Finally, both the URL and method of the form submission can be\r
- * overidden using the 'url' and 'mth' arguments.\r
- *\r
- * @param target   arg for the target id element to render\r
- * @param post_cb  callback after any results are returned\r
- * @param pre_cb   callback function before submission\r
- * @param url      form action override\r
- * @param mth      form method override\r
- * @return         "this" object\r
- * @see            ajaxForm(), serialize(), load(), $.ajax()\r
- * @author         Mark Constable (markc@renta.net)\r
- * @author         G. vd Hoven, Mike Alsup, Sam Collett, John Resig\r
- */\r
-$.fn.ajaxSubmit = function(target, post_cb, pre_cb, url, mth) {\r
-       if ( !this.vars ) this.serialize();\r
-       \r
-       if (pre_cb && pre_cb.constructor == Function && pre_cb(this.vars) === false) return;\r
-\r
-       var f = this.get(0);\r
-       var url = url || f.action || '';\r
-       var mth = mth || f.method || 'POST';\r
-\r
-       if (target && target.constructor == Function)\r
-               $.ajax(mth, url, $.param(this.vars), target);\r
-       else if (target && target.constructor == String)\r
-               $(target).load(url, this.vars, post_cb);\r
-       else {\r
-               this.vars.push({name: 'evaljs', value: 1});\r
-               $.ajax(mth, url, $.param(this.vars), function(r) {\r
-                       eval(r.responseText);\r
-               });\r
-       }\r
-\r
-       return this;\r
-};\r
-\r
-/**\r
- * This function can be used to turn any HTML form into a form\r
- * that submits using AJAX only.\r
- *\r
- * The purpose of using this method, instead of the ajaxSubmit()\r
- * and submit() methods, is to make absolutely sure that the\r
- * coordinates of <input type="image"/> elements are transmitted\r
- * correctly OR figuring out exactly which <input type="submit"/>\r
- * element was clicked to submit the form.\r
- *\r
- * If neither of the above points are important to you, then you'll\r
- * probably just want to stick with the simpler ajaxSubmit() function.\r
- *\r
- * Usage examples, similar to ajaxSubmit():\r
- *\r
- * 1. Just eval the results returned from the backend.\r
- *    $('#form-id').ajaxForm();\r
- *\r
- * 2. Render backend results directly to target ID (expects (x)HTML).\r
- *    $('#form-id').ajaxForm('#target-id');\r
- *\r
- * 3. Submit to backend URL (form action) then call this function.\r
- *    $('#form-id').ajaxForm(post_callback);\r
- *\r
- * 4. Load target ID with backend results then call a function.\r
- *    $('#form-id').ajaxForm('#target-id', post_callback);\r
- *\r
- * 5. Call a browser function (for validation) and then (optionally)\r
- *    load server results to target ID.\r
- *    $('#form-id').ajaxForm('#target-id', null, pre_callback);\r
- *\r
- * 6. Call validation function first then load server results to\r
- *    target ID and then also call a browser function.\r
- *    $('#form-id').ajaxForm('#target-id', post_callback, pre_callback);\r
- *\r
- * @param target   arg for the target id element to render\r
- * @param post_cb  callback after any results are returned\r
- * @param pre_cb   callback function before submission\r
- * @return         the jQuery Object\r
- * @type jQuery\r
- * @see            serialize(), ajaxSubmit()\r
- * @author         Mark Constable (markc@renta.net)\r
- * @author         G. vd Hoven, Mike Alsup, Sam Collett, John Resig\r
- */\r
-$.fn.ajaxForm = function(target, post_cb, pre_cb) {\r
-       return this.each(function(){\r
-               $("input[@type=submit],input[@type=image]", this).click(function(ev){\r
-                       this.form.clicked = this;\r
-                       if (ev.offsetX != undefined) {\r
-                               this.form.clicked_x = ev.offsetX;\r
-                               this.form.clicked_y = ev.offsetY;\r
-                       } else {\r
-                               this.form.clicked_x = ev.pageX - this.offsetLeft;\r
-                               this.form.clicked_y = ev.pageY - this.offsetTop;\r
-                       }\r
-               });\r
-       }).submit(function(e){\r
-               $(this).ajaxSubmit(target, post_cb, pre_cb);\r
-               return false;\r
-       });\r
-};\r
-\r
-/**\r
- * A simple wrapper function that sits around the .serialize()\r
- * method, allowing you to easily extract the data stored within\r
- * a form.\r
- *\r
- * Usage examples:\r
- *\r
- * 1. Serialize the contents of a form to a & and = delmited string:\r
- *    $.param( $("form").formdata() );\r
- *\r
- * @return         An array of name/value pairs representing the form\r
- * @type Array<Object>\r
- * @see            serialize()\r
- # @author         John Resig\r
- */\r
-$.fn.formdata = function(){\r
-       this.serialize();\r
-       return this.vars;\r
-};\r
-\r
-/**\r
- * This function gathers form element variables into an array that\r
- * is embedded into the current "this" variable as "this.vars". It\r
- * is normally used in conjunction with formdata() or ajaxSubmit() but can\r
- * be used standalone as long as you don't need the x and y coordinates\r
- * associated with an <input type="image"/> element..\r
- *\r
- * Standalone usage examples:\r
- *\r
- * 1. Gather form vars and return array to LHS variable.\r
- *    var myform = $('#form-id').serialize();\r
- *\r
- * 2. Provide a serialized URL-ready string (after 1. above).\r
- *    var mystring = $.param(myform.vars);\r
- *\r
- * 3. Gather form vars and send to RHS plugin via "this.vars".\r
- *    $('#form-id').serialize().some_other_plugin();\r
- *\r
- * @return         the jQuery Object\r
- * @return jQuery\r
- * @see            ajaxForm(), ajaxSubmit()\r
- * @author         Mark Constable (markc@renta.net)\r
- * @author         G. vd Hoven, Mike Alsup, Sam Collett, John Resig\r
- */\r
-$.fn.serialize = function() {\r
-       var a = [];\r
-       var ok = {INPUT:true, TEXTAREA:true, OPTION:true};\r
-\r
-       $('*', this).each(function() {\r
-               var par = this.parentNode;\r
-               var p = par.nodeName.toUpperCase();\r
-               var n = this.name || p == 'OPTGROUP' && par.parentNode.name || p == 'SELECT' && par.name || this.id;\r
-\r
-               if ( !n || this.disabled || this.type == 'reset' || \r
-                       (this.type == 'checkbox' || this.type == 'radio') && !this.checked || \r
-                       !ok[this.nodeName.toUpperCase()] ||\r
-                       (this.type == 'submit' || this.type == 'image') && this.form.clicked != this ||\r
-                       (p == 'SELECT' || p == 'OPTGROUP') && !this.selected ) return;\r
-\r
-               if (this.type == 'image' && this.form.clicked_x)\r
-                       return a.push(\r
-                               {name: this.name+'_x', value: this.form.clicked_x},\r
-                               {name: this.name+'_y', value: this.form.clicked_y}\r
-                       );\r
-\r
-               a.push({name: n, value: this.value});\r
-       });\r
-       \r
-       this.vars = a;\r
-\r
-       return this;\r
-};\r
diff --git a/plugins/compat/compat.js b/plugins/compat/compat.js
new file mode 100644 (file)
index 0000000..390c0e6
--- /dev/null
@@ -0,0 +1,41 @@
+       // Since we're using Prototype's $ function,
+       // be nice and have backwards compatability
+       if ( typeof Prototype != "undefined" ) {
+               if ( $a.constructor == String ) {
+                       var re = new RegExp( "[^a-zA-Z0-9_-]" );
+                       if ( !re.test($a) ) {
+                               $c = $c && $c.documentElement || document;
+                               if ( $c.getElementsByTagName($a).length === 0 ) {
+                                       var obj = $c.getElementById($a);
+                                       if ( obj ) { return obj; }
+                               }
+                       }
+               } else if ( $a.constructor == Array ) {
+                       return $.map( $a, function(b){
+                               if ( b.constructor == String ) {
+                                       return document.getElementById(b);
+                               }
+                               return b;
+                       });
+               }
+       }
+
+// TODO: Remove need to return this
+       for ( var i in $.fn ) {
+               if ( self[i] !== null )
+                       self["_"+i] = self[i];
+               self[i] = $.fn[i];
+       }
+
+       if ( typeof Prototype != "undefined" && $a.constructor != String ) {
+               if ( $c ) $a = self.get();
+               for ( var k in self ) {(function(j){
+                       try {
+                               if ( !$a[j] )
+                                       $a[j] = function() {
+                                               return $.apply(self,self[j],arguments);
+                                       };
+                       } catch(e) {}
+               })(k);}
+               return $a;
+       }
diff --git a/plugins/form/form.js b/plugins/form/form.js
new file mode 100644 (file)
index 0000000..13b513b
--- /dev/null
@@ -0,0 +1,200 @@
+/**\r
+ * A method for submitting an HTML form using AJAX, as opposed to the\r
+ * standard page-load way.\r
+ *\r
+ * This method attempts to mimic the functionality of the original form\r
+ * as best as possible (duplicating the method, action, and exact contents\r
+ * of the form).\r
+ *\r
+ * There are three different resulting operations that can occur, after\r
+ * your form has been submitted.\r
+ *\r
+ * 1. The form is submitted and a callback is fired, letting you know\r
+ *    when it's done:\r
+ *    $("form").ajaxSubmit(function(){\r
+ *      alert("all done!");\r
+ *    });\r
+ *\r
+ * 2. The form is submitted and the resulting HTML contents are injected\r
+ *    into the page, at your specified location.\r
+ *    $("form").ajaxSubmit("#destination");\r
+ *\r
+ * 3. The form is submitted and the results returned from the server are\r
+ *    automatically executed (useful for having the server return more\r
+ *    Javascript commands to execute).\r
+ *    $("form").ajaxSubmit();\r
+ *\r
+ * Additionally, an optional pre-submit callback can be provided. If it,\r
+ * when called with the contents of the form, returns false, the form will\r
+ * not be submitted.\r
+ *\r
+ * Finally, both the URL and method of the form submission can be\r
+ * overidden using the 'url' and 'mth' arguments.\r
+ *\r
+ * @param target   arg for the target id element to render\r
+ * @param post_cb  callback after any results are returned\r
+ * @param pre_cb   callback function before submission\r
+ * @param url      form action override\r
+ * @param mth      form method override\r
+ * @return         "this" object\r
+ * @see            ajaxForm(), serialize(), load(), $.ajax()\r
+ * @author         Mark Constable (markc@renta.net)\r
+ * @author         G. vd Hoven, Mike Alsup, Sam Collett, John Resig\r
+ */\r
+$.fn.ajaxSubmit = function(target, post_cb, pre_cb, url, mth) {\r
+       if ( !this.vars ) this.serialize();\r
+       \r
+       if (pre_cb && pre_cb.constructor == Function && pre_cb(this.vars) === false) return;\r
+\r
+       var f = this.get(0);\r
+       var url = url || f.action || '';\r
+       var mth = mth || f.method || 'POST';\r
+\r
+       if (target && target.constructor == Function)\r
+               $.ajax(mth, url, $.param(this.vars), target);\r
+       else if (target && target.constructor == String)\r
+               $(target).load(url, this.vars, post_cb);\r
+       else {\r
+               this.vars.push({name: 'evaljs', value: 1});\r
+               $.ajax(mth, url, $.param(this.vars), function(r) {\r
+                       eval(r.responseText);\r
+               });\r
+       }\r
+\r
+       return this;\r
+};\r
+\r
+/**\r
+ * This function can be used to turn any HTML form into a form\r
+ * that submits using AJAX only.\r
+ *\r
+ * The purpose of using this method, instead of the ajaxSubmit()\r
+ * and submit() methods, is to make absolutely sure that the\r
+ * coordinates of <input type="image"/> elements are transmitted\r
+ * correctly OR figuring out exactly which <input type="submit"/>\r
+ * element was clicked to submit the form.\r
+ *\r
+ * If neither of the above points are important to you, then you'll\r
+ * probably just want to stick with the simpler ajaxSubmit() function.\r
+ *\r
+ * Usage examples, similar to ajaxSubmit():\r
+ *\r
+ * 1. Just eval the results returned from the backend.\r
+ *    $('#form-id').ajaxForm();\r
+ *\r
+ * 2. Render backend results directly to target ID (expects (x)HTML).\r
+ *    $('#form-id').ajaxForm('#target-id');\r
+ *\r
+ * 3. Submit to backend URL (form action) then call this function.\r
+ *    $('#form-id').ajaxForm(post_callback);\r
+ *\r
+ * 4. Load target ID with backend results then call a function.\r
+ *    $('#form-id').ajaxForm('#target-id', post_callback);\r
+ *\r
+ * 5. Call a browser function (for validation) and then (optionally)\r
+ *    load server results to target ID.\r
+ *    $('#form-id').ajaxForm('#target-id', null, pre_callback);\r
+ *\r
+ * 6. Call validation function first then load server results to\r
+ *    target ID and then also call a browser function.\r
+ *    $('#form-id').ajaxForm('#target-id', post_callback, pre_callback);\r
+ *\r
+ * @param target   arg for the target id element to render\r
+ * @param post_cb  callback after any results are returned\r
+ * @param pre_cb   callback function before submission\r
+ * @return         the jQuery Object\r
+ * @type jQuery\r
+ * @see            serialize(), ajaxSubmit()\r
+ * @author         Mark Constable (markc@renta.net)\r
+ * @author         G. vd Hoven, Mike Alsup, Sam Collett, John Resig\r
+ */\r
+$.fn.ajaxForm = function(target, post_cb, pre_cb) {\r
+       return this.each(function(){\r
+               $("input[@type=submit],input[@type=image]", this).click(function(ev){\r
+                       this.form.clicked = this;\r
+                       if (ev.offsetX != undefined) {\r
+                               this.form.clicked_x = ev.offsetX;\r
+                               this.form.clicked_y = ev.offsetY;\r
+                       } else {\r
+                               this.form.clicked_x = ev.pageX - this.offsetLeft;\r
+                               this.form.clicked_y = ev.pageY - this.offsetTop;\r
+                       }\r
+               });\r
+       }).submit(function(e){\r
+               $(this).ajaxSubmit(target, post_cb, pre_cb);\r
+               return false;\r
+       });\r
+};\r
+\r
+/**\r
+ * A simple wrapper function that sits around the .serialize()\r
+ * method, allowing you to easily extract the data stored within\r
+ * a form.\r
+ *\r
+ * Usage examples:\r
+ *\r
+ * 1. Serialize the contents of a form to a & and = delmited string:\r
+ *    $.param( $("form").formdata() );\r
+ *\r
+ * @return         An array of name/value pairs representing the form\r
+ * @type Array<Object>\r
+ * @see            serialize()\r
+ # @author         John Resig\r
+ */\r
+$.fn.formdata = function(){\r
+       this.serialize();\r
+       return this.vars;\r
+};\r
+\r
+/**\r
+ * This function gathers form element variables into an array that\r
+ * is embedded into the current "this" variable as "this.vars". It\r
+ * is normally used in conjunction with formdata() or ajaxSubmit() but can\r
+ * be used standalone as long as you don't need the x and y coordinates\r
+ * associated with an <input type="image"/> element..\r
+ *\r
+ * Standalone usage examples:\r
+ *\r
+ * 1. Gather form vars and return array to LHS variable.\r
+ *    var myform = $('#form-id').serialize();\r
+ *\r
+ * 2. Provide a serialized URL-ready string (after 1. above).\r
+ *    var mystring = $.param(myform.vars);\r
+ *\r
+ * 3. Gather form vars and send to RHS plugin via "this.vars".\r
+ *    $('#form-id').serialize().some_other_plugin();\r
+ *\r
+ * @return         the jQuery Object\r
+ * @return jQuery\r
+ * @see            ajaxForm(), ajaxSubmit()\r
+ * @author         Mark Constable (markc@renta.net)\r
+ * @author         G. vd Hoven, Mike Alsup, Sam Collett, John Resig\r
+ */\r
+$.fn.serialize = function() {\r
+       var a = [];\r
+       var ok = {INPUT:true, TEXTAREA:true, OPTION:true};\r
+\r
+       $('*', this).each(function() {\r
+               var par = this.parentNode;\r
+               var p = par.nodeName.toUpperCase();\r
+               var n = this.name || p == 'OPTGROUP' && par.parentNode.name || p == 'SELECT' && par.name || this.id;\r
+\r
+               if ( !n || this.disabled || this.type == 'reset' || \r
+                       (this.type == 'checkbox' || this.type == 'radio') && !this.checked || \r
+                       !ok[this.nodeName.toUpperCase()] ||\r
+                       (this.type == 'submit' || this.type == 'image') && this.form.clicked != this ||\r
+                       (p == 'SELECT' || p == 'OPTGROUP') && !this.selected ) return;\r
+\r
+               if (this.type == 'image' && this.form.clicked_x)\r
+                       return a.push(\r
+                               {name: this.name+'_x', value: this.form.clicked_x},\r
+                               {name: this.name+'_y', value: this.form.clicked_y}\r
+                       );\r
+\r
+               a.push({name: n, value: this.value});\r
+       });\r
+       \r
+       this.vars = a;\r
+\r
+       return this;\r
+};\r