Skip to content

Commit

Permalink
Merge pull request #68 from crystal-community/feat/highlight-search
Browse files Browse the repository at this point in the history
Highlight search with mark js
  • Loading branch information
hugoabonizio authored Apr 11, 2018
2 parents d1d2026 + b0e6d22 commit 975d902
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions public/javascripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ document.addEventListener("DOMContentLoaded", (event) => {
toggleSecondary();
signoutListener();
runPrettify();
runHighlighter();
});

function toggleSecondary() {
Expand Down Expand Up @@ -44,3 +45,11 @@ function signoutListener() {
function runPrettify() {
hljs.initHighlightingOnLoad();
}

function runHighlighter() {
var search = document.getElementById("search-input");
if (search) {
var context = document.querySelectorAll(".entry-header, .entry-content");
new Mark(context).mark(search.value);
}
}
2 changes: 1 addition & 1 deletion src/views/layouts/_search.slang
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

aside.widget.search
form name="search" action="/"
input.search-input name="query" type="text" placeholder="Search..." value="#{query}"
input.search-input id="search-input" name="query" type="text" placeholder="Search..." value="#{query}"
- if user
input type="hidden" name="user" value="#{user}"
- if type
Expand Down
1 change: 1 addition & 0 deletions src/views/layouts/application.slang
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ html

script src="/javascripts/main.js"
script src="/javascripts/highlight.pack.js"
script src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js"

== render partial: "layouts/_ga.slang"

0 comments on commit 975d902

Please sign in to comment.