PageSourceSearch

https://eletricista.adm.br/wp-content/plugins/profit_builder//js/form_validate.js?ver=1.0.5

js eletricista.adm.br collected 2026-10-06 13:16:02 UTC 5,584 bytes, 194 lines download raw bytes

1jQuery( document ).ready(function() {
2    var heightToAdd = jQuery(".pbuilder_row_stick_top").height();
3    heightToAdd = heightToAdd-28;
4    jQuery('.stick-top-div').css('height', heightToAdd+'px');
5});
6(function ($) {
7    /*
8     Validation Singleton
9     */
10    var Validation = function () {
11
12        var rules = {
13            email: {
14                check: function (value, default_value) {
15					if (value !== default_value)
16                        return testPattern(value, "[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])");
17                    return true;
18                },
19                msg: "Enter a valid e-mail address."
20            },
21            url: {
22                check: function (value, default_value) {
23
24                    if (value !== default_value)
25                        return testPattern(value, "^https?://(.+\.)+.{2,4}(/.*)?$");
26                    return true;
27                },
28                msg: "Enter a valid URL."
29            },
30            required: {
31                check: function (value, default_value) {
32                    if (value !== default_value)
33                        return true;
34                    else
35                        return false;
36                },
37                msg: "This field is required."
38            }
39        }
40        var testPattern = function (value, pattern) {
41
42            var regExp = new RegExp(pattern, "");
43            return regExp.test(value);
44        }
45        return {
46            addRule: function (name, rule) {
47
48                rules[name] = rule;
49            },
50            getRule: function (name) {
51
52                return rules[name];
53            }
54        }
55    }
56
57    /* 
58     Form factory 
59     */
60    var Form = function (form) {
61
62        var fields = [];
63
64        form.find("[validation]").each(function () {
65            var field = $(this);
66
67            if (field.attr('validation') !== undefined) {
68                fields.push(new Field(field));
69            }
70        });
71        this.fields = fields;
72    }
73    Form.prototype = {
74        validate: function () {
75
76            for (field in this.fields) {
77                if(field != "remove"){
78                this.fields[field].validate();
79            }
80            }
81        },
82        isValid: function () {
83
84            for (field in this.fields) {
85
86                if(field != "remove"){
87                if (!this.fields[field].valid) {
88                    this.fields[field].field.focus();
89                    return false;
90                }
91				}
92            }
93            return true;
94        }
95    }
96
97    /* 
98     Field factory 
99     */
100    var Field = function (field) {
101
102        this.field = field;
103        this.valid = false;
104        this.attach("change");
105    }
106    Field.prototype = {
107        attach: function (event) {
108
109            var obj = this;
110            if (event == "change") {
111                obj.field.bind("change", function () {
112                    return obj.validate();
113                });
114            }
115            if (event == "keyup") {
116                obj.field.bind("keyup", function (e) {
117                    return obj.validate();
118                });
119            }
120        },
121        validate: function () {
122
123            var obj = this,
124                    field = obj.field,
125                    errorClass = "errorlist",
126                    errorlist = $(document.createElement("ul")).addClass(errorClass),
127                    types = field.attr("validation").split(" "),
128                    container = field.parent(),
129                    errors = [];
130
131            field.next(".errorlist").remove();
132
133            for (var type in types) {
134                if (type != "remove") {
135                    var rule = $.Validation.getRule(types[type]);
136                    if (!rule.check(field.val(), field.attr('default-value'))) {
137                        container.addClass("error");
138                       
139                        errors.push(field.attr('error-message'));
140                        container.css("margin", '');
141                        field.css("border-color", 'red !important;');
142                        
143                    }
144                }
145            }
146            if (errors.length) {
147
148                obj.field.unbind("keyup")
149                obj.attach("keyup");
150                field.after(errorlist.empty());
151                
152                for (error in errors) {
153                    if(error != "remove"){
154                    errorlist.append("<li>" + errors[error].toString() + "</li>");
155                    }
156                }
157                obj.valid = false;
158            }
159            else {
160                errorlist.remove();
161                container.removeClass("error");
162                obj.valid = true;
163            }
164        }
165    }
166
167    /*
168     Validation extends jQuery prototype
169     */
170    $.extend($.fn, {
171        validation: function () {
172
173            var validator = new Form($(this));
174            $.data($(this)[0], 'validator', validator);
175
176            $(this).bind("submit", function (e) {
177                validator.validate();
178                if (!validator.isValid()) {
179                    e.preventDefault();
180                }
181            });
182        },
183        validate: function (form) {
184
185            var validator = new Form(form);
186            $.data(form, 'validator', validator);
187            validator.validate();
188            return validator.isValid();
189
190        }
191    });
192    $.Validation = new Validation();
193})(jQuery);
194

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.