Skip to content

Commit c001a81

Browse files
committed
Core library splitted into several files
1 parent 9b79aea commit c001a81

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+5678
-854
lines changed

Gruntfile.js

Lines changed: 54 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
1+
2+
const SRC_DIR = './form-validator/src/';
3+
const MODULE_DIR = './form-validator/';
4+
const LANG_DIR = './form-validator/lang/';
5+
const MAIN_PLUGIN_FILE = 'form-validator/jquery.form-validator.min.js';
6+
const JS_EXTENSION = '.js';
7+
const DEV_EXTENSION = '.dev.js';
8+
19
var fs = require('fs'),
210
filesToBuild = {
311
uglify: {},
4-
concat: {},
12+
concat: {
13+
main:{
14+
src:[SRC_DIR+'core-validators.js'],
15+
dest: MAIN_PLUGIN_FILE
16+
}
17+
},
518
devFiles: []
619
},
20+
isJavascriptFile = function(fileName) {
21+
return fileName.substr(-3) == JS_EXTENSION;
22+
},
23+
isDevFile = function(fileName) {
24+
return fileName.substr(-1 * DEV_EXTENSION.length) == DEV_EXTENSION;
25+
},
726
readFile = function (file) {
827
return fs.readFileSync(file, 'utf-8');
928
},
@@ -13,20 +32,29 @@ var fs = require('fs'),
1332

