diff --git a/src/General/Build.coffee b/src/General/Build.coffee
index 2ae0788b2..d3a82f827 100755
--- a/src/General/Build.coffee
+++ b/src/General/Build.coffee
@@ -311,10 +311,9 @@ Build =
fullThread: (board, data) -> Build.postFromObject data, board.ID
- threadCatalog: (thread) ->
+ catalogThread: (thread) ->
{staticPath, gifIcon} = Build
- for data in Index.liveThreadData
- break if data.no is thread.ID
+ data = Index.liveThreadData[Index.liveThreadIDs.indexOf thread.ID]
if data.spoiler and !Conf['Reveal Spoiler Thumbnails']
src = "#{staticPath}spoiler"
@@ -363,6 +362,7 @@ Build =
'
'
) %>
+ root.dataset.fullID = thread.fullID
$.addClass root, 'pinned' if thread.isPinned
$.addClass root, thread.OP.highlights... if thread.OP.highlights
diff --git a/src/General/Index.coffee b/src/General/Index.coffee
index da390b367..9606a7791 100644
--- a/src/General/Index.coffee
+++ b/src/General/Index.coffee
@@ -7,7 +7,10 @@ Index =
@db = new DataBoard 'pinnedThreads'
Thread.callbacks.push
name: 'Thread Pinning'
- cb: @node
+ cb: @threadNode
+ CatalogThread.callbacks.push
+ name: 'Catalog Features'
+ cb: @catalogNode
@button = $.el 'a',
className: 'index-refresh-shortcut fa fa-refresh'
@@ -136,9 +139,24 @@ Index =
new Notice 'info', "Last page reached.", 2
setTimeout reset, 3 * $.SECOND
- node: ->
+ threadNode: ->
return unless data = Index.db.get {boardID: @board.ID, threadID: @ID}
@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) ->
if thread.isPinned
thread.unpin()
@@ -395,6 +413,16 @@ Index =
Main.handleErrors errors if errors
Main.callbackNodes Post, posts
+ buildCatalogViews: ->
+ threads = Index.sortedNodes
+ .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: ->
{liveThreadIDs, liveThreadData} = Index
sortedThreadIDs = {
@@ -444,10 +472,7 @@ Index =
when 'all pages'
nodes = Index.sortedNodes
when 'catalog'
- nodes = Index.sortedNodes
- .map((threadRoot) -> Get.threadFromRoot threadRoot)
- .filter((thread) -> !thread.isHidden)
- .map (thread) -> thread.getCatalogView()
+ nodes = Index.buildCatalogViews()
else
nodes = Index.buildSinglePage Index.getCurrentPage()
$.rmAll Index.root
diff --git a/src/General/lib/catalogthread.class b/src/General/lib/catalogthread.class
new file mode 100644
index 000000000..f656d2123
--- /dev/null
+++ b/src/General/lib/catalogthread.class
@@ -0,0 +1,14 @@
+class CatalogThread
+ @callbacks = new Callbacks 'CatalogThread'
+ 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 = @
diff --git a/src/General/lib/classes.coffee b/src/General/lib/classes.coffee
index eba1788af..3b0b36558 100755
--- a/src/General/lib/classes.coffee
+++ b/src/General/lib/classes.coffee
@@ -1,9 +1,10 @@
<%= grunt.file.read('src/General/lib/callbacks.class') %>
<%= grunt.file.read('src/General/lib/board.class') %>
<%= grunt.file.read('src/General/lib/thread.class') %>
+<%= grunt.file.read('src/General/lib/catalogthread.class') %>
<%= grunt.file.read('src/General/lib/post.class') %>
<%= grunt.file.read('src/General/lib/clone.class') %>
<%= grunt.file.read('src/General/lib/databoard.class') %>
<%= grunt.file.read('src/General/lib/notice.class') %>
<%= grunt.file.read('src/General/lib/randomaccesslist.class') %>
-<%= grunt.file.read('src/General/lib/simpledict.class') %>
\ No newline at end of file
+<%= grunt.file.read('src/General/lib/simpledict.class') %>
diff --git a/src/General/lib/thread.class b/src/General/lib/thread.class
index b34a8fa6e..c81218e2d 100755
--- a/src/General/lib/thread.class
+++ b/src/General/lib/thread.class
@@ -10,17 +10,19 @@ class Thread
@postLimit = false
@fileLimit = false
+ @OP = null
+ @catalogView = null
+
g.threads.push @fullID, board.threads.push @, @
setPage: (pageNum) ->
icon = $ '.page-num', @OP.nodes.post
for key in ['title', 'textContent']
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) ->
return unless @catalogView
- el = $ ".#{type}-count", @catalogView
+ el = @catalogView.nodes["#{type}Count"]
el.textContent = count
(if reachedLimit then $.addClass else $.rmClass) el, 'warning'
@@ -52,28 +54,12 @@ class Thread
root = $ '.thread-icons', @catalogView
(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: ->
@isOnTop = @isPinned = true
- $.addClass @catalogView, 'pinned' if @catalogView
+ $.addClass @catalogView.nodes.root, 'pinned' if @catalogView
unpin: ->
@isOnTop = @isPinned = false
- $.rmClass @catalogView, 'pinned' if @catalogView
+ $.rmClass @catalogView.nodes.root, 'pinned' if @catalogView
kill: ->
@isDead = true