-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcc.js
292 lines (261 loc) · 8.85 KB
/
cc.js
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
var cc = (function ()
{
/**
* 返回顶部
* @param id
*/
function backTop(id) {
var btn = document.getElementById(id);
var d = document.documentElement;
var b = document.body;
window.onscroll = set;
btn.style.display = "none";
btn.onclick = function() {
btn.style.display = "none";
window.onscroll = null;
this.timer = setInterval(function() {
d.scrollTop -= Math.ceil((d.scrollTop + b.scrollTop) * 0.1);
b.scrollTop -= Math.ceil((d.scrollTop + b.scrollTop) * 0.1);
if ((d.scrollTop + b.scrollTop) == 0) clearInterval(btn.timer, window.onscroll = set);
}, 10);
};
function set() {
btn.style.display = (d.scrollTop + b.scrollTop > 400) ? 'block': "none";
}
}
/**
* 子框架设值父框架站点信息
*/
function subframeSetParentframeSite() {
var site = '<a href="/manager/"><i class="iconfont"></i></a>';
site += window.document.title.replace('|','<i class="iconfont"></i>');
parent.window.document.getElementById("siteInner").innerHTML=site
}
/**
* 折叠 fold
* @param title 点击切换
* @param mode 1:只打开一个,可以关闭; 2:必须有一个打开; 3:可打开多个
* @param info 切换内容
* @param speed
* @param event click,mouseover
*/
function fold (title, mode, info, speed, event){
if(!title) { title = '.fold-item .title';}
if(!mode) { mode = 1;}
if(!info) { info = '.fold-item .info';}
if(!speed) { speed = 'fast';}
if(!event) { event = 'click'; }
if(mode === 2){
$(title+":first").find("em").html("-");
$(info+":first").show();
}
$(title).bind(event,function(){
if($(this).next().is(":visible")){
if(mode === 2){
return false;
}
else{
$(this).next().slideUp(speed).end().removeClass("selected");
$(this).find("em").html("+");
}
}
else{
if(mode === 3){
$(this).next().slideDown(speed).end().addClass("selected");
$(this).find("em").html("-");
}else{
$(this).parent().parent().find(info).slideUp(speed);
$(this).parent().parent().find(title).removeClass("selected");
$(this).parent().parent().find("em").html("+");
$(this).next().slideDown(speed).end().addClass("selected");
$(this).find("em").html("-");
}
}
});
}
/**
* tab 切换
* @param tabBar 点击切换
* @param mode 默认显示第0个
* @param tabCon 内容切换
* @param tabEvent click, mouseover
* @param className 切换的样式名
*/
function tab( tabBar, mode, tabCon, tabEvent, className){
if(!tabBar) { tabBar = '.cc-tab .tabBar';}
if(!mode) { mode = 0 }
if(!tabCon) { tabCon = '.tabCon .tab-item'}
if(!tabEvent) { tabEvent = 'click' }
if(!className){ className = 'current' }
$tab = $(tabBar).find('li');
// init
$tab.eq(mode).addClass(className).siblings().removeClass(className);
$tab.parent().parent().find(tabCon).eq(mode).addClass('show').siblings().removeClass('show');
$tab.bind(tabEvent,function(){
$(this).addClass(className).siblings().removeClass(className);
$(this).parent().parent().find(tabCon).eq($(this).index()).addClass('show').siblings().removeClass('show');
})
}
/*************************************************
* set cookie
* @param name
* @param value
* @param Days
*/
function setCookie(name, value, Days){
if(Days == null || Days == ''){
Days = 300;
}
var exp = new Date();
exp.setTime(exp.getTime() + Days*24*60*60*1000);
document.cookie = name + "="+ escape (value) + "; path=/;expires=" + exp.toGMTString();
}
// get cookie by name
function getCookie(name) {
var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
if(arr=document.cookie.match(reg)){
return unescape(arr[2]);
} else{
return null;
}
}
// get all cookie
function getAllCookie(){
return document.cookie;
}
// del cookie by name
function delCookie(name){
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval=getCookie(name);
if(cval!=null){
document.cookie= name + "="+cval+"; path=/;expires="+exp.toGMTString();
}
}
// clear cookie
function clearCookie(name){
setCookie(name, '', -1);
}
/**
* 获取格式化的当前时间
* @returns
*/
function getNowFormatDate() {
var date = new Date();
var seperator1 = '-';
var seperator2 = ':';
var month = date.getMonth() + 1;
var strDate = date.getDate();
if (month >= 1 && month <= 9) {
month = '0' + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = '0' + strDate;
}
var currentdate = date.getFullYear() + seperator1 + month + seperator1
+ strDate + ' ' + date.getHours() + seperator2
+ date.getMinutes() + seperator2 + date.getSeconds();
return currentdate;
}
/**
* 表单验证
* @param formElement 表单元素
* @param callback 返回验证结果:false, true
* @param src 动态增加插件到页面
* @param jqueryAfter 插件添加的位子, 一般放在(依赖)jquery后
*/
function validate(formElement, callback, src, jqueryAfter){
// 1. 加载validate 插件到页面
var script = document.createElement('script');
script.src = src ? src : '/assets/admin/js/libs/jquery.validate.js';
jqueryAfter = jqueryAfter ? jqueryAfter : '#minjq';
$(jqueryAfter).after(script);
// 2. 对输入框内容进行验证
$(formElement).validate({
onFocus: function() {
this.parent().addClass('active');
return false;
},
onBlur: function() {
var $parent = this.parent();
var _status = parseInt(this.attr('data-status'));
$parent.removeClass('active');
if (!_status) {
$parent.addClass('error');
}
return false;
}
});
// 3. 提交验证
$(formElement).on('submit', function(event) {
if(event && event.preventDefault){
event.preventDefault();
}else{
window.event.returnValue = false; //注意加window
}
// return boolean;
callback($(this).validate('submitValidate'));
});
}
/*************************************************
* 调用返回
*/
return {
/**
* 返回顶部
* @param: id
*/
backTop : backTop,
/**
* 折叠 fold
* @param title 点击切换
* @param mode 1:只打开一个,可以关闭; 2:必须有一个打开; 3:可打开多个
* @param info 切换内容
* @param speed
* @param event click,mouseover
*/
fold : fold,
/**
* tab 切换
* @param tabBar 点击切换
* @param mode 默认显示第0个
* @param tabCon 内容切换
* @param tabEvent click, mouseover
* @param className 切换的样式名
*/
tab : tab,
/**
* 子框架设值父框架站点信息
*/
subframeSetParentframeSite : subframeSetParentframeSite,
/**
* 获取格式化的当前时间
*/
getNowFormatDate : getNowFormatDate,
/**
* set cookie
* @param: name, value, Days
*/
setCookie : setCookie,
/**
* get cookie by name
* @param: name
*/
getCookie : getCookie,
getAllCookie : getAllCookie,
/**
* del cookie by name
* @param: name
*/
delCookie : delCookie,
clearCookie : clearCookie,
/**
* 表单验证
* @param formElement 表单元素
* @param callback 返回验证结果:false, true
* @param src 动态增加插件到页面
* @param jqueryAfter 插件添加的位子, 一般放在(依赖)jquery后
*/
validate : validate
}
}());