From 154ad07cd7e57e2b5df0f1e829b273a379dc3a15 Mon Sep 17 00:00:00 2001 From: Mayhem Date: Sat, 25 Jan 2014 17:01:06 +0100 Subject: [PATCH] Initial index catalog mode work. --- css/style.css | 28 +++++++++++++++++ html/General/Thread-catalog-view.html | 8 +++++ src/General/Build.coffee | 44 +++++++++++++++++++++++++-- src/General/Index.coffee | 26 +++++++++++----- src/General/Thread.coffee | 4 +++ 5 files changed, 101 insertions(+), 9 deletions(-) create mode 100644 html/General/Thread-catalog-view.html diff --git a/css/style.css b/css/style.css index f697b45e2..8d23bde6c 100644 --- a/css/style.css +++ b/css/style.css @@ -401,6 +401,34 @@ a[href="javascript:;"] { .summary { text-decoration: none; } +.catalog-mode { + text-align: center; +} +.catalog-thread { + display: inline-block; + vertical-align: top; + padding-top: 5px; + width: 165px; + max-height: 320px; + overflow: hidden; + word-break: break-word; +} +.thumb { + max-width: 150px; + max-height: 150px; + box-shadow: 0 0 5px rgba(0, 0, 0, .25); +} +.thread-stats { + cursor: help; + font-size: 10px; + font-weight: 700; + line-height: .8; + margin-top: 1px; + float: none; +} +.catalog-thread .subject { + font-weight: 700; +} /* Announcement Hiding */ :root.hide-announcement #globalMessage, diff --git a/html/General/Thread-catalog-view.html b/html/General/Thread-catalog-view.html new file mode 100644 index 000000000..9592c56a0 --- /dev/null +++ b/html/General/Thread-catalog-view.html @@ -0,0 +1,8 @@ + + + +
+ #{postCount} / #{fileCount} / #{pageCount} +
+#{subject} +
#{comment}
diff --git a/src/General/Build.coffee b/src/General/Build.coffee index 6fa1278b8..ad1c14558 100644 --- a/src/General/Build.coffee +++ b/src/General/Build.coffee @@ -254,9 +254,49 @@ Build = [posts, files] = if Conf['Show Replies'] [data.omitted_posts, data.omitted_images] else - # XXX data.images is not accurate. - [data.replies, data.omitted_images + data.last_replies.filter((data) -> !!data.ext).length] + [data.replies, data.images] nodes.push Build.summary board.ID, data.no, posts, files $.add root, nodes root + threadCatalog: (thread) -> + for data in Index.liveThreadData + break if data.no is thread.ID + + if data.spoiler and !Conf['Reveal Spoilers'] + src = "#{Build.staticPath}spoiler" + if spoilerRange = Build.spoilerRange[thread.board] + # Randomize the spoiler image. + src += "-#{thread.board}" + Math.floor 1 + spoilerRange * Math.random() + src += '.png' + imgWidth = imgHeight = 100 + else if data.filedeleted + src = "#{Build.staticPath}filedeleted-res#{Build.gifIcon}" + imgWidth = 127 + imgHeight = 13 + else + src = thread.OP.file.thumbURL + max = Math.max data.tn_w, data.tn_h + imgWidth = data.tn_w * 150 / max + imgHeight = data.tn_h * 150 / max + + postCount = data.replies + 1 + fileCount = data.images + !!data.ext + pageCount = Math.floor Index.liveThreadIDs.indexOf(thread.ID) / Index.threadsNumPerPage + + subject = if thread.OP.info.subject + "
#{thread.OP.info.subject}
" + else + '' + comment = thread.OP.nodes.comment.innerHTML.replace /(
){2,}/g, '
' + + root = $.el 'div', + className: 'catalog-thread' + innerHTML: <%= importHTML('General/Thread-catalog-view') %> + + if data.bumplimit + $.addClass $('.post-count', root), 'warning' + if data.imagelimit + $.addClass $('.file-count', root), 'warning' + + root diff --git a/src/General/Index.coffee b/src/General/Index.coffee index 79a935099..1d763746f 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -14,6 +14,7 @@ Index = subEntries: [ { el: $.el 'label', innerHTML: ' Paged' } { el: $.el 'label', innerHTML: ' All threads' } + { el: $.el 'label', innerHTML: ' Catalog' } ] for label in modeEntry.subEntries input = label.el.firstChild @@ -68,6 +69,7 @@ Index = $.addClass doc, 'index-loading' @update() @root = $.el 'div', className: 'board' + Index.cb.rootClass() @pagelist = $.el 'div', className: 'pagelist' hidden: true @@ -101,7 +103,10 @@ Index = $.replace $('.pagelist'), Index.pagelist cb: + rootClass: -> + (if Conf['Index Mode'] is 'catalog' then $.addClass else $.rmClass) Index.root, 'catalog-mode' mode: -> + Index.cb.rootClass() Index.togglePagelist() Index.buildIndex() sort: -> @@ -368,14 +373,21 @@ Index = Index.sortedNodes.splice offset++ * 2, 0, Index.sortedNodes.splice(i, 2)... return buildIndex: -> - if Conf['Index Mode'] is 'paged' - pageNum = Index.getCurrentPage() - nodesPerPage = Index.threadsNumPerPage * 2 - nodes = Index.sortedNodes[nodesPerPage * pageNum ... nodesPerPage * (pageNum + 1)] - else - nodes = Index.sortedNodes + switch Conf['Index Mode'] + when 'paged' + pageNum = Index.getCurrentPage() + nodesPerPage = Index.threadsNumPerPage * 2 + nodes = Index.sortedNodes[nodesPerPage * pageNum ... nodesPerPage * (pageNum + 1)] + when 'catalog' + nodes = Index.sortedNodes + .filter((n, i) -> !(i % 2)) + .map((threadRoot) -> Get.threadFromRoot threadRoot) + .filter((thread) -> !thread.isHidden) + .map (thread) -> thread.getCatalogView() + else + nodes = Index.sortedNodes $.rmAll Index.root - Index.buildReplies nodes if Conf['Show Replies'] + Index.buildReplies nodes if Conf['Show Replies'] and Conf['Index Mode'] isnt 'catalog' $.event 'IndexBuild', nodes $.add Index.root, nodes diff --git a/src/General/Thread.coffee b/src/General/Thread.coffee index 410a4288a..d7dd92fa3 100644 --- a/src/General/Thread.coffee +++ b/src/General/Thread.coffee @@ -39,6 +39,10 @@ class Thread $ '[title="Quote this post"]', @OP.nodes.info $.after root, [$.tn(' '), icon] + getCatalogView: -> + return @catalogView if @catalogView + @catalogView = Build.threadCatalog @ + kill: -> @isDead = true @timeOfDeath = Date.now()