PageSourceSearch

https://store.sgsonline.com.cn/app/topc/statics/scripts/formplus.js?1599222418

js sgsonline.com.cn collected 2026-10-02 18:49:43 UTC 6,910 bytes, 236 lines download raw bytes

1/*------- Author: Tyler [email protected] -------*/
2
3//=密码强度检测
4var passwordStrength = function(value, key, className){
5    //最小最大长度
6    var minLength = 5;
7    var maxLength = 20;
8
9    //密码复杂度定义
10    var lower = /[a-z]/g;
11    var upper = /[A-Z]/g;
12    var numberic = /\d/g;
13    var symbols = /[\W_]/g;
14    var repeat = new RegExp('(.{' + parseInt(value.length / 2) + ',})\1', 'g');
15
16    //初始状态
17    var status = 'poor';
18    var strength = -1;
19
20    if(!value || value.length < minLength) {
21        strength = -1;
22    }
23    else {
24        strength = parseInt(value.length / minLength) - 1;
25    }
26    if(value.match(repeat)) {
27        strength --;
28    }
29    if(value.match(lower) || value.match(upper)) {
30        strength ++;
31    }
32    if(value.match(numberic)) {
33        strength ++;
34    }
35    if(value.match(symbols)) {
36        strength ++;
37    }
38    if(value.length > minLength && strength < 2) {
39        strength ++;
40    }
41
42    switch(strength) {
43        case -1:
44        case 0:
45        case 1:
46            status = 'poor';
47            break;
48        case 2:
49            status = 'weak';
50            break;
51        case 3:
52            status = 'good';
53            break;
54        default:
55            status = 'strong';
56            break;
57    }
58    key.className = (className ? className + ' ' : '') + 'password-' + status;
59};
60passwordStrength.init = function(element, key) {
61    $(element).each(function(index, el){
62        if(!el) return;
63        if(key) {
64            key = $(el.parentNode).find(key);
65        }
66        else {
67            key = $(el).next();
68        }
69        if(!key) return;
70        // key.css('visibility', 'visible');
71        var className = key[0].className;
72        $(el).on('input propertychange', function(e){
73            if(e.type === 'propertychange' && e.propertyName && e.propertyName.toLowerCase() !== 'value') return; 
74            var prev = passwordStrength.prev;
75            var value = this.value;
76            if(prev !== value) {
77                passwordStrength(value, key[0], className);
78            }
79            passwordStrength.prev = value;
80        });
81    });
82}
83
84//点击更换验证码
85function changeVerify(element, hasEvent) {
86    $(element).each(function(index){
87        var $el = $(this);
88        var url;
89        var img;
90        if(this.tagName === 'IMG') {
91            img = $(this);
92            url = $el.attr('src');
93        }
94        else {
95            img = $el.siblings('img');
96            url = $el.attr('href');
97        }
98        if(hasEvent) $el.on('click', function() {
99            changeCode(img, url);
100        });
101        else changeCode(img, url);
102    });
103}
104function changeCode(img, url){
105    url = url || img.attr('src');
106    var random = +new Date;
107    var urlrandom = url.match(/\b_=([\d]+)\b/);
108    if(urlrandom) {
109        url = url.replace(urlrandom[1], random);
110    }
111    else {
112        url += (url.indexOf('?') > -1 ? '&' : '?') + '_=' + random;
113    }
114    img.attr('src', url);
115    return false;
116}
117
118//=全选
119function checkAll(el, elements) {
120    $(elements).prop('checked', $(el).prop('checked'));
121}
122
123//= placeholder兼容性实现
124//页面初始化时对所有input做初始化
125//Placeholder.init();
126//或者单独设置某个元素
127//Placeholder.create($('t1'));
128var Placeholder = {
129    support: (function() {
130        return 'placeholder' in document.createElement('input');
131    })(),
132    //提示文字的样式
133    className: 'placeholder',
134    init: function() {
135        if (!this.support) {
136            this.create($('input, textarea'));
137        }
138    },
139    build: function(input, html) {
140        var parent = input.parent();
141        var $this = Placeholder;
142        if(parent.css('position') == 'static') {
143            parent.css('position', 'relative');
144        }
145        var placeholder = input.prev('.' + this.className) || $('<span>', {
146            'class': this.className,
147            html: html,
148            style: 'visibility:hidden;'
149        }).before(input)
150        .locate({target: input, from:'lc', to:'lc', offset:{x:4}, offsetParent:true})
151        .on('click', function(e){
152            $this.hide(this);
153            input.focus();
154        });
155        return placeholder;
156    },
157    create: function(inputs) {
158        var $this = this;
159        $(inputs).each(function(index){
160            var el = $(this);
161            if (!$this.support && el.attr('placeholder')) {
162                var value = el.attr('placeholder');
163                el.data('placeholder', $this.build(el, value));
164
165                $this.show(el);
166
167                el.on('focusin', function(e) {
168                    $this.hide(this);
169                }).on('focusout', function(e) {
170                    $this.show(this);
171                });
172            }
173        });
174    },
175    show: function(el) {
176        if(!this.support && el.value === '' && $(el).is(':visible') && $(el).css('visibility') !== 'hidden') {
177            $(el).data('placeholder').css('visibility', 'visible');
178        }
179    },
180    hide: function(el) {
181        if(!this.support) ($(el).data('placeholder') || $(el)).css('visibility', 'hidden');
182    }
183};
184
185$(function(){
186    var forms = document.forms;
187    if(forms.length) {
188
189        //= 自动检测密码强度
190        passwordStrength.init($('form .auto-password-check-handle'), '.password-check');
191
192        //= 自动绑定更换验证码
193        changeVerify($('form .auto-change-verify-handle'), true);
194
195        //= 记住帐号
196        $('form .action-remember-account').on('change', function(e){
197            if(this.checked) {
198                $.cookie('S[SIGN][REMEMBER]', '1', 365);
199            }
200            else {
201                $.cookie('S[SIGN][REMEMBER]', '0', 365);
202            }
203        }).trigger('change');
204
205        //检测帐号重复
206        $('form [data-remote]').on('change', function(e) {
207            var element = $(this);
208            var value = this.value;
209            var name = this.name;
210            var url = $(this).data('remote');
211            var method = element.data('remoteType') || element.parents('form').attr('method');
212            var callback = element.data('remoteCallback');
213            if(url && name && value) {
214                $[method](url, name + '=' + value, function(rs) {
215                    if(typeof rs === 'string') {
216                        rs = JSON.parse(rs);
217                    }
218                    if(callback) return callback.call(element, rs);
219                    var tips = new Tips({target: element.closest('.form-row')});
220                    if(rs.error) {
221                        return tips.error(rs.message);
222                    }
223                    else if(rs.success) {
224                        return tips.success(rs.message);
225                    }
226                })
227            }
228        });
229    }
230
231    //处理 type=number 格式容错
232
233
234    //处理input placeholder兼容
235    Placeholder.init();
236});

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.