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
|
@searchInput = $ '#index-search', @navLinks
|
||||||
|
|
||||||
@searchTest()
|
@searchTest true
|
||||||
|
|
||||||
@hideLabel = $ '#hidden-label', @navLinks
|
@hideLabel = $ '#hidden-label', @navLinks
|
||||||
@selectMode = $ '#index-mode', @navLinks
|
@selectMode = $ '#index-mode', @navLinks
|
||||||
@ -268,11 +268,15 @@ Index =
|
|||||||
{hash} = window.location
|
{hash} = window.location
|
||||||
window.location = './' + hash
|
window.location = './' + hash
|
||||||
|
|
||||||
searchTest: ->
|
searchTest: (init) ->
|
||||||
return unless hash = window.location.hash
|
return false unless hash = window.location.hash
|
||||||
return unless match = hash.match /s=([\w]+)/
|
return false unless match = hash.match /s=([\w]+)/
|
||||||
@searchInput.value = match[1]
|
@searchInput.value = match[1]
|
||||||
$.on d, '4chanXInitFinished', @onSearchInput
|
if init
|
||||||
|
$.on d, '4chanXInitFinished', Index.onSearchInput
|
||||||
|
else
|
||||||
|
Index.onSearchInput()
|
||||||
|
return true
|
||||||
|
|
||||||
setupNavLinks: ->
|
setupNavLinks: ->
|
||||||
for el in $$ '.navLinks.desktop > a'
|
for el in $$ '.navLinks.desktop > a'
|
||||||
@ -621,26 +625,25 @@ Index =
|
|||||||
Index.updateHideLabel()
|
Index.updateHideLabel()
|
||||||
$.event 'IndexRefresh'
|
$.event 'IndexRefresh'
|
||||||
|
|
||||||
buildReplies: (threads) ->
|
buildReplies: (thread) ->
|
||||||
return unless Conf['Show Replies']
|
return unless Conf['Show Replies']
|
||||||
posts = []
|
posts = []
|
||||||
for thread in threads
|
i = Index.liveThreadIDs.indexOf thread.ID
|
||||||
i = Index.liveThreadIDs.indexOf thread.ID
|
return unless lastReplies = Index.liveThreadData[i].last_replies
|
||||||
continue unless lastReplies = Index.liveThreadData[i].last_replies
|
nodes = []
|
||||||
nodes = []
|
for data in lastReplies
|
||||||
for data in lastReplies
|
if post = thread.posts[data.no]
|
||||||
if post = thread.posts[data.no]
|
nodes.push post.nodes.root
|
||||||
nodes.push post.nodes.root
|
continue
|
||||||
continue
|
nodes.push node = Build.postFromObject data, thread.board.ID
|
||||||
nodes.push node = Build.postFromObject data, thread.board.ID
|
try
|
||||||
try
|
posts.push new Post node, thread, thread.board
|
||||||
posts.push new Post node, thread, thread.board
|
catch err
|
||||||
catch err
|
# Skip posts that we failed to parse.
|
||||||
# Skip posts that we failed to parse.
|
errors = [] unless errors
|
||||||
errors = [] unless errors
|
errors.push
|
||||||
errors.push
|
message: "Parsing of Post No.#{data.no} failed. Post will be skipped."
|
||||||
message: "Parsing of Post No.#{data.no} failed. Post will be skipped."
|
error: err
|
||||||
error: err
|
|
||||||
$.add thread.OP.nodes.root.parentNode, nodes
|
$.add thread.OP.nodes.root.parentNode, nodes
|
||||||
|
|
||||||
Main.handleErrors errors if errors
|
Main.handleErrors errors if errors
|
||||||
@ -738,11 +741,11 @@ Index =
|
|||||||
threads = []
|
threads = []
|
||||||
i = threadsPerPage * pageNum
|
i = threadsPerPage * pageNum
|
||||||
max = i + threadsPerPage
|
max = i + threadsPerPage
|
||||||
while i < max
|
while i < max and thread = sortedThreads[i++]
|
||||||
threads.push thread = sortedThreads[i++]
|
threads.push thread
|
||||||
nodes.push thread.OP.nodes.root.parentNode, $.el 'hr'
|
nodes.push thread.OP.nodes.root.parentNode, $.el 'hr'
|
||||||
|
Index.buildReplies thread
|
||||||
|
|
||||||
Index.buildReplies threads
|
|
||||||
Index.buildPagelist()
|
Index.buildPagelist()
|
||||||
Index.setPage()
|
Index.setPage()
|
||||||
|
|
||||||
@ -755,7 +758,8 @@ Index =
|
|||||||
i = 0
|
i = 0
|
||||||
while thread = sortedThreads[i++]
|
while thread = sortedThreads[i++]
|
||||||
nodes.push thread.OP.nodes.root.parentNode, $.el 'hr'
|
nodes.push thread.OP.nodes.root.parentNode, $.el 'hr'
|
||||||
Index.buildReplies sortedThreads
|
Index.buildReplies thread
|
||||||
|
|
||||||
$.rmAll Index.root unless infinite
|
$.rmAll Index.root unless infinite
|
||||||
$.add Index.root, nodes
|
$.add Index.root, nodes
|
||||||
$.event 'IndexBuild', nodes
|
$.event 'IndexBuild', nodes
|
||||||
|
|||||||
@ -11,7 +11,7 @@ Navigate =
|
|||||||
|
|
||||||
@title = -> return
|
@title = -> return
|
||||||
|
|
||||||
@el = $.el 'div',
|
@el = $.el 'span',
|
||||||
id: 'breadCrumb'
|
id: 'breadCrumb'
|
||||||
|
|
||||||
Thread.callbacks.push
|
Thread.callbacks.push
|
||||||
@ -172,14 +172,16 @@ Navigate =
|
|||||||
|
|
||||||
navigate: (e) ->
|
navigate: (e) ->
|
||||||
return if @hostname isnt 'boards.4chan.org' or window.location.hostname is 'rs.4chan.org'
|
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 @pathname is Navigate.path
|
||||||
if g.VIEW is 'thread'
|
if g.VIEW is 'thread'
|
||||||
ThreadUpdater.update()
|
ThreadUpdater.update()
|
||||||
else
|
else
|
||||||
Index.update()
|
unless Index.searchTest()
|
||||||
|
Index.update()
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@ -478,6 +478,9 @@ div.center:not(.ad-cnt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Index */
|
/* Index */
|
||||||
|
#index-menu {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
:root.thread #index-menu,
|
:root.thread #index-menu,
|
||||||
:root.index-loading .navLinks,
|
:root.index-loading .navLinks,
|
||||||
:root.index-loading .board,
|
:root.index-loading .board,
|
||||||
@ -485,6 +488,7 @@ div.center:not(.ad-cnt) {
|
|||||||
:root.thread .pagelist {
|
:root.thread .pagelist {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
:root:not(.catalog-mode) #index-size,
|
||||||
.index:not(.catalog-mode) #returnlink {
|
.index:not(.catalog-mode) #returnlink {
|
||||||
display: none;
|
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">
|
<span id="index-menu">
|
||||||
<input type="search" id="index-search" class="field" placeholder="Search">
|
<input type="search" id="index-search" class="field" placeholder="Search">
|
||||||
<a id="index-search-clear" class="fa fa-times-circle" href="javascript:;"></a>
|
<a id="index-search-clear" class="fa fa-times-circle" href="javascript:;"></a>
|
||||||
|
|
||||||
<time id="index-last-refresh" title="Last index refresh">...</time>
|
<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 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">
|
<select id="index-mode" name="Index Mode">
|
||||||
<option disabled>Index Mode</option>
|
<option disabled>Index Mode</option>
|
||||||
<option value="paged">Paged</option>
|
<option value="paged">Paged</option>
|
||||||
@ -26,4 +25,6 @@
|
|||||||
<option value="small">Small</option>
|
<option value="small">Small</option>
|
||||||
<option value="large">Large</option>
|
<option value="large">Large</option>
|
||||||
</select>
|
</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