PageSourceSearch

http://028yw.cn/static/js/common.js

js 028yw.cn collected 2026-10-09 04:34:08 UTC 15,454 bytes, 437 lines download raw bytes

1;(function($, window, document, undefined){
2
3    $.extend({
4
5
6        // 验证手机号是否正确
7        checkTel:function(tel){
8            var check = (/^1[3|4|5|7|8]\d{9}$/.test(tel));
9            return check;
10        },
11
12
13        // 验证网址是否正确
14        checkUrl:function(url){
15            var check = (/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/.test(url));
16            return check;
17        },
18
19
20        // 邮箱
21        checkEmail:function(email){
22            var check = (/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(email));
23            return check;
24        },
25
26
27        // 获取网址参数值
28        getUrlParam:function(name){
29            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
30            var r = window.location.search.substr(1).match(reg);
31            if (r != null) return r[2]; return null;
32        },
33
34
35        // 获取时间戳所在月的第一天(返回一个时间对象)
36        getFirstDayObj: function(timestamp){
37            var date = new Date(parseInt(timestamp));
38            date.setDate(1);
39            return date;
40        },
41
42
43        // 获取时间戳所在月的最后一天(返回一个时间对象)
44        getLastDayObj: function(timestamp){
45            var date = new Date(parseInt(timestamp));
46            var currentMonth = date.getMonth();
47            var nextMonth = ++currentMonth;
48            var lastDate = new Date(date.getFullYear(),nextMonth,0);
49            return lastDate;
50        },
51
52
53        //写入cookie
54        setCookie:function(name,value){
55            var Days = 30; //此 cookie 将被保存 30 天
56            var exp = new Date();
57            exp.setTime(exp.getTime() + Days*24*60*60*1000);
58            document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
59        },
60
61
62        ///删除cookie
63        delCookie:function(name){
64            var exp = new Date();
65            exp.setTime(exp.getTime() - 1);
66            var cval = $.getCookie(name);
67            if(cval!=null){
68                document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
69            }
70        },
71
72
73        //读取cookie
74        getCookie:function(name){
75            var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
76            if(arr != null) return unescape(arr[2]);
77            return null;
78        },
79
80        
81        msg: function(text, status) {
82            var $msg = $('<div class="msg-box ' + (status ? 'correct' : 'error') + '">
82' + text + '</div>');
83            $('body').find('.msg-box').remove();
84            $('body').append($msg);
85            setTimeout(function(){
86                $msg.fadeOut(400, function(){
87                    $msg.remove();
88                })
89            }, 1000);
90        }
91    });
92
93
94    /**
95     * time:倒计时持续时长
96     * txt:倒计时中显示的文本
97     * className:倒计时进行时元素应呈现的class
98     * callback:回调函数,会先执行回调再倒计时
99     */
100    $.fn.timer = function(options){
101        var self = $(this);
102        if(self.data('lock')){return;}
103        var time = options.time || 60,
104            txt = options.txt || 's后重新发送',
105            classname = options.classname || 'on',
106            callback = options.callback || function(){};
107
108        var start_txt = self.text();
109        var time = parseInt(time);
110        self.text(time + txt).addClass(classname).data('lock',true);
111
112        // 执行回调函数
113        var fn = eval(callback);
114        if(typeof fn === 'function') fn.call(this);
115
116        var t = setInterval(function(){
117            time--;
118            if(time <= 0){
119                clearTimeout(t);
120                self.removeClass(classname).text(start_txt).data('lock',false);
121            }else{
122                self.text(time + txt);
123            }
124        },1000);
125    };
126
127
128    /**
129     * 过渡动画结束后执行回调函数
130     * callback: 回调函数
131     */
132    $.fn.transitionEnd = function(callback) {
133        var events = ['webkitTransitionEnd', 'transitionend', 'oTransitionEnd', 'MSTransitionEnd', 'msTransitionEnd'],i,dom = this;
134
135        function fireCallBack(e) {
136            if (e.target !== this) return;
137            callback.call(this, e);
138            for (i = 0; i < events.length; i++) {
139                dom.off(events[i], fireCallBack);
140            }
141        }
142
143        if (callback) {
144            for (i = 0; i < events.length; i++) {
145                dom.on(events[i], fireCallBack);
146            }
147        }
148        return this;
149    };
150
151
152    /**
153     * 仿照选择框
154     */
155    $.fn.fcheck = function(){
156        var self = this;
157        self.each(function(){
158            if($(this).data('fcheck')) return true;
159            
160            var $fcheck = $(this),
161                $input = $(this).find('input'),
162                checked = $input.prop("checked");
163
164            checked ? $(this).addClass('checked') : $(this).removeClass('checked');
165
166            $input.on('change',function(){
167                var checked = $(this).prop("checked");
168                if($(this).attr('type') == 'checkbox'){
169                    checked ? $fcheck.addClass('checked') : $fcheck.removeClass('checked');
170                }else{
171                    var name = $(this).attr('name');
172                    if(!!name){
173                        var $form = $(this).closest('form'),
174                            $objArr = $form.length ? $form.find('input[name="' + name + '"]') : $('input[name="' + name + '"]');
175                        $objArr.each(function(){
176                            var temp = $(this).prop("checked"),
177                                $obj = $(this).closest('label');
178                            temp ? $obj.addClass('checked') : $obj.removeClass('checked');
179                        });
180                    }else{
181                        checked ? $fcheck.addClass('checked') : $fcheck.removeClass('checked');
182                    }
183                }
184            });
185            $(this).data('fcheck',true);
186        });
187
188        return self;
189    };
190
191
192    // 仿输入框(有增加减少按钮的数字输入框)
193    $.fn.finput = function(options){
194        var self = this,
195            defaults = {
196                change: function(){}
197            };
198        self.options = $.extend({}, defaults, options);
199        self.each(function(){
200            $(this).append('<div class="plus btn"></div><div class="minus btn"></div>');
201            var $input = $(this).find('input'),
202                $plus = $(this).find('.plus'),
203                $minus = $(this).find('.minus'),
204                step = $(this).data('step') || 1,
205                max = $(this).data('max') !== undefined ? parseInt($(this).data('max')) : null,
206                min = $(this).data('min') !== undefined ? parseInt($(this).data('min')) : null,
207                startVal = $input.val(),
208                event = eval(self.options.change);
209
210            if(startVal == ''){
211                $input.val(min === null ? ((max === null || max > 0) ? 0 : max) : min);
212            }else{
213                if(min !== null && startVal < min) startVal = min;
214                if(max !== null && startVal > max) startVal = max;
215                $input.val(startVal);
216            }
217
218            $input.on('blur',function(){
219                var value = $(this).val(),
220                    val = value.replace(/\D|^0/g,'');
221                // val = value.replace(/\D|^/g,'');val = value.replace(/\D|^0/g,'');
222                if(min !== null && val < min) val = min;
223                if(max !== null && val > max) val = max;
224                $(this).val(val);
225                if(typeof event === 'function') event.call(this, val);
226            });
227            $plus.on('click', function(){
228                var val = (parseInt($input.val()/step) + 1)*step;
229                if(max !== null && val > max) val = max;
230                $input.val(val);
231                if(typeof event === 'function') event.call(this, val);
232            });
233            $minus.on('click', function(){
234                var inputVal = parseInt($input.val()),
235                    stepLength = parseInt(inputVal / step);
236                var val = inputVal%step ? (stepLength*step) : ((stepLength - 1)*step);
237                if(min !== null && val < min) val = min;
238                $input.val(val);
239                if(typeof event === 'function') event.call(this, val);
240            });
241        });
242
243        return self;
244    };
245
246
247    // 仿下拉框
248    $.fn.fselect = function(str){
249        var self = this;
250
251        self.each(function(){
252            if(str != 'update'){
253                $(this).wrap('<div class="fselect"></div>');
254                $(this).before('<span class="text"></span>');
255            }
256
257            var $text = $(this).prev(),
258                text = $(this).find(":selected").text(),
259                disabled = $(this).attr('disabled'),
260                $selectBox = $(this).closest('.fselect');
261
262            $text.text(text);
263            disabled ? $selectBox.addClass('disabled') : $selectBox.removeClass('disabled');
264
265            if(str != 'update'){
266                $(this).on("change",function(){
267                    var text = $(this).find(":selected").text();
268                    $text.text(text);
269                });
270            }
271        });
272
273        return self;
274
275    };
276
277
278    // 整数输入框。str为'+'只能输入正整数,否则可输入包括0的正整数
279    $.fn.intInput = function(str) {
280        var self = this;
281
282        self.each(function() {
283            $(this).on('blur', function() {
284                var value = $(this).val(),
285                    val = (str == '+') ? value.replace(/\D|^0/g,'') : value.replace(/\D|^/g,'');
286                $(this).val(val);
287            });
288        });
289
290        return self;
291    };
292
293
294    // 不能有特殊字符只能由数字、大小写字母组成
295    $.fn.specialCharacter = function(str) {
296        var self = this;
297
298        self.each(function() {
299            $(this).on('blur', function() {
300                var value = $(this).val(),
301                    str = /^[A-Za-z0-9]*$/,
302                    str1 = /[\u4e00-\u9fa5\!\.@#\$%\^&\*\(\)\[\]\\?\\\/\|\-~`\+\=\,\r\n\:\'\"。,;……!¥\{\}]/g;
303
304                if(str.test(value) == false){
305                    var va = value.replace(str1, "");
306                    $(this).val(va);
307                }else{
308                    $(this).val(value);
309                }
310            });
311        });
312
313        return self;
314    };
315
316
317    //序列化表单(序列化后的值为一个Object)
318    $.fn.serializeObject = function() {
319        var obj = {},
320            arr = this.serializeArray();
321
322        $.each(arr, function() {
323            if (obj[this.name] !== undefined) {
324                if (!obj[this.name].push) obj[this.name] = [obj[this.name]];
325                obj[this.name].push(this.value || '');
326            } else {
327                obj[this.name] = this.value || '';
328            }
329        });
330        return obj;
331    };
332
333
334    $.fn.countTo = function (options) {
335        options = options || {};
336        
337        return $(this).each(function () {
338            // set options for current element
339            var settings = $.extend({}, $.fn.countTo.defaults, {
340                from:            $(this).data('from'),
341                to:              $(this).data('to'),
342                speed:           $(this).data('speed'),
343                refreshInterval: $(this).data('refresh-interval'),
344                decimals:        $(this).data('decimals')
345            }, options);
346            
347            // how many times to update the value, and how much to increment the value on each update
348            var loops = Math.ceil(settings.speed / settings.refreshInterval),
349                increment = (settings.to - settings.from) / loops;
350            
351            // references & variables that will change with each update
352            var self = this,
353                $self = $(this),
354                loopCount = 0,
355                value = settings.from,
356                data = $self.data('countTo') || {};
357            
358            $self.data('countTo', data);
359            
360            // if an existing interval can be found, clear it first
361            if (data.interval) {
362                clearInterval(data.interval);
363            }
364            data.interval = setInterval(updateTimer, settings.refreshInterval);
365            
366            // initialize the element with the starting value
367            render(value);
368            
369            function updateTimer() {
370                value += increment;
371                loopCount++;
372                
373                render(value);
374                
375                if (typeof(settings.onUpdate) == 'function') {
376                    settings.onUpdate.call(self, value);
377                }
378                
379                if (loopCount >= loops) {
380                    // remove the interval
381                    $self.removeData('countTo');
382                    clearInterval(data.interval);
383                    value = settings.to;
384                    
385                    if (typeof(settings.onComplete) == 'function') {
386                        settings.onComplete.call(self, value);
387                    }
388                }
389            }
390            
391            function render(value) {
392                var formattedValue = settings.formatter.call(self, value, settings);
393                $self.html(formattedValue);
394            }
395        });
396    };
397
398    $.fn.countTo.defaults = {
399        from: 0,               // the number the element should start at
400        to: 0,                 // the number the element should end at
401        speed: 1000,           // how long it should take to count between the target numbers
402        refreshInterval: 100,  // how often the element should be updated
403        decimals: 0,           // the number of decimal places to show
404        formatter: null,  // handler for formatting the value before rendering
405        onUpdate: null,        // callback method for every time the element is updated
406        onComplete: null       // callback method for when the element finishes updating
407    };
408
409
410})(jQuery, window, document);
411
412
413/* 
414 * eg:format="yyyy-MM-dd hh:mm:ss";
415 */
416Date.prototype.format = function(format) {
417    var o = {  
418        "M+" : this.getMonth() + 1, // month  
419        "d+" : this.getDate(), // day  
420        "h+" : this.getHours(), // hour  
421        "m+" : this.getMinutes(), // minute  
422        "s+" : this.getSeconds(), // second  
423        "q+" : Math.floor((this.getMonth() + 3) / 3), // quarter  
424        "S" : this.getMilliseconds()  // millisecond  
425    }  
426  
427    if (/(y+)/.test(format)) {  
428        format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));  
429    }  
430  
431    for (var k in o) {  
432        if (new RegExp("(" + k + ")").test(format)) {  
433            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));  
434        }  
435    }  
436    return format;  
437}

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.