Skip to content

Commit

Permalink
Fix and improve the search functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiesigner committed Aug 7, 2019
1 parent 55533f8 commit 4f90657
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion assets/js/app.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion assets/js/post.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@
"desktop": "assets/screenshot-desktop.jpg",
"mobile": "assets/screenshot-mobile.jpg"
},
"version": "0.1.9"
"version": "0.2.0"
}
12 changes: 7 additions & 5 deletions src/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ $(document).ready(() => {
matchAllTokens: true,
maxPatternLength: 32,
minMatchCharLength: 1,
keys: ['title']
keys: ['title', 'custom_excerpt', 'html']
}

api.posts.browse({
limit: 'all',
fields: 'id, title, url, published_at'
fields: 'id, title, url, published_at, custom_excerpt, html'
})
.then((posts) => {
for (var i = 0, len = posts.length; i < len; i++) {
Expand Down Expand Up @@ -182,18 +182,20 @@ $(document).ready(() => {
$inputSearch.keyup(() => {
if ($inputSearch.val().length > 0 && fuse) {
const results = fuse.search($inputSearch.val())
let htmlString = ''

if (results.length > 0) {
for (var i = 0, len = results.length; i < len; i++) {
$searchResults.html(`
htmlString += `
<article class="m-result">\
<a href="${results[i].url}" class="m-result__link">\
<h3 class="m-result__title">${results[i].title}</h3>\
<span class="m-result__date">${formatDate(results[i].published_at)}</span>\
</a>\
</article>
`)
</article>`
}

$searchResults.html(htmlString)
} else {
$searchResults.html('<p class="m-no-found align-center">0 results for your search, try something different.</>')
}
Expand Down
24 changes: 12 additions & 12 deletions src/js/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ function onScrolling() {
requestTicking()
}

function adjustShare(timeout) {
if (!isMobile('1023px')) {
stickybits('.js-sticky', { stickyBitStickyOffset: 100 })
$('body').removeClass('share-menu-displayed')
} else {
$('body').addClass('share-menu-displayed')
setTimeout(() => {
$aosWrapper.removeAttr('data-aos')
}, timeout)
}
}

function onResizing() {
setHeights()
adjustShare(100)
Expand Down Expand Up @@ -109,18 +121,6 @@ $(document).ready(() => {
}
}

function adjustShare(timeout) {
if (!isMobile('1023px')) {
stickybits('.js-sticky', { stickyBitStickyOffset: 100 })
$('body').removeClass('share-menu-displayed')
} else {
$('body').addClass('share-menu-displayed')
setTimeout(() => {
$aosWrapper.removeAttr('data-aos')
}, timeout)
}
}

adjustImageGallery()
adjustShare(1000)

Expand Down

0 comments on commit 4f90657

Please sign in to comment.