Skip to content

Commit 1ef6f61

Browse files
committed
chore: merge jquery-form history into third-party/projects/
In service of: #394 Basically, we want to pull in the code from this third-party project (which is mostly on life-support at this point) and apply a small patch on top. We don't anticipate having to change it much, if ever, so we are sticking it under "third-party/projects/" and we won't cover it with our normal linting/formatting/testing. Note that because everything else in the repo pulls in history via subtree merge, doing it here as well. That way if we ever need to `git blame` in here we'll have something useful to look at. Note also that in liferay-portal we are using v3.51 of this plugin and have no plans to switch to the latest (v4.3.0) at this time, but I am still pulling in and re-writing all of the tags so that we can easily merge the newer stuff in in the future if we want to. Steps follow. Grab the code: git remote add -f jquery-form https://github.com/jquery-form/form.git Make directory for it. Note that it is going to live at "third-party/projects/jquery-form/" and not "third-party/jquery-form/"; we want to reserve the top-level inside of "third-party/" for any future tooling that we might want to share across projects, or any common READMEs or other docs: mkdir -p third-party/projects Create annotated tags seeing as all the tags in the project are unannotated: for TAG in \ 3.25.0-2013.01.18 \ 3.32.0-2013.04.09 \ 3.36 \ 3.37.0 \ 3.45.0 \ 3.46.0 \ 3.49 \ 3.50 \ 3.51; do git tag -f -a -m jquery-form/v$TAG $TAG $TAG done for TAG in \ v3.19 \ v4.0.0 \ v4.0.1 \ v4.1.0 \ v4.2.0 \ v4.2.1 \ v4.2.2 \ v4.3.0; do git tag -f -a -m jquery-form/$TAG $TAG $TAG done Rewrite tags to have a prefix. First tags starting with "v" and then those without a leading "v": support/filter-tags.sh jquery-form/master 'sed "s#^v#jquery-form/v#"' support/filter-tags.sh jquery-form/master 'sed "s#^\([0-9]\)#jquery-form/v\1#"' Do the actual subtree merge: git merge -s ours --no-commit --allow-unrelated-histories jquery-form/v3.51 git read-tree --prefix=third-party/projects/jquery-form -u jquery-form/v3.51 git commit -m 'chore: merge jquery-form history into third-party/projects/' Make sure shape of DAG is sane: git log --oneline --decorate --graph --all Push rewritten tags so that entire history will be reachable/explorable: git push upstream-rw --tags --dry-run git push upstream-rw --tags Kill temporary remote that was added earlier. We don't want this lying around because a careless `fetch` could pull down all the tags that we don't want (because they aren't prefixed, or annotated, or even consistent), and it is all too easy to accidentally contaminate the upstream with these tags by a push. If we ever need to resync with upstream history again, we can just re-add the remote: git remote remove jquery-form Amend commit to make these notes that you're reading now: git commit --amend
2 parents c473044 + 6bf24a5 commit 1ef6f61

File tree

7 files changed

+1636
-0
lines changed

7 files changed