1433
module.exports = function (grunt) {
1534

16-
// Gather up all js files
17-
['form-validator/', 'form-validator/lang/'].forEach(function (path) {
35+
// Gather up all module and language files
36+
[MODULE_DIR, LANG_DIR].forEach(function (path) {
1837
fs.readdirSync(path).forEach(function (fileName) {
19-
if (fileName.substr(-7) == '.dev.js') {
20-
var name = fileName.substr(0, fileName.length - 7);
21-
filesToBuild.uglify[path + name + '.js'] = [path + name + '.js'];
38+
if (isDevFile(fileName)) {
39+
var name = fileName.substr(0, fileName.length - DEV_EXTENSION.length),
40+
fullPath = path + name + JS_EXTENSION;
41+
42+
filesToBuild.uglify[fullPath] = [fullPath];
2243
filesToBuild.concat['file' + name] = {
2344
src: [path + fileName],
24-
dest: path + name + '.js'
45+
dest: path + name + JS_EXTENSION
2546
};
2647
filesToBuild.devFiles.push(path + fileName);
2748
}
2849
});
2950
});
51+
// Gather up all source files that will added to minified core library
52+
fs.readdirSync(SRC_DIR).forEach(function (fileName) {
53+
var fullPath = SRC_DIR + fileName;
54+
if (isJavascriptFile(fileName) && filesToBuild.concat.main.src.indexOf(fullPath) == -1) {
55+
filesToBuild.concat.main.src.unshift(fullPath);
56+
}
57+
});
3058

3159
// Add options for concat ang ugligy
3260
filesToBuild.concat.options = {
@@ -36,12 +64,8 @@ module.exports = function (grunt) {
3664
banner: "<%= meta.banner %>"
3765
};
3866

39-
// Add main script to concat/uglify
40-
filesToBuild.uglify['form-validator/jquery.form-validator.min.js'] = 'form-validator/jquery.form-validator.min.js';
41-
filesToBuild.concat.main = {
42-
src: ['form-validator/jquery.form-validator.js', 'form-validator/jquery.form-validator-default.js'],
43-
dest: 'form-validator/jquery.form-validator.min.js'
44-
};
67+
// Add main script to uglify
68+
// filesToBuild.uglify[MAIN_PLUGIN_FILE] = MAIN_PLUGIN_FILE;
4569

4670
grunt.initConfig({
4771

@@ -59,14 +83,12 @@ module.exports = function (grunt) {
5983
" */\n"
6084
},
6185

62-
// Concat definitions. The only purpose of this
63-
// is to create a distribution file out
64-
// of files name *.dev.js
86+
// Concat definitions.
6587
concat: filesToBuild.concat,
6688

6789
// Lint definitions
6890
jshint: {
69-
files: ["form-validator/*.dev.js", "form-validator/jquery.form-validator.js"],
91+
files: [MODULE_DIR+"*"+DEV_EXTENSION, SRC_DIR+"*.js"],
7092
options: {
7193
jshintrc: ".jshintrc"
7294
}
@@ -79,15 +101,17 @@ module.exports = function (grunt) {
79101
// Better than calling grunt a million times
80102
// (call 'grunt watch')
81103
watch: {
82-
files: ['form-validator/*'],
104+
files: [SRC_DIR+'/*', LANG_DIR+'/*', MODULE_DIR+'/*'],
83105
tasks: ['build'],
84106
options : { nospawn : true }
85107
},
86108

109+
// Unit tests
87110
qunit: {
88111
all: ['test/qunit.html']
89112
},
90113

114+
// Standalone servers
91115
connect: {
92116
server: {
93117
options: {
@@ -117,16 +141,23 @@ module.exports = function (grunt) {
117141
}
118142

119143
grunt.log.writeln('* Moving from version ' + currentVersion + ' to ' + newVersion);
144+
var fromVersion = '@version ' + currentVersion,
145+
toVersion = '@version ' + newVersion;
146+
120147

121148
// replace version in config files and dev-files
122-
replaceInFile('form-validator/jquery.form-validator.min.js', '@version ' + currentVersion, '@version ' + newVersion);
123-
replaceInFile('form-validator/jquery.form-validator.js', '@version ' + currentVersion, '@version ' + newVersion);
124-
replaceInFile('package.json', '"version": "' + currentVersion + '"', '"version": "' + newVersion + '"');
125-
replaceInFile('formvalidator.jquery.json', '"version": "' + currentVersion + '"', '"version": "' + newVersion + '"');
149+
fs.readdirSync(SRC_DIR).forEach(function(file) {
150+
if (isJavascriptFile(file)) {
151+
replaceInFile(SRC_DIR+file, fromVersion, toVersion);
152+
}
153+
});
126154
filesToBuild.devFiles.forEach(function (filePath) {
127-
replaceInFile(filePath, '@version ' + currentVersion, '@version ' + newVersion);
155+
replaceInFile(filePath, fromVersion, toVersion);
128156
});
129157

158+
replaceInFile('package.json', '"version": "' + currentVersion + '"', '"version": "' + newVersion + '"');
159+
replaceInFile('formvalidator.jquery.json', '"version": "' + currentVersion + '"', '"version": "' + newVersion + '"');
160+
130161
// Set new version globally (can later on be used by concat/uglify)
131162
pkg.version = newVersion;
132163
grunt.config.set('pkg', pkg);

form-validator/brazil.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
* @website http://formvalidator.net/#brazil-validators
1313
* @license MIT
14-
* @version 2.2.117
14+
* @version 2.2.135
1515
*/
1616

1717
$.formUtils.addValidator({

form-validator/brazil.js

Lines changed: 116 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,120 @@
33
*
44
* @author Victor Jonsson, http://victorjonsson.se
55
* @license MIT
6-
* @version 2.2.117
6+
* @version 2.2.135
77
*/
8-
$.formUtils.addValidator({name:"cpf",validatorFunction:function(a){var b=a.replace(/\D/g,""),c=0,d=0,e=0,f=0;if(11!==b.length||"00000000000"===b)return!1;for(i=1;i<=9;i++)c+=parseInt(b.substring(i-1,i))*(11-i);if(e=10*c%11,e>=10&&(e=0),e!==parseInt(b.substring(9,10)))return!1;for(i=1;i<=10;i++)d+=parseInt(b.substring(i-1,i))*(12-i);return f=10*d%11,f>=10&&(f=0),f!==parseInt(b.substring(10,11))?!1:!0},errorMessage:"",errorMessageKey:"badBrazilCPFAnswer"}),$.formUtils.addValidator({name:"brphone",validatorFunction:function(a){return a.match(/^(\+[\d]{1,3}[\s]{0,1}){0,1}(\(){0,1}(\d){2}(\)){0,1}(\s){0,1}(\d){4,5}([-. ]){0,1}(\d){4}$/g)?!0:!1},errorMessage:"",errorMessageKey:"badBrazilTelephoneAnswer"}),$.formUtils.addValidator({name:"cep",validatorFunction:function(a){return a.match(/^(\d){5}([-. ]){0,1}(\d){3}$/g)?!0:!1},errorMessage:"",errorMessageKey:"badBrazilCEPAnswer"});
8+
/**
9+
* jQuery Form Validator Module: Brazil
10+
* ------------------------------------------
11+
* Created by Eduardo Cuducos <http://cuducos.me/>
12+
*
13+
* This form validation module adds validators typically used on
14+
* websites in the Brazil. This module adds the following validators:
15+
* - cpf
16+
* - cep
17+
* - brphone
18+
*
19+
* @website http://formvalidator.net/#brazil-validators
20+
* @license MIT
21+
* @version 2.2.135
22+
*/
23+
24+
$.formUtils.addValidator({
25+
name : 'cpf',
26+
validatorFunction : function(string) {
27+
28+
// Based on this post from DevMedia:
29+
// http://www.devmedia.com.br/validar-cpf-com-javascript/23916
30+
31+
// clean up the input (digits only) and set some support vars
32+
var cpf = string.replace(/\D/g,'');
33+
var sum1 = 0;
34+
var sum2 = 0;
35+
var remainder1 = 0;
36+
var remainder2 = 0;
37+
38+
// skip special cases
39+
if (cpf.length !== 11 || cpf === '00000000000') {
40+
return false;
41+
}
42+
43+
// check 1st verification digit
44+
for (i = 1; i<= 9; i++) {
45+
sum1 += parseInt(cpf.substring(i - 1, i)) * (11 - i);
46+
}
47+
remainder1 = (sum1 * 10) % 11;
48+
if (remainder1 >= 10) {
49+
remainder1 = 0;
50+
}
51+
if (remainder1 !== parseInt(cpf.substring(9, 10))) {
52+
return false;
53+
}
54+
55+
// check 2nd verification digit
56+
for (i = 1; i <= 10; i++) {
57+
sum2 += parseInt(cpf.substring(i - 1, i)) * (12 - i);
58+
}
59+
remainder2 = (sum2 * 10) % 11;
60+
if (remainder2 >= 10) {
61+
remainder2 = 0;
62+
}
63+
if (remainder2 !== parseInt(cpf.substring(10, 11))) {
64+
return false;
65+
}
66+
67+
return true;
68+
69+
},
70+
errorMessage : '',
71+
errorMessageKey: 'badBrazilCPFAnswer'
72+
73+
});
74+
75+
$.formUtils.addValidator({
76+
name : 'brphone',
77+
validatorFunction : function(string) {
78+
79+
// validates telefones such as (having X as numbers):
80+
// (XX) XXXX-XXXX
81+
// (XX) XXXXX-XXXX
82+
// XX XXXXXXXX
83+
// XX XXXXXXXXX
84+
// XXXXXXXXXX
85+
// XXXXXXXXXXX
86+
// +XX XX XXXXX-XXXX
87+
// +X XX XXXX-XXXX
88+
// And so on…
89+
90+
if (string.match(/^(\+[\d]{1,3}[\s]{0,1}){0,1}(\(){0,1}(\d){2}(\)){0,1}(\s){0,1}(\d){4,5}([-. ]){0,1}(\d){4}$/g)) {
91+
return true;
92+
}
93+
94+
return false;
95+
96+
},
97+
errorMessage : '',
98+
errorMessageKey: 'badBrazilTelephoneAnswer'
99+
100+
});
101+
102+
$.formUtils.addValidator({
103+
name : 'cep',
104+
validatorFunction : function(string) {
105+
106+
// validates CEP such as (having X as numbers):
107+
// XXXXX-XXX
108+
// XXXXX.XXX
109+
// XXXXX XXX
110+
// XXXXXXXX
111+
112+
if (string.match(/^(\d){5}([-. ]){0,1}(\d){3}$/g)) {
113+
return true;
114+
}
115+
116+
return false;
117+
118+
},
119+
errorMessage : '',
120+
errorMessageKey: 'badBrazilCEPAnswer'
121+
122+
});

form-validator/date.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* @website http://formvalidator.net/#location-validators
1212
* @license MIT
13-
* @version 2.2.117
13+
* @version 2.2.135
1414
*/
1515
(function($) {
1616

form-validator/date.js

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,86 @@
33
*
44
* @author Victor Jonsson, http://victorjonsson.se
55
* @license MIT
6-
* @version 2.2.117
6+
* @version 2.2.135
77
*/
8-
!function(a){a.formUtils.addValidator({name:"time",validatorFunction:function(a){if(null===a.match(/^(\d{2}):(\d{2})$/))return!1;var b=parseInt(a.split(":")[0],10),c=parseInt(a.split(":")[1],10);return b>23||c>59?!1:!0},errorMessage:"",errorMessageKey:"badTime"}),a.formUtils.addValidator({name:"birthdate",validatorFunction:function(b,c,d){var e="yyyy-mm-dd";c.valAttr("format")?e=c.valAttr("format"):"undefined"!=typeof d.dateFormat&&(e=d.dateFormat);var f=a.formUtils.parseDate(b,e);if(!f)return!1;var g=new Date,h=g.getFullYear(),i=f[0],j=f[1],k=f[2];if(i===h){var l=g.getMonth()+1;if(j===l){var m=g.getDate();return m>=k}return l>j}return h>i&&i>h-124},errorMessage:"",errorMessageKey:"badDate"})}(jQuery);
8+
/**
9+
* jQuery Form Validator Module: Date
10+
* ------------------------------------------
11+
* Created by Victor Jonsson <http://www.victorjonsson.se>
12+
* Documentation and issue tracking on Github <https://github.com/victorjonsson/jQuery-Form-Validator/>
13+
*
14+
* The following validators will be added by this module:
15+
* - Time (HH:mmm)
16+
* - Birth date
17+
*
18+
* @website http://formvalidator.net/#location-validators
19+
* @license MIT
20+
* @version 2.2.135
21+
*/
22+
(function($) {
23+
24+
/*
25+
* Validate time hh:mm
26+
*/
27+
$.formUtils.addValidator({
28+
name : 'time',
29+
validatorFunction : function(time) {
30+
if (time.match(/^(\d{2}):(\d{2})$/) === null) {
31+
return false;
32+
} else {
33+
var hours = parseInt(time.split(':')[0],10);
34+
var minutes = parseInt(time.split(':')[1],10);
35+
if( hours > 23 || minutes > 59 ) {
36+
return false;
37+
}
38+
}
39+
return true;
40+
},
41+
errorMessage : '',
42+
errorMessageKey: 'badTime'
43+
});
44+
45+
/*
46+
* Is this a valid birth date
47+
*/
48+
$.formUtils.addValidator({
49+
name : 'birthdate',
50+
validatorFunction : function(val, $el, conf) {
51+
var dateFormat = 'yyyy-mm-dd';
52+
if($el.valAttr('format')) {
53+
dateFormat = $el.valAttr('format');
54+
}
55+
else if(typeof conf.dateFormat !== 'undefined') {
56+
dateFormat = conf.dateFormat;
57+
}
58+
59+
var inputDate = $.formUtils.parseDate(val, dateFormat);
60+
if (!inputDate) {
61+
return false;
62+
}
63+
64+
var d = new Date();
65+
var currentYear = d.getFullYear();
66+
var year = inputDate[0];
67+
var month = inputDate[1];
68+
var day = inputDate[2];
69+
70+
if (year === currentYear) {
71+
var currentMonth = d.getMonth() + 1;
72+
if (month === currentMonth) {
73+
var currentDay = d.getDate();
74+
return day <= currentDay;
75+
}
76+
else {
77+
return month < currentMonth;
78+
}
79+
}
80+
else {
81+
return year < currentYear && year > (currentYear - 124); // we can not live for ever yet...
82+
}
83+
},
84+
errorMessage : '',
85+
errorMessageKey: 'badDate'
86+
});
87+
88+
})(jQuery);

form-validator/file.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* @website http://formvalidator.net/#file-validators
1212
* @license MIT
13-
* @version 2.2.117
13+
* @version 2.2.135
1414
*/
1515
(function($, window) {
1616

0 commit comments

Comments
 (0)