').html( text );
item.append( warning );
}
-
- item.removeClass('bad');
- // a delay so the "alert" could be transitioned via CSS
+
+ item.removeClass(defaults.classes.bad);
+ // a delay so the "alert" could be transitioned via CSS
setTimeout(function(){
- item.addClass('bad');
+ item.addClass(defaults.classes.bad);
}, 0);
- };
- /* un-marks invalid fields
- */
- unmark = function( field ){
- if( !field || !field.length ){
- console.warn('no "field" argument, null or DOM object not found');
- return false;
- }
+ };
+ /* un-marks invalid fields
+ */
+ unmark = function( field ){
+ if( !field || !field.length ){
+ console.warn('no "field" argument, null or DOM object not found');
+ return false;
+ }
- field.parents('.item')
- .removeClass('bad')
- .find('.alert').remove();
- };
+ field.closest('.' + defaults.classes.item)
+ .removeClass(defaults.classes.bad)
+ .find('.'+ defaults.classes.alert).remove();
+ };
- function testByType(type, value){
- if( type == 'tel' )
- pattern = pattern || 'phone';
+ function testByType(type, value){
+ if( type == 'tel' )
+ pattern = pattern || 'phone';
- if( !type || type == 'password' || type == 'tel' )
- type = 'text';
+ if( !type || type == 'password' || type == 'tel' || type == 'search' || type == 'file' )
+ type = 'text';
- return tests[type](value);
- }
- function prepareFieldData(el){
- field = $(el);
+ return tests[type] ? tests[type](value, true) : true;
+ }
- field.data( 'valid', true ); // initialize validness of field by first checking if it's even filled out of now
- field.data( 'type', field.attr('type') ); // every field starts as 'valid=true' until proven otherwise
- pattern = el.pattern;
- }
+ function prepareFieldData(el){
+ field = $(el);
- /* Validations per-character keypress
- */
- function keypress(e){
- prepareFieldData(this);
+ field.data( 'valid', true ); // initialize validity of field
+ field.data( 'type', field.attr('type') ); // every field starts as 'valid=true' until proven otherwise
+ pattern = field.attr('pattern');
+ }
- if( e.charCode )
- return testByType( data.type, String.fromCharCode(e.charCode) );
- }
+ /* Validations per-character keypress
+ */
+ function keypress(e){
+ prepareFieldData(this);
+ // String.fromCharCode(e.charCode)
- /* Checks a single form field by it's type and specific (custom) attributes
- */
- function checkField(){
- // skip testing fields whom their type is not HIDDEN but they are HIDDEN via CSS.
- if( this.type !='hidden' && $(this).is(':hidden') )
- return true;
+ if( e.charCode ){
+ return testByType( this.type, this.value );
+ }
+ }
- prepareFieldData(this);
+ /* Checks a single form field by it's type and specific (custom) attributes
+ */
+ function checkField(){
+ // skip testing fields whom their type is not HIDDEN but they are HIDDEN via CSS.
+ if( this.type !='hidden' && $(this).is(':hidden') )
+ return true;
- field.data( 'val', field[0].value.replace(/^\s+|\s+$/g, "") ); // cache the value of the field and trim it
- data = field.data();
+ prepareFieldData(this);
- // Check if there is a specific error message for that field, if not, use the default 'invalid' message
- alertTxt = message[field.prop('name')] || message.invalid;
+ field.data( 'val', field[0].value.replace(/^\s+|\s+$/g, "") ); // cache the value of the field and trim it
+ data = field.data();
- // SELECT / TEXTAREA nodes needs special treatment
- if( field[0].nodeName.toLowerCase() === "select" ){
- data.type = 'select';
- }
- if( field[0].nodeName.toLowerCase() === "textarea" ){
- data.type = 'text';
- }
- /* Gather Custom data attributes for specific validation:
- */
- validateWords = data['validateWords'] || 0;
- lengthRange = data['validateLengthRange'] ? (data['validateLengthRange']+'').split(',') : [1];
- lengthLimit = data['validateLength'] ? (data['validateLength']+'').split(',') : false;
- minmax = data['validateMinmax'] ? (data['validateMinmax']+'').split(',') : ''; // for type 'number', defines the minimum and/or maximum for the value as a number.
+ // Check if there is a specific error message for that field, if not, use the default 'invalid' message
+ alertTxt = message[field.prop('name')] || message.invalid;
- data.valid = tests.hasValue(data.val);
- // check if field has any value
- if( data.valid ){
- /* Validate the field's value is different than the placeholder attribute (and attribute exists)
- * this is needed when fixing the placeholders for older browsers which does not support them.
- * in this case, make sure the "placeholder" jQuery plugin was even used before proceeding
- */
- if( tests.sameAsPlaceholder(field) ){
- alertTxt = message.empty;
- data.valid = false;
- }
+ // Special treatment
+ if( field[0].nodeName.toLowerCase() === "select" ){
+ data.type = 'select';
+ }
+ else if( field[0].nodeName.toLowerCase() === "textarea" ){
+ data.type = 'text';
+ }
+ /* Gather Custom data attributes for specific validation:
+ */
+ validateWords = data['validateWords'] || 0;
+ lengthRange = data['validateLengthRange'] ? (data['validateLengthRange']+'').split(',') : [1];
+ lengthLimit = data['validateLength'] ? (data['validateLength']+'').split(',') : false;
+ minmax = data['validateMinmax'] ? (data['validateMinmax']+'').split(',') : ''; // for type 'number', defines the minimum and/or maximum for the value as a number.
- // if this field is linked to another field (their values should be the same)
- if( data.validateLinked ){
- var linkedTo = data['validateLinked'].indexOf('#') == 0 ? $(data['validateLinked']) : $(':input[name=' + data['validateLinked'] + ']');
- data.valid = tests.linked( data.val, linkedTo.val() );
- }
- /* validate by type of field. use 'attr()' is proffered to get the actual value and not what the browsers sees for unsupported types.
- */
- else if( data.valid || data.type == 'select' )
- data.valid = testByType(data.type, data.val);
+ data.valid = tests.hasValue(data.val);
- // optional fields are only validated if they are not empty
- if( field.hasClass('optional') && !data.val )
- data.valid = true;
- }
+ if( field.hasClass('optional') && !data.valid )
+ data.valid = true;
- // mark / unmark the field, and set the general 'submit' flag accordingly
- if( data.valid )
- unmark( field );
- else{
- mark( field, alertTxt );
- submit = false;
- }
- return data.valid;
- }
+ // for checkboxes
+ if( field[0].type === "checkbox" ){
+ data.valid = field[0].checked;
+ alertTxt = message.checked;
+ }
- /* vaildates all the REQUIRED fields prior to submiting the form
- */
- function checkAll( $form ){
- $form = $($form);
+ // check if field has any value
+ else if( data.valid ){
+ /* Validate the field's value is different than the placeholder attribute (and attribute exists)
+ * this is needed when fixing the placeholders for older browsers which does not support them.
+ * in this case, make sure the "placeholder" jQuery plugin was even used before proceeding
+ */
+ if( tests.sameAsPlaceholder(field) ){
+ alertTxt = message.empty;
+ data.valid = false;
+ }
- if( $form.length == 0 ){
- console.warn('element not found');
- return false;
- }
+ // if this field is linked to another field (their values should be the same)
+ if( data.validateLinked ){
+ var linkedTo = data['validateLinked'].indexOf('#') == 0 ? $(data['validateLinked']) : $(':input[name=' + data['validateLinked'] + ']');
+ data.valid = tests.linked( data.val, linkedTo.val() );
+ }
+ /* validate by type of field. use 'attr()' is proffered to get the actual value and not what the browsers sees for unsupported types.
+ */
+ else if( data.valid || data.type == 'select' )
+ data.valid = testByType(data.type, data.val);
- var that = this,
- submit = true, // save the scope
- fieldsToCheck = $form.find(':input').filter('[required=required], .required, .optional').not('[disabled=disabled]');
+ }
- fieldsToCheck.each(function(){
- // use an AND operation, so if any of the fields returns 'false' then the submitted result will be also FALSE
- submit = submit * checkField.apply(this);
- });
+ // mark / unmark the field, and set the general 'submit' flag accordingly
+ if( data.valid )
+ unmark( field );
+ else{
+ mark( field, alertTxt );
+ submit = false;
+ }
- return !!submit; // casting the variable to make sure it's a boolean
- }
+ return data.valid;
+ }
- return {
- defaults : defaults,
- checkField : checkField,
- keypress : keypress,
- checkAll : checkAll,
- mark : mark,
- unmark : unmark,
- message : message,
- tests : tests
- }
-})(jQuery);
\ No newline at end of file
+ /* vaildates all the REQUIRED fields prior to submiting the form
+ */
+ function checkAll( $form ){
+ $form = $($form);
+
+ if( $form.length == 0 ){
+ console.warn('element not found');
+ return false;
+ }
+
+ var that = this,
+ submit = true, // save the scope
+ // get all the input/textareas/select fields which are required or optional (meaning, they need validation only if they were filled)
+ fieldsToCheck = $form.find(':input').filter('[required=required], .required, .optional').not('[disabled=disabled]');
+
+ fieldsToCheck.each(function(){
+ // use an AND operation, so if any of the fields returns 'false' then the submitted result will be also FALSE
+ submit = submit * checkField.apply(this);
+ });
+
+ return !!submit; // casting the variable to make sure it's a boolean
+ }
+
+ return {
+ defaults : defaults,
+ checkField : checkField,
+ keypress : keypress,
+ checkAll : checkAll,
+ mark : mark,
+ unmark : unmark,
+ message : message,
+ tests : tests
+ }
+})(jQuery);
diff --git a/production/media_gallery.html b/production/media_gallery.html
index 443f34dc..709d1af0 100755
--- a/production/media_gallery.html
+++ b/production/media_gallery.html
@@ -563,9 +563,8 @@