PageSourceSearch

https://superhumanoid.info/superblog/wp-content/plugins/profit_builder//js/form_validate.js?ver=1.0.5

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