Skip to content

Commit c58dda7

Browse files
committed
Added theme css victorjonsson#256, added ratio validation victorjonsson#229
1 parent d6376bc commit c58dda7

28 files changed

+345
-92
lines changed

build

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ var fs = require('fs'),
88
mainMinifiedScript = jsPath + 'jquery.form-validator.min.js',
99
newVersion = -1;
1010

11-
/*
12-
* Find out new version number
13-
*/
11+
// Find out new version number
1412
var versionParts = fs.readFileSync(mainScript, 'utf-8').split('@version ')[1].split('*/')[0].trim().split('.');
1513
if(versionParts.length < 3) {
1614
// new version number is decided in code
@@ -32,24 +30,30 @@ documentation = docParts[0] +'@version '+newVersion+'\n'+docParts[1].split('\n')
3230

3331
/**
3432
* Create new minified version of a file and change version number
35-
* @param {String} path
36-
* @param {String} newName
33+
* @param {String} sourceFile
34+
* @param {String} targetFile
35+
* @param {String} [bin]
3736
*/
38-
function buildFile(path, newName) {
39-
var codeParts = fs.readFileSync(path, 'utf-8').split('@version ');
40-
var lastCodeParts = codeParts[1].split("\n");
41-
var origCode = codeParts[0] + '@version '+newVersion+ "\n" + lastCodeParts.slice(1, lastCodeParts.length).join("\n") + "";
42-
fs.writeFileSync(path, origCode);
43-
fs.writeFileSync(newName, '');
44-
exec('uglifyjs '+path+' >> '+newName, function (error, stdout, stderr) {
37+
function buildFile(sourceFile, targetFile, bin) {
38+
var codeParts = fs.readFileSync(sourceFile, 'utf-8').split('@version '),
39+
lastCodeParts = codeParts[1].split("\n"),
40+
origCode = codeParts[0] + '@version '+newVersion+ "\n" + lastCodeParts.slice(1, lastCodeParts.length).join("\n") + "";
41+
42+
fs.writeFileSync(sourceFile, origCode);
43+
fs.writeFileSync(targetFile, '');
44+
45+
if(!bin)
46+
bin = 'uglifyjs %source% >> %target%';
47+
48+
exec(bin.replace('%source%', sourceFile).replace('%target%', targetFile), function (error, stdout, stderr) {
4549
if(stdout)
4650
console.log('stdout: '+stdout);
4751
if(error)
4852
console.log('error: '+error);
4953
if(stderr)
5054
console.log('stderror: '+stderr);
5155

52-
console.log('* '+newName);
56+
console.log('* '+targetFile);
5357
});
5458
}
5559

@@ -69,3 +73,5 @@ fs.writeFileSync(mainMinifiedScript, documentation+"\n"+fs.readFileSync(mainMini
6973
});
7074
});
7175

76+
// Minify default theme css
77+
buildFile(jsPath+'theme-default.css', jsPath+'theme-default.min.css', 'sqwish %source%');

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 Dual licensed under the MIT or GPL Version 2 licenses
13-
* @version 2.2.24
13+
* @version 2.2.34
1414
*/
1515
(function($) {
1616

form-validator/file.dev.js

Lines changed: 93 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* @website http://formvalidator.net/#file-validators
1212
* @license Dual licensed under the MIT or GPL Version 2 licenses
13-
* @version 2.2.24
13+
* @version 2.2.34
1414
*/
1515
(function($, window) {
1616

@@ -66,6 +66,7 @@
6666
reader.onload = function(fileObj) {
6767

6868
image.onload = function() {
69+
$(window).trigger('imageValidation', [this]);
6970
successCallback(this);
7071
};
7172

@@ -203,6 +204,91 @@
203204
return false;
204205
};
205206

207+
/**
208+
* Attach dimension check onto formUtils only for unit testing purpose
209+
* @param {HTMLImageElement} img
210+
* @param {String} dimDeclaration
211+
* @param {Boolean|String} Returns error message if image was invalid, false otherwise
212+
*/
213+
$.formUtils.checkImageDimension = function(img, dimDeclaration, language) {
214+
var error = false,
215+
restrictedDim = {width:0, height:0},
216+
getDimRestriction = function(dimDeclaration) {
217+
dimDeclaration = dimDeclaration.replace('min', '').replace('max', '');
218+
var chunks = dimDeclaration.split('x');
219+
restrictedDim.width = chunks[0];
220+
restrictedDim.height = chunks[1] ? chunks[1] : chunks[0];
221+
},
222+
minDeclaration = false,
223+
maxDeclaration = false,
224+
declarationParts = dimDeclaration.split('-');
225+
226+
if( declarationParts.length == 1 ) {
227+
if( declarationParts[0].indexOf('min') === 0 ) {
228+
minDeclaration = declarationParts[0];
229+
} else {
230+
maxDeclaration = declarationParts[0];
231+
}
232+
} else {
233+
minDeclaration = declarationParts[0];
234+
maxDeclaration = declarationParts[1];
235+
}
236+
237+
if( minDeclaration ) {
238+
// check min
239+
getDimRestriction(minDeclaration);
240+
if( img.width < restrictedDim.width || img.height < restrictedDim.height ) {
241+
error = language.imageTooSmall + ' ('+language.min+' '+restrictedDim.width+'x'+restrictedDim.height+'px)';
242+
}
243+
}
244+
245+
if( !error && maxDeclaration ) {
246+
// Check max
247+
getDimRestriction(maxDeclaration);
248+
if( img.width > restrictedDim.width || img.height > restrictedDim.height ) {
249+
if( img.width > restrictedDim.width ) {
250+
error = language.imageTooWide +' '+restrictedDim.width+'px';
251+
} else {
252+
error = language.imageTooTall +' '+restrictedDim.height+'px';
253+
}
254+
error += ' ('+language.max+' '+restrictedDim.width+'x'+restrictedDim.height+'px)';
255+
}
256+
}
257+
258+
return error;
259+
};
260+
261+
/**
262+
* Attach ratio validation onto formUtils only for unit testing purpose
263+
* @param {HTMLImageElement} img
264+
* @param {String} dimDeclaration
265+
* @param {Boolean|String} Returns error message if image was invalid, false otherwise
266+
*/
267+
$.formUtils.checkImageRatio = function(img, ratioDeclaration, language) {
268+
var ratio = img.width / img.height,
269+
minRatio = false,
270+
maxRatio = false,
271+
calculateRatio = function(declaration) {
272+
var dims = declaration.replace('max', '').replace('min', '').split(':');
273+
return dims[0] / dims[1];
274+
},
275+
declarationParts = ratioDeclaration.split('-'),
276+
isWithin = function(val, min, max) {
277+
console.log(val+ '>='+min +' && '+val+' <= '+max);
278+
return val >= min && val <= max;
279+
};
280+
281+
if( declarationParts.length == 1 ) {
282+
if( ratio !== calculateRatio(declarationParts[0]) )
283+
return language.imageRatioNotAccepted;
284+
}
285+
else if( declarationParts.length == 2 && !isWithin(ratio, calculateRatio(declarationParts[0]), calculateRatio(declarationParts[1])) ) {
286+
return language.imageRatioNotAccepted;
287+
}
288+
289+
return false;
290+
};
291+
206292
/**
207293
* Validate image dimension
208294
*/
@@ -247,36 +333,13 @@
247333
}
248334

249335
_loadImage(file[0], function(img) {
250-
var error = false,
251-
restrictedDim = {width:0, height:0},
252-
getDimRestriction = function(attrVal) {
253-
var chunks = attrVal.split('x');
254-
restrictedDim.width = chunks[0];
255-
restrictedDim.height = chunks[1] ? chunks[1] : chunks[0];
256-
},
257-
minDeclaration = ($input.valAttr('min-dimension') || '').replace('px', ''),
258-
maxDeclaration = ($input.valAttr('max-dimension') || '').replace('px', '');
259-
260-
if( minDeclaration ) {
261-
// check min
262-
getDimRestriction(minDeclaration);
263-
if( img.width < restrictedDim.width || img.height < restrictedDim.height ) {
264-
error = language.imageTooSmall + ' ('+language.min+' '+restrictedDim.width+'x'+restrictedDim.height+'px)';
265-
}
266-
}
336+
var error = false;
267337

268-
if( !error && maxDeclaration ) {
269-
// Check max
270-
getDimRestriction(maxDeclaration);
271-
if( img.width > restrictedDim.width || img.height > restrictedDim.height ) {
272-
if( img.width > restrictedDim.width ) {
273-
error = language.imageTooWide +' '+restrictedDim.width+'px';
274-
} else {
275-
error = language.imageTooTall +' '+restrictedDim.height+'px';
276-
}
277-
error += ' ('+language.max+' '+restrictedDim.width+'x'+restrictedDim.height+'px)';
278-
}
279-
}
338+
if( $input.valAttr('dimension') )
339+
error = $.formUtils.checkImageDimension(img, $input.valAttr('dimension'), language);
340+
341+
if( !error && $input.valAttr('ratio') )
342+
error = $.formUtils.checkImageRatio(img, $input.valAttr('ratio'), language);
280343

281344
// Set validation result flag on input
282345
if( error ) {

0 commit comments

Comments
 (0)