Refactor the catalog thread views business with a class.
Conflicts: Gruntfile.coffee src/General/Build.coffee src/General/Index.coffee src/General/lib/thread.class
This commit is contained in:
parent
c3e37a8077
commit
12c2e7c0a2
@ -311,10 +311,9 @@ Build =
|
|||||||
|
|
||||||
fullThread: (board, data) -> Build.postFromObject data, board.ID
|
fullThread: (board, data) -> Build.postFromObject data, board.ID
|
||||||
|
|
||||||
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 Spoiler Thumbnails']
|
if data.spoiler and !Conf['Reveal Spoiler Thumbnails']
|
||||||
src = "#{staticPath}spoiler"
|
src = "#{staticPath}spoiler"
|
||||||
@ -363,6 +362,7 @@ Build =
|
|||||||
'<div class="comment">&{thread.OP.nodes.comment}</div>'
|
'<div class="comment">&{thread.OP.nodes.comment}</div>'
|
||||||
) %>
|
) %>
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,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'
|
||||||
@ -136,9 +139,24 @@ Index =
|
|||||||
new Notice 'info', "Last page reached.", 2
|
new Notice 'info', "Last page reached.", 2
|
||||||
setTimeout reset, 3 * $.SECOND
|
setTimeout reset, 3 * $.SECOND
|
||||||
|
|
||||||
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()
|
||||||
@ -395,6 +413,16 @@ Index =
|
|||||||
Main.handleErrors errors if errors
|
Main.handleErrors errors if errors
|
||||||
Main.callbackNodes Post, posts
|
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: ->
|
sort: ->
|
||||||
{liveThreadIDs, liveThreadData} = Index
|
{liveThreadIDs, liveThreadData} = Index
|
||||||
sortedThreadIDs = {
|
sortedThreadIDs = {
|
||||||
@ -444,10 +472,7 @@ Index =
|
|||||||
when 'all pages'
|
when 'all pages'
|
||||||
nodes = Index.sortedNodes
|
nodes = Index.sortedNodes
|
||||||
when 'catalog'
|
when 'catalog'
|
||||||
nodes = Index.sortedNodes
|
nodes = Index.buildCatalogViews()
|
||||||
.map((threadRoot) -> Get.threadFromRoot threadRoot)
|
|
||||||
.filter((thread) -> !thread.isHidden)
|
|
||||||
.map (thread) -> thread.getCatalogView()
|
|
||||||
else
|
else
|
||||||
nodes = Index.buildSinglePage Index.getCurrentPage()
|
nodes = Index.buildSinglePage Index.getCurrentPage()
|
||||||
$.rmAll Index.root
|
$.rmAll Index.root
|
||||||
|
|||||||
14
src/General/lib/catalogthread.class
Normal file
14
src/General/lib/catalogthread.class
Normal file
@ -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 = @
|
||||||
@ -1,9 +1,10 @@
|
|||||||
<%= grunt.file.read('src/General/lib/callbacks.class') %>
|
<%= grunt.file.read('src/General/lib/callbacks.class') %>
|
||||||
<%= grunt.file.read('src/General/lib/board.class') %>
|
<%= grunt.file.read('src/General/lib/board.class') %>
|
||||||
<%= grunt.file.read('src/General/lib/thread.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/post.class') %>
|
||||||
<%= grunt.file.read('src/General/lib/clone.class') %>
|
<%= grunt.file.read('src/General/lib/clone.class') %>
|
||||||
<%= grunt.file.read('src/General/lib/databoard.class') %>
|
<%= grunt.file.read('src/General/lib/databoard.class') %>
|
||||||
<%= grunt.file.read('src/General/lib/notice.class') %>
|
<%= grunt.file.read('src/General/lib/notice.class') %>
|
||||||
<%= grunt.file.read('src/General/lib/randomaccesslist.class') %>
|
<%= grunt.file.read('src/General/lib/randomaccesslist.class') %>
|
||||||
<%= grunt.file.read('src/General/lib/simpledict.class') %>
|
<%= grunt.file.read('src/General/lib/simpledict.class') %>
|
||||||
|
|||||||
@ -10,17 +10,19 @@ class Thread
|
|||||||
@postLimit = false
|
@postLimit = false
|
||||||
@fileLimit = false
|
@fileLimit = false
|
||||||
|
|
||||||
|
@OP = null
|
||||||
|
@catalogView = null
|
||||||
|
|
||||||
g.threads.push @fullID, board.threads.push @, @
|
g.threads.push @fullID, board.threads.push @, @
|
||||||
|
|
||||||
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'
|
||||||
|
|
||||||
@ -52,28 +54,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