Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
node-slate
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nguyễn Hải Sơn
node-slate
Commits
18cd1048
Commit
18cd1048
authored
Jul 03, 2014
by
Robert Lord
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add better search results in a sliding search results area
parent
51e537ac
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
20 deletions
+17
-20
search.js
source/javascripts/app/search.js
+13
-19
layout.erb
source/layouts/layout.erb
+4
-1
No files found.
source/javascripts/app/search.js
View file @
18cd1048
...
@@ -15,9 +15,9 @@
...
@@ -15,9 +15,9 @@
$
(
bind
);
$
(
bind
);
function
populate
()
{
function
populate
()
{
$
(
'h1'
).
each
(
function
()
{
$
(
'h1
, h2
'
).
each
(
function
()
{
var
title
=
$
(
this
);
var
title
=
$
(
this
);
var
body
=
title
.
nextUntil
(
'h1'
);
var
body
=
title
.
nextUntil
(
'h1
, h2
'
);
index
.
add
({
index
.
add
({
id
:
title
.
prop
(
'id'
),
id
:
title
.
prop
(
'id'
),
title
:
title
.
text
(),
title
:
title
.
text
(),
...
@@ -31,13 +31,7 @@
...
@@ -31,13 +31,7 @@
darkBox
=
$
(
'.dark-box'
);
darkBox
=
$
(
'.dark-box'
);
searchResults
=
$
(
'.search-results'
);
searchResults
=
$
(
'.search-results'
);
$
(
'#input-search'
).
on
(
'keyup'
,
function
(
e
)
{
$
(
'#input-search'
).
on
(
'keyup'
,
search
);
if
(
$
(
this
).
val
()
===
""
)
{
inactive
(
e
);
}
else
{
search
(
e
);
}
});
}
}
function
search
(
event
)
{
function
search
(
event
)
{
...
@@ -48,25 +42,25 @@
...
@@ -48,25 +42,25 @@
if
(
event
.
keyCode
===
27
)
this
.
value
=
''
;
if
(
event
.
keyCode
===
27
)
this
.
value
=
''
;
if
(
this
.
value
)
{
if
(
this
.
value
)
{
var
results
=
index
.
search
(
this
.
value
);
var
results
=
index
.
search
(
this
.
value
).
filter
(
function
(
r
)
{
return
r
.
score
>
0.0001
;
});
if
(
results
.
length
)
{
if
(
results
.
length
)
{
searchResults
.
empty
();
$
.
each
(
results
,
function
(
index
,
result
)
{
$
.
each
(
results
,
function
(
index
,
result
)
{
var
header
=
$
(
'.tocify-item[data-unique='
+
result
.
ref
+
']'
).
closest
(
'.tocify-header'
);
searchResults
.
append
(
"<li><a href='#"
+
result
.
ref
+
"'>"
+
$
(
'#'
+
result
.
ref
).
text
()
+
"</a></li>"
);
if
(
header
.
length
>
0
)
header
=
header
[
0
];
if
(
header
)
$
(
"#"
+
header
.
id
+
" li a"
).
append
(
"<span>"
+
result
.
score
+
"</span>"
);
});
});
highlight
.
call
(
this
);
highlight
.
call
(
this
);
}
else
{
}
else
{
searchResults
.
text
(
'No Results Found for "'
+
this
.
value
+
'"'
).
show
(
);
searchResults
.
html
(
'<li>No Results Found for "'
+
this
.
value
+
'"</li>'
);
}
}
}
else
{
unhighlight
();
searchResults
.
removeClass
(
'visible'
);
}
}
}
}
function
inactive
()
{
unhighlight
();
searchResults
.
removeClass
(
'visible'
);
}
function
highlight
()
{
function
highlight
()
{
if
(
this
.
value
)
content
.
highlight
(
this
.
value
,
highlightOpts
);
if
(
this
.
value
)
content
.
highlight
(
this
.
value
,
highlightOpts
);
}
}
...
...
source/layouts/layout.erb
View file @
18cd1048
...
@@ -64,7 +64,10 @@ under the License.
...
@@ -64,7 +64,10 @@ under the License.
<div
class=
"search"
>
<div
class=
"search"
>
<input
type=
"text"
class=
"search"
id=
"input-search"
placeholder=
"Search"
>
<input
type=
"text"
class=
"search"
id=
"input-search"
placeholder=
"Search"
>
</div>
</div>
<div
class=
"search-results"
></div>
<ul
class=
"search-results"
>
<li><a
href=
"#"
>
Introduction
</a></li>
<li><a
href=
"#"
>
Cats
</a></li>
</ul>
<%
end
%>
<%
end
%>
<div
id=
"toc"
>
<div
id=
"toc"
>
</div>
</div>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment