1(function ($) { 2 delete $.validator.methods.email; 3 4 var adapters = $.validator.unobtrusive.adapters; 5 adapters.fxbAddNumberVal = function (adapterName, attribute, ruleName) { 6 attribute = attribute || "val"; 7 ruleName = ruleName || adapterName; 8 this.add(adapterName, [attribute], function(options) { 9 var attrVal = options.params[attribute]; 10 if ((attrVal || attrVal === 0) && !isNaN(attrVal)) { 11 options.rules[ruleName] = Number(attrVal); 12 } 13 if (options.message) { 14 options.messages[ruleName] = options.message; 15 } 16 }); 17 }; 18 19 adapters.fxbAddMinMax = function(adapterName, minRuleName, maxRuleName, minAttribute, maxAttribute) { 20 minAttribute = minAttribute || "min"; 21 maxAttribute = maxAttribute || "max"; 22 this.add(adapterName, [minAttribute, maxAttribute], function(options) { 23 if (options.params[minAttribute] && options.params[maxAttribute]) { 24 if (!options.rules.hasOwnProperty(minRuleName)) { 25 if (options.message) { 26 options.messages[minRuleName] = options.message; 27 } 28 } 29 if (!options.rules.hasOwnProperty(maxRuleName)) { 30 if (options.message) { 31 options.messages[maxRuleName] = options.message; 32 } 33 } 34 } 35 }); 36 }; 37 38 adapters.addBool("ischecked", "required"); 39 40 $.validator.addMethod( 41 "daterange", 42 function(value, element, params) { 43 return this.optional(element) || (value >= params.min && value <= params.max); 44 }); 45 46 adapters.add( 47 "daterange", 48 ["min", "max"], 49 function(options) { 50 var params = { 51 min: options.params.min, 52 max: options.params.max 53 }; 54 options.rules["daterange"] = params; 55 options.messages["daterange"] = options.message; 56 }); 57 58 adapters.addSingleVal("filesize", "max"); 59 $.validator.addMethod( 60 "filesize", 61 function (value, element, max) { 62 if (!this.optional(element)) { 63 for (var i = 0; i < element.files.length; i++) { 64 if (element.files[i].size > max) { 65 return false; 66 } 67 } 68 } 69 return true; 70 }); 71 72 adapters.addSingleVal("filecount", "max"); 73 $.validator.addMethod( 74 "filecount", 75 function (value, element, max) { 76 if (!this.optional(element)) { 77 if (element.files.length > max) { 78 return false; 79 } 80 } 81 return true; 82 }); 83 84 adapters.addSingleVal("filetype", "allowedcontenttypes"); 85 $.validator.addMethod( 86 "filetype", 87 function (value, element, allowedContentTypes) { 88 if (!this.optional(element)) { 89 var allowedContentTypesArray = allowedContentTypes.split(",").filter(function (s) { 90 // Remove empty entries 91 return s !== ""; 92 }); 93 if (allowedContentTypesArray.length) { 94 for (var i = 0; i < element.files.length; i++) { 95 var file = element.files[i]; 96 var isValid = false; 97 for (var j = 0; j < allowedContentTypesArray.length; j++) { 98 var allowedContentType = allowedContentTypesArray[j]; 99 if (allowedContentType.indexOf("/") !== -1) { 100 // MIME type comparison if there is a slash "/" 101 isValid = allowedContentType.toLowerCase() === file.type.toLowerCase(); 102 } else { 103 // File extension comparison 104 isValid = allowedContentType.toLowerCase() === "." + file.name.split(".").pop().toLowerCase(); 105 } 106 107 if (isValid) { 108 break; 109 } 110 } 111 112 if (!isValid) { 113 return false; 114 } 115 } 116 } 117 } 118 return true; 119 }); 120 121 adapters.fxbAddNumberVal("min"); 122 adapters.fxbAddNumberVal("max"); 123 adapters.fxbAddNumberVal("step"); 124 125 adapters.fxbAddMinMax("range", "min", "max"); 126 adapters.fxbAddMinMax("length", "minlength", "maxlength"); 127 adapters.fxbAddMinMax("daterange", "min", "max"); 128})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.