Refactor the catalog thread views business with a class.
This commit is contained in:
parent
9f682bea14
commit
a4ef601748
@ -40,6 +40,7 @@ module.exports = (grunt) ->
|
|||||||
# <--|
|
# <--|
|
||||||
'src/General/Board.coffee'
|
'src/General/Board.coffee'
|
||||||
'src/General/Thread.coffee'
|
'src/General/Thread.coffee'
|
||||||
|
'src/General/CatalogThread.coffee'
|
||||||
'src/General/Post.coffee'
|
'src/General/Post.coffee'
|
||||||
'src/General/Clone.coffee'
|
'src/General/Clone.coffee'
|
||||||
'src/General/DataBoard.coffee'
|
'src/General/DataBoard.coffee'
|
||||||
|
|||||||
@ -259,10 +259,9 @@ Build =
|
|||||||
|
|
||||||
$.add root, nodes
|
$.add root, nodes
|
||||||
root
|
root
|
||||||
threadCatalog: (thread) ->
|
catalogThread: (thread) ->
|
||||||
{staticPath, gifIcon} = Build
|
{staticPath, gifIcon} = Build
|
||||||
for data in Index.liveThreadData
|
data = Index.liveThreadData[Index.liveThreadIDs.indexOf thread.ID]
|
||||||
break if data.no is thread.ID
|
|
||||||
|
|
||||||
if data.spoiler and !Conf['Reveal Spoilers']
|
if data.spoiler and !Conf['Reveal Spoilers']
|
||||||
src = "#{staticPath}spoiler"
|
src = "#{staticPath}spoiler"
|
||||||
@ -297,6 +296,7 @@ Build =
|
|||||||
className: 'catalog-thread'
|
className: 'catalog-thread'
|
||||||
innerHTML: <%= importHTML('General/Thread-catalog-view') %>
|
innerHTML: <%= importHTML('General/Thread-catalog-view') %>
|
||||||
|
|
||||||
|
root.dataset.fullID = thread.fullID
|
||||||
$.addClass root, 'pinned' if thread.isPinned
|
$.addClass root, 'pinned' if thread.isPinned
|
||||||
$.addClass root, thread.OP.highlights... if thread.OP.highlights
|
$.addClass root, thread.OP.highlights... if thread.OP.highlights
|
||||||
|
|
||||||
|
|||||||
14
src/General/CatalogThread.coffee
Normal file
14
src/General/CatalogThread.coffee
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
class CatalogThread
|
||||||
|
@callbacks = []
|
||||||
|
toString: -> @ID
|
||||||
|
|
||||||
|
constructor: (root, @thread) ->
|
||||||
|
@ID = @thread.ID
|
||||||
|
@board = @thread.board
|
||||||
|
@nodes =
|
||||||
|
root: root
|
||||||
|
thumb: $ '.thumb', root
|
||||||
|
postCount: $ '.post-count', root
|
||||||
|
fileCount: $ '.file-count', root
|
||||||
|
pageCount: $ '.page-count', root
|
||||||
|
@thread.catalogView = @
|
||||||
@ -15,7 +15,10 @@ Index =
|
|||||||
@db = new DataBoard 'pinnedThreads'
|
@db = new DataBoard 'pinnedThreads'
|
||||||
Thread.callbacks.push
|
Thread.callbacks.push
|
||||||
name: 'Thread Pinning'
|
name: 'Thread Pinning'
|
||||||
cb: @node
|
cb: @threadNode
|
||||||
|
CatalogThread.callbacks.push
|
||||||
|
name: 'Catalog Features'
|
||||||
|
cb: @catalogNode
|
||||||
|
|
||||||
@button = $.el 'a',
|
@button = $.el 'a',
|
||||||
className: 'index-refresh-shortcut fa fa-refresh'
|
className: 'index-refresh-shortcut fa fa-refresh'
|
||||||
@ -117,9 +120,24 @@ Index =
|
|||||||
$.asap (-> $('.pagelist') or d.readyState isnt 'loading'), ->
|
$.asap (-> $('.pagelist') or d.readyState isnt 'loading'), ->
|
||||||
$.replace $('.pagelist'), Index.pagelist
|
$.replace $('.pagelist'), Index.pagelist
|
||||||
|
|
||||||
node: ->
|
threadNode: ->
|
||||||
return unless data = Index.db.get {boardID: @board.ID, threadID: @ID}
|
return unless data = Index.db.get {boardID: @board.ID, threadID: @ID}
|
||||||
@pin() if data.isPinned
|
@pin() if data.isPinned
|
||||||
|
catalogNode: ->
|
||||||
|
$.on @nodes.thumb, 'click', Index.onClick
|
||||||
|
onClick: (e) ->
|
||||||
|
return if e.button isnt 0
|
||||||
|
root = @parentNode.parentNode
|
||||||
|
thread = g.threads[root.dataset.fullID]
|
||||||
|
if e.shiftKey
|
||||||
|
$.rm root
|
||||||
|
ThreadHiding.hide thread
|
||||||
|
ThreadHiding.saveHiddenState thread
|
||||||
|
else if e.altKey
|
||||||
|
Index.togglePin thread
|
||||||
|
else
|
||||||
|
return
|
||||||
|
e.preventDefault()
|
||||||
togglePin: (thread) ->
|
togglePin: (thread) ->
|
||||||
if thread.isPinned
|
if thread.isPinned
|
||||||
thread.unpin()
|
thread.unpin()
|
||||||
@ -374,6 +392,16 @@ Index =
|
|||||||
|
|
||||||
Main.handleErrors errors if errors
|
Main.handleErrors errors if errors
|
||||||
Main.callbackNodes Post, posts
|
Main.callbackNodes Post, posts
|
||||||
|
buildCatalogViews: ->
|
||||||
|
threads = Index.sortedNodes
|
||||||
|
.filter((n, i) -> !(i % 2))
|
||||||
|
.map((threadRoot) -> Get.threadFromRoot threadRoot)
|
||||||
|
.filter (thread) -> !thread.isHidden
|
||||||
|
catalogThreads = []
|
||||||
|
for thread in threads when !thread.catalogView
|
||||||
|
catalogThreads.push new CatalogThread Build.catalogThread(thread), thread
|
||||||
|
Main.callbackNodes CatalogThread, catalogThreads
|
||||||
|
threads.map (thread) -> thread.catalogView.nodes.root
|
||||||
sort: ->
|
sort: ->
|
||||||
switch Conf['Index Sort']
|
switch Conf['Index Sort']
|
||||||
when 'bump'
|
when 'bump'
|
||||||
@ -414,11 +442,7 @@ Index =
|
|||||||
nodesPerPage = Index.threadsNumPerPage * 2
|
nodesPerPage = Index.threadsNumPerPage * 2
|
||||||
nodes = Index.sortedNodes[nodesPerPage * pageNum ... nodesPerPage * (pageNum + 1)]
|
nodes = Index.sortedNodes[nodesPerPage * pageNum ... nodesPerPage * (pageNum + 1)]
|
||||||
when 'catalog'
|
when 'catalog'
|
||||||
nodes = Index.sortedNodes
|
nodes = Index.buildCatalogViews()
|
||||||
.filter((n, i) -> !(i % 2))
|
|
||||||
.map((threadRoot) -> Get.threadFromRoot threadRoot)
|
|
||||||
.filter((thread) -> !thread.isHidden)
|
|
||||||
.map (thread) -> thread.getCatalogView()
|
|
||||||
else
|
else
|
||||||
nodes = Index.sortedNodes
|
nodes = Index.sortedNodes
|
||||||
$.rmAll Index.root
|
$.rmAll Index.root
|
||||||
|
|||||||
@ -10,16 +10,19 @@ class Thread
|
|||||||
@postLimit = false
|
@postLimit = false
|
||||||
@fileLimit = false
|
@fileLimit = false
|
||||||
|
|
||||||
|
@OP = null
|
||||||
|
@catalogView = null
|
||||||
|
|
||||||
g.threads[@fullID] = board.threads[@] = @
|
g.threads[@fullID] = board.threads[@] = @
|
||||||
|
|
||||||
setPage: (pageNum) ->
|
setPage: (pageNum) ->
|
||||||
icon = $ '.page-num', @OP.nodes.post
|
icon = $ '.page-num', @OP.nodes.post
|
||||||
for key in ['title', 'textContent']
|
for key in ['title', 'textContent']
|
||||||
icon[key] = icon[key].replace /\d+/, pageNum
|
icon[key] = icon[key].replace /\d+/, pageNum
|
||||||
$('.page-count', @catalogView).textContent = pageNum if @catalogView
|
@catalogView.nodes.pageCount.textContent = pageNum if @catalogView
|
||||||
setCount: (type, count, reachedLimit) ->
|
setCount: (type, count, reachedLimit) ->
|
||||||
return unless @catalogView
|
return unless @catalogView
|
||||||
el = $ ".#{type}-count", @catalogView
|
el = @catalogView.nodes["#{type}Count"]
|
||||||
el.textContent = count
|
el.textContent = count
|
||||||
(if reachedLimit then $.addClass else $.rmClass) el, 'warning'
|
(if reachedLimit then $.addClass else $.rmClass) el, 'warning'
|
||||||
setStatus: (type, status) ->
|
setStatus: (type, status) ->
|
||||||
@ -50,28 +53,12 @@ class Thread
|
|||||||
root = $ '.thread-icons', @catalogView
|
root = $ '.thread-icons', @catalogView
|
||||||
(if type is 'Sticky' and @isClosed then $.prepend else $.add) root, icon.cloneNode()
|
(if type is 'Sticky' and @isClosed then $.prepend else $.add) root, icon.cloneNode()
|
||||||
|
|
||||||
getCatalogView: ->
|
|
||||||
return @catalogView if @catalogView
|
|
||||||
@catalogView = Build.threadCatalog @
|
|
||||||
$.on $('.thumb', @catalogView), 'click', @onCatalogViewClick
|
|
||||||
@catalogView
|
|
||||||
onCatalogViewClick: (e) =>
|
|
||||||
return if e.button isnt 0
|
|
||||||
if e.shiftKey
|
|
||||||
$.rm @catalogView
|
|
||||||
ThreadHiding.hide @
|
|
||||||
ThreadHiding.saveHiddenState @
|
|
||||||
else if e.altKey
|
|
||||||
Index.togglePin @
|
|
||||||
else
|
|
||||||
return
|
|
||||||
e.preventDefault()
|
|
||||||
pin: ->
|
pin: ->
|
||||||
@isOnTop = @isPinned = true
|
@isOnTop = @isPinned = true
|
||||||
$.addClass @catalogView, 'pinned' if @catalogView
|
$.addClass @catalogView.nodes.root, 'pinned' if @catalogView
|
||||||
unpin: ->
|
unpin: ->
|
||||||
@isOnTop = @isPinned = false
|
@isOnTop = @isPinned = false
|
||||||
$.rmClass @catalogView, 'pinned' if @catalogView
|
$.rmClass @catalogView.nodes.root, 'pinned' if @catalogView
|
||||||
|
|
||||||
kill: ->
|
kill: ->
|
||||||
@isDead = true
|
@isDead = true
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user