+1636
-0
lines changed
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
#[jQuery Form Plugin](http://jquery.malsup.com/form/)
2+
3+
##Overview
4+
The jQuery Form Plugin allows you to easily and unobtrusively upgrade HTML forms to use AJAX. The main methods, ajaxForm and ajaxSubmit, gather information from the form element to determine how to manage the submit process. Both of these methods support numerous options which allows you to have full control over how the data is submitted.
5+
6+
No special markup is needed, just a normal form. Submitting a form with AJAX doesn't get any easier than this!
7+
8+
---
9+
10+
##API
11+
12+
###jqXHR
13+
The jqXHR object is stored in element <em>data</em>-cache with the <code>jqxhr</code> key after each <code>ajaxSubmit</code>
14+
call. It can be accessed like this:
15+
````javascript
16+
var form = $('#myForm').ajaxSubmit({ /* options */ });
17+
var xhr = form.data('jqxhr');
18+
19+
xhr.done(function() {
20+
...
21+
});
22+
````
23+
24+
###ajaxForm( options )
25+
Prepares a form to be submitted via AJAX by adding all of the necessary event listeners. It does **not** submit the form. Use `ajaxForm` in your document's `ready` function to prepare existing forms for AJAX submission, or with the `delegation` option to handle forms not yet added to the DOM.
26+
Use ajaxForm when you want the plugin to manage all the event binding for you.
27+
28+
````javascript
29+
// prepare all forms for ajax submission
30+
$('form').ajaxForm({
31+
target: '#myResultsDiv'
32+
});
33+
````
34+
35+
###ajaxSubmit( options )
36+
Immediately submits the form via AJAX. In the most common use case this is invoked in response to the user clicking a submit button on the form.
37+
Use ajaxSubmit if you want to bind your own submit handler to the form.
38+
39+
````javascript
40+
// bind submit handler to form
41+
$('form').on('submit', function(e) {
42+
e.preventDefault(); // prevent native submit
43+
$(this).ajaxSubmit({
44+
target: 'myResultsDiv'
45+
})
46+
});
47+
````
48+
49+
---
50+
51+
##Options
52+
Note: all standard [$.ajax](http://api.jquery.com/jQuery.ajax) options can be used.
53+
54+
###beforeSerialize
55+
Callback function invoked prior to form serialization. Provides an opportunity to manipulate the form before its values are retrieved. Returning `false` from the callback will prevent the form from being submitted. The callback is invoked with two arguments: the jQuery wrapped form object and the options object.
56+
57+
````javascript
58+
beforeSerialize: function($form, options) {
59+
// return false to cancel submit
60+
}
61+
````
62+
63+
###beforeSubmit
64+
Callback function invoked prior to form submission. This provides an opportunity to manipulate the form before it's values are retrieved. Returning `false` from the callback will prevent the form from being submitted. The callback is invoked with three arguments: the form data in array format, the jQuery wrapped form object, and the options Oobject.
65+
66+
````javascript
67+
beforeSubmit: function(arr, $form, options) {
68+
// form data array is an array of objects with name and value properties
69+
// [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]
70+
// return false to cancel submit
71+
}
72+
````
73+
74+
###clearForm
75+
Boolean flag indicating whether the form should be cleared if the submit is successful
76+
77+
###data
78+
An object containing extra data that should be submitted along with the form.
79+
80+
````javascript
81+
data: { key1: 'value1', key2: 'value2' }
82+
````
83+
84+
###dataType
85+
Expected data type of the response. One of: null, 'xml', 'script', or 'json'. The dataType option provides a means for specifying how the server response should be handled. This maps directly to jQuery's dataType method. The following values are supported:
86+
87+
* 'xml': server response is treated as XML and the 'success' callback method, if specified, will be passed the responseXML value
88+
* 'json': server response will be evaluted and passed to the 'success' callback, if specified
89+
* 'script': server response is evaluated in the global context
90+
91+
###delegation
92+
true to enable support for event delegation
93+
*requires jQuery v1.7+*
94+
95+
````javascript
96+
// prepare all existing and future forms for ajax submission
97+
$('form').ajaxForm({
98+
delegation: true
99+
});
100+
````
101+
102+
###error
103+
Callback function to be invoked upon error.
104+
105+
###forceSync
106+
Only applicable when explicity using the iframe option or when uploading files on browses that don't support XHR2.
107+
Set to `true` to remove the short delay before posting form when uploading files. The delay is used to allow the browser to render DOM updates prior to performing a native form submit. This improves usability when displaying notifications to the user, such as "Please Wait..."
108+
109+
###iframe
110+
Boolean flag indicating whether the form should *always* target the server response to an iframe instead of leveraging XHR when possible.
111+
112+
###iframeSrc
113+
String value that should be used for the iframe's src attribute when/if an iframe is used.
114+
115+
###iframeTarget
116+
Identifies the iframe element to be used as the response target for file uploads. By default, the plugin will create a temporary iframe element to capture the response when uploading files. This options allows you to use an existing iframe if you wish. When using this option the plugin will make no attempt at handling the response from the server.
117+
118+
###replaceTarget
119+
Optionally used along with the the target option. Set to true if the target should be replaced or false if only the target contents should be replaced.
120+
121+
###resetForm
122+
Boolean flag indicating whether the form should be reset if the submit is successful
123+
124+
###semantic
125+
Boolean flag indicating whether data must be submitted in strict semantic order (slower). Note that the normal form serialization is done in semantic order with the exception of input elements of `type="image"`. You should only set the semantic option to true if your server has strict semantic requirements and your form contains an input element of `type="image"`.
126+
127+
###success
128+
Callback function to be invoked after the form has been submitted. If a `success` callback function is provided it is invoked after the response has been returned from the server. It is passed the following arguments:
129+
130+
1. responseText or responseXML value (depending on the value of the dataType option).
131+
2. statusText
132+
3. xhr (or the jQuery-wrapped form element if using jQuery < 1.4)
133+
4. jQuery-wrapped form element (or undefined if using jQuery < 1.4)
134+
135+
###target
136+
Identifies the element(s) in the page to be updated with the server response. This value may be specified as a jQuery selection string, a jQuery object, or a DOM element.
137+
138+
###type
139+
The method in which the form data should be submitted, 'GET' or 'POST'.
140+
141+
###uploadProgress
142+
Callback function to be invoked with upload progress information (if supported by the browser). The callback is passed the following arguments:
143+
144+
1. event; the browser event
145+
2. position (integer)
146+
3. total (integer)
147+
4. percentComplete (integer)
148+
149+
###url
150+
URL to which the form data will be submitted.
151+
152+
---
153+
154+
##Utility Methods
155+
###formSerialize
156+
Serializes the form into a query string. This method will return a string in the format: `name1=value1&name2=value2`
157+
158+
````javascript
159+
var queryString = $('#myFormId').formSerialize();
160+
````
161+
162+
###fieldSerialize
163+
Serializes field elements into a query string. This is handy when you need to serialize only part of a form. This method will return a string in the format: `name1=value1&name2=value2`
164+
165+
````javascript
166+
var queryString = $('#myFormId .specialFields').fieldSerialize();
167+
````
168+
169+
###fieldValue
170+
Returns the value(s) of the element(s) in the matched set in an array. This method always returns an array. If no valid value can be determined the array will be empty, otherwise it will contain one or more values.
171+
172+
###resetForm
173+
Resets the form to its original state by invoking the form element's native DOM method.
174+
175+
###clearForm
176+
Clears the form elements. This method emptys all of the text inputs, password inputs and textarea elements, clears the selection in any select elements, and unchecks all radio and checkbox inputs. It does *not* clear hidden field values.
177+
178+
###clearFields
179+
Clears selected field elements. This is handy when you need to clear only a part of the form.
180+
181+
---
182+
183+
##File Uploads
184+
The Form Plugin supports use of [XMLHttpRequest Level 2]("http://www.w3.org/TR/XMLHttpRequest/") and [FormData](https://developer.mozilla.org/en/XMLHttpRequest/FormData) objects on browsers that support these features. As of today (March 2012) that includes Chrome, Safari, and Firefox. On these browsers (and future Opera and IE10) files uploads will occur seamlessly through the XHR object and progress updates are available as the upload proceeds. For older browsers, a fallback technology is used which involves iframes. [More Info](http://malsup.com/jquery/form/#file-upload)
185+
186+
---
187+
188+
##CDN Support
189+
`<script src="//oss.maxcdn.com/jquery.form/3.50/jquery.form.min.js"></script>`
190+
191+
##Copyright and License
192+
Copyright 2006-2013 (c) M. Alsup
193+
194+
All versions, present and past, of the jQuery Form plugin are dual licensed under the MIT and GPL licenses:
195+
196+
* [MIT](http://malsup.github.com/mit-license.txt)
197+
* [GPL](http://malsup.github.com/gpl-license-v2.txt)
198+
199+
You may use either license. The MIT License is recommended for most projects because it is simple and easy to understand and it places almost no restrictions on what you can do with the plugin.
200+
201+
If the GPL suits your project better you are also free to use the plugin under that license.
202+
203+
You don't have to do anything special to choose one license or the other and you don't have to notify anyone which license you are using. You are free to use the jQuery Form Plugin in commercial projects as long as the copyright header is left intact.
204+
205+
206+
---
207+
208+
Additional documentation and examples at: http://malsup.com/jquery/form/
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "jquery-form",
3+
"version": "3.51.0",
4+
"main": "jquery.form.js",
5+
"author": "M. Alsup",
6+
"dependencies": {
7+
"jquery": ">=1.5"
8+
},
9+
"ignore": [
10+
"README.md",
11+
"composer.json",
12+
"form.jquery.json",
13+
"package.json"
14+
]
15+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "malsup/form",
3+
"description": "A simple way to AJAX-ify any form on your page; with file upload and progress support.",
4+
"type": "component",
5+
"homepage": "http://jquery.malsup.com/form/",
6+
"keywords": [
7+
"form",
8+
"upload",
9+
"ajax"
10+
],
11+
"support": {
12+
"issues": "https://github.com/malsup/form/issues",
13+
"wiki": "http://jquery.malsup.com/form/"
14+
},
15+
"authors": [
16+
{
17+
"name": "M. Alsup",
18+
"homepage": "http://jquery.malsup.com"
19+
}
20+
],
21+
"license": [
22+
"MIT",
23+
"GPL-2.0"
24+
],
25+
"require": {
26+
"components/jquery": ">=1.5"
27+
},
28+
"extra": {
29+
"component": {
30+
"scripts": [
31+
"jquery.form.js"
32+
],
33+
"shim": {
34+
"deps": [
35+
"jquery"
36+
]
37+
}
38+
}
39+
}
40+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "form",
3+
"title": "Form",
4+
"description": "A simple way to AJAX-ify any form on your page; with file upload and progress support.",
5+
"keywords": [
6+
"form",
7+
"upload",
8+
"ajax"
9+
],
10+
"version": "3.51.0",
11+
"author": {
12+
"name": "M. Alsup",
13+
"url": "http://jquery.malsup.com"
14+
},
15+
"licenses": [
16+
{
17+
"type": "MIT",
18+
"url": "http://malsup.github.com/mit-license.txt"
19+
},
20+
{
21+
"type": "GPL",
22+
"url": "http://malsup.github.com/gpl-license-v2.txt"
23+
}
24+
],
25+
"bugs": "https://github.com/malsup/form/issues",
26+
"homepage": "http://jquery.malsup.com/form/",
27+
"docs": "http://jquery.malsup.com/form/",
28+
"download": "http://malsup.github.com/jquery.form.js",
29+
"dependencies": {
30+
"jquery": ">=1.5"
31+
}
32+
}
33+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* buildfile for jquery.form plugin */
2+
var gulp = require('gulp'),
3+
concat = require('gulp-concat'),
4+
jshint = require('gulp-jshint'),
5+
uglify = require('gulp-uglify');
6+
7+
gulp.task('default', function() {
8+
gulp.src(['jquery.form.js'])
9+
.pipe(jshint())
10+
.pipe(jshint.reporter('default'))
11+
.pipe(uglify({ preserveComments: 'some' }))
12+
.pipe(concat('jquery.form.min.js'))
13+
.pipe(gulp.dest('.'));
14+
});
15+
16+
gulp.task('watch', function () {
17+
gulp.watch('jquery.form.js', ['default']);
18+
});

0 commit comments

Comments
 (0)