1// ReSharper disable once UnusedParameter 2(function (lgan, $, undefined) { 3 "use strict"; 4 5 let growl; 6 const onSuccess = []; 7 const onFail = []; 8 9 const validate = lgan.Class.extend({ 10 init: function (useGrowl) { 11 const me = this; 12 13 growl = useGrowl || true; 14 15 me.checks = []; 16 me.list = $("<ul><ul>"); 17 18 me.e = $("#errors").hide().addClass("ui-widget").append( 19 $("<div class='ui-state-error ui-corner-all'></div>") 20 .append("<span class='ui-icon ui-icon-alert' style='float: left; margin-right: .3em;'></span><strong>Error:</strong>") 21 .append(me.list) 22 ); 23 24 return this; 25 }, 26 27 growl: function (useGrowl) { 28 growl = useGrowl; 29 30 return this; 31 }, 32 33 onSuccess: function (success) { 34 if (typeof success === "function") { 35 onSuccess.push(lgan.createBoundedWrapper(this, success)); 36 } 37 38 return this; 39 }, 40 41 onFail: function (fail) { 42 if (typeof fail === "function") { 43 onFail.push(lgan.createBoundedWrapper(this, fail)); 44 } 45 46 return this; 47 }, 48 49 add: function (title, message, method, stickiness) { 50 const v = {stickiness: stickiness}; 51 52 if (typeof title === "function") { 53 v.method = title; 54 } 55 56 if (typeof title === "string" && typeof message === "function") { 57 v.message = title; 58 v.method = message; 59 } 60 61 if (typeof title === "string" && typeof message === "string" && typeof method === "function") { 62 v.title = title; 63 v.message = message; 64 v.method = method; 65 } 66 67 this.checks.push(v); 68 69 return this; 70 }, 71 72 empty: function () { 73 this.checks = []; 74 }, 75 76 validate: function (success, fail) { 77 let me = this, 78 isValid = true; 79 80 me.onSuccess(success).onFail(fail); 81 82 me.list.empty(); 83 84 if (me.checks.length > 0) { 85 let ar = [], check; 86 87 let iCheck = 0, lCheck = me.checks.length; 88 for (; iCheck < lCheck; iCheck++) { 89 check = me.checks[iCheck]; 90 ar[iCheck] = check.method(); 91 isValid = isValid && ar[iCheck]; 92 93 if (!ar[iCheck] && check.message) { 94 if (growl) { 95 lgan.growl("error", check.message, check.title || "Validation Error", check.stickiness); 96 } else { 97 me.list.append("<li>" + check.message + "</li>"); 98 } 99 } 100 } 101 } 102 103 if (isValid) { 104 me.e.hide(); 105 106 if (onSuccess.length > 0) { 107 let iSuc = 0, lSuc = onSuccess.length; 108 for (; iSuc < lSuc; iSuc++) { 109 onSuccess[iSuc](); 110 } 111 } 112 } else { 113 if (!growl) { 114 me.e.show(); 115 } 116 117 if (onFail.length > 0) { 118 let iFail = 0, lFail = onFail.length; 119 for (; iFail < lFail; iFail++) { 120 onFail[iFail](); 121 } 122 } 123 } 124 125 return isValid; 126 } 127 }); 128 129 lgan.ns({Validate: validate}); 130}(window.lgan = window.lgan || {}, jQuery)); 131 132
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.