Showing
2 changed files
with
107 additions
and
58 deletions
1 | const $ = require('jquery'); | 1 | const $ = require('jquery'); |
2 | const lazyload = require('../plugins/lazyload'); | 2 | const lazyload = require('../plugins/lazyload'); |
3 | +const common = require('./common'); | ||
3 | 4 | ||
4 | let indexObj = { | 5 | let indexObj = { |
5 | init: function() { | 6 | init: function() { |
6 | 7 | ||
7 | - if (this.queryString().openType === 'baidu') { | ||
8 | - this.setCookie('openType', '1', {path: '/', expires: 1}); | 8 | + if (common.queryString().openType === 'baidu') { |
9 | + common.setCookie('openType', '1', {path: '/', expires: 1}); | ||
9 | } | 10 | } |
10 | 11 | ||
11 | this.lazyLoad(); | 12 | this.lazyLoad(); |
@@ -38,69 +39,33 @@ let indexObj = { | @@ -38,69 +39,33 @@ let indexObj = { | ||
38 | _this.resizeInit(); | 39 | _this.resizeInit(); |
39 | }); | 40 | }); |
40 | }, | 41 | }, |
41 | - cookie: function(name) { | ||
42 | - let cookies = document.cookie, | ||
43 | - cookieVal; | ||
44 | 42 | ||
45 | - if (cookies) { | ||
46 | - cookies = cookies.split(';'); | 43 | + // cookie: function(name) { |
44 | + // let cookies = document.cookie, | ||
45 | + // cookieVal; | ||
47 | 46 | ||
48 | - for (let i = 0; i < cookies.length; i++) { | ||
49 | - if (cookies[i].indexOf(name) > -1) { | ||
50 | - cookieVal = decodeURIComponent($.trim(cookies[i].replace(name + '=', ''))); | ||
51 | - break; | ||
52 | - } | ||
53 | - } | ||
54 | - } | 47 | + // if (cookies) { |
48 | + // cookies = cookies.split(';'); | ||
55 | 49 | ||
56 | - return cookieVal; | ||
57 | - }, | 50 | + // for (let i = 0; i < cookies.length; i++) { |
51 | + // if (cookies[i].indexOf(name) > -1) { | ||
52 | + // cookieVal = decodeURIComponent($.trim(cookies[i].replace(name + '=', ''))); | ||
53 | + // break; | ||
54 | + // } | ||
55 | + // } | ||
56 | + // } | ||
57 | + // return cookieVal; | ||
58 | + // }, | ||
58 | downShow: function() { | 59 | downShow: function() { |
59 | - if (this.cookie('ignoreDownload') || this.cookie('openType')) { | 60 | + if (common.getCookie('ignoreDownload') || common.getCookie('openType') || |
61 | + common.queryString().openType === 'baidu') { | ||
60 | $('.download').remove(); | 62 | $('.download').remove(); |
61 | } | 63 | } |
62 | - }, | ||
63 | - queryString: function() { | ||
64 | - var vars = [], | ||
65 | - hash, | ||
66 | - i; | ||
67 | - var hashes = window.location.search.slice(1).split('&'); | ||
68 | - | ||
69 | - for (i = 0; i < hashes.length; i++) { | ||
70 | - hash = hashes[i].split('='); | ||
71 | - vars.push(hash[0]); | ||
72 | - vars[hash[0]] = hash[1]; | ||
73 | - } | ||
74 | - return vars; | ||
75 | - }, | ||
76 | - setCookie: function(name, value, options) { | ||
77 | - var expires = '', | ||
78 | - path, | ||
79 | - domain, | ||
80 | - secure, | ||
81 | - date; | ||
82 | - | ||
83 | - if (typeof value !== 'undefined') { | ||
84 | - options = options || {}; | ||
85 | - if (value === null) { | ||
86 | - value = ''; | ||
87 | - options.expires = -1; | ||
88 | - } | ||
89 | 64 | ||
90 | - if (options.expires && | ||
91 | - (typeof options.expires === 'number' || options.expires.toUTCString)) { | ||
92 | - if (typeof options.expires === 'number') { | ||
93 | - date = new Date(); | ||
94 | - date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); | ||
95 | - } else { | ||
96 | - date = options.expires; | ||
97 | - } | ||
98 | - expires = '; expires=' + date.toUTCString(); | ||
99 | - } | ||
100 | - path = options.path ? '; path=' + options.path : ''; | ||
101 | - domain = options.domain ? '; domain=' + options.domain : ''; | ||
102 | - secure = options.secure ? '; secure' : ''; | ||
103 | - document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); | 65 | + if (common.getCookie('openType') || common.queryString().openType === 'baidu') { |
66 | + $('.shop-detail-page .h5-download').remove(); | ||
67 | + $('.shop-detail-page .city-list').remove(); | ||
68 | + $('.detail-page .h5-download').remove(); | ||
104 | } | 69 | } |
105 | }, | 70 | }, |
106 | }; | 71 | }; |
src/js/common/common.js
0 → 100644
1 | +module.exports = { | ||
2 | + queryString() { | ||
3 | + var vars = [], | ||
4 | + hash, | ||
5 | + i; | ||
6 | + var hashes = window.location.search.slice(1).split('&'); | ||
7 | + | ||
8 | + for (i = 0; i < hashes.length; i++) { | ||
9 | + hash = hashes[i].split('='); | ||
10 | + vars.push(hash[0]); | ||
11 | + vars[hash[0]] = hash[1]; | ||
12 | + } | ||
13 | + return vars; | ||
14 | + }, | ||
15 | + setCookie(name, value, options) { | ||
16 | + var expires = '', | ||
17 | + path, | ||
18 | + domain, | ||
19 | + secure, | ||
20 | + date; | ||
21 | + | ||
22 | + if (typeof value !== 'undefined') { | ||
23 | + options = options || {}; | ||
24 | + if (value === null) { | ||
25 | + value = ''; | ||
26 | + options.expires = -1; | ||
27 | + } | ||
28 | + | ||
29 | + if (options.expires && | ||
30 | + (typeof options.expires === 'number' || options.expires.toUTCString)) { | ||
31 | + if (typeof options.expires === 'number') { | ||
32 | + date = new Date(); | ||
33 | + date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); | ||
34 | + } else { | ||
35 | + date = options.expires; | ||
36 | + } | ||
37 | + expires = '; expires=' + date.toUTCString(); | ||
38 | + } | ||
39 | + path = options.path ? '; path=' + options.path : ''; | ||
40 | + domain = options.domain ? '; domain=' + options.domain : ''; | ||
41 | + secure = options.secure ? '; secure' : ''; | ||
42 | + document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); | ||
43 | + } | ||
44 | + }, | ||
45 | + getCookie(name) { | ||
46 | + var re = new RegExp(name + '=([^;$]*)', 'i'), | ||
47 | + matchPattern = '$1'; | ||
48 | + | ||
49 | + try { | ||
50 | + return re.test(decodeURIComponent(document.cookie)) ? RegExp[matchPattern] : ''; | ||
51 | + } catch (e) { | ||
52 | + return decodeURIComponent(re.test(document.cookie) ? RegExp[matchPattern] : ''); | ||
53 | + } | ||
54 | + }, | ||
55 | + delCookie(name, value, options) { | ||
56 | + var expires = '', | ||
57 | + path, | ||
58 | + domain, | ||
59 | + secure, | ||
60 | + date; | ||
61 | + | ||
62 | + if (typeof value !== 'undefined') { | ||
63 | + options = options || {}; | ||
64 | + if (value === '') { | ||
65 | + options.expires = -1; | ||
66 | + } | ||
67 | + | ||
68 | + if (options.expires && | ||
69 | + (typeof options.expires === 'number' || options.expires.toUTCString)) { | ||
70 | + if (typeof options.expires === 'number') { | ||
71 | + date = new Date(); | ||
72 | + date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); | ||
73 | + } else { | ||
74 | + date = options.expires; | ||
75 | + } | ||
76 | + expires = '; expires=' + date.toUTCString(); | ||
77 | + } | ||
78 | + path = options.path ? '; path=' + options.path : ''; | ||
79 | + domain = options.domain ? '; domain=' + options.domain : ''; | ||
80 | + secure = options.secure ? '; secure' : ''; | ||
81 | + document.cookie = [name, '=', this.getCookie(name), expires, path, domain, secure].join(''); | ||
82 | + } | ||
83 | + }, | ||
84 | +}; |
-
Please register or login to post a comment