Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
YOHOBUYPC
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
2
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
wangqing
9 years ago
Commit
3aa3889df22395db9ec824b52bd96ed69416f501
1 parent
308cbf53
header commit
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
183 additions
and
4 deletions
web-static/js/header.js
web-static/plugin/yohocart.js
web-static/plugin/yohocookie.js
web-static/js/header.js
View file @
3aa3889
...
...
@@ -5,8 +5,8 @@
*/
var
$
=
require
(
'jquery'
);
var
$yohocookie
=
require
(
'./common/yohocookie'
);
var
$yohocart
=
require
(
'./common/yohocart'
);
var
$yohocookie
=
require
(
'../plugin/yohocookie'
);
var
$yohocart
=
require
(
'../plugin/yohocart'
);
var
yohodoT
=
require
(
'../plugin/yohodoT'
);
var
noticeSuccess
=
false
;
/**
...
...
@@ -558,7 +558,7 @@ function loadCartData() {
}
if
(
$
(
'#miniCartBox .goods-list li'
).
length
<
1
)
{
shoppingInfo
=
$
.
cookie
(
'_g'
);
shoppingData
=
eval
(
'('
+
shoppingInfo
+
')'
);
shoppingData
=
JSON
.
parse
(
'('
+
shoppingInfo
+
')'
);
if
(
shoppingData
!==
null
)
{
strK
=
'{"_k":"'
+
shoppingData
.
_k
+
'","_nac":0'
+
',"_ac":0,"_r":0}'
;
$
.
setcookie
(
'_g'
,
strK
,
{
...
...
@@ -586,7 +586,7 @@ function delCartGoods(id, isreduce) {
isreduce
:
isreduce
},
function
(
jsonData
)
{
var
shoppingInfo
=
$
.
cookie
(
'_g'
);
var
shoppingData
=
eval
(
'('
+
shoppingInfo
+
')'
);
var
shoppingData
=
JSON
.
parse
(
'('
+
shoppingInfo
+
')'
);
var
strK
=
'{"_k":"'
+
shoppingData
.
_k
+
'","_nac":'
+
jsonData
.
total_goods_num
+
',"_ac":0,"_r":0}'
;
$
.
setcookie
(
'_g'
,
strK
,
{
...
...
@@ -801,4 +801,8 @@ exports.init = function() {
actionUpdateCartNum
();
//更新购物车数量
actionLoopUpdCartNum
();
//循环检测购物车数量
actionSearch
();
//搜索执行
delCartGoods
();
clickMiniCartBox
();
$yohocookie
();
$yohocart
();
};
\ No newline at end of file
...
...
web-static/plugin/yohocart.js
0 → 100644
View file @
3aa3889
var
jQuery
=
require
(
'jquery'
);
var
$yohocookie
=
require
(
'./yohocookie'
);
(
function
(
$
)
{
$
.
fn
.
miniCart
=
function
(
options
)
{
var
defaults
=
{
'cookie'
:
'_g'
,
'cartNum'
:
''
};
var
params
=
$
.
extend
(
defaults
,
options
);
var
cartInfo
=
eval
(
'('
+
$
.
cookie
(
params
.
cookie
)
+
')'
);
if
(
cartInfo
!=
null
)
{
var
totalNum
=
parseInt
(
cartInfo
.
_nac
)
+
parseInt
(
cartInfo
.
_ac
);
if
(
totalNum
==
0
)
{
$
(
'#icart-num'
).
attr
(
'class'
,
'icart-num icart-none'
);
}
else
{
$
(
'#icart-num'
).
attr
(
'class'
,
'icart-num'
);
}
$
(
params
.
cartNum
).
html
(
totalNum
);
}
}
$
.
fn
.
search
=
function
(
searchDomain
)
{
var
query_num
=
0
;
var
list_index
=
0
;
var
tmp_list
=
0
;
function
getKeywords
(
obj
)
{
var
key
=
$
.
trim
(
$
(
obj
).
val
());
key
=
key
.
replace
(
new
RegExp
(
"'"
,
"gm"
),
''
);
//去掉特殊字符
if
(
key
==
''
)
{
$
(
'.search-list'
).
hide
();
return
false
;
}
key
=
encodeURI
(
key
);
//编码
$
.
get
(
searchDomain
+
'?callback=?&query='
+
key
,
function
(
htmlData
)
{
$
(
'.search-list'
).
html
(
htmlData
[
'data'
]);
query_num
=
$
(
'.search-list'
).
children
(
'li'
).
length
;
list_index
=
-
1
;
if
(
query_num
>
0
)
{
$
(
'.search-list'
).
show
();
}
else
{
$
(
'.search-list'
).
hide
();
}
//绑定事件
$
(
'.search-list'
).
find
(
'a'
).
hover
(
function
()
{
$
(
this
).
css
(
"background-color"
,
"#eee"
);
},
function
()
{
$
(
this
).
css
(
"background-color"
,
"#fff"
);
});
},
'jsonp'
);
}
function
getText
(
obj
)
{
$
(
'.search-list li:eq('
+
tmp_list
+
')'
).
children
(
'a'
).
css
(
"background-color"
,
"#fff"
);
$
(
'.search-list li:eq('
+
list_index
+
')'
).
children
(
'a'
).
css
(
"background-color"
,
"#eee"
);
var
text
=
$
(
'.search-list li:eq('
+
list_index
+
')'
).
children
(
'a'
).
attr
(
"title"
);
$
(
'#query_key'
).
val
(
text
);
}
return
this
.
each
(
function
()
{
$
(
this
).
keyup
(
function
(
event
)
{
if
(
event
.
which
==
38
)
{
if
(
query_num
==
0
)
{
return
false
;
}
if
(
list_index
==
-
1
)
{
list_index
=
0
;
}
tmp_list
=
list_index
;
list_index
=
(
list_index
-
1
+
query_num
)
%
query_num
;
getText
(
this
);
}
else
if
(
event
.
which
==
40
)
{
if
(
query_num
==
0
)
{
return
false
;
}
tmp_list
=
list_index
;
list_index
=
(
list_index
+
1
)
%
query_num
;
getText
(
this
);
}
else
if
(
event
.
which
==
13
)
{
submitSearch
();
}
else
{
getKeywords
(
this
);
}
});
});
};
$
.
extend
({
getData
:
function
(
domain
,
options
,
onSuccess
)
{
var
defaults
=
{
'page'
:
1
,
'method'
:
''
,
'v'
:
1
,
'return_type'
:
'jsonp'
,
'open_key'
:
'12345'
,
'tmp'
:
Math
.
random
()
};
if
(
typeof
(
domain
)
==
undefined
||
domain
==
''
)
{
console
.
log
(
'请设置请求的api地址'
);
return
false
;
}
var
params
=
$
.
extend
(
defaults
,
options
);
params
.
page
=
params
.
page
||
1
;
if
(
params
.
method
==
''
)
{
console
.
log
(
'请设置请求的URL'
);
return
false
;
}
try
{
$
.
getJSON
(
domain
+
'/?callback=?'
,
params
,
function
(
_data
)
{
if
(
onSuccess
!=
''
)
{
eval
(
onSuccess
(
_data
.
data
));
return
false
;
}
});
}
catch
(
e
)
{
console
.
log
(
e
.
message
);
}
},
getShoppingKey
:
function
()
{
var
shoppingInfo
=
$
.
cookie
(
'_g'
);
if
(
typeof
shoppingInfo
==
'undefined'
||
shoppingInfo
==
null
)
{
return
''
;
}
var
shoppingData
=
eval
(
'('
+
shoppingInfo
+
')'
);
return
shoppingData
.
_k
;
},
})
})(
jQuery
);
\ No newline at end of file
...
...
web-static/plugin/yohocookie.js
0 → 100644
View file @
3aa3889
var
jQuery
=
require
(
'jquery'
);
(
function
(
$
)
{
$
.
extend
({
cookie
:
function
(
name
)
{
var
cookieValue
=
null
;
if
(
document
.
cookie
&&
document
.
cookie
!=
''
)
{
var
cookies
=
document
.
cookie
.
split
(
';'
);
for
(
var
i
=
0
;
i
<
cookies
.
length
;
i
++
)
{
var
cookie
=
jQuery
.
trim
(
cookies
[
i
]);
if
(
cookie
.
substring
(
0
,
name
.
length
+
1
)
==
(
name
+
'='
))
{
cookieValue
=
decodeURIComponent
(
cookie
.
substring
(
name
.
length
+
1
));
break
;
}
}
}
return
cookieValue
;
},
setcookie
:
function
(
name
,
value
,
options
)
{
var
expires
=
''
;
if
(
typeof
value
!=
'undefined'
)
{
options
=
options
||
{};
if
(
value
===
null
)
{
value
=
''
;
options
.
expires
=
-
1
;
}
if
(
options
.
expires
&&
(
typeof
options
.
expires
==
'number'
||
options
.
expires
.
toUTCString
))
{
var
date
;
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
();
// use expires attribute, max-age is not supported by IE
}
var
path
=
options
.
path
?
'; path='
+
options
.
path
:
''
;
var
domain
=
options
.
domain
?
'; domain='
+
options
.
domain
:
''
;
var
secure
=
options
.
secure
?
'; secure'
:
''
;
document
.
cookie
=
[
name
,
'='
,
encodeURIComponent
(
value
),
expires
,
path
,
domain
,
secure
].
join
(
''
);
}
}
})
})(
jQuery
);
\ No newline at end of file
...
...
Please
register
or
login
to post a comment