Skip to content

Commit

Permalink
Updated distribution to version 2.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Semantic-Pusher-Robot committed Jul 17, 2015
1 parent 0a3b848 commit 1417771
Show file tree
Hide file tree
Showing 36 changed files with 1,534 additions and 1,329 deletions.
224 changes: 134 additions & 90 deletions definitions/behaviors/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ $.fn.form = function(parameters) {
var
keys = Object.keys(parameters),
isLegacySettings = (keys.length > 0)
? (parameters[keys[0]].identifier !== undefined)
? (parameters[keys[0]].identifier !== undefined && parameters[keys[0]].rules !== undefined)
: false
;
if(isLegacySettings) {
Expand Down Expand Up @@ -495,6 +495,9 @@ $.fn.form = function(parameters) {

field: function(identifier) {
module.verbose('Checking for existence of a field with identifier', identifier);
if(typeof identifier !== 'string') {
module.error(error.identifier, identifier);
}
if( $field.filter('#' + identifier).length > 0 ) {
return true;
}
Expand Down Expand Up @@ -760,9 +763,11 @@ $.fn.form = function(parameters) {
ancillary,
functionType
;
// cast to string
value = $.trim($field.val() + '');

// cast to string avoiding encoding special values
value = (value === undefined || value === '' || value === null)
? ''
: $.trim(value + '')
;
// if bracket notation is used, pass in extra parameters
if(bracket) {
ancillary = '' + bracket[1];
Expand Down Expand Up @@ -1015,9 +1020,10 @@ $.fn.form.settings = {
},

error: {
oldSyntax : 'Starting in 2.0 forms now only take a single settings object. Validation settings converted to new syntax automatically.',
noRule : 'There is no rule matching the one you specified',
method : 'The method you called is not defined.'
oldSyntax : 'Starting in 2.0 forms now only take a single settings object. Validation settings converted to new syntax automatically.',
identifier : 'You must specify a string identifier for each field',
noRule : 'There is no rule matching the one you specified',
method : 'The method you called is not defined.'
},

templates: {
Expand Down Expand Up @@ -1045,25 +1051,16 @@ $.fn.form.settings = {

rules: {

// is not empty or blank string
empty: function(value) {
return !(value === undefined || '' === value || $.isArray(value) && value.length === 0);
},

// checkbox checked
checked: function() {
return ($(this).filter(':checked').length > 0);
},

// value contains text (insensitive)
contains: function(value, text) {
// escape regex characters
text = text.replace($.fn.form.settings.regExp.escape, "\\$&");
return (value.search( new RegExp(text, 'i') ) !== -1);
},

// value contains text (case sensitive)
containsExactly: function(value, text) {
// escape regex characters
text = text.replace($.fn.form.settings.regExp.escape, "\\$&");
return (value.search( new RegExp(text) ) !== -1);
},

// is most likely an email
email: function(value){
var
Expand All @@ -1072,12 +1069,32 @@ $.fn.form.settings = {
return emailRegExp.test(value);
},

// is not empty or blank string
empty: function(value) {
return !(value === undefined || '' === value || $.isArray(value) && value.length === 0);
// value is most likely url
url: function(value) {
return $.fn.form.settings.regExp.url.test(value);
},

// matches specified regExp
regExp: function(value, regExp) {
var
regExpParts = regExp.match($.fn.form.settings.regExp.flags),
flags
;
// regular expression specified as /baz/gi (flags)
if(regExpParts) {
regExp = (regExpParts.length >= 2)
? regExpParts[1]
: regExp
;
flags = (regExpParts.length >= 3)
? regExpParts[2]
: ''
;
}
return value.match( new RegExp(regExp, flags) );
},

// is valid integer
// is valid integer or matches range
integer: function(value, range) {
var
intRegExp = $.fn.form.settings.regExp.integer,
Expand Down Expand Up @@ -1109,6 +1126,7 @@ $.fn.form.settings = {
);
},


// is value (case insensitive)
is: function(value, text) {
text = (typeof text == 'string')
Expand All @@ -1127,17 +1145,78 @@ $.fn.form.settings = {
return (value == text);
},

// is at least string length
// value is not another value (case insensitive)
not: function(value, notValue) {
value = (typeof value == 'string')
? value.toLowerCase()
: value
;
notValue = (typeof notValue == 'string')
? notValue.toLowerCase()
: notValue
;
return (value != notValue);
},

// value is not another value (case sensitive)
notExactly: function(value, notValue) {
return (value != notValue);
},

// value contains text (insensitive)
contains: function(value, text) {
// escape regex characters
text = text.replace($.fn.form.settings.regExp.escape, "\\$&");
return (value.search( new RegExp(text, 'i') ) !== -1);
},

// value contains text (case sensitive)
containsExactly: function(value, text) {
// escape regex characters
text = text.replace($.fn.form.settings.regExp.escape, "\\$&");
return (value.search( new RegExp(text) ) !== -1);
},

// value contains text (insensitive)
doesntContain: function(value, text) {
// escape regex characters
text = text.replace($.fn.form.settings.regExp.escape, "\\$&");
return (value.search( new RegExp(text, 'i') ) === -1);
},

// value contains text (case sensitive)
doesntContainExactly: function(value, text) {
// escape regex characters
text = text.replace($.fn.form.settings.regExp.escape, "\\$&");
return (value.search( new RegExp(text) ) === -1);
},

// is exactly length
length: function(value, requiredLength) {
return (value !== undefined)
? (value.length == requiredLength)
: false
;
},

// is at least string length
minLength: function(value, requiredLength) {
return (value !== undefined)
? (value.length >= requiredLength)
: false
;
},

// is less than length
maxLength: function(value, maxLength) {
return (value !== undefined)
? (value.length <= maxLength)
: false
;
},

// matches another field
different: function(value, identifier) {
// use either id or name of field
match: function(value, identifier) {
var
$form = $(this),
matchingValue
Expand All @@ -1155,13 +1234,13 @@ $.fn.form.settings = {
matchingValue = $('[name="' + identifier +'[]"]');
}
return (matchingValue !== undefined)
? ( value.toString() !== matchingValue.toString() )
? ( value.toString() == matchingValue.toString() )
: false
;
},

// matches another field
match: function(value, identifier) {
// different than another field
different: function(value, identifier) {
// use either id or name of field
var
$form = $(this),
Expand All @@ -1180,74 +1259,39 @@ $.fn.form.settings = {
matchingValue = $('[name="' + identifier +'[]"]');
}
return (matchingValue !== undefined)
? ( value.toString() == matchingValue.toString() )
? ( value.toString() !== matchingValue.toString() )
: false
;
},

maxCount: function(value, count) {
value = value.split(',');
return ($.isArray(value) && value.length <= count);
},

exactCount: function(value, count) {
value = value.split(',');
return ($.isArray(value) && value.length == count);
},

minCount: function(value, count) {
value = value.split(',');
return ($.isArray(value) && value.length >= count);
},

regExp: function(value, regExp) {
var
regExpParts = regExp.match($.fn.form.settings.regExp.flags),
flags
;
// regular expression specified as /baz/gi (flags)
if(regExpParts) {
regExp = (regExpParts.length >= 2)
? regExpParts[1]
: regExp
;
flags = (regExpParts.length >= 3)
? regExpParts[2]
: ''
;
exactCount: function(value, exactCount) {
if(exactCount == 0) {
return (value === '');
}
return value.match( new RegExp(regExp, flags) );
},

// string length is less than max length
maxLength: function(value, maxLength) {
return (value !== undefined)
? (value.length <= maxLength)
: false
;
},

// value is not value (case insensitive)
not: function(value, notValue) {
value = (typeof value == 'string')
? value.toLowerCase()
: value
;
notValue = (typeof notValue == 'string')
? notValue.toLowerCase()
: notValue
;
return (value != notValue);
if(exactCount == 1) {
return (value !== '' && value.search(',') === -1);
}
return (value.split(',').length == exactCount);
},

// value is not value (case sensitive)
notExactly: function(value, notValue) {
return (value != notValue);
minCount: function(value, minCount) {
if(minCount == 0) {
return true;
}
if(minCount == 1) {
return (value !== '');
}
return (value.split(',').length >= minCount);
},

// value is most likely url
url: function(value) {
return $.fn.form.settings.regExp.url.test(value);
maxCount: function(value, maxCount) {
if(maxCount == 0) {
return false;
}
if(maxCount == 1) {
return (value.search(',') === -1);
}
return (value.split(',').length <= maxCount);
}
}

Expand Down
15 changes: 9 additions & 6 deletions definitions/behaviors/visibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -1137,9 +1137,18 @@ $.fn.visibility.settings = {
// whether to use mutation observers to follow changes
observeChanges : true,

// check position immediately on init
initialCheck : true,

// whether to refresh calculations after all page images load
refreshOnLoad : true,

// whether to refresh calculations after page resize event
refreshOnResize : true,

// should call callbacks on refresh event (resize, etc)
checkOnRefresh : true,

// callback should only occur one time
once : true,

Expand All @@ -1155,9 +1164,6 @@ $.fn.visibility.settings = {
// scroll context for visibility checks
context : window,

// check position immediately on init
initialCheck : true,

// visibility check delay in ms (defaults to animationFrame)
throttle : false,

Expand All @@ -1171,9 +1177,6 @@ $.fn.visibility.settings = {
// array of callbacks for percentage
onPassed : {},

// should call callbacks on refresh event (resize, etc)
checkOnRefresh : true,

// standard callbacks
onOnScreen : false,
onOffScreen : false,
Expand Down
7 changes: 6 additions & 1 deletion definitions/collections/form.less
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
Field
---------------------*/

.ui.form .fields .field,
.ui.form .field {
clear: both;
margin: @fieldMargin;
Expand All @@ -55,6 +54,12 @@
margin-bottom: 0em;
}

.ui.form .fields .field {
clear: both;
margin: @fieldMargin;
}


/*--------------------
Labels
---------------------*/
Expand Down
Loading

0 comments on commit 1417771

Please sign in to comment.