Skip to content
Browse files

build version 0.7.2

  • Loading branch information...
1 parent 2d6fd6c commit c0d9b0638b1d30b5fbbc3bd14e825e8f810927a3 @wilkerlucio committed
Showing with 113 additions and 1 deletion.
  1. +1 −1 VERSION
  2. +112 −0 dist/jcheck-0.7.2 .min.js
View
2 VERSION
@@ -1 +1 @@
-0.7.1
+0.7.2
View
112 dist/jcheck-0.7.2 .min.js
@@ -0,0 +1,112 @@
+/**
+ * Copyright (c) 2010 Wilker Lúcio
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+(function($){Array.wrap=function(data){if($.isArray(data)){return data;}else{return[data];}};Array.prototype.extract_options=function(){if($.isPlainObject(this[this.length-1])){return this.pop();}else{return{};}};Array.prototype.isEqual=function(other){var key,value,_len;if(!$.isArray(other)){return false;}
+if(this.length!==other.length){return false;}
+for(key=0,_len=this.length;key<_len;key++){value=this[key];if(value!==other[key]){return false;}}
+return true;};String.prototype.simple_template_replace=function(options){var key,replacement,text;text=this+"";for(key in options){replacement=options[key];text=text.replace("%{"+key+"}",replacement);}
+return text;};String.prototype.uc_first=function(){return this.charAt(0).toUpperCase()+this.substr(1);};String.prototype.camelize=function(){var parts,str;parts=(function(){var _i,_len,_ref,_results;_ref=this.split("_");_results=[];for(_i=0,_len=_ref.length;_i<_len;_i++){str=_ref[_i];_results.push(str.uc_first());}
+return _results;}).call(this);return parts.join('');};$.isString=function(value){return(typeof value)==="string";};window.is_blank=function(object){if(object==null){return true;}
+if($.isString(object)&&object.replace(/^\s+|\s+$/,'').length===0){return true;}
+return false;};window.delete_object_property=function(object,property){var value;value=object[property]||null;delete object[property];return value;};window.object_without_properties=function(object,properties){var obj,property,_i,_len;obj=$.extend({},object);for(_i=0,_len=properties.length;_i<_len;_i++){property=properties[_i];delete obj[property];}
+return obj;};window.extract_keys=function(object){var key,_results;_results=[];for(key in object){_results.push(key);}
+return _results;};window.slice_object=function(object,keys){var key,obj,_i,_len;obj={};for(_i=0,_len=keys.length;_i<_len;_i++){key=keys[_i];if(object[key]!=null){obj[key]=object[key];}}
+return obj;};window.slice_object_and_remove=function(object,keys){var k,obj,v;obj={};for(k in object){v=object[k];if($.inArray(k,keys)===-1){obj[k]=object[k];delete object[k];}}
+return obj;};if(window.console==null){return window.console={log:function(){},dir:function(){},error:function(){}};}})(jQuery);var __bind=function(fn,me){return function(){return fn.apply(me,arguments);};};(function($){$.FormCheck=(function(){function FormCheck(form,options){this.form=form;this.options=$.extend({prevent_submit:true,field_prefix:null,notifiers:$.FormCheck.default_notifiers,live_notifiers:$.FormCheck.default_live_notifiers,language:$.FormCheck.default_locale,auto_parse:true,enabled:true},options||{});this.field_cache={};this.errors=new $.FormCheck.Errors(this);this.validations=[];this.hook_events();this.setup_notifiers();if(this.options.auto_parse){this.parse_inline_validations();}}
+FormCheck.prototype.parse_inline_validations=function(){return this.form.find(":input[data-validations]").each(__bind(function(index,element){var e,field_name,validations;e=$(element);field_name=this.parse_field_name(e);validations=this.parse_validation_string(e.attr("data-validations"));return this.validates(field_name,validations);},this));};FormCheck.prototype.parse_validation_string=function(validation_string){var validations;validations={};try{validations=eval("({"+validation_string+"})");}catch(e){console.error("can't parse \""+validation_string+"\"");}
+return validations;};FormCheck.prototype.hook_events=function(){var self;this.form.submit(__bind(function(e){var notifier,_i,_len,_ref,_results;if(!this.options.enabled){return;}
+if(!this.is_valid()){if(this.options.prevent_submit){e.preventDefault();}
+_ref=this.notifiers;_results=[];for(_i=0,_len=_ref.length;_i<_len;_i++){notifier=_ref[_i];_results.push(notifier.notify());}
+return _results;}},this));self=this;return this.form.find(":input").each(function(){var field,name;name=self.parse_field_name($(this));if(name){field=self.field(name);if(self.options.live_notifiers){return(function(el){var f,n;n=name;f=field;el.focus(function(e){self.is_valid();return self.dispatch_live_notifiers("focus",n,e,f.live_notifiers);});return el.blur(function(e){self.is_valid();return self.dispatch_live_notifiers("blur",n,e,f.live_notifiers);});})($(this));}}});};FormCheck.prototype.dispatch_live_notifiers=function(callback,attribute,event,notifiers){var current_notifiers,n,notifier,_i,_j,_len,_len2,_results;current_notifiers=[];for(_i=0,_len=notifiers.length;_i<_len;_i++){n=notifiers[_i];if(n===":parent"){current_notifiers=current_notifiers.concat(this.live_notifiers);}else{current_notifiers.push(this.get_notifier(n));}}
+_results=[];for(_j=0,_len2=current_notifiers.length;_j<_len2;_j++){notifier=current_notifiers[_j];_results.push(notifier[callback](attribute,event));}
+return _results;};FormCheck.prototype.setup_notifiers=function(){var kind,type,_i,_len,_ref,_results;_ref=["notifiers","live_notifiers"];_results=[];for(_i=0,_len=_ref.length;_i<_len;_i++){type=_ref[_i];this[type]=[];_results.push((function(){var _j,_len2,_ref2,_results2;if(this.options[type]){_ref2=this.options[type];_results2=[];for(_j=0,_len2=_ref2.length;_j<_len2;_j++){kind=_ref2[_j];_results2.push(this[type]=this.get_notifier(kind));}
+return _results2;}}).call(this));}
+return _results;};FormCheck.prototype.get_notifier=function(notifier){var creator,notifier_class,parameters;parameters=[this];if($.isArray(notifier)){parameters=parameters.concat(notifier.slice(1));notifier=notifier[0];}
+if($.isString(notifier)){notifier_class=$.FormCheck.find_notifier(notifier);creator=function(){return notifier_class.apply(this,parameters);};creator.prototype=notifier_class.prototype;return new creator();}else{notifier.form=this;return notifier;}};FormCheck.prototype.validate=function(validator){return this.validations.push(validator);};FormCheck.prototype.field=function(name){var _base,_ref;if((_ref=(_base=this.field_cache)[name])!=null){_ref;}else{_base[name]=new $.FormCheck.Field(this,this.field_name(name),name);};return this.field_cache[name];};FormCheck.prototype.is_valid=function(){var validation,_i,_len,_ref;this.errors.clear();_ref=this.validations;for(_i=0,_len=_ref.length;_i<_len;_i++){validation=_ref[_i];validation(this);}
+return this.errors.size()===0;};FormCheck.prototype.parse_field_name=function(input){var name;name=input.attr("name");if(!name){return null;}
+return this.reverse_field_name(name);};FormCheck.prototype.reverse_field_name=function(name){var matches;if(this.options.field_prefix){if(matches=name.match(new RegExp(""+this.options.field_prefix+"\\[(.+?)\\](.*)"))){name=matches[1]+(matches[2]||"");}else{name=":"+name;}}
+return name;};FormCheck.prototype.field_name=function(name){var matches,subparts;if(matches=name.match(/^:(.+)/)){return matches[1];}
+if(this.options.field_prefix){subparts="";if(matches=name.match(/(.+?)(\[.+)$/)){name=matches[1];subparts=matches[2];}
+return""+this.options.field_prefix+"["+name+"]"+subparts;}else{return name;}};FormCheck.prototype.disable=function(){return this.options.enabled=false;};FormCheck.prototype.enable=function(){return this.options.enabled=true;};return FormCheck;})();$.FormCheck.default_locale="en";$.FormCheck.default_notifiers=["notification_dialog"];$.FormCheck.default_live_notifiers=["tip_balloons"];$.FormCheck.Field=(function(){function Field(form,name,attribute){var evt,_i,_len,_ref;this.form_checker=form;this.field_name=name;this.attribute=attribute;this.live_notifiers=[":parent"];this.element=this.form_checker.form.find(":input[name='"+name+"']");this.custom_label=null;if(this.form_checker.options.live_notifiers){_ref=this.events_for_element();for(_i=0,_len=_ref.length;_i<_len;_i++){evt=_ref[_i];this.element[evt](__bind(function(e){this.form_checker.is_valid();return this.form_checker.dispatch_live_notifiers("notify",this.attribute,e,this.live_notifiers);},this));}}}
+Field.prototype.events_for_element=function(){if(this.element.length===0){return[];}
+if(this.element.attr("type")==="radio"||this.element.attr("type")==="checkbox"){return["change"];}
+if(this.element[0].tagName.toLowerCase()==="select"){return["keyup","change"];}
+return["keyup"];};Field.prototype.value=function(){if(this.element.attr("type")==="radio"){return this.value_for_radio();}
+if(this.element.attr("type")==="checkbox"){return this.value_for_checkbox();}
+return this.value_for_text();};Field.prototype.value_for_text=function(){return this.element.val()||"";};Field.prototype.value_for_radio=function(){return this.element.filter(":checked").val()||"";};Field.prototype.value_for_checkbox=function(){if(this.element.length>1){return $.makeArray(this.element.filter(":checked").map(function(){return $(this).val();}));}else{if(this.element[0].checked){return this.element.val();}else{return"";}}};Field.prototype.label=function(){var field_id,label_element,matches;if(this.custom_label!==null){if($.isFunction(this.custom_label)){return this.custom_label.call(this);}else{return this.custom_label;}}
+field_id=this.element.attr("id");if(this.element.length>1){if(matches=field_id.match(/(.+)_.+$/)){field_id=matches[1];}}
+label_element=this.form_checker.form.find("label[for='"+field_id+"']");if(label_element.length>0){return label_element.text();}else{return this.field_name;}};return Field;})();$.fn.jcheck=function(options){return new $.FormCheck($(this),options||{});};return $(function(){return $("form[data-jcheck=true]").jcheck();});})(jQuery);var __bind=function(fn,me){return function(){return fn.apply(me,arguments);};};(function($){return $.FormCheck.Errors=(function(){function Errors(form){this.form_checker=form;this.clear();}
+Errors.prototype.clear=function(){return this.errors={};};Errors.prototype.add=function(field,message,options){var _base,_ref;if(options!=null){options;}else{options={};};if(message!=null){message;}else{message=":invalid";};if((_ref=(_base=this.errors)[field])!=null){_ref;}else{_base[field]=[];};if(options.message!=null){message=options.message;}
+message=this.generate_message(message,options);message=message.simple_template_replace(options);return this.errors[field].push(message);};Errors.prototype.attributes_with_errors=function(){var attribute,attributes,errors,_ref;attributes=[];_ref=this.errors;for(attribute in _ref){errors=_ref[attribute];if(errors.length>0){attributes.push(attribute);}}
+return attributes;};Errors.prototype.on=function(attribute){var _base,_ref;if((_ref=(_base=this.errors)[attribute])!=null){_ref;}else{_base[attribute]=[];};return this.errors[attribute];};Errors.prototype.each=function(fn){var attribute,error,errors,_ref,_results;_ref=this.errors;_results=[];for(attribute in _ref){errors=_ref[attribute];_results.push((function(){var _i,_len,_results2;_results2=[];for(_i=0,_len=errors.length;_i<_len;_i++){error=errors[_i];_results2.push(fn(attribute,error));}
+return _results2;})());}
+return _results;};Errors.prototype.size=function(){var attribute,messages,sum,_ref;sum=0;_ref=this.errors;for(attribute in _ref){messages=_ref[attribute];sum+=messages.length;}
+return sum;};Errors.prototype.full_messages=function(){var messages;messages=[];this.each(__bind(function(attribute,message){attribute=this.form_checker.field(attribute).label();return messages.push(""+attribute+" "+message);},this));return messages;};Errors.prototype.generate_message=function(message){var match;if(match=message.match(/^:(.+)/)){return $.FormCheck.i18n.translate("errors.messages."+match[1],this.form_checker.options.language);}else{return message;}};return Errors;})();})(jQuery);var __hasProp=Object.prototype.hasOwnProperty,__extends=function(child,parent){for(var key in parent){if(__hasProp.call(parent,key))child[key]=parent[key];}
+function ctor(){this.constructor=child;}
+ctor.prototype=parent.prototype;child.prototype=new ctor;child.__super__=parent.prototype;return child;},__bind=function(fn,me){return function(){return fn.apply(me,arguments);};};(function($){$.FormCheck.Notifiers={};$.FormCheck.Notifiers.create=function(name,object,base){var class_name,notifier;object=$.extend({constructor:function(){},focus:function(){return this.notify.apply(this,arguments);},blur:function(){},notify:function(){}},object||{});if(base!=null){base;}else{base=$.FormCheck.Notifiers.Base;};class_name=name.camelize()+"Notifier";notifier=(function(){function notifier(){notifier.__super__.constructor.apply(this,arguments);this.constructor.apply(this,arguments);}
+__extends(notifier,base);return notifier;})();$.extend(notifier.prototype,object);notifier.kind=name;$.FormCheck.Notifiers[class_name]=notifier;return notifier;};$.FormCheck.find_notifier=function(kind){var name,notifier,_ref;_ref=$.FormCheck.Notifiers;for(name in _ref){notifier=_ref[name];if(notifier.kind===kind){return notifier;}}};$.FormCheck.Notifiers.Base=(function(){function Base(form){this.form=form;}
+Base.prototype.focus=function(attribute){};Base.prototype.notify=function(attribute){};Base.prototype.blur=function(attribute){};return Base;})();$.FormCheck.Notifiers.DialogBase=(function(){function DialogBase(){DialogBase.__super__.constructor.apply(this,arguments);}
+__extends(DialogBase,$.FormCheck.Notifiers.Base);DialogBase.prototype.populate_dialog=function(dialog,messages){var html,m,_i,_len;html="<ul>";for(_i=0,_len=messages.length;_i<_len;_i++){m=messages[_i];html+="<li>* "+m+"</li>";}
+html+="</ul>";return dialog.html(html);};return DialogBase;})();$.FormCheck.Notifiers.NotificationDialog=(function(){function NotificationDialog(form,options){NotificationDialog.__super__.constructor.call(this,form);this.options=$.extend({autoclose_in:4000},options||{});}
+__extends(NotificationDialog,$.FormCheck.Notifiers.DialogBase);NotificationDialog.prototype.notify=function(){var dialog;dialog=this.generate_dialog();dialog.css({left:"-1000px"});this.populate_dialog(dialog,this.form.errors.full_messages());dialog.css({"margin-top":"-"+(dialog.outerHeight()+10)+"px",left:"50%","margin-left":"-"+(Math.round(dialog.outerWidth()/2))+"px"});dialog.show();dialog.animate({"margin-top":"0px"});return dialog.mouseout();};NotificationDialog.prototype.close_dialog=function(){return this.current_dialog.animate({"margin-top":"-"+(this.current_dialog.outerHeight()+10)+"px"},{complete:function(){return $(this).hide();}});};NotificationDialog.prototype.generate_dialog=function(){var dialog,dialog_id;if($.FormCheck.Notifiers.NotificationDialog.dialog_timer){clearTimeout($.FormCheck.Notifiers.NotificationDialog.dialog_timer);}
+dialog_id="jcheck-error-dialog";$("#"+dialog_id).remove();dialog=$(document.createElement("div"));dialog.attr("id",dialog_id);this.current_dialog=dialog;if($.browser.msie&&parseInt($.browser.version)<7){dialog.addClass("ie-fixed");}
+dialog.click(__bind(function(){return this.close_dialog();},this));if(this.options.autoclose_in){dialog.mouseover(__bind(function(){if($.FormCheck.Notifiers.NotificationDialog.dialog_timer){return clearTimeout($.FormCheck.Notifiers.NotificationDialog.dialog_timer);}},this));dialog.mouseout(__bind(function(){var callback,self;self=this;callback=function(){return self.close_dialog();};return $.FormCheck.Notifiers.NotificationDialog.dialog_timer=setTimeout(callback,this.options.autoclose_in);},this));}
+$(document.body).append(dialog);return dialog;};return NotificationDialog;})();$.FormCheck.Notifiers.NotificationDialog.dialog_timer=0;$.FormCheck.Notifiers.NotificationDialog.kind="notification_dialog";$.FormCheck.Notifiers.TipBalloons=(function(){function TipBalloons(form){TipBalloons.__super__.constructor.call(this,form);this.balloons={};}
+__extends(TipBalloons,$.FormCheck.Notifiers.DialogBase);TipBalloons.prototype.focus=function(attribute,evt){return this.notify(attribute,evt||null);};TipBalloons.prototype.notify=function(attribute,evt){var dialog,element,messages,offset,populate_and_reposition;dialog=this.dialog_for_attribute(attribute);messages=this.form.errors.on(attribute);if(messages.isEqual(dialog.messages)){return;}
+element=evt&&evt.target?$(evt.target):this.form.element;offset=element.offset();populate_and_reposition=__bind(function(messages){this.populate_dialog(dialog,messages);return dialog.css({top:""+(offset.top-dialog.outerHeight())+"px",left:""+(offset.left+Math.round(element.outerWidth()*0.9))+"px"});},this);if(messages.length>0){if(dialog.messages&&dialog.messages.length>0){populate_and_reposition(messages);}else{dialog.css({left:"-1000px",top:"-1000px"});dialog.hide();populate_and_reposition(messages);dialog.fadeIn("fast");}}else{this.close_dialog(attribute);}
+return dialog.messages=messages;};TipBalloons.prototype.blur=function(attribute){return this.close_dialog(attribute);};TipBalloons.prototype.dialog_for_attribute=function(attribute){if(!this.balloons[attribute]){this.balloons[attribute]=this.generate_dialog();}
+return this.balloons[attribute];};TipBalloons.prototype.close_dialog=function(attribute){var dialog;dialog=this.dialog_for_attribute(attribute);dialog.messages=null;return dialog.fadeOut("fast");};TipBalloons.prototype.generate_dialog=function(){var arrow,content_area,dialog;dialog=null;dialog=$(document.createElement("div"));dialog.addClass("jcheck-inline-balloon-tip");dialog.css({position:"absolute",top:"-1000px",left:"-1000px"});content_area=$(document.createElement("div"));content_area.addClass("content");dialog.append(content_area);arrow=this.generate_arrow();dialog.append(arrow);$(document.body).append(dialog);return dialog;};TipBalloons.prototype.generate_arrow=function(){var center,container,i,line,max_width,x;i=10;container=$(document.createElement("div"));container.addClass("arrow-container");center=i/2;max_width=null;while(i>0){x=i*2-center;if(x<0){x=center+x-1;}
+line=$(document.createElement("div"));line.addClass("line"+i);line.css({'font-size':0,width:""+x+"px",height:"1px",margin:"0 auto"});container.append(line);i-=1;}
+return container;};TipBalloons.prototype.populate_dialog=function(dialog,messages){return TipBalloons.__super__.populate_dialog.call(this,dialog.find(".content"),messages);};return TipBalloons;})();return $.FormCheck.Notifiers.TipBalloons.kind="tip_balloons";})(jQuery);var __hasProp=Object.prototype.hasOwnProperty,__extends=function(child,parent){for(var key in parent){if(__hasProp.call(parent,key))child[key]=parent[key];}
+function ctor(){this.constructor=child;}
+ctor.prototype=parent.prototype;child.prototype=new ctor;child.__super__=parent.prototype;return child;},__slice=Array.prototype.slice;(function($){$.FormCheck.Validations={};$.FormCheck.find_validator=function(kind){var k,validator,_ref;_ref=$.FormCheck.Validations;for(k in _ref){validator=_ref[k];if(validator.kind===kind){return validator;}}
+return null;};$.FormCheck.Validator=(function(){function Validator(options){this.options=options;}
+Validator.prototype.kind=function(){};Validator.prototype.validate=function(form){};return Validator;})();$.FormCheck.EachValidator=(function(){function EachValidator(options){this.attributes=Array.wrap(delete_object_property(options,"attributes"));if(options["allow_nil"]){options["allow_blank"]=true;}
+if(options["allow_blank"]){options["allow_nil"]=true;}
+EachValidator.__super__.constructor.call(this,options);this.check_valitity();}
+__extends(EachValidator,$.FormCheck.Validator);EachValidator.prototype.validate=function(form){var attribute,value,_i,_len,_ref,_results;_ref=this.attributes;_results=[];for(_i=0,_len=_ref.length;_i<_len;_i++){attribute=_ref[_i];value=form.field(attribute).value();if(is_blank(value)&&this.options["allow_blank"]){continue;}
+_results.push(this.validate_each(form,attribute,value));}
+return _results;};EachValidator.prototype.validate_each=function(record,attribute,value){};EachValidator.prototype.check_valitity=function(){};return EachValidator;})();$.FormCheck.prototype.validates_with=function(){var options,validator,validator_klass,validators,_i,_j,_len,_results;validators=2<=arguments.length?__slice.call(arguments,0,_i=arguments.length-1):(_i=0,[]),options=arguments[_i++];_results=[];for(_j=0,_len=validators.length;_j<_len;_j++){validator_klass=validators[_j];validator=new validator_klass(options);_results.push(this.validate(function(form){return validator.validate(form);}));}
+return _results;};$.FormCheck.prototype.attributes_for_with=function(attributes){var options;options=attributes.extract_options();return $.extend(options,{attributes:attributes});};$.FormCheck.Validator.create=function(name,object,base){var class_name,validator;object=$.extend({constructor:function(){}},object||{});if(base!=null){base;}else{base=$.FormCheck.EachValidator;};class_name=name.camelize()+"Validator";validator=(function(){function validator(){validator.__super__.constructor.apply(this,arguments);this.constructor.apply(this,arguments);}
+__extends(validator,base);return validator;})();$.extend(validator.prototype,object);validator.kind=name;$.FormCheck.Validations[class_name]=validator;$.FormCheck.prototype["validates_"+name+"_of"]=function(){var attributes;attributes=1<=arguments.length?__slice.call(arguments,0):[];return this.validates_with(validator,this.attributes_for_with(attributes));};return validator;};$.FormCheck.Validations.BlockValidator=(function(){function BlockValidator(options){this.callback=delete_object_property(options,'callback')||$.noop;BlockValidator.__super__.constructor.call(this,options);}
+__extends(BlockValidator,$.FormCheck.EachValidator);BlockValidator.prototype.validate_each=function(form,attribute,value){return this.callback.call(this,form,attribute,value);};return BlockValidator;})();$.FormCheck.prototype.validates_each=function(){var attributes,options;attributes=1<=arguments.length?__slice.call(arguments,0):[];options=this.attributes_for_with(attributes);if($.isFunction(options.attributes[options.attributes.length-1])){options.callback=attributes.pop();}
+return this.validates_with($.FormCheck.Validations.BlockValidator,options);};$.FormCheck.Validations.AcceptanceValidator=(function(){function AcceptanceValidator(options){AcceptanceValidator.__super__.constructor.call(this,$.extend({accept:'1'},options));}
+__extends(AcceptanceValidator,$.FormCheck.EachValidator);AcceptanceValidator.prototype.validate_each=function(form,attribute,value){if(value!==this.options.accept){return form.errors.add(attribute,":accepted",object_without_properties(this.options,['accept','allow_nil']));}};return AcceptanceValidator;})();$.FormCheck.Validations.AcceptanceValidator.kind="acceptance";$.FormCheck.prototype.validates_acceptance_of=function(){var attributes;attributes=1<=arguments.length?__slice.call(arguments,0):[];return this.validates_with($.FormCheck.Validations.AcceptanceValidator,this.attributes_for_with(attributes));};$.FormCheck.Validations.ConfirmationValidator=(function(){function ConfirmationValidator(){ConfirmationValidator.__super__.constructor.apply(this,arguments);}
+__extends(ConfirmationValidator,$.FormCheck.EachValidator);ConfirmationValidator.prototype.validate_each=function(form,attribute,value){var confirmed,confirmed_field_name;confirmed_field_name=attribute+"_confirmation";confirmed=form.field(confirmed_field_name).value();if(value!==confirmed){return form.errors.add(confirmed_field_name,":confirmation",this.options);}};return ConfirmationValidator;})();$.FormCheck.Validations.ConfirmationValidator.kind="confirmation";$.FormCheck.prototype.validates_confirmation_of=function(){var attributes;attributes=1<=arguments.length?__slice.call(arguments,0):[];return this.validates_with($.FormCheck.Validations.ConfirmationValidator,this.attributes_for_with(attributes));};$.FormCheck.Validations.ExclusionValidator=(function(){function ExclusionValidator(){ExclusionValidator.__super__.constructor.apply(this,arguments);}
+__extends(ExclusionValidator,$.FormCheck.EachValidator);ExclusionValidator.prototype.validate_each=function(form,attribute,value){if($.inArray(value,this.options["in"])>-1){return form.errors.add(attribute,":exclusion",$.extend(object_without_properties(this.options,['in']),{value:value}));}};return ExclusionValidator;})();$.FormCheck.Validations.ExclusionValidator.kind="exclusion";$.FormCheck.prototype.validates_exclusion_of=function(){var attributes;attributes=1<=arguments.length?__slice.call(arguments,0):[];return this.validates_with($.FormCheck.Validations.ExclusionValidator,this.attributes_for_with(attributes));};$.FormCheck.Validations.FormatValidator=(function(){function FormatValidator(options){var opt,_i,_len,_ref;_ref=["with","without"];for(_i=0,_len=_ref.length;_i<_len;_i++){opt=_ref[_i];if((options[opt]!=null)&&$.isString(options[opt])){options[opt]=$.FormCheck.Validations.FormatValidator.FORMATS[options[opt]];}}
+FormatValidator.__super__.constructor.call(this,options);}
+__extends(FormatValidator,$.FormCheck.EachValidator);FormatValidator.prototype.validate_each=function(form,attribute,value){if(this.options["with"]&&!((value+"").match(this.options["with"]))){form.errors.add(attribute,":invalid",$.extend(object_without_properties(this.options,['with']),{value:value}));}
+if(this.options["without"]&&(value+"").match(this.options["without"])){return form.errors.add(attribute,":invalid",$.extend(object_without_properties(this.options,['without']),{value:value}));}};return FormatValidator;})();$.FormCheck.Validations.FormatValidator.FORMATS={email:/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i,url:/^[A-Za-z]+:\/\/[A-Za-z0-9-_]+(\.[a-zA-Z0-9]+)+(:\d+)?[A-Za-z0-9-_%&\?\/.=]+$/};$.FormCheck.Validations.FormatValidator.kind="format";$.FormCheck.prototype.validates_format_of=function(){var attributes;attributes=1<=arguments.length?__slice.call(arguments,0):[];return this.validates_with($.FormCheck.Validations.FormatValidator,this.attributes_for_with(attributes));};$.FormCheck.Validations.InclusionValidator=(function(){function InclusionValidator(){InclusionValidator.__super__.constructor.apply(this,arguments);}
+__extends(InclusionValidator,$.FormCheck.EachValidator);InclusionValidator.prototype.validate_each=function(form,attribute,value){if($.inArray(value,this.options["in"])===-1){return form.errors.add(attribute,":inclusion",$.extend(object_without_properties(this.options,['in']),{value:value}));}};return InclusionValidator;})();$.FormCheck.Validations.InclusionValidator.kind="inclusion";$.FormCheck.prototype.validates_inclusion_of=function(){var attributes;attributes=1<=arguments.length?__slice.call(arguments,0):[];return this.validates_with($.FormCheck.Validations.InclusionValidator,this.attributes_for_with(attributes));};$.FormCheck.Validations.LengthValidator=(function(){function LengthValidator(options){LengthValidator.__super__.constructor.call(this,$.extend({tokenizer:$.FormCheck.Validations.LengthValidator.DEFAULT_TOKENIZER},options));}
+__extends(LengthValidator,$.FormCheck.EachValidator);LengthValidator.prototype.validate_each=function(form,attribute,value){var _base,_base2,_base3,_ref,_ref2,_ref3;if($.isString(value)){value=this.options.tokenizer(value);}
+if(this.options["is"]&&this.options["is"]!==value.length){if(this.options["wrong_length"]!=null){if((_ref=(_base=this.options)["message"])!=null){_ref;}else{_base["message"]=this.options["wrong_length"];};}
+form.errors.add(attribute,":wrong_length",$.extend(object_without_properties(this.options,$.FormCheck.Validations.LengthValidator.RESERVED_OPTIONS),{count:this.options["is"]}));}
+if(this.options["minimum"]&&this.options["minimum"]>value.length){if(this.options["too_short"]!=null){if((_ref2=(_base2=this.options)["message"])!=null){_ref2;}else{_base2["message"]=this.options["too_short"];};}
+form.errors.add(attribute,":too_short",$.extend(object_without_properties(this.options,$.FormCheck.Validations.LengthValidator.RESERVED_OPTIONS),{count:this.options["minimum"]}));}
+if(this.options["maximum"]&&this.options["maximum"]<value.length){if(this.options["too_long"]!=null){if((_ref3=(_base3=this.options)["message"])!=null){_ref3;}else{_base3["message"]=this.options["too_long"];};}
+return form.errors.add(attribute,":too_long",$.extend(object_without_properties(this.options,$.FormCheck.Validations.LengthValidator.RESERVED_OPTIONS),{count:this.options["maximum"]}));}};return LengthValidator;})();$.FormCheck.Validations.LengthValidator.DEFAULT_TOKENIZER=function(value){return value.split('');};$.FormCheck.Validations.LengthValidator.RESERVED_OPTIONS=["minimum","maximum","is","tokenizer","too_long","too_short"];$.FormCheck.Validations.LengthValidator.kind="length";$.FormCheck.prototype.validates_length_of=function(){var attributes;attributes=1<=arguments.length?__slice.call(arguments,0):[];return this.validates_with($.FormCheck.Validations.LengthValidator,this.attributes_for_with(attributes));};$.FormCheck.Validations.NumericalityValidator=(function(){function NumericalityValidator(){NumericalityValidator.__super__.constructor.apply(this,arguments);}
+__extends(NumericalityValidator,$.FormCheck.EachValidator);NumericalityValidator.prototype.validate_each=function(form,attribute,value){var check,raw_value,val,_ref,_results;raw_value=value;value=parseFloat(value);if(isNaN(value)||!(raw_value.match(/\d+$/))){form.errors.add(attribute,":not_a_number",this.filtered_options(raw_value));return;}
+if(this.options.only_integer&&!(raw_value.match(/^[-]?\d+$/))){form.errors.add(attribute,":not_an_integer",this.filtered_options(raw_value));return;}else{value=parseInt(value);}
+_ref=slice_object(this.options,extract_keys($.FormCheck.Validations.NumericalityValidator.CHECKS));_results=[];for(check in _ref){val=_ref[check];_results.push((function(){switch(check){case"odd":case"even":if(!$.FormCheck.Validations.NumericalityValidator.CHECKS[check](value)){return form.errors.add(attribute,":"+check,this.filtered_options(val));}
+break;default:if(!$.FormCheck.Validations.NumericalityValidator.CHECKS[check](value,val)){return form.errors.add(attribute,":"+check,this.filtered_options(val));}}}).call(this));}
+return _results;};NumericalityValidator.prototype.filtered_options=function(value){return $.extend(object_without_properties(this.options,$.FormCheck.Validations.NumericalityValidator.RESERVED_OPTIONS),{count:value});};return NumericalityValidator;})();$.FormCheck.Validations.NumericalityValidator.CHECKS={greater_than:function(a,b){return a>b;},greater_than_or_equal_to:function(a,b){return a>=b;},equal_to:function(a,b){return a===b;},less_than:function(a,b){return a<b;},less_than_or_equal_to:function(a,b){return a<=b;},odd:function(n){return(n%2)===1;},even:function(n){return(n%2)===0;}};$.FormCheck.Validations.NumericalityValidator.RESERVED_OPTIONS=extract_keys($.FormCheck.Validations.NumericalityValidator.CHECKS).concat(["only_integer"]);$.FormCheck.Validations.NumericalityValidator.kind="numericality";$.FormCheck.prototype.validates_numericality_of=function(){var attributes;attributes=1<=arguments.length?__slice.call(arguments,0):[];return this.validates_with($.FormCheck.Validations.NumericalityValidator,this.attributes_for_with(attributes));};$.FormCheck.Validations.PresenceValidator=(function(){function PresenceValidator(){PresenceValidator.__super__.constructor.apply(this,arguments);}
+__extends(PresenceValidator,$.FormCheck.EachValidator);PresenceValidator.prototype.validate_each=function(form,attribute,value){if(is_blank(value)){return form.errors.add(attribute,":blank",this.options);}};return PresenceValidator;})();$.FormCheck.Validations.PresenceValidator.kind='presence';$.FormCheck.prototype.validates_presence_of=function(){var attributes;attributes=1<=arguments.length?__slice.call(arguments,0):[];return this.validates_with($.FormCheck.Validations.PresenceValidator,this.attributes_for_with(attributes));};$.FormCheck.prototype.validates=function(){var attributes,current_options,defaults,kind,options,validations,validator,_results;attributes=1<=arguments.length?__slice.call(arguments,0):[];defaults=attributes.extract_options();validations=slice_object_and_remove(defaults,["if","unless","allow_blank","allow_nil"]);$.extend(defaults,{attributes:attributes});_results=[];for(kind in validations){options=validations[kind];validator=$.FormCheck.find_validator(kind);current_options=$.extend({},defaults);_results.push(validator?this.validates_with(validator,$.extend(current_options,$.FormCheck.parse_validates_options(options))):void 0);}
+return _results;};return $.FormCheck.parse_validates_options=function(options){if($.isArray(options)){return{"in":options};}
+if(options.test!=null){return{"with":options};}
+if(options===true){return{};}
+if($.isPlainObject){return options;}
+return{};};})(jQuery);(function($){return $.FormCheck.i18n={default_language:"en",translate:function(path,language){var steps;if(language!=null){language;}else{language=$.FormCheck.i18n.default_language;};steps=path.split(".");steps.unshift(language);return $.FormCheck.i18n.translation_from_path(steps);},translation_from_path:function(steps){var current,step,_i,_len;current=$.FormCheck.i18n.languages;for(_i=0,_len=steps.length;_i<_len;_i++){step=steps[_i];current=current[step];if(current==null){return"";}}
+return current;},languages:{}};})(jQuery);jQuery.FormCheck.i18n.languages["en"]={errors:{messages:{inclusion:"%{value} is not a valid option",exclusion:"%{value} is reserved",invalid:"is invalid",confirmation:"doesn't match confirmation",accepted:"must be accepted",empty:"can't be empty",blank:"can't be blank",too_long:"is too long (maximum is %{count} characters)",too_short:"is too short (minimum is %{count} characters)",wrong_length:"is the wrong length (should be %{count} characters)",not_a_number:"is not a number",not_an_integer:"must be an integer",greater_than:"must be greater than %{count}",greater_than_or_equal_to:"must be greater than or equal to %{count}",equal_to:"must be equal to %{count}",less_than:"must be less than %{count}",less_than_or_equal_to:"must be less than or equal to %{count}",odd:"must be odd",even:"must be even"}}};

0 comments on commit c0d9b06

Please sign in to comment.
Something went wrong with that request. Please try again.