Skip to content

Commit efc71b0

Browse files
committed
version 2.0 here we go
1 parent 217b147 commit efc71b0

15 files changed

+2679
-8
lines changed

build

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/node
2+
3+
var fs = require('fs'),
4+
sys = require('sys'),
5+
exec = require('child_process').exec,
6+
jsPath = 'form-validator/',
7+
mainScript = jsPath + 'jquery.form-validator.js',
8+
mainMinifiedScript = jsPath + 'jquery.form-validator.min.js',
9+
newVersion = -1;
10+
11+
/*
12+
* Find out new version number
13+
*/
14+
var versionParts = fs.readFileSync(mainScript, 'utf-8').split('@version ')[1].split('*/')[0].trim().split('.');
15+
if(versionParts.length < 3) {
16+
// new version number is decided in code
17+
newVersion = versionParts.join('.');
18+
}
19+
else {
20+
// Increase the last number by one
21+
var newSubVersion = parseInt(versionParts.splice(versionParts.length-1, 1)[0]) + 1;
22+
newVersion = versionParts.join('.') + '.' + newSubVersion.toString();
23+
}
24+
25+
console.log('Build version: '+newVersion);
26+
27+
/*
28+
* Get code docs
29+
*/
30+
var documentation = fs.readFileSync(mainScript, 'utf-8').split('*/')[0]+'*/';
31+
var docParts = documentation.split('@version ');
32+
documentation = docParts[0] +'@version '+newVersion+'\n'+docParts[1].split('\n')[1];
33+
34+
35+
/**
36+
* Create new minified version of a file and change
37+
* version number
38+
* @param {String} path
39+
* @param {String} newName
40+
*/
41+
function buildFile(path, newName) {
42+
var codeParts = fs.readFileSync(path, 'utf-8').split('@version ');
43+
var lastCodeParts = codeParts[1].split("\n");
44+
var origCode = codeParts[0] + '@version '+newVersion+ "\n" + lastCodeParts.slice(1, lastCodeParts.length).join("\n") + "";
45+
fs.writeFileSync(path, origCode);
46+
fs.writeFileSync(newName, '');
47+
exec('uglifyjs '+path+' >> '+newName, function (error, stdout, stderr) {
48+
if(stdout)
49+
console.log('stdout: '+stdout);
50+
if(error)
51+
console.log('error: '+error);
52+
if(stderr)
53+
console.log('stderror: '+stderr);
54+
55+
console.log('* '+newName);
56+
});
57+
}
58+
59+
buildFile(mainScript, mainMinifiedScript);
60+
fs.readdirSync(jsPath).forEach(function(f) {
61+
if(f.substr(-7) == '.dev.js') {
62+
var compressedFileName = jsPath + f.substr(0, f.length - 6) + 'js';
63+
buildFile(jsPath+f, compressedFileName);
64+
}
65+
});
66+
67+
/*
68+
* Add docs to main script
69+
*/
70+
fs.writeFileSync(mainMinifiedScript, documentation+"\n"+fs.readFileSync(mainMinifiedScript, 'utf-8'));

form-validator/date.dev.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/**
2+
* jQuery Form Validator Module: Date
3+
* ------------------------------------------
4+
* Created by Victor Jonsson <http://www.victorjonsson.se>
5+
* Documentation and issue tracking on Github <https://github.com/victorjonsson/jQuery-Form-Validator/>
6+
*
7+
* This form validation module adds validators used to validate date
8+
* and time values. The following validators will be added by
9+
* this module:
10+
* - validate_time
11+
* - validate_birthdate
12+
*
13+
*
14+
* @license Dual licensed under the MIT or GPL Version 2 licenses
15+
* @version 2.0.3
16+
*/
17+
(function($) {
18+
19+
/*
20+
* Validate time hh:mm
21+
*/
22+
$.formUtils.addValidator({
23+
name : 'validate_time',
24+
validate : function(time) {
25+
if (time.match(/^(\d{2}):(\d{2})$/) === null) {
26+
return false;
27+
} else {
28+
var hours = parseInt(time.split(':')[0],10);
29+
var minutes = parseInt(time.split(':')[1],10);
30+
if( hours > 23 || minutes > 59 ) {
31+
return false;
32+
}
33+
}
34+
return true;
35+
},
36+
errorMessage : '',
37+
errorMessageKey: 'badTime'
38+
});
39+
40+
/*
41+
* Is this a valid birth date
42+
*/
43+
$.formUtils.addValidator({
44+
name : 'validate_birthdate',
45+
validate : function(val, $el, conf) {
46+
var dateFormat = 'yyyy-mm-dd';
47+
if($el.valAttr('format')) {
48+
dateFormat = $el.valAttr('format');
49+
}
50+
else if(typeof conf.dateFormat != 'undefined') {
51+
dateFormat = conf.dateFormat;
52+
}
53+
54+
var inputDate = $.formUtils.parseDate(val, dateFormat);
55+
if (!inputDate) {
56+
return false;
57+
}
58+
59+
var d = new Date();
60+
var currentYear = d.getFullYear();
61+
var year = inputDate[0];
62+
var month = inputDate[1];
63+
var day = inputDate[2];
64+
65+
if (year === currentYear) {
66+
var currentMonth = d.getMonth() + 1;
67+
if (month === currentMonth) {
68+
var currentDay = d.getDate();
69+
return day <= currentDay;
70+
}
71+
else {
72+
return month < currentMonth;
73+
}
74+
}
75+
else {
76+
return year < currentYear && year > (currentYear - 124); // we can not live for ever yet...
77+
}
78+
},
79+
errorMessage : '',
80+
errorMessageKey: 'badDate'
81+
});
82+
83+
})(jQuery);

form-validator/date.js

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

0 commit comments

Comments
 (0)