hdw
2018-12-14 e2ce9886ff1456cd48e72f73c9efba70ad9320f5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// 页面中底部按钮对象
var FooterMenu = function (footer) {
    this.cShow = 'footer-menu-content-show';
    this.bActive = 'this-active'
    this.footer = footer;
    this._init();
};
 
// 设置页面底部导航的方法
FooterMenu.prototype = {
    _init: function() {
        var btnA = this.footer.find('.hdw-btn a');
        // 遍历内容
        var cId = '';
        var aIndex = 0;
        btnA.each(function(i) {
            if($(this).hasClass(this.bActive)) {        // 获取被激活按钮的下标
                aIndex = i;
            }
        });
        var _btn = btnA.eq(aIndex);     // 获取被激活的按钮
        cId = _btn.data('href');        // 获取需要显示内容的id
        $(cId).addClass(this.cShow);
 
        this._click(btnA);  // 添加点击事件      
    }
    ,_click: function(btn) {
        var _this = this;
        btn.off('click.footerMenu').on('click.footerMenu', function() {
            var _id = $(this).data('href');  // 获取需要显示内容的id
            _this._initDom(btn);
            $(this).addClass(_this.bActive);
            $(_id).addClass(_this.cShow);
        });
    }
    ,_initDom: function(btn) {
        var _this = this;
        // 遍历btn的内容
        btn.each(function(i) {
            var _id = $(this).data('href');
            $(_id).removeClass(_this.cShow);
            $(this).removeClass(_this.bActive);
        });
    }
};
 
var CheckData = function() {
    this.reg = new RegExp('.*');
    this.source = [];
};
 
// 定义检测数据方法
CheckData.prototype = {
    _setReg: function(reg) {
        if(reg) {
            var _reg = this._formaterReg(reg);
            this.reg = new RegExp(_reg);
        }else {
            this.reg = new RegExp('.*');
        }
    }
    ,setSource: function(source) {
        this.source = source;
    }
    ,getData: function(reg) {
        this._setReg(reg);      // 设置匹配规则
        // 遍历source
        var data = [];
        for(var i=0; i<this.source.length; i++) {
            var _source = this.source[i];
            var label = _source.label;
            if(this.reg.test(label)) {
                data.push(_source);
            }
        }
 
        return data;
    },
    _formaterReg: function(reg) {        // 检测特殊的字符并进行转义
        var ptn = /([\(\)\.])/g;
        var str = reg.replace(ptn, '\\'+'$&');
        return str;
    }
};
 
//格式化时间
Date.prototype.format =function(format)
{
    var o = {
    "M+" : this.getMonth()+1, //month
    "d+" : this.getDate(),    //day
    "h+" : this.getHours(),   //hour
    "m+" : this.getMinutes(), //minute
    "s+" : this.getSeconds(), //second
    "q+" : Math.floor((this.getMonth()+3)/3),  //quarter
    "S" : this.getMilliseconds() //millisecond
    };
    if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
    (this.getFullYear()+"").substr(4- RegExp.$1.length));
    for(var k in o)if(new RegExp("("+ k +")").test(format))
    format = format.replace(RegExp.$1,
    RegExp.$1.length==1? o[k] :
    ("00"+ o[k]).substr((""+ o[k]).length));
    return format;
};