PageSourceSearch

https://sellersprite.ai/assets-frontend/js/components/hs.validation.js

js sellersprite.ai collected 2026-09-24 13:04:10 UTC 3,290 bytes, 127 lines download raw bytes

1/**
2 * Validation wrapper.
3 *
4 * @author Htmlstream
5 * @version 1.0
6 * @requires
7 *
8 */
9var isEmpty = function isEmpty(f) {
10  return (/^function[^{]+\{\s*\}/m.test(f.toString())
11  );
12}
13
14;(function ($) {
15  'use strict';
16
17  $.HSCore.components.HSValidation = {
18    /**
19     *
20     *
21     * @var Object _baseConfig
22     */
23    _baseConfig: {
24      errorElement: 'div',
25      errorClass: 'invalid-feedback',
26      rules: {},
27      onkeyup: function(element){$(element).valid()},
28      errorPlacement: function(){},
29      highlight: function(){},
30      unhighlight: function(){}
31    },
32
33    /**
34     *
35     *
36     * @var jQuery pageCollection
37     */
38    pageCollection: $(),
39
40    /**
41     * Initialization of Validation wrapper.
42     *
43     * @param String selector (optional)
44     * @param Object config (optional)
45     *
46     * @return jQuery pageCollection - collection of initialized items.
47     */
48
49    init: function (selector, config) {
50      this.collection = selector && $(selector).length ? $(selector) : $();
51      if (!$(selector).length) return;
52
53      this.config = config && $.isPlainObject(config) ?
54        $.extend({}, this._baseConfig, config) : this._baseConfig;
55
56      this.config.itemSelector = selector;
57
58      this.initValidation();
59
60      return this.pageCollection;
61    },
62
63    initValidation: function () {
64      //Variables
65      var $self = this,
66        config = $self.config,
67        collection = $self.pageCollection;
68
69      //Actions
70      this.collection.each(function (i, el) {
71        //Variables
72        var $this = $(el);
73
74        if ($this.hasClass('js-step-form')) {
75          $.validator.setDefaults({
76            ignore: ':hidden:not(.active select)'
77          });
78        } else {
79          $.validator.setDefaults({
80            ignore: ':hidden:not(select)'
81          });
82        }
83
84        $this.validate({
85          errorElement: config['errorElement'],
86          errorClass: config['errorClass'],
87          rules: config['rules'],
88          onkeyup: config['onkeyup'],
89          errorPlacement: isEmpty(config['errorPlacement']) == true ? $self.errorPlacement : config['errorPlacement'],
90          highlight: isEmpty(config['highlight']) == true ? $self.highlight : config['highlight'],
91          unhighlight: isEmpty(config['unhighlight']) == true ? $self.unHighlight : config['unhighlight']
92        });
93
94        $('select').change(function () {
95          $(this).valid();
96        });
97
98        //Actions
99        collection = collection.add($this);
100      });
101    },
102
103    errorPlacement: function (error, element) {
104      var $this = $(element),
105        errorMsgClasses = $this.data('msg-classes');
106
107      error.addClass(errorMsgClasses);
108      error.appendTo(element.parents('.js-form-message'));
109    },
110
111    highlight: function (element) {
112      var $this = $(element),
113        errorClass = $this.data('error-class'),
114        successClass = $this.data('success-class');
115
116      $this.parents('.js-form-message').removeClass(successClass).addClass(errorClass);
117    },
118
119    unHighlight: function (element) {
120      var $this = $(element),
121        errorClass = $this.data('error-class'),
122        successClass = $this.data('success-class');
123
124      $this.parents('.js-form-message').removeClass(errorClass).addClass(successClass);
125    }
126  }
127})(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.