diff --git a/Gruntfile.coffee b/Gruntfile.coffee index e7226450a..7e0db8c07 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -17,6 +17,7 @@ module.exports = (grunt) -> 'src/General/Header.coffee' 'src/General/Notice.coffee' 'src/General/Settings.coffee' + 'src/General/Index.coffee' 'src/General/Get.coffee' 'src/General/Build.coffee' # Features --> diff --git a/css/style.css b/css/style.css index 8e57b3adc..31f6e7d8b 100644 --- a/css/style.css +++ b/css/style.css @@ -364,6 +364,7 @@ a[href="javascript:;"] { /* Index */ :root.index-loading .board, +:root.index-loading .pagelist, :root.index-hide-pagelist .pagelist { display: none; } diff --git a/html/General/Index-pagelist.html b/html/General/Index-pagelist.html new file mode 100644 index 000000000..d8b1d7c99 --- /dev/null +++ b/html/General/Index-pagelist.html @@ -0,0 +1,11 @@ + +
+ diff --git a/src/Miscellaneous/Index.coffee b/src/General/Index.coffee similarity index 81% rename from src/Miscellaneous/Index.coffee rename to src/General/Index.coffee index 16fef5eaa..0915f01c4 100644 --- a/src/Miscellaneous/Index.coffee +++ b/src/General/Index.coffee @@ -25,10 +25,10 @@ Index = el: $.el 'span', textContent: 'Sort by' subEntries: [ { el: $.el 'label', innerHTML: ' Bump order' } + { el: $.el 'label', innerHTML: ' Last reply' } { el: $.el 'label', innerHTML: ' Creation date' } { el: $.el 'label', innerHTML: ' Reply count' } { el: $.el 'label', innerHTML: ' File count' } - { el: $.el 'label', innerHTML: ' Last reply' } ] for label in sortEntry.subEntries input = label.el.firstChild @@ -44,11 +44,16 @@ Index = subEntries: [modeEntry, sortEntry] $.addClass doc, 'index-loading' - Index.togglePagelist() - Index.root = $.el 'div', className: 'board' Index.update() - $.asap (-> $('.board', doc) or d.readyState isnt 'loading'), -> - $.replace $('.board'), Index.root + Index.root = $.el 'div', className: 'board' + Index.pagelist = $.el 'div', + className: 'pagelist' + innerHTML: """ + <%= grunt.file.read('html/General/Index-pagelist.html').replace(/>\s+<').trim() %> + """ + $.asap (-> $('.pagelist', doc) or d.readyState isnt 'loading'), -> + $.replace $('.board'), Index.root + $.replace $('.pagelist'), Index.pagelist $.rmClass doc, 'index-loading' cb: @@ -61,6 +66,39 @@ Index = togglePagelist: -> (if Conf['Index Mode'] is 'paged' then $.rmClass else $.addClass) doc, 'index-hide-pagelist' + buildPagelist: -> + pagesRoot = $ '.pages', Index.pagelist + if pagesRoot.childElementCount isnt Index.pagesNum + nodes = [] + for i in [0..Index.pagesNum - 1] + a = $.el 'a', + textContent: i + href: if i then i else './' + nodes.push $.tn('['), a, $.tn '] ' + $.rmAll pagesRoot + $.add pagesRoot, nodes + Index.setPage() + setPage: -> + pageNum = +window.location.pathname.split('/')[2] + pagesRoot = $ '.pages', Index.pagelist + # Previous/Next buttons + prev = pagesRoot.previousSibling.firstChild + next = pagesRoot.nextSibling.firstChild + href = Math.max pageNum - 1, 0 + prev.href = if href is 0 then './' else href + prev.firstChild.disabled = href is pageNum + href = Math.min pageNum + 1, Index.pagesNum - 1 + next.href = if href is 0 then './' else href + next.firstChild.disabled = href is pageNum + # current page + if strong = $ 'strong', pagesRoot + return if +strong.textContent is pageNum + $.replace strong, strong.firstChild + else + strong = $.el 'strong' + a = pagesRoot.children[pageNum] + $.before a, strong + $.add strong, a update: -> return unless navigator.onLine @@ -104,7 +142,9 @@ Index = Index.buildAll() Index.sort() Index.buildIndex() + Index.buildPagelist() parseThreadList: (pages) -> + Index.pagesNum = pages.length Index.threadsNumPerPage = pages[0].threads.length Index.liveThreadData = pages.reduce ((arr, next) -> arr.concat next.threads), [] Index.liveThreadIDs = Index.liveThreadData.map (data) -> data.no @@ -145,18 +185,18 @@ Index = switch Conf['Index Sort'] when 'bump' sortedThreadIDs = Index.liveThreadIDs - when 'birth' - sortedThreadIDs = [Index.liveThreadIDs...].sort (a, b) -> b - a - when 'replycount' - sortedThreadIDs = [Index.liveThreadData...].sort((a, b) -> b.replies - a.replies).map (data) -> data.no - when 'filecount' - sortedThreadIDs = [Index.liveThreadData...].sort((a, b) -> b.images - a.images).map (data) -> data.no when 'lastreply' sortedThreadIDs = [Index.liveThreadData...].sort((a, b) -> a = a.last_replies[a.last_replies.length - 1] if 'last_replies' of a b = b.last_replies[b.last_replies.length - 1] if 'last_replies' of b b.no - a.no ).map (data) -> data.no + when 'birth' + sortedThreadIDs = [Index.liveThreadIDs...].sort (a, b) -> b - a + when 'replycount' + sortedThreadIDs = [Index.liveThreadData...].sort((a, b) -> b.replies - a.replies).map (data) -> data.no + when 'filecount' + sortedThreadIDs = [Index.liveThreadData...].sort((a, b) -> b.images - a.images).map (data) -> data.no Index.sortedNodes = [] for threadID in sortedThreadIDs i = Index.liveThreadIDs.indexOf(threadID) * 2