Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
YOHO-ACTIVITY-PHP
·
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
0e937762cdfafa96978e9556da3ba8f6b5663cf5
1 parent
e90a9d5a
trigger input search
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
32 deletions
static/js/category/brand.js
static/js/category/brand.js
View file @
0e93776
...
...
@@ -70,43 +70,46 @@ function searchResult() {
i
=
0
,
html
=
''
;
// 遍历首字母搜索
$
.
each
(
brandsData
,
function
(
k
,
v
)
{
if
(
$
.
isArray
(
v
))
{
if
(
keyword
!==
''
)
{
// 遍历首字母搜索
$
.
each
(
brandsData
,
function
(
k
,
v
)
{
if
(
$
.
isArray
(
v
))
{
// 遍历品牌,进行匹配
$
.
each
(
v
,
function
(
i
,
brand
)
{
if
(
brand
.
name
.
toLowerCase
().
indexOf
(
keyword
)
>
-
1
)
{
result
[
k
]
=
result
[
k
]
||
[];
result
[
k
].
push
(
brand
);
}
});
}
});
// 遍历品牌,进行匹配
// 根据搜索结果生成 HTML
$
.
each
(
result
,
function
(
k
,
v
)
{
var
brandHtml
=
[
'<div class="brand-list bar-'
,
i
,
'">'
];
i
++
;
brandHtml
.
push
(
'<div class="title-bar"><h2>'
);
brandHtml
.
push
(
k
);
brandHtml
.
push
(
'</h2></div>'
);
$
.
each
(
v
,
function
(
i
,
brand
)
{
if
(
brand
.
name
.
toLowerCase
().
indexOf
(
keyword
)
>
-
1
)
{
result
[
k
]
=
result
[
k
]
||
[];
result
[
k
].
push
(
brand
);
brandHtml
.
push
(
'<p><a href="'
+
brand
.
url
+
'">'
+
brand
.
name
);
if
(
brand
.
isNew
)
{
brandHtml
.
push
(
'<i class="icon-hot">HOT</i>'
);
}
if
(
brand
.
isHot
)
{
brandHtml
.
push
(
'<i class="icon-new">NEW</i>'
);
}
brandHtml
.
push
(
'</a></p>'
);
});
}
});
brandHtml
.
push
(
'</div>'
);
html
+=
brandHtml
.
join
(
''
);
// 根据搜索结果生成 HTML
$
.
each
(
result
,
function
(
k
,
v
)
{
var
brandHtml
=
[
'<div class="brand-list bar-'
,
i
,
'">'
];
i
++
;
brandHtml
.
push
(
'<div class="title-bar"><h2>'
);
brandHtml
.
push
(
k
);
brandHtml
.
push
(
'</h2></div>'
);
$
.
each
(
v
,
function
(
i
,
brand
)
{
brandHtml
.
push
(
'<p><a href="'
+
brand
.
url
+
'">'
+
brand
.
name
);
if
(
brand
.
isNew
)
{
brandHtml
.
push
(
'<i class="icon-hot">HOT</i>'
);
}
if
(
brand
.
isHot
)
{
brandHtml
.
push
(
'<i class="icon-new">NEW</i>'
);
}
brandHtml
.
push
(
'</a></p>'
);
});
brandHtml
.
push
(
'</div>'
);
html
+=
brandHtml
.
join
(
''
);
});
}
// 插入 dom,绑定事件
$
(
'.search-result'
).
html
(
html
);
...
...
@@ -118,7 +121,6 @@ if ($('.brand-search-page').length) {
$keyword
.
on
(
'input'
,
function
()
{
if
(
$keyword
.
val
().
length
)
{
searchResult
();
$icon
.
css
(
'color'
,
'#000'
);
$
(
this
).
closest
(
'.search-box'
).
css
(
'width'
,
'11.25rem'
);
$
(
'.search-action'
).
show
();
...
...
@@ -127,6 +129,7 @@ if ($('.brand-search-page').length) {
$
(
this
).
closest
(
'.search-box'
).
css
(
'width'
,
'12.5rem'
);
$
(
'.search-action'
).
hide
();
}
searchResult
();
}).
focus
();
clearTextHammer
=
new
Hammer
(
$
(
'.clear-text'
)[
0
]);
...
...
Please
register
or
login
to post a comment