Allow searching from URL bar without refreshing the page (add #s=search)
Reduce loops. Because we build threads in a loop, we can build replies as we're building threads. Go us.
This commit is contained in:
parent
4fd7f628f5
commit
60b3d447c5
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -96,7 +96,7 @@ Index =
|
||||
|
||||
@searchInput = $ '#index-search', @navLinks
|
||||
|
||||
@searchTest()
|
||||
@searchTest true
|
||||
|
||||
@hideLabel = $ '#hidden-label', @navLinks
|
||||
@selectMode = $ '#index-mode', @navLinks
|
||||
@ -268,11 +268,15 @@ Index =
|
||||
{hash} = window.location
|
||||
window.location = './' + hash
|
||||
|
||||
searchTest: ->
|
||||
return unless hash = window.location.hash
|
||||
return unless match = hash.match /s=([\w]+)/
|
||||
searchTest: (init) ->
|
||||
return false unless hash = window.location.hash
|
||||
return false unless match = hash.match /s=([\w]+)/
|
||||
@searchInput.value = match[1]
|
||||
$.on d, '4chanXInitFinished', @onSearchInput
|
||||
if init
|
||||
$.on d, '4chanXInitFinished', Index.onSearchInput
|
||||
else
|
||||
Index.onSearchInput()
|
||||
return true
|
||||
|
||||
setupNavLinks: ->
|
||||
for el in $$ '.navLinks.desktop > a'
|
||||
@ -621,26 +625,25 @@ Index =
|
||||
Index.updateHideLabel()
|
||||
$.event 'IndexRefresh'
|
||||
|
||||
buildReplies: (threads) ->
|
||||
buildReplies: (thread) ->
|
||||
return unless Conf['Show Replies']
|
||||
posts = []
|
||||
for thread in threads
|
||||
i = Index.liveThreadIDs.indexOf thread.ID
|
||||
continue unless lastReplies = Index.liveThreadData[i].last_replies
|
||||
nodes = []
|
||||
for data in lastReplies
|
||||
if post = thread.posts[data.no]
|
||||
nodes.push post.nodes.root
|
||||
continue
|
||||
nodes.push node = Build.postFromObject data, thread.board.ID
|
||||
try
|
||||
posts.push new Post node, thread, thread.board
|
||||
catch err
|
||||
# Skip posts that we failed to parse.
|
||||
errors = [] unless errors
|
||||
errors.push
|
||||
message: "Parsing of Post No.#{data.no} failed. Post will be skipped."
|
||||
error: err
|
||||
i = Index.liveThreadIDs.indexOf thread.ID
|
||||
return unless lastReplies = Index.liveThreadData[i].last_replies
|
||||
nodes = []
|
||||
for data in lastReplies
|
||||
if post = thread.posts[data.no]
|
||||
nodes.push post.nodes.root
|
||||
continue
|
||||
nodes.push node = Build.postFromObject data, thread.board.ID
|
||||
try
|
||||
posts.push new Post node, thread, thread.board
|
||||
catch err
|
||||
# Skip posts that we failed to parse.
|
||||
errors = [] unless errors
|
||||
errors.push
|
||||
message: "Parsing of Post No.#{data.no} failed. Post will be skipped."
|
||||
error: err
|
||||
$.add thread.OP.nodes.root.parentNode, nodes
|
||||
|
||||
Main.handleErrors errors if errors
|
||||
@ -738,11 +741,11 @@ Index =
|
||||
threads = []
|
||||
i = threadsPerPage * pageNum
|
||||
max = i + threadsPerPage
|
||||
while i < max
|
||||
threads.push thread = sortedThreads[i++]
|
||||
while i < max and thread = sortedThreads[i++]
|
||||
threads.push thread
|
||||
nodes.push thread.OP.nodes.root.parentNode, $.el 'hr'
|
||||
Index.buildReplies thread
|
||||
|
||||
Index.buildReplies threads
|
||||
Index.buildPagelist()
|
||||
Index.setPage()
|
||||
|
||||
@ -755,7 +758,8 @@ Index =
|
||||
i = 0
|
||||
while thread = sortedThreads[i++]
|
||||
nodes.push thread.OP.nodes.root.parentNode, $.el 'hr'
|
||||
Index.buildReplies sortedThreads
|
||||
Index.buildReplies thread
|
||||
|
||||
$.rmAll Index.root unless infinite
|
||||
$.add Index.root, nodes
|
||||
$.event 'IndexBuild', nodes
|
||||
|
||||
@ -11,7 +11,7 @@ Navigate =
|
||||
|
||||
@title = -> return
|
||||
|
||||
@el = $.el 'div',
|
||||
@el = $.el 'span',
|
||||
id: 'breadCrumb'
|
||||
|
||||
Thread.callbacks.push
|
||||
@ -172,14 +172,16 @@ Navigate =
|
||||
|
||||
navigate: (e) ->
|
||||
return if @hostname isnt 'boards.4chan.org' or window.location.hostname is 'rs.4chan.org'
|
||||
return if e and (e.shiftKey or e.ctrlKey or (e.type is 'click' and e.button isnt 0)) # Not simply a left click
|
||||
|
||||
if e
|
||||
if e.shiftKey or e.ctrlKey or (e.type is 'click' and e.button isnt 0) # Not simply a left click
|
||||
return
|
||||
|
||||
if @pathname is Navigate.path
|
||||
if g.VIEW is 'thread'
|
||||
ThreadUpdater.update()
|
||||
else
|
||||
Index.update()
|
||||
unless Index.searchTest()
|
||||
Index.update()
|
||||
e.preventDefault()
|
||||
return
|
||||
|
||||
|
||||
@ -478,6 +478,9 @@ div.center:not(.ad-cnt) {
|
||||
}
|
||||
|
||||
/* Index */
|
||||
#index-menu {
|
||||
display: flex;
|
||||
}
|
||||
:root.thread #index-menu,
|
||||
:root.index-loading .navLinks,
|
||||
:root.index-loading .board,
|
||||
@ -485,6 +488,7 @@ div.center:not(.ad-cnt) {
|
||||
:root.thread .pagelist {
|
||||
display: none;
|
||||
}
|
||||
:root:not(.catalog-mode) #index-size,
|
||||
.index:not(.catalog-mode) #returnlink {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
<span class=brackets-wrap id=returnlink><a href=.././>Return</a></span>
|
||||
<span class=brackets-wrap id=bottomlink><a href="#bottom">Bottom</a></span>
|
||||
<span id="index-menu">
|
||||
<input type="search" id="index-search" class="field" placeholder="Search">
|
||||
<a id="index-search-clear" class="fa fa-times-circle" href="javascript:;"></a>
|
||||
|
||||
<time id="index-last-refresh" title="Last index refresh">...</time>
|
||||
<span id="hidden-label" hidden> — <span id="hidden-count"></span> <span id="hidden-toggle">[<a href="javascript:;">Show</a>]</span></span>
|
||||
<span style='flex: 1'></span>
|
||||
<select id="index-mode" name="Index Mode">
|
||||
<option disabled>Index Mode</option>
|
||||
<option value="paged">Paged</option>
|
||||
@ -26,4 +25,6 @@
|
||||
<option value="small">Small</option>
|
||||
<option value="large">Large</option>
|
||||
</select>
|
||||
</span>
|
||||
</span>
|
||||
<span class=brackets-wrap id=returnlink><a href=.././>Return</a></span>
|
||||
<span class=brackets-wrap id=bottomlink><a href="#bottom">Bottom</a></span>
|
||||
Loading…
x
Reference in New Issue
Block a user