From 6b9059182fdf97001f013efc57150ff3dc14d80a Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sat, 18 Jul 2015 11:23:26 -0700 Subject: [PATCH 01/12] Revert "Suppress post thumbnails from loading until they are actually inserted into the index." This reverts commit 6ad0064f415f0d97c7b6ddaadb2f5f476de2ac8a. Conflicts: src/General/Build.coffee src/General/html/Build/File.html src/Images/ImageLoader.coffee --- src/General/Build.coffee | 9 ++++----- src/General/Index.coffee | 4 ---- src/General/html/Build/File.html | 4 ++-- src/General/lib/clone.class | 5 ----- src/Images/ImageLoader.coffee | 6 ++---- src/Images/RevealSpoilers.coffee | 5 +---- 6 files changed, 9 insertions(+), 24 deletions(-) diff --git a/src/General/Build.coffee b/src/General/Build.coffee index 0b76f84e1..1854fd9bd 100755 --- a/src/General/Build.coffee +++ b/src/General/Build.coffee @@ -88,11 +88,10 @@ Build = .replace(/<[^>]*>/g, '') o.info.comment = Build.unescape html - postFromObject: (data, boardID, suppressThumb) -> - o = Build.parseJSON data, boardID - Build.post o, suppressThumb + postFromObject: (data, boardID) -> + Build.post Build.parseJSON data, boardID - post: (o, suppressThumb) -> + post: (o) -> {postID, threadID, boardID, file} = o {subject, email, name, tripcode, capcode, uniqueID, flagCode, flag, dateUTC, dateText, commentHTML} = o.info {staticPath, gifIcon} = Build @@ -178,7 +177,7 @@ Build = root excerptThread: (board, data, OP) -> - nodes = [if OP then OP.nodes.root else Build.postFromObject data, board.ID, true] + nodes = [if OP then OP.nodes.root else Build.postFromObject data, board.ID] if data.omitted_posts or !Conf['Show Replies'] and data.replies [posts, files] = if Conf['Show Replies'] # XXX data.omitted_images is not accurate. diff --git a/src/General/Index.coffee b/src/General/Index.coffee index 74a4dfaab..88b47d7ed 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -650,10 +650,6 @@ Index = buildStructure: (nodes) -> for node in nodes - if thumb = $ 'img[data-src]', node - thumb.src = thumb.dataset.src - # XXX https://bugzilla.mozilla.org/show_bug.cgi?id=1021289 - thumb.removeAttribute 'data-src' $.add Index.root, [node, $.el 'hr'] $.event 'PostsInserted' if doc.contains Index.root ThreadHiding.onIndexBuild nodes diff --git a/src/General/html/Build/File.html b/src/General/html/Build/File.html index d48f11db2..5d3014a24 100644 --- a/src/General/html/Build/File.html +++ b/src/General/html/Build/File.html @@ -15,8 +15,8 @@ (${file.size}, ${file.dimensions || "PDF"}) - ${file.size} doc.contains clone.nodes.root file.isPrefetched = true @@ -72,8 +72,6 @@ ImageLoader = $.on el, 'load', -> clone.file.thumb.src = url for clone in post.clones thumb.src = url - # XXX https://bugzilla.mozilla.org/show_bug.cgi?id=1021289 - thumb.removeAttribute 'data-src' el.src = url toggle: -> diff --git a/src/Images/RevealSpoilers.coffee b/src/Images/RevealSpoilers.coffee index ed159a4ca..4c3e65709 100755 --- a/src/Images/RevealSpoilers.coffee +++ b/src/Images/RevealSpoilers.coffee @@ -13,7 +13,4 @@ RevealSpoilers = thumb.removeAttribute 'style' # Enforce thumbnail size if thumbnail is replaced. thumb.style.maxHeight = thumb.style.maxWidth = if @isReply then '125px' else '250px' - if thumb.src - thumb.src = @file.thumbURL - else - thumb.dataset.src = @file.thumbURL + thumb.src = @file.thumbURL From e97a0b8d633583ac13694b1b09736dd769b2b0ae Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sat, 18 Jul 2015 14:03:55 -0700 Subject: [PATCH 02/12] Rearrange Index.init for clarity. --- src/General/Index.coffee | 47 +++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/src/General/Index.coffee b/src/General/Index.coffee index 88b47d7ed..2dd42baa7 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -18,6 +18,11 @@ Index = command: location.href.match(/#(.*)/)?[1] replace: true + $.addClass doc, 'index-loading', "#{Conf['Index Mode'].replace /\ /g, '-'}-mode" + $.on window, 'popstate', @cb.popstate + $.on d, 'scroll', Index.scroll + + # Header refresh button @button = $.el 'a', className: 'index-refresh-shortcut fa fa-refresh' title: 'Refresh' @@ -26,6 +31,7 @@ Index = $.on @button, 'click', -> Index.update() Header.addShortcut @button, 1 + # Header "Index Navigation" submenu repliesEntry = el: UI.checkbox 'Show Replies', 'Show replies' pinEntry = el: UI.checkbox 'Pin Watched Threads', 'Pin watched threads' anchorEntry = el: UI.checkbox 'Anchor Hidden Threads', 'Anchor hidden threads' @@ -49,30 +55,27 @@ Index = order: 100 subEntries: [repliesEntry, pinEntry, anchorEntry, refNavEntry] - $.addClass doc, 'index-loading', "#{Conf['Index Mode'].replace /\ /g, '-'}-mode" - @root = $.el 'div', className: 'board' - @cb.size() - @pagelist = $.el 'div', className: 'pagelist' - $.extend @pagelist, <%= importHTML('Features/Index-pagelist') %> - $('.cataloglink a', @pagelist).href = CatalogLinks.catalog() + # Navigation links at top of index @navLinks = $.el 'div', className: 'navLinks' $.extend @navLinks, <%= importHTML('Features/Index-navlinks') %> $('.cataloglink a', @navLinks).href = CatalogLinks.catalog() $('.archlistlink', @navLinks).hidden = true if g.BOARD.ID is 'b' + $.on $('#index-last-refresh a', @navLinks), 'click', @cb.refreshFront + + # Search field @searchInput = $ '#index-search', @navLinks @setupSearch() - @hideLabel = $ '#hidden-label', @navLinks - @selectMode = $ '#index-mode', @navLinks - @selectSort = $ '#index-sort', @navLinks - @selectSize = $ '#index-size', @navLinks - $.on window, 'popstate', @cb.popstate - - $.on d, 'scroll', Index.scroll - $.on @pagelist, 'click', @cb.pageNav $.on @searchInput, 'input', @onSearchInput - $.on $('#index-last-refresh a', @navLinks), 'click', @cb.refreshFront - $.on $('#index-search-clear', @navLinks), 'click', @clearSearch - $.on $('#hidden-toggle a', @navLinks), 'click', @cb.toggleHiddenThreads + $.on $('#index-search-clear', @navLinks), 'click', @clearSearch + + # Hidden threads toggle + @hideLabel = $ '#hidden-label', @navLinks + $.on $('#hidden-toggle a', @navLinks), 'click', @cb.toggleHiddenThreads + + # Drop-down menus + @selectMode = $ '#index-mode', @navLinks + @selectSort = $ '#index-sort', @navLinks + @selectSize = $ '#index-size', @navLinks $.on @selectMode, 'change', @cb.mode for select in [@selectMode, @selectSort, @selectSize] select.value = Conf[select.name] @@ -80,6 +83,16 @@ Index = $.on @selectSort, 'change', @cb.sort $.on @selectSize, 'change', @cb.size + # Thread container + @root = $.el 'div', className: 'board' + @cb.size() + + # Page list + @pagelist = $.el 'div', className: 'pagelist' + $.extend @pagelist, <%= importHTML('Features/Index-pagelist') %> + $('.cataloglink a', @pagelist).href = CatalogLinks.catalog() + $.on @pagelist, 'click', @cb.pageNav + @update() $.asap (-> $('title + *', doc) or d.readyState isnt 'loading'), -> From 3f2dfd9333cbb6c51fdd5aee5bc45fe1ca8ad3dc Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sat, 18 Jul 2015 15:37:15 -0700 Subject: [PATCH 03/12] Index: Replace $.asap with $.onExists. --- src/General/Index.coffee | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/General/Index.coffee b/src/General/Index.coffee index 2dd42baa7..97d21500a 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -95,11 +95,10 @@ Index = @update() - $.asap (-> $('title + *', doc) or d.readyState isnt 'loading'), -> + $.onExists doc, 'title + *', true, -> d.title = d.title.replace /\ -\ Page\ \d+/, '' - $.asap (-> $('.board > .thread > .postContainer', doc) or d.readyState isnt 'loading'), -> - return unless Main.isThisPageLegit() + $.onExists doc, '.board > .thread > .postContainer, .board + *', true, -> Index.hat = $ '.board > .thread > img:first-child' if Index.hat and Index.nodes for threadRoot in Index.nodes @@ -123,8 +122,7 @@ Index = $.before topNavPos, $.el 'hr' $.before topNavPos, Index.navLinks - $.asap (-> $('.pagelist', doc) or d.readyState isnt 'loading'), -> - return unless Main.isThisPageLegit() + Main.ready -> if pagelist = $('.pagelist') $.replace pagelist, Index.pagelist else From 39b4971621cee7a3e1b281b092f8a4192a697fb1 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sat, 18 Jul 2015 15:40:28 -0700 Subject: [PATCH 04/12] Don't hide our own stuff while the index is loading. --- src/General/Index.coffee | 6 +++--- src/General/css/style.css | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/General/Index.coffee b/src/General/Index.coffee index 97d21500a..875f4bf58 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -56,7 +56,7 @@ Index = subEntries: [repliesEntry, pinEntry, anchorEntry, refNavEntry] # Navigation links at top of index - @navLinks = $.el 'div', className: 'navLinks' + @navLinks = $.el 'div', className: 'navLinks json-index' $.extend @navLinks, <%= importHTML('Features/Index-navlinks') %> $('.cataloglink a', @navLinks).href = CatalogLinks.catalog() $('.archlistlink', @navLinks).hidden = true if g.BOARD.ID is 'b' @@ -84,11 +84,11 @@ Index = $.on @selectSize, 'change', @cb.size # Thread container - @root = $.el 'div', className: 'board' + @root = $.el 'div', className: 'board json-index' @cb.size() # Page list - @pagelist = $.el 'div', className: 'pagelist' + @pagelist = $.el 'div', className: 'pagelist json-index' $.extend @pagelist, <%= importHTML('Features/Index-pagelist') %> $('.cataloglink a', @pagelist).href = CatalogLinks.catalog() $.on @pagelist, 'click', @cb.pageNav diff --git a/src/General/css/style.css b/src/General/css/style.css index 4c0c788f1..1636f99f4 100755 --- a/src/General/css/style.css +++ b/src/General/css/style.css @@ -611,9 +611,9 @@ div[data-checked="false"] > .suboption-list { } /* Index */ -:root.index-loading .navLinks, -:root.index-loading .board, -:root.index-loading .pagelist, +:root.index-loading .navLinks:not(.json-index), +:root.index-loading .board:not(.json-index), +:root.index-loading .pagelist:not(.json-index), :root.infinite-mode .pagelist, :root.all-pages-mode .pagelist, :root.catalog-mode .pagelist, From 086803686776c886898572c18f345a6a91b93148 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sat, 18 Jul 2015 16:40:31 -0700 Subject: [PATCH 05/12] Remove unused parameter. --- src/General/Index.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/General/Index.coffee b/src/General/Index.coffee index 875f4bf58..8720fb167 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -670,8 +670,8 @@ Index = Index.onSearchInput() Index.searchInput.focus() - setupSearch: (noUpdate) -> - Index.searchInput.value = Index.search unless noUpdate + setupSearch: -> + Index.searchInput.value = Index.search if Index.search Index.searchInput.dataset.searching = 1 else From 49b947c80431c4db732e6d33afc79c4f72cc77b6 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sat, 18 Jul 2015 19:55:20 -0700 Subject: [PATCH 06/12] Set Index.changed flags instead of passing around object. --- src/General/Index.coffee | 137 ++++++++++++++++++++------------------- 1 file changed, 71 insertions(+), 66 deletions(-) diff --git a/src/General/Index.coffee b/src/General/Index.coffee index 8720fb167..a0fe8d1a0 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -1,5 +1,7 @@ Index = showHiddenThreads: false + changed: {} + init: -> return if g.BOARD.ID is 'f' or !Conf['JSON Navigation'] or g.VIEW isnt 'index' @@ -13,10 +15,7 @@ Index = if history.state?.mode Conf['Index Mode'] = history.state?.mode @currentPage = @getCurrentPage() - @pushState - # XXX https://bugzilla.mozilla.org/show_bug.cgi?id=483304 - command: location.href.match(/#(.*)/)?[1] - replace: true + @processHash() $.addClass doc, 'index-loading', "#{Conf['Index Mode'].replace /\ /g, '-'}-mode" $.on window, 'popstate', @cb.popstate @@ -212,7 +211,8 @@ Index = unless mode is 'catalog' Conf['Previous Index Mode'] = mode $.set 'Previous Index Mode', mode - Index.pageLoad Index.pushState {mode} + Index.pushState {mode} + Index.pageLoad false sort: -> Index.sort() @@ -239,25 +239,21 @@ Index = if e?.state {search, mode} = e.state page = Index.getCurrentPage() - state = {} if Index.search isnt search - state.search = Index.search = search + Index.changed.search = true + Index.search = search if Conf['Index Mode'] isnt mode - state.mode = mode + Index.changed.mode = true Index.saveMode mode if Index.currentPage isnt page - state.page = Index.currentPage = page - if state.search? or state.mode? or state.page? - Index.pageLoad state + Index.changed.page = true + Index.currentPage = page + if Object.keys(Index.changed).length + Index.pageLoad() else # page load or hash change - state = Index.pushState - # XXX https://bugzilla.mozilla.org/show_bug.cgi?id=483304 - command: location.href.match(/#(.*)/)?[1] - replace: true - scroll: true - if state.command - Index[if Conf['Refreshed Navigation'] then 'update' else 'pageLoad'] state + if Index.processHash() + Index[if Conf['Refreshed Navigation'] then 'update' else 'pageLoad']() pageNav: (e) -> return if e.shiftKey or e.altKey or e.ctrlKey or e.metaKey or e.button isnt 0 @@ -274,7 +270,8 @@ Index = Index.userPageNav +a.pathname.split('/')[2] or 1 refreshFront: -> - Index.update Index.pushState {page: 1, scroll: true} + Index.pushState {page: 1} + Index.update() scrollToIndex: -> Header.scrollToIfNeeded Index.navLinks @@ -286,53 +283,57 @@ Index = +window.location.pathname.split('/')[2] or 1 userPageNav: (page) -> - state = Index.pushState {page, scroll: true} + Index.pushState {page} if Conf['Refreshed Navigation'] - Index.update state + Index.update() else - Index.pageLoad state if state.page + Index.pageLoad() if Object.keys(Index.changed).length - pushState: (state) -> - {pathname, hash} = location + processHash: -> + # XXX https://bugzilla.mozilla.org/show_bug.cgi?id=483304 + command = location.href.match(/#(.*)/)?[1] + state = + replace: true + hash: '' + if command in ['paged', 'infinite', 'all-pages', 'catalog'] + state.mode = command.replace /-/g, ' ' + else if command is 'index' + state.mode = Conf['Previous Index Mode'] + state.page = 1 + else if /^s=/.test command + state.search = decodeURIComponent(command[2..]).replace(/\+/g, ' ').trim() + else + delete state.hash + Index.pushState state + state.hash is '' + + pushState: ({search, mode, page, hash, replace}) -> pageBeforeSearch = history.state?.oldpage - if state.command? - {command} = state - if command in ['paged', 'infinite', 'all-pages', 'catalog'] - state.mode = command.replace /-/g, ' ' - else if command is 'index' - state.mode = Conf['Previous Index Mode'] - state.page = 1 - else if /^s=/.test command - state.search = decodeURIComponent(command[2..]).replace(/\+/g, ' ').trim() - hash = '' - else - delete state.command - if state.search? - {search} = state - state.page = if search then 1 else (pageBeforeSearch or 1) + if search? + Index.changed.search = true + page = if search then 1 else (pageBeforeSearch or 1) if !search pageBeforeSearch = undefined else if !Index.search pageBeforeSearch = Index.currentPage Index.search = search - if state.mode? - {mode} = state - delete state.mode if mode is Conf['Index Mode'] + if mode? + Index.changed.mode = true unless mode is Conf['Index Mode'] Index.saveMode mode - state.page = 1 if mode in ['all pages', 'catalog'] - hash = '' - if state.page? - {page} = state - delete state.page if page is Index.currentPage + page = 1 if mode in ['all pages', 'catalog'] + hash ?= '' + if page? + Index.changed.page = true unless page is Index.currentPage Index.currentPage = page pathname = if page is 1 then "/#{g.BOARD}/" else "/#{g.BOARD}/#{page}" - hash = '' - history[if state.replace then 'replaceState' else 'pushState'] + hash ?= '' + pathname ?= location.pathname + hash ?= location.hash + history[if replace then 'replaceState' else 'pushState'] mode: Conf['Index Mode'] search: Index.search oldpage: pageBeforeSearch , '', pathname + hash - state saveMode: (mode) -> unless Conf['Index Mode'] is mode @@ -342,15 +343,17 @@ Index = Conf['Previous Index Mode'] = mode $.set 'Previous Index Mode', mode - pageLoad: ({sort, search, mode, scroll}) -> - if sort or search? + pageLoad: (scroll=true) -> + {threads, search, mode} = Index.changed + if threads or search Index.sort() Index.buildPagelist() - Index.setupSearch() if search? - Index.applyMode() if mode? + Index.setupSearch() if search + Index.applyMode() if mode Index.buildIndex() Index.setPage() Index.scrollToIndex() if scroll + Index.changed = {} applyMode: -> for mode in ['paged', 'infinite', 'all pages', 'catalog'] @@ -422,7 +425,7 @@ Index = else "#{hiddenCount} hidden threads" - update: (state) -> + update: -> delete Index.pageNum Index.req?.abort() Index.notice?.close() @@ -440,12 +443,12 @@ Index = ), 3 * $.SECOND - (Date.now() - now) Index.req = $.ajax "//a.4cdn.org/#{g.BOARD}/catalog.json", - onloadend: (e) -> Index.load e, state + onloadend: Index.load , whenModified: 'Index' $.addClass Index.button, 'fa-spin' - load: (e, state) -> + load: (e) -> $.rmClass Index.button, 'fa-spin' {req, notice, nTimeout} = Index clearTimeout nTimeout if nTimeout @@ -470,9 +473,9 @@ Index = try if req.status is 200 - Index.parse req.response, state - else if req.status is 304 and state? - Index.pageLoad state + Index.parse req.response + else if req.status is 304 and Object.keys(Index.changed).length + Index.pageLoad() catch err c.error "Index failure: #{err.message}", err.stack # network error or non-JSON content for example. @@ -497,13 +500,12 @@ Index = RelativeDates.update timeEl Index.scrollToIndex() - parse: (pages, state) -> + parse: (pages) -> $.cleanCache (url) -> /^\/\/a\.4cdn\.org\//.test url Index.parseThreadList pages Index.buildThreads() - state or= {} - state.sort = true - Index.pageLoad state + Index.changed.threads = true + Index.pageLoad() parseThreadList: (pages) -> Index.pagesNum = pages.length @@ -642,7 +644,9 @@ Index = i = 0 i++ while Index.followedThreadID isnt Get.threadFromRoot(Index.sortedNodes[i]).ID page = i // Index.threadsNumPerPage + 1 - Index.pushState {page} if page isnt Index.getCurrentPage() + if page isnt Index.getCurrentPage() + Index.currentPage = page + Index.pushState {page} nodes = Index.buildSinglePage Index.getCurrentPage() $.rmAll Index.root $.rmAll Header.hover @@ -681,9 +685,10 @@ Index = onSearchInput: -> search = Index.searchInput.value.trim() return if search is Index.search - Index.pageLoad Index.pushState + Index.pushState search: search replace: !!search is !!Index.search + Index.pageLoad false querySearch: (query) -> return unless keywords = query.toLowerCase().match /\S+/g From 029ce9fe37591fdd29aae7c30ad1310dfcd42eb6 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sat, 18 Jul 2015 20:24:51 -0700 Subject: [PATCH 07/12] Remove unnecessary use of Index.getCurrentPage. --- src/General/Index.coffee | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/General/Index.coffee b/src/General/Index.coffee index a0fe8d1a0..19d605b32 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -130,7 +130,7 @@ Index = scroll: -> return if Index.req or Conf['Index Mode'] isnt 'infinite' or (window.scrollY <= doc.scrollHeight - (300 + window.innerHeight)) - Index.pageNum = Index.getCurrentPage() unless Index.pageNum? # Avoid having to pushState to keep track of the current page + Index.pageNum ?= Index.currentPage # Avoid having to pushState to keep track of the current page pageNum = ++Index.pageNum return Index.endNotice() if pageNum > Index.pagesNum @@ -386,7 +386,7 @@ Index = $.add pagesRoot, nodes setPage: -> - pageNum = Index.getCurrentPage() + pageNum = Index.currentPage maxPageNum = Index.getMaxPageNum() pagesRoot = $ '.pages', Index.pagelist @@ -644,10 +644,10 @@ Index = i = 0 i++ while Index.followedThreadID isnt Get.threadFromRoot(Index.sortedNodes[i]).ID page = i // Index.threadsNumPerPage + 1 - if page isnt Index.getCurrentPage() + if page isnt Index.currentPage Index.currentPage = page Index.pushState {page} - nodes = Index.buildSinglePage Index.getCurrentPage() + nodes = Index.buildSinglePage Index.currentPage $.rmAll Index.root $.rmAll Header.hover if Conf['Index Mode'] is 'catalog' From 92d51398f47a40337db0b56abf874dae30d789bf Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sat, 18 Jul 2015 21:12:52 -0700 Subject: [PATCH 08/12] This should have scroll=false. Fixes mistake in commit 49b947c80431c4db732e6d33afc79c4f72cc77b6. --- src/General/Index.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/General/Index.coffee b/src/General/Index.coffee index 56bd5d7c9..2a7b4cd9d 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -249,7 +249,7 @@ Index = Index.changed.page = true Index.currentPage = page if Object.keys(Index.changed).length - Index.pageLoad() + Index.pageLoad false else # page load or hash change if Index.processHash() From 9f0c2e59f47a42f7d280a3d5673ca3848297e6fe Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sat, 18 Jul 2015 22:32:44 -0700 Subject: [PATCH 09/12] Move check of whether any changes have occured into Index.pageLoad. Minor changes in under what circumstances we scroll to the top. --- src/General/Index.coffee | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/General/Index.coffee b/src/General/Index.coffee index 6000d4fce..8b068e93a 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -248,8 +248,7 @@ Index = if Index.currentPage isnt page Index.changed.page = true Index.currentPage = page - if Object.keys(Index.changed).length - Index.pageLoad false + Index.pageLoad false else # page load or hash change if Index.processHash() @@ -287,7 +286,7 @@ Index = if Conf['Refreshed Navigation'] Index.update() else - Index.pageLoad() if Object.keys(Index.changed).length + Index.pageLoad() processHash: -> # XXX https://bugzilla.mozilla.org/show_bug.cgi?id=483304 @@ -344,14 +343,15 @@ Index = $.set 'Previous Index Mode', mode pageLoad: (scroll=true) -> - {threads, search, mode} = Index.changed + {threads, search, mode, page} = Index.changed if threads or search Index.sort() Index.buildPagelist() Index.setupSearch() if search Index.applyMode() if mode - Index.buildIndex() - Index.setPage() + if threads or search or mode or page + Index.buildIndex() + Index.setPage() Index.scrollToIndex() if scroll Index.changed = {} @@ -474,7 +474,7 @@ Index = try if req.status is 200 Index.parse req.response - else if req.status is 304 and Object.keys(Index.changed).length + else if req.status is 304 Index.pageLoad() catch err c.error "Index failure: #{err.message}", err.stack @@ -498,7 +498,6 @@ Index = timeEl = $ '#index-last-refresh time', Index.navLinks timeEl.dataset.utc = Date.parse req.getResponseHeader 'Last-Modified' RelativeDates.update timeEl - Index.scrollToIndex() parse: (pages) -> $.cleanCache (url) -> /^\/\/a\.4cdn\.org\//.test url From 1540e0f3ed933e25665f64ff49bc06199c8dec7b Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sat, 18 Jul 2015 23:25:30 -0700 Subject: [PATCH 10/12] Remove no-longer-used Index.board. --- src/General/Index.coffee | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/General/Index.coffee b/src/General/Index.coffee index 8b068e93a..c2f247d2f 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -5,8 +5,6 @@ Index = init: -> return if g.BOARD.ID is 'f' or !Conf['JSON Navigation'] or g.VIEW isnt 'index' - @board = "#{g.BOARD}" - CatalogThread.callbacks.push name: 'Catalog Features' cb: @catalogNode From 0c78647b92cd90b550c936cfaf4a3619ebb1ff89 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sun, 19 Jul 2015 13:08:03 -0700 Subject: [PATCH 11/12] Always use generated pathname and hash; consolidate some code. --- src/General/Index.coffee | 65 ++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 39 deletions(-) diff --git a/src/General/Index.coffee b/src/General/Index.coffee index c2f247d2f..36074be29 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -236,16 +236,8 @@ Index = popstate: (e) -> if e?.state {search, mode} = e.state - if Index.search isnt search - Index.changed.search = true - Index.search = search - if Conf['Index Mode'] isnt mode - Index.changed.mode = true - Index.saveMode mode page = Index.getCurrentPage() - if Index.currentPage isnt page - Index.changed.page = true - Index.currentPage = page + Index.setState {search, mode, page} Index.pageLoad false else # page load or hash change @@ -274,10 +266,7 @@ Index = Header.scrollToIfNeeded Index.navLinks getCurrentPage: -> - if Conf['Index Mode'] in ['all pages', 'catalog'] - 1 - else - +window.location.pathname.split('/')[2] or 1 + +window.location.pathname.split('/')[2] or 1 userPageNav: (page) -> Index.pushState {page} @@ -288,10 +277,10 @@ Index = processHash: -> # XXX https://bugzilla.mozilla.org/show_bug.cgi?id=483304 - command = location.href.match(/#(.*)/)?[1] + hash = location.href.match(/#.*/)?[0] or '' + command = hash[1..] state = replace: true - hash: '' if command in ['paged', 'infinite', 'all-pages', 'catalog'] state.mode = command.replace /-/g, ' ' else if command is 'index' @@ -300,45 +289,43 @@ Index = else if /^s=/.test command state.search = decodeURIComponent(command[2..]).replace(/\+/g, ' ').trim() else - delete state.hash + state.hash = hash Index.pushState state - state.hash is '' + !state.hash? - pushState: ({search, mode, page, hash, replace}) -> + pushState: (state) -> + {search, hash, replace} = state pageBeforeSearch = history.state?.oldpage - if search? - Index.changed.search = true - page = if search then 1 else (pageBeforeSearch or 1) + if search? and search isnt Index.search + state.page = if search then 1 else (pageBeforeSearch or 1) if !search pageBeforeSearch = undefined else if !Index.search pageBeforeSearch = Index.currentPage - Index.search = search - if mode? - Index.changed.mode = true unless mode is Conf['Index Mode'] - Index.saveMode mode - page = 1 if mode in ['all pages', 'catalog'] - hash ?= '' - if page? - Index.changed.page = true unless page is Index.currentPage - Index.currentPage = page - pathname = if page is 1 then "/#{g.BOARD}/" else "/#{g.BOARD}/#{page}" - hash ?= '' - pathname ?= location.pathname - hash ?= location.hash + Index.setState state + pathname = if Index.currentPage is 1 then "/#{g.BOARD}/" else "/#{g.BOARD}/#{Index.currentPage}" + hash or= '' history[if replace then 'replaceState' else 'pushState'] mode: Conf['Index Mode'] search: Index.search oldpage: pageBeforeSearch , '', pathname + hash - saveMode: (mode) -> - unless Conf['Index Mode'] is mode + setState: ({search, mode, page}) -> + if search? and search isnt Index.search + Index.changed.search = true + Index.search = search + if mode? and mode isnt Conf['Index Mode'] + Index.changed.mode = true Conf['Index Mode'] = mode $.set 'Index Mode', mode - unless mode is 'catalog' or Conf['Previous Index Mode'] is mode - Conf['Previous Index Mode'] = mode - $.set 'Previous Index Mode', mode + unless mode is 'catalog' or Conf['Previous Index Mode'] is mode + Conf['Previous Index Mode'] = mode + $.set 'Previous Index Mode', mode + page = 1 if Conf['Index Mode'] in ['all pages', 'catalog'] + if page? and page isnt Index.currentPage + Index.changed.page = true + Index.currentPage = page pageLoad: (scroll=true) -> {threads, search, mode, page} = Index.changed From f14e850af00c27ef2b18593b4b626313292e41eb Mon Sep 17 00:00:00 2001 From: ccd0 Date: Fri, 22 Jan 2016 19:49:57 -0800 Subject: [PATCH 12/12] Revert "Revert "Suppress post thumbnails from loading until they are actually inserted into the index."" This reverts commit 6b9059182fdf97001f013efc57150ff3dc14d80a. --- src/General/Build.coffee | 9 +++++---- src/General/Index.coffee | 4 ++++ src/General/html/Build/File.html | 4 ++-- src/General/lib/clone.class | 5 +++++ src/Images/ImageLoader.coffee | 6 ++++-- src/Images/RevealSpoilers.coffee | 5 ++++- 6 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/General/Build.coffee b/src/General/Build.coffee index 1854fd9bd..0b76f84e1 100755 --- a/src/General/Build.coffee +++ b/src/General/Build.coffee @@ -88,10 +88,11 @@ Build = .replace(/<[^>]*>/g, '') o.info.comment = Build.unescape html - postFromObject: (data, boardID) -> - Build.post Build.parseJSON data, boardID + postFromObject: (data, boardID, suppressThumb) -> + o = Build.parseJSON data, boardID + Build.post o, suppressThumb - post: (o) -> + post: (o, suppressThumb) -> {postID, threadID, boardID, file} = o {subject, email, name, tripcode, capcode, uniqueID, flagCode, flag, dateUTC, dateText, commentHTML} = o.info {staticPath, gifIcon} = Build @@ -177,7 +178,7 @@ Build = root excerptThread: (board, data, OP) -> - nodes = [if OP then OP.nodes.root else Build.postFromObject data, board.ID] + nodes = [if OP then OP.nodes.root else Build.postFromObject data, board.ID, true] if data.omitted_posts or !Conf['Show Replies'] and data.replies [posts, files] = if Conf['Show Replies'] # XXX data.omitted_images is not accurate. diff --git a/src/General/Index.coffee b/src/General/Index.coffee index 36074be29..d099d3d08 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -650,6 +650,10 @@ Index = buildStructure: (nodes) -> for node in nodes + if thumb = $ 'img[data-src]', node + thumb.src = thumb.dataset.src + # XXX https://bugzilla.mozilla.org/show_bug.cgi?id=1021289 + thumb.removeAttribute 'data-src' $.add Index.root, [node, $.el 'hr'] $.event 'PostsInserted' if doc.contains Index.root ThreadHiding.onIndexBuild nodes diff --git a/src/General/html/Build/File.html b/src/General/html/Build/File.html index 5d3014a24..d48f11db2 100644 --- a/src/General/html/Build/File.html +++ b/src/General/html/Build/File.html @@ -15,8 +15,8 @@ (${file.size}, ${file.dimensions || "PDF"}) - ${file.size} doc.contains clone.nodes.root file.isPrefetched = true @@ -72,6 +72,8 @@ ImageLoader = $.on el, 'load', -> clone.file.thumb.src = url for clone in post.clones thumb.src = url + # XXX https://bugzilla.mozilla.org/show_bug.cgi?id=1021289 + thumb.removeAttribute 'data-src' el.src = url toggle: -> diff --git a/src/Images/RevealSpoilers.coffee b/src/Images/RevealSpoilers.coffee index 4c3e65709..ed159a4ca 100755 --- a/src/Images/RevealSpoilers.coffee +++ b/src/Images/RevealSpoilers.coffee @@ -13,4 +13,7 @@ RevealSpoilers = thumb.removeAttribute 'style' # Enforce thumbnail size if thumbnail is replaced. thumb.style.maxHeight = thumb.style.maxWidth = if @isReply then '125px' else '250px' - thumb.src = @file.thumbURL + if thumb.src + thumb.src = @file.thumbURL + else + thumb.dataset.src = @file.thumbURL