hdw
2019-01-18 8306010ebd06cdef8237fa06c32463b7ecf3e3c6
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// 页面中底部按钮对象
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;
    }
};
 
 
//依赖ckplayer.js
var CkVideo = function(container, video) {
    this.urls = [];
    this.container = $(container);
    this.opts = {
    container: video, //容器的ID或className
    variable: 'player', //播放函数名称
    loop: false, //播放结束是否循环播放
    autoplay: false,//是否自动播放
    //poster: 'material/poster.jpg', //封面图片
    preview: {},
    drag: 'start', //拖动的属性
    video: [
        ['', 'video/mp4']
        ]
       };
    
    this._slide();
    this._change();
};
CkVideo.prototype = {
    init: function(data, sid) {
        this.urls = [];
        for(var i=0; i<data.length; i++) {
            var _data = data[i];
            var tmp = {};
            tmp.fileName = _data.fileName;
            tmp.fileUrl = '../../../stationsrc/'+sid+'/video/'+_data.fileName;
            this.urls.push(tmp);
        }
        
        // 设置播放列表
        this._list();
    }
    ,player: function(url) {
        this.opts.video = [[url, 'video/mp4']];
        new ckplayer(this.opts); 
    }
    ,_list: function() {
        var container = this.container.find('.ck-video-list-container ul');
        container.text("");
        // 遍历urls
        for(var i=0; i<this.urls.length; i++) {
            var _url = this.urls[i];
            var _li  = $('<li></li>');
            var _a = $('<a href="javascript:;"></a>');
            if(i == 0) {
                _a.addClass('active-this');
            }
            var _icon = $('<i class="fa fa-video-camera"></i>');
            var _span = $('<span>'+_url.fileName+'</span>');
            
            _a.append(_icon);
            _a.append(_span);
            _a.data('url', _url);
            _li.append(_a);
            container.append(_li);
        }
        
        var rsUrl = this.getAcUrl();
        this.player(rsUrl);
        
    }
    ,_slide: function() {
        var _list = this.container.find('.ck-video-list');
        var _slide = this.container.find('.ck-video-slide');
        var _this = this;
        _slide.off('click.ck.slide').on('click.ck.slide', function() {
            _list.toggleClass('slide-hide');
        });
    }
    ,_change: function() {
        var container = this.container.find('.ck-video-list-container ul');
        var _this = this;
        container.off('click.ck.change').on('click.ck.change', 'li a', function() {
            container.find('li a').removeClass('active-this');
            $(this).addClass('active-this');
            var url = $(this).data('url').fileUrl;
            _this.player(url);
        });
    }
    ,getAcUrl: function() {
        var container = this.container.find('.ck-video-list-container ul');
        var acUrl = container.find('.active-this');
        var url = '';
        if(acUrl.length != 0) {
            url = acUrl.data('url').fileUrl;
        }
        return url;
    }
};
 
//格式化时间
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;
};