Skip to content

Commit 6c72f5c

Browse files
committed
Add gruntfile and cleanup.
1 parent 5a69c7f commit 6c72f5c

File tree

3 files changed

+141
-48
lines changed

3 files changed

+141
-48
lines changed

Gruntfile.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*global module:false*/
2+
module.exports = function(grunt) {
3+
"use strict";
4+
5+
// Project configuration.
6+
grunt.initConfig({
7+
8+
plugin: {
9+
file: 'jquery.form.js'
10+
},
11+
12+
uglify: {
13+
core: {
14+
options: {
15+
banner: '/*\n* jQuery Form Plugin; v<%= grunt.template.today("yyyymmdd") %>\n' +
16+
'* http://jquery.malsup.com/form/\n' +
17+
'* Copyright (c) <%= grunt.template.today("yyyy") %> M. Alsup; Dual licensed: MIT/GPL\n' +
18+
'* https://github.com/malsup/form#copyright-and-license\n' +
19+
'*/\n;'
20+
},
21+
files: {
22+
'jquery.form.min.js': [ '<%= plugin.file %>' ]
23+
}
24+
}
25+
},
26+
27+
jshint: {
28+
files: [ '<%= plugin.file %>' ],
29+
options: {
30+
curly: true
31+
}
32+
},
33+
34+
watch: {
35+
files: [ '<%= plugin.file %>' ],
36+
tasks: 'jshint'
37+
}
38+
39+
});
40+
41+
grunt.loadNpmTasks('grunt-contrib-jshint');
42+
grunt.loadNpmTasks('grunt-contrib-uglify');
43+
grunt.loadNpmTasks('grunt-contrib-watch');
44+
45+
grunt.registerTask('default', [ 'jshint', 'uglify' ]);
46+
};

jquery.form.js

Lines changed: 89 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
* jQuery Form Plugin
3-
* version: 3.47.0-2013.12.27
3+
* version: 3.48.0-2013.12.28
44
* Requires jQuery v1.5 or later
55
* Copyright (c) 2013 M. Alsup
66
* Examples and documentation at: http://malsup.com/jquery/form/
@@ -76,11 +76,13 @@ var hasProp = !!$.fn.prop;
7676
// contains inputs with names like "action" or "method"; in those
7777
// cases "prop" returns the element
7878
$.fn.attr2 = function() {
79-
if ( ! hasProp )
79+
if ( ! hasProp ) {
8080
return this.attr.apply(this, arguments);
81+
}
8182
var val = this.prop.apply(this, arguments);
82-
if ( ( val && val.jquery ) || typeof val === 'string' )
83+
if ( ( val && val.jquery ) || typeof val === 'string' ) {
8384
return val;
85+
}
8486
return this.attr.apply(this, arguments);
8587
};
8688

@@ -258,8 +260,9 @@ $.fn.ajaxSubmit = function(options) {
258260
$form.removeData('jqxhr').data('jqxhr', jqxhr);
259261

260262
// clear element array
261-
for (var k=0; k < elements.length; k++)
263+
for (var k=0; k < elements.length; k++) {
262264
elements[k] = null;
265+
}
263266

264267
// fire 'notify' event
265268
this.trigger('form-submit-notify', [this, options]);
@@ -291,9 +294,11 @@ $.fn.ajaxSubmit = function(options) {
291294

292295
if (options.extraData) {
293296
var serializedData = deepSerialize(options.extraData);
294-
for (i=0; i < serializedData.length; i++)
295-
if (serializedData[i])
297+
for (i=0; i < serializedData.length; i++) {
298+
if (serializedData[i]) {
296299
formdata.append(serializedData[i][0], serializedData[i][1]);
300+
}
301+
}
297302
}
298303

299304
options.data = null;
@@ -328,12 +333,15 @@ $.fn.ajaxSubmit = function(options) {
328333
var beforeSend = s.beforeSend;
329334
s.beforeSend = function(xhr, o) {
330335
//Send FormData() provided by user
331-
if (options.formData)
336+
if (options.formData) {
332337
o.data = options.formData;
333-
else
338+
}
339+
else {
334340
o.data = formdata;
335-
if(beforeSend)
341+
}
342+
if(beforeSend) {
336343
beforeSend.call(this, xhr, o);
344+
}
337345
};
338346
return $.ajax(s);
339347
}
@@ -352,10 +360,12 @@ $.fn.ajaxSubmit = function(options) {
352360
// ensure that every serialized input is still enabled
353361
for (i=0; i < elements.length; i++) {
354362
el = $(elements[i]);
355-
if ( hasProp )
363+
if ( hasProp ) {
356364
el.prop('disabled', false);
357-
else
365+
}
366+
else {
358367
el.removeAttr('disabled');
368+
}
359369
}
360370
}
361371

@@ -365,10 +375,12 @@ $.fn.ajaxSubmit = function(options) {
365375
if (s.iframeTarget) {
366376
$io = $(s.iframeTarget);
367377
n = $io.attr2('name');
368-
if (!n)
369-
$io.attr2('name', id);
370-
else
378+
if (!n) {
379+
$io.attr2('name', id);
380+
}
381+
else {
371382
id = n;
383+
}
372384
}
373385
else {
374386
$io = $('<iframe name="' + id + '" src="'+ s.iframeSrc +'" />');
@@ -400,12 +412,15 @@ $.fn.ajaxSubmit = function(options) {
400412

401413
$io.attr('src', s.iframeSrc); // abort op in progress
402414
xhr.error = e;
403-
if (s.error)
415+
if (s.error) {
404416
s.error.call(s.context, xhr, e, status);
405-
if (g)
417+
}
418+
if (g) {
406419
$.event.trigger("ajaxError", [xhr, s, e]);
407-
if (s.complete)
420+
}
421+
if (s.complete) {
408422
s.complete.call(s.context, xhr, e);
423+
}
409424
}
410425
};
411426

@@ -524,14 +539,16 @@ $.fn.ajaxSubmit = function(options) {
524539
try {
525540
var state = getDoc(io).readyState;
526541
log('state = ' + state);
527-
if (state && state.toLowerCase() == 'uninitialized')
542+
if (state && state.toLowerCase() == 'uninitialized') {
528543
setTimeout(checkState,50);
544+
}
529545
}
530546
catch(e) {
531547
log('Server abort: ' , e, ' (', e.name, ')');
532548
cb(SERVER_ABORT);
533-
if (timeoutHandle)
549+
if (timeoutHandle) {
534550
clearTimeout(timeoutHandle);
551+
}
535552
timeoutHandle = undefined;
536553
}
537554
}
@@ -560,10 +577,12 @@ $.fn.ajaxSubmit = function(options) {
560577
// add iframe to doc and submit the form
561578
$io.appendTo('body');
562579
}
563-
if (io.attachEvent)
580+
if (io.attachEvent) {
564581
io.attachEvent('onload', cb);
565-
else
582+
}
583+
else {
566584
io.addEventListener('load', cb, false);
585+
}
567586
setTimeout(checkState,15);
568587

569588
try {
@@ -619,13 +638,16 @@ $.fn.ajaxSubmit = function(options) {
619638

620639
if (!doc || doc.location.href == s.iframeSrc) {
621640
// response not received yet
622-
if (!timedOut)
641+
if (!timedOut) {
623642
return;
643+
}
624644
}
625-
if (io.detachEvent)
645+
if (io.detachEvent) {
626646
io.detachEvent('onload', cb);
627-
else
647+
}
648+
else {
628649
io.removeEventListener('load', cb, false);
650+
}
629651

630652
var status = 'success', errMsg;
631653
try {
@@ -652,8 +674,9 @@ $.fn.ajaxSubmit = function(options) {
652674
var docRoot = doc.body ? doc.body : doc.documentElement;
653675
xhr.responseText = docRoot ? docRoot.innerHTML : null;
654676
xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc;
655-
if (isXml)
677+
if (isXml) {
656678
s.dataType = 'xml';
679+
}
657680
xhr.getResponseHeader = function(header){
658681
var headers = {'content-type': s.dataType};
659682
return headers[header.toLowerCase()];
@@ -716,42 +739,52 @@ $.fn.ajaxSubmit = function(options) {
716739

717740
// ordering of these callbacks/triggers is odd, but that's how $.ajax does it
718741
if (status === 'success') {
719-
if (s.success)
742+
if (s.success) {
720743
s.success.call(s.context, data, 'success', xhr);
744+
}
721745
deferred.resolve(xhr.responseText, 'success', xhr);
722-
if (g)
746+
if (g) {
723747
$.event.trigger("ajaxSuccess", [xhr, s]);
748+
}
724749
}
725750
else if (status) {
726-
if (errMsg === undefined)
751+
if (errMsg === undefined) {
727752
errMsg = xhr.statusText;
728-
if (s.error)
753+
}
754+
if (s.error) {
729755
s.error.call(s.context, xhr, status, errMsg);
756+
}
730757
deferred.reject(xhr, 'error', errMsg);
731-
if (g)
758+
if (g) {
732759
$.event.trigger("ajaxError", [xhr, s, errMsg]);
760+
}
733761
}
734762

735-
if (g)
763+
if (g) {
736764
$.event.trigger("ajaxComplete", [xhr, s]);
765+
}
737766

738767
if (g && ! --$.active) {
739768
$.event.trigger("ajaxStop");
740769
}
741770

742-
if (s.complete)
771+
if (s.complete) {
743772
s.complete.call(s.context, xhr, status);
773+
}
744774

745775
callbackProcessed = true;
746-
if (s.timeout)
776+
if (s.timeout) {
747777
clearTimeout(timeoutHandle);
778+
}
748779

749780
// clean up
750781
setTimeout(function() {
751-
if (!s.iframeTarget)
782+
if (!s.iframeTarget) {
752783
$io.remove();
753-
else //adding else to clean up existing iframe response.
784+
}
785+
else { //adding else to clean up existing iframe response.
754786
$io.attr('src', s.iframeSrc);
787+
}
755788
xhr.responseXML = null;
756789
}, 100);
757790
}
@@ -779,8 +812,9 @@ $.fn.ajaxSubmit = function(options) {
779812
data = xml ? xhr.responseXML : xhr.responseText;
780813

781814
if (xml && data.documentElement.nodeName === 'parsererror') {
782-
if ($.error)
815+
if ($.error) {
783816
$.error('parsererror');
817+
}
784818
}
785819
if (s && s.dataFilter) {
786820
data = s.dataFilter(data, type);
@@ -916,14 +950,16 @@ $.fn.formToArray = function(semantic, elements) {
916950
var els = semantic ? form.getElementsByTagName('*') : form.elements;
917951
var els2;
918952

919-
if ( els )
953+
if ( els ) {
920954
els = $(els).get(); // convert to standard array
955+
}
921956

922957
// #386; account for inputs outside the form which use the 'form' attribute
923958
if ( formId ) {
924959
els2 = $(':input[form=' + formId + ']').get();
925-
if ( els2.length )
960+
if ( els2.length ) {
926961
els = (els || []).concat(els2);
962+
}
927963
}
928964

929965
if (!els || !els.length) {
@@ -949,15 +985,17 @@ $.fn.formToArray = function(semantic, elements) {
949985

950986
v = $.fieldValue(el, true);
951987
if (v && v.constructor == Array) {
952-
if (elements)
988+
if (elements) {
953989
elements.push(el);
990+
}
954991
for(j=0, jmax=v.length; j < jmax; j++) {
955992
a.push({name: n, value: v[j]});
956993
}
957994
}
958995
else if (feature.fileapi && el.type == 'file') {
959-
if (elements)
996+
if (elements) {
960997
elements.push(el);
998+
}
961999
var files = el.files;
9621000
if (files.length) {
9631001
for (j=0; j < files.length; j++) {
@@ -970,8 +1008,9 @@ $.fn.formToArray = function(semantic, elements) {
9701008
}
9711009
}
9721010
else if (v !== null && typeof v != 'undefined') {
973-
if (elements)
1011+
if (elements) {
9741012
elements.push(el);
1013+
}
9751014
a.push({name: n, value: v, type: el.type, required: el.required});
9761015
}
9771016
}
@@ -1067,10 +1106,12 @@ $.fn.fieldValue = function(successful) {
10671106
if (v === null || typeof v == 'undefined' || (v.constructor == Array && !v.length)) {
10681107
continue;
10691108
}
1070-
if (v.constructor == Array)
1109+
if (v.constructor == Array) {
10711110
$.merge(val, v);
1072-
else
1111+
}
1112+
else {
10731113
val.push(v);
1114+
}
10741115
}
10751116
return val;
10761117
};
@@ -1104,7 +1145,7 @@ $.fieldValue = function(el, successful) {
11041145
if (op.selected) {
11051146
var v = op.value;
11061147
if (!v) { // extra pain for IE...
1107-
v = (op.attributes && op.attributes['value'] && !(op.attributes['value'].specified)) ? op.text : op.value;
1148+
v = (op.attributes && op.attributes.value && !(op.attributes.value.specified)) ? op.text : op.value;
11081149
}
11091150
if (one) {
11101151
return v;
@@ -1160,8 +1201,9 @@ $.fn.clearFields = $.fn.clearInputs = function(includeHidden) {
11601201
// $('#myForm').clearForm('.special:hidden')
11611202
// the above would clean hidden inputs that have the class of 'special'
11621203
if ( (includeHidden === true && /hidden/.test(t)) ||
1163-
(typeof includeHidden == 'string' && $(this).is(includeHidden)) )
1204+
(typeof includeHidden == 'string' && $(this).is(includeHidden)) ) {
11641205
this.value = '';
1206+
}
11651207
}
11661208
});
11671209
};
@@ -1220,8 +1262,9 @@ $.fn.ajaxSubmit.debug = false;
12201262

12211263
// helper fn for console logging
12221264
function log() {
1223-
if (!$.fn.ajaxSubmit.debug)
1265+
if (!$.fn.ajaxSubmit.debug) {
12241266
return;
1267+
}
12251268
var msg = '[jquery.form] ' + Array.prototype.join.call(arguments,'');
12261269
if (window.console && window.console.log) {
12271270
window.console.log(msg);

0 commit comments

Comments
 (0)