area-common.js
3.05 KB
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
const $ = require('jquery');
const lazyload = require('../plugins/lazyload');
let indexObj = {
init: function() {
if (this.queryString().openType === 'baidu') {
this.setCookie('openType', '1', {path: '/', expires: 1});
}
this.lazyLoad();
this.resizeInit();
this.resize();
this.downShow();
},
lazyLoad: function() {
lazyload($('img.lazy'), {
threshold: 1000,
q: 80
});
},
resizeInit: function() {
let winW = $(window).width();
let $page = $('body').find('div:first');
if (winW > 1150) {
$page.addClass('width-pc');
$('.download').hide();
} else {
$page.removeClass('width-pc');
$('.download').show();
}
},
resize: function() {
let _this = this;
$(window).resize(function() {
_this.resizeInit();
});
},
cookie: function(name) {
let cookies = document.cookie,
cookieVal;
if (cookies) {
cookies = cookies.split(';');
for (let i = 0; i < cookies.length; i++) {
if (cookies[i].indexOf(name) > -1) {
cookieVal = decodeURIComponent($.trim(cookies[i].replace(name + '=', '')));
break;
}
}
}
return cookieVal;
},
downShow: function() {
if (this.cookie('ignoreDownload') || this.cookie('openType')) {
$('.download').remove();
}
},
queryString: function() {
var vars = [],
hash,
i;
var hashes = window.location.search.slice(1).split('&');
for (i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
},
setCookie: function(name, value, options) {
var expires = '',
path,
domain,
secure,
date;
if (typeof value !== 'undefined') {
options = options || {};
if (value === null) {
value = '';
options.expires = -1;
}
if (options.expires &&
(typeof options.expires === 'number' || options.expires.toUTCString)) {
if (typeof options.expires === 'number') {
date = new Date();
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
} else {
date = options.expires;
}
expires = '; expires=' + date.toUTCString();
}
path = options.path ? '; path=' + options.path : '';
domain = options.domain ? '; domain=' + options.domain : '';
secure = options.secure ? '; secure' : '';
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
}
},
};
$(
function() {
indexObj.init();
}
);