Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
YOHOBUYWAP
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
xuqi
9 years ago
Commit
4bddc76e1c08fb86acf00d07d216bfb6982c0800
1 parent
de32e55f
search local store
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
93 additions
and
22 deletions
static/js/index/search.js
static/js/index/write-search.js
static/js/product/list.js
template/m.yohobuy.com/actions/index/search/index.phtml
template/m.yohobuy.com/partials/product/list.phtml
static/js/index/search.js
View file @
4bddc76
...
...
@@ -10,18 +10,20 @@ var $input = $('#search-input input');
var
$clear
=
$
(
'#search-input .clear-input'
);
var
$form
=
$
(
'#search-form'
);
var
$history
=
$
(
'.history'
);
$
(
'#clear-history'
).
bind
(
'tap'
,
function
()
{
$
.
ajax
({
type
:
'POST'
,
url
:
'/search/clearHistory'
,
success
:
function
(
data
)
{
if
(
data
.
code
===
200
)
{
$history
.
html
(
''
);
//clear search history items
}
}
});
var
$clearHistory
=
$
(
'#clear-history'
);
var
writeSearch
=
require
(
'./write-search'
);
var
ranToken
=
writeSearch
.
getRanToken
();
$clearHistory
.
bind
(
'tap'
,
function
()
{
localStorage
.
removeItem
(
'historys'
);
$history
.
html
(
''
);
});
$input
.
bind
(
'input'
,
function
()
{
...
...
@@ -34,4 +36,33 @@ $input.bind('input', function() {
$clear
.
bind
(
'tap'
,
function
()
{
$input
.
val
(
''
).
trigger
(
'input'
);
});
\ No newline at end of file
});
//初始化历史搜索的内容
(
function
()
{
var
html
=
''
,
history
,
historys
,
i
;
if
(
localStorage
)
{
historys
=
localStorage
.
getItem
(
'historys'
);
if
(
historys
&&
historys
.
length
>
0
)
{
historys
=
historys
.
split
(
ranToken
);
for
(
i
=
0
;
i
<
historys
.
length
;
i
++
)
{
history
=
historys
[
i
];
if
(
history
===
''
)
{
continue
;
}
html
+=
'<li><a href="?query='
+
history
+
'">'
+
history
+
'</li>'
;
}
$history
.
html
(
html
);
$clearHistory
.
removeClass
(
'hide'
);
}
}
}());
writeSearch
.
bindWirteLocal
(
$form
);
\ No newline at end of file
...
...
static/js/index/write-search.js
0 → 100644
View file @
4bddc76
/**
* 将搜索结果存localStorage
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/10/29
*/
var
ranToken
=
' ??++ '
;
//获取分隔符
function
getRanToken
()
{
return
ranToken
;
}
//绑定提交前的存local操作
function
bindWirteLocal
(
$form
)
{
$form
.
on
(
'submit'
,
function
()
{
var
query
=
this
.
query
.
value
,
historys
;
if
(
localStorage
)
{
historys
=
localStorage
.
getItem
(
'historys'
);
historys
=
historys
?
historys
:
''
;
if
(
historys
.
indexOf
(
ranToken
+
query
+
ranToken
)
>
-
1
)
{
return
;
}
if
(
historys
===
''
)
{
query
=
ranToken
+
query
;
}
historys
+=
query
+
ranToken
;
localStorage
.
setItem
(
'historys'
,
historys
);
}
});
}
exports
.
getRanToken
=
getRanToken
;
exports
.
bindWirteLocal
=
bindWirteLocal
;
\ No newline at end of file
...
...
static/js/product/list.js
View file @
4bddc76
...
...
@@ -13,6 +13,8 @@ var $brandHeader = $('#brand-header'),
var
filter
=
require
(
'../plugin/filter'
);
var
writeSearch
=
require
(
'../index/write-search'
);
var
tip
=
require
(
'../plugin/tip'
);
var
loading
=
require
(
'../plugin/loading'
);
...
...
@@ -210,6 +212,8 @@ lazyLoad($('.lazy'));
filter
.
registerCbFn
(
search
);
writeSearch
.
bindWirteLocal
(
$
(
'#search-form'
));
//导航栏点击逻辑说明:
//1.点击非active项时切换active状态
//2.价格和折扣active状态时继续点击切换排序
...
...
template/m.yohobuy.com/actions/index/search/index.phtml
View file @
4bddc76
...
...
@@ -2,7 +2,7 @@
<div
class=
"search-page yoho-page"
>
{
{#
search
}
}
<div
id=
"search-input"
class=
"search-input"
>
<form
action=
"/product/list/index"
method=
"get"
>
<form
id=
"search-form"
action=
{
{url
}
}
method=
"get"
>
<i
class=
"search-icon iconfont"
>
60
f;</i>
<input
type=
"text"
placeholder=
"搜索商品"
name=
"query"
>
<i
class=
"clear-input iconfont hide"
>
626
;</i>
...
...
@@ -10,7 +10,7 @@
</form>
</div>
<div
class=
"search-items"
>
<div
class=
"hot-search"
>
<div
class=
"hot-search
hide
"
>
<h
3
>热门搜索</h
3
>
<ul
class=
"hot clearfix"
>
{
{#
hot
}
}
...
...
@@ -22,15 +22,9 @@
</div>
<div
class=
"history-search"
>
<h
3
>历史搜索</h
3
>
<ul
class=
"history clearfix"
>
{
{#
history
}
}
<li>
<a
href=
{
{url
}
}>
{
{name
}
}</a>
</li>
{
{/
history
}
}
</ul>
<ul
class=
"history clearfix"
></ul>
</div>
<button
id=
"clear-history"
class=
"clear-history"
>清空搜索历史</button>
<button
id=
"clear-history"
class=
"clear-history
hide
"
>清空搜索历史</button>
</div>
{
{/
search
}
}
</div>
...
...
template/m.yohobuy.com/partials/product/list.phtml
View file @
4bddc76
{
{#
goodList
}
}
{
{#
search
}
}
<div
id=
"search-input"
class=
"search-input"
>
<form
action=
{
{url
}
}
method=
"get"
>
<form
id=
"search-form"
action=
{
{url
}
}
method=
"get"
>
<i
class=
"search-icon iconfont"
>
60
f;</i>
<input
type=
"text"
value=
{
{default
}
}
name=
"query"
>
<i
class=
"clear-input iconfont hide"
>
61
a;</i>
...
...
Please
register
or
login
to post a comment