Add index searching. Close #1318
This commit is contained in:
parent
c318fb37b9
commit
a8209eaa89
@ -1,3 +1,11 @@
|
||||
- Searching in the index will now show matched OPs by:
|
||||
- comment
|
||||
- subject
|
||||
- filename
|
||||
- name
|
||||
- tripcode
|
||||
- e-mail
|
||||
|
||||
### 3.12.1 - *2013-11-04*
|
||||
|
||||
- The index refreshing notification will now only appear on initial page load with slow connections.
|
||||
|
||||
@ -363,6 +363,7 @@ a[href="javascript:;"] {
|
||||
}
|
||||
|
||||
/* Index */
|
||||
:root.index-loading .navLinks,
|
||||
:root.index-loading .board,
|
||||
:root.index-loading .pagelist {
|
||||
display: none;
|
||||
|
||||
2
html/General/Index-navlinks.html
Normal file
2
html/General/Index-navlinks.html
Normal file
@ -0,0 +1,2 @@
|
||||
[<a href="./catalog">Catalog</a>]
|
||||
<input type="search" id="index-search" placeholder="Search">
|
||||
@ -183,7 +183,7 @@ Config =
|
||||
'Open front page': ['Shift+0', 'Open page 0 in a new tab.']
|
||||
'Next page': ['Right', 'Jump to the next page.']
|
||||
'Previous page': ['Left', 'Jump to the previous page.']
|
||||
'Search form': ['Ctrl+Alt+s', 'Open the search field on the board index.']
|
||||
'Search form': ['Ctrl+Alt+s', 'Focus the search field on the board index.']
|
||||
# Thread Navigation
|
||||
'Next thread': ['Down', 'See next thread.']
|
||||
'Previous thread': ['Up', 'See previous thread.']
|
||||
|
||||
@ -50,13 +50,21 @@ Index =
|
||||
className: 'pagelist'
|
||||
hidden: true
|
||||
innerHTML: <%= importHTML('General/Index-pagelist') %>
|
||||
@navLinks = $.el 'div',
|
||||
className: 'navLinks'
|
||||
innerHTML: <%= importHTML('General/Index-navlinks') %>
|
||||
@searchInput = $ '#index-search', @navLinks
|
||||
@currentPage = @getCurrentPage()
|
||||
$.on window, 'popstate', @cb.popstate
|
||||
$.on @pagelist, 'click', @cb.pageNav
|
||||
$.on @searchInput, 'input', @onSearchInput
|
||||
$.asap (-> $('.pagelist', doc) or d.readyState isnt 'loading'), ->
|
||||
$.replace $('.board'), Index.root
|
||||
$.replace $('.pagelist'), Index.pagelist
|
||||
$.rmClass doc, 'index-loading'
|
||||
for navLink in $$ '.navLinks'
|
||||
$.rm navLink
|
||||
$.after $.x('child::form/preceding-sibling::hr'), Index.navLinks
|
||||
|
||||
cb:
|
||||
mode: ->
|
||||
@ -276,13 +284,14 @@ Index =
|
||||
offset = 0
|
||||
for threadRoot, i in Index.sortedNodes by 2 when Get.threadFromRoot(threadRoot).isSticky
|
||||
Index.sortedNodes.splice offset++ * 2, 0, Index.sortedNodes.splice(i, 2)...
|
||||
return unless Conf['Filter']
|
||||
if Conf['Filter']
|
||||
# Put the highlighted thread & <hr> on top of the index
|
||||
# while keeping the original order they appear in.
|
||||
offset = 0
|
||||
for threadRoot, i in Index.sortedNodes by 2 when Get.threadFromRoot(threadRoot).isOnTop
|
||||
Index.sortedNodes.splice offset++ * 2, 0, Index.sortedNodes.splice(i, 2)...
|
||||
return
|
||||
if Index.searchInput.value
|
||||
Index.sortedNodes = Index.querySearch(Index.searchInput.value) or Index.sortedNodes
|
||||
buildIndex: ->
|
||||
if Conf['Index Mode'] is 'paged'
|
||||
pageNum = Index.getCurrentPage()
|
||||
@ -294,3 +303,24 @@ Index =
|
||||
Index.buildReplies nodes
|
||||
$.event 'IndexBuild', nodes
|
||||
$.add Index.root, nodes
|
||||
|
||||
onSearchInput: ->
|
||||
Index.sort()
|
||||
Index.buildIndex()
|
||||
querySearch: (query) ->
|
||||
return unless keywords = query.toLowerCase().match /\S+/g
|
||||
Index.search keywords
|
||||
search: (keywords) ->
|
||||
found = []
|
||||
for threadRoot, i in Index.sortedNodes by 2
|
||||
{OP} = Get.threadFromRoot threadRoot
|
||||
text = []
|
||||
for key in ['comment', 'subject', 'name', 'tripcode', 'email']
|
||||
text.push OP.info[key] if key of OP.info
|
||||
text.push OP.file.name if 'file' of OP
|
||||
text = text.join(' ').toLowerCase()
|
||||
for keyword in keywords
|
||||
continue if -1 is text.indexOf keyword
|
||||
found.push Index.sortedNodes[i], Index.sortedNodes[i + 1]
|
||||
break
|
||||
found
|
||||
|
||||
@ -49,7 +49,7 @@ class Post
|
||||
|
||||
@parseComment()
|
||||
@parseQuotes()
|
||||
@parseFile(that)
|
||||
@parseFile that
|
||||
|
||||
@clones = []
|
||||
g.posts[@fullID] = thread.posts[@] = board.posts[@] = @
|
||||
|
||||
@ -87,7 +87,7 @@ Keybinds =
|
||||
return unless g.VIEW is 'index' and Conf['Index Mode'] is 'paged'
|
||||
$('.prev button', Index.pagelist).click()
|
||||
when Conf['Search form']
|
||||
$.id('search-btn').click()
|
||||
Index.searchInput.focus()
|
||||
# Thread Navigation
|
||||
when Conf['Next thread']
|
||||
return if g.VIEW isnt 'index'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user