Skip to content

Commit 8b148b0

Browse files
author
GrayYoung
committed
Update to version 1.2.0
Add reset method in clearForm plugin.
1 parent bc259d6 commit 8b148b0

8 files changed

Lines changed: 126 additions & 30 deletions

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"jquery": "jquery#1.11.1",
1818
"bootstrap": "bootstrap#latest"
1919
},
20-
"version" : "1.1.9",
20+
"version" : "1.2.0",
2121
"keywords" : [
2222
"test browser",
2323
"utilities",

dist/jquery.browser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* jQuery.Utilities - Browser
3-
* Version: 1.1.9
3+
* Version: 1.2.0
44
* Author: Gray Young
55
*
66
* Copyright 2016 Released under the MIT license.

dist/jquery.browser.min.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* jQuery.Utilities - Browser
3-
* Version: 1.1.9
3+
* Version: 1.2.0
44
* Author: Gray Young
55
*
66
* Copyright 2016 Released under the MIT license.

dist/jquery.clearForm.js

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* jQuery.Utilities - Clear Form
3-
* Version: 1.1.9
3+
* Version: 1.2.0
44
* Author: Gray Young
55
*
66
* Copyright 2016 Released under the MIT license.
@@ -16,7 +16,7 @@
1616
}
1717
}(function($) {
1818
$.fn.clearForm = function(options) {
19-
var opts = $.extend({}, $.fn.clearForm.defaults, options);
19+
var opts = $.fn.clearForm.defaults;
2020
var _supporType = {
2121
textGroup : [ 'input', 'textarea' ],
2222
unitGroup : [ 'radio', 'checkbox' ],
@@ -30,17 +30,66 @@
3030
};
3131

3232
if ($.inArray(element.type.toLowerCase(), _supporType.unitGroup) >= 0) {
33-
ui.item.prop('checked', false);
33+
ui.item.prop('checked', ui.item.prop('defaultChecked'));
3434
} else if ($.inArray(tagName, _supporType.textGroup) >= 0) {
35-
ui.item.val('');
35+
ui.item.val(ui.item.prop('defaultValue'));
3636
} else if ($.inArray(tagName, _supporType.listGroup) >= 0) {
37-
element.selectedIndex = opts.defaultSelectedIndex;
37+
ui.item.children().each(function(index) {
38+
if(this.defaultSelected) {
39+
ui.item.prop('selectedIndex', index);
40+
return false;
41+
}
42+
});
3843
}
39-
if ($.type(opts.itemCleared) == 'function') {
40-
opts.itemCleared(event, ui);
44+
if ($.type(opts.after) === 'function') {
45+
opts.after(event, ui);
4146
}
4247
};
4348

49+
switch($.type(arguments[0])) {
50+
case 'undefined':
51+
case 'string':
52+
if($.type(arguments[0]) === 'undefined' || arguments[0] === 'reset') {
53+
_clearField = function(element) {
54+
var tagName = element.tagName.toLowerCase();
55+
var event = null, ui = {
56+
item : $(element)
57+
};
58+
59+
if ($.inArray(element.type.toLowerCase(), _supporType.unitGroup) >= 0) {
60+
ui.item.prop('checked', ui.item.prop('defaultChecked'));
61+
} else if ($.inArray(tagName, _supporType.textGroup) >= 0) {
62+
ui.item.val(ui.item.prop('defaultValue'));
63+
} else if ($.inArray(tagName, _supporType.listGroup) >= 0) {
64+
ui.item.children().each(function(index) {
65+
if(this.defaultSelected) {
66+
ui.item.prop('selectedIndex', index);
67+
return false;
68+
}
69+
});
70+
}
71+
if ($.type(opts.after) === 'function') {
72+
opts.after(event, ui);
73+
}
74+
};
75+
} else {
76+
throw new Error(arguments[0] + ' method dosen\'t exist.');
77+
}
78+
break;
79+
case 'object':
80+
opts = $.extend({}, $.fn.clearForm.defaults, options);
81+
break;
82+
default:
83+
throw new Error('Illegal parameter ' + arguments[0]);
84+
}
85+
if(arguments[1]) {
86+
if($.type(arguments[1]) === 'object') {
87+
opts = $.extend({}, $.fn.clearForm.defaults, options);
88+
} else {
89+
throw new Error('Illegal parameter ' + arguments[1]);
90+
}
91+
}
92+
4493
return this.each(function() {
4594
var tagName = this.tagName.toLowerCase();
4695
var event = null, ui = {
@@ -53,16 +102,15 @@
53102
$(':input:not(:' + _supporType.excludeType.join(', :') + ')', this).each(function() {
54103
_clearField(this);
55104
});
56-
if ($.type(opts.cleared) == 'function') {
57-
opts.cleared(event, ui);
105+
if ($.type(opts.complete) === 'function') {
106+
opts.complete(event, ui);
58107
}
59108
}
60109
});
61110
};
62111

63112
$.fn.clearForm.defaults = {
64-
defaultSelectedIndex : 0,
65-
cleared : null,
66-
itemCleared : null
113+
complete: null,
114+
after: null
67115
};
68116
}));

dist/jquery.clearForm.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/jquery.cookie.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* jQuery.Utilities - Cookie
3-
* Version: 1.1.9
3+
* Version: 1.2.0
44
* Author: Gray Young
55
*
66
* Copyright 2016 Released under the MIT license.

dist/jquery.cookie.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/jquery.clearForm.js

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
}
1717
}(function($) {
1818
$.fn.clearForm = function(options) {
19-
var opts = $.extend({}, $.fn.clearForm.defaults, options);
19+
var opts = $.fn.clearForm.defaults;
2020
var _supporType = {
2121
textGroup : [ 'input', 'textarea' ],
2222
unitGroup : [ 'radio', 'checkbox' ],
@@ -30,17 +30,66 @@
3030
};
3131

3232
if ($.inArray(element.type.toLowerCase(), _supporType.unitGroup) >= 0) {
33-
ui.item.prop('checked', false);
33+
ui.item.prop('checked', ui.item.prop('defaultChecked'));
3434
} else if ($.inArray(tagName, _supporType.textGroup) >= 0) {
35-
ui.item.val('');
35+
ui.item.val(ui.item.prop('defaultValue'));
3636
} else if ($.inArray(tagName, _supporType.listGroup) >= 0) {
37-
element.selectedIndex = opts.defaultSelectedIndex;
37+
ui.item.children().each(function(index) {
38+
if(this.defaultSelected) {
39+
ui.item.prop('selectedIndex', index);
40+
return false;
41+
}
42+
});
3843
}
39-
if ($.type(opts.itemCleared) == 'function') {
40-
opts.itemCleared(event, ui);
44+
if ($.type(opts.after) === 'function') {
45+
opts.after(event, ui);
4146
}
4247
};
4348

49+
switch($.type(arguments[0])) {
50+
case 'undefined':
51+
case 'string':
52+
if($.type(arguments[0]) === 'undefined' || arguments[0] === 'reset') {
53+
_clearField = function(element) {
54+
var tagName = element.tagName.toLowerCase();
55+
var event = null, ui = {
56+
item : $(element)
57+
};
58+
59+
if ($.inArray(element.type.toLowerCase(), _supporType.unitGroup) >= 0) {
60+
ui.item.prop('checked', ui.item.prop('defaultChecked'));
61+
} else if ($.inArray(tagName, _supporType.textGroup) >= 0) {
62+
ui.item.val(ui.item.prop('defaultValue'));
63+
} else if ($.inArray(tagName, _supporType.listGroup) >= 0) {
64+
ui.item.children().each(function(index) {
65+
if(this.defaultSelected) {
66+
ui.item.prop('selectedIndex', index);
67+
return false;
68+
}
69+
});
70+
}
71+
if ($.type(opts.after) === 'function') {
72+
opts.after(event, ui);
73+
}
74+
};
75+
} else {
76+
throw new Error(arguments[0] + ' method dosen\'t exist.');
77+
}
78+
break;
79+
case 'object':
80+
opts = $.extend({}, $.fn.clearForm.defaults, options);
81+
break;
82+
default:
83+
throw new Error('Illegal parameter ' + arguments[0]);
84+
}
85+
if(arguments[1]) {
86+
if($.type(arguments[1]) === 'object') {
87+
opts = $.extend({}, $.fn.clearForm.defaults, options);
88+
} else {
89+
throw new Error('Illegal parameter ' + arguments[1]);
90+
}
91+
}
92+
4493
return this.each(function() {
4594
var tagName = this.tagName.toLowerCase();
4695
var event = null, ui = {
@@ -53,16 +102,15 @@
53102
$(':input:not(:' + _supporType.excludeType.join(', :') + ')', this).each(function() {
54103
_clearField(this);
55104
});
56-
if ($.type(opts.cleared) == 'function') {
57-
opts.cleared(event, ui);
105+
if ($.type(opts.complete) === 'function') {
106+
opts.complete(event, ui);
58107
}
59108
}
60109
});
61110
};
62111

63112
$.fn.clearForm.defaults = {
64-
defaultSelectedIndex : 0,
65-
cleared : null,
66-
itemCleared : null
113+
complete: null,
114+
after: null
67115
};
68116
}));

0 commit comments

Comments
 (0)