From 1e7fc8ea650d4d8d9457f006fd0685d96ead3d5c Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Wed, 8 Jan 2014 15:40:57 -0700 Subject: [PATCH] Reflows. --- builds/4chan-X.user.js | 66 +++++++++++++------------------- builds/crx/script.js | 80 +++++++++++++++++---------------------- src/General/Header.coffee | 2 +- src/General/Index.coffee | 4 +- src/General/Main.coffee | 43 +++++++++------------ 5 files changed, 81 insertions(+), 114 deletions(-) diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index ccf4772f7..14abfb29a 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -2017,7 +2017,7 @@ $.addClass(doc, args[0]); $.rmClass(doc, args[1]); Header.bar.parentNode.className = args[2]; - return $[args[3]](Header.bar, Header.notify); + return $[args[3]](Header.bar, Header.noticesRoot); }, toggleBarPosition: function() { $.cb.checked.call(this); @@ -2377,7 +2377,7 @@ return Header.scrollToIfNeeded(Index.root); }, getCurrentPage: function() { - return +window.location.pathname.split('/')[2] || 0; + return +window.location.pathname.split('/')[2]; }, userPageNav: function(pageNum) { if (Conf['Refreshed Navigation'] && Conf['Index Mode'] === 'paged') { @@ -2510,7 +2510,7 @@ } } catch (_error) { err = _error; - c.error('Index failure:', err.stack); + c.error('Index failure:', err); if (notice) { notice.setType('error'); notice.el.lastElementChild.textContent = 'Index refresh failed.'; @@ -12791,35 +12791,26 @@ history.pushState(null, '', this.pathname); } view = threadID ? 'thread' : view || 'index'; - if (view === g.VIEW) { - if (view === 'index') { - if (boardID !== g.BOARD.ID) { - Main.clean(); - Main.updateBoard(boardID); - } - Index.update(); - } else { - Main.refresh({ - boardID: boardID, - view: view, - threadID: threadID - }); + if (view !== g.VIEW) { + Main.clean(); + Main.disconnect(view); + } + if (view === 'index') { + if (boardID !== g.BOARD.ID) { + Main.updateBoard(boardID); } - } else { - if (view === 'index') { - Main.disconnect(view); - Main.clean(); - if (boardID !== g.BOARD.ID) { - Main.updateBoard(boardID); - } + if (Index.root) { Index.connect.call(Index); } else { - Main.refresh({ - boardID: boardID, - view: view, - threadID: threadID - }); + Index.update(); } + } else { + c.error('How?'); + Main.refresh({ + boardID: boardID, + view: view, + threadID: threadID + }); } return Header.setBoardList(); }, @@ -12875,20 +12866,15 @@ return $('.boardTitle').innerHTML = d.title = "/" + board.board + "/ - " + board.title; }, refresh: function(context) { - var boardID, name, threadID, view, _results, _results1; + var boardID, feature, name, threadID, view, _i, _len, _ref, _ref1; + return; boardID = context.boardID, view = context.view, threadID = context.threadID; - if (view === 'thread') { - _results = []; - for (name in Main.features) { - _results.push(Main.features[name].thread()); + _ref = Main.features; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + _ref1 = _ref[_i], name = _ref1[0], feature = _ref1[1]; + if (feature.refresh) { + feature.refresh(); } - return _results; - } else { - _results1 = []; - for (name in Main.features) { - _results1.push(Main.features[name].index()); - } - return _results1; } } }; diff --git a/builds/crx/script.js b/builds/crx/script.js index 9443cf0fd..62e2d0fc1 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -2027,7 +2027,7 @@ $.addClass(doc, args[0]); $.rmClass(doc, args[1]); Header.bar.parentNode.className = args[2]; - return $[args[3]](Header.bar, Header.notify); + return $[args[3]](Header.bar, Header.noticesRoot); }, toggleBarPosition: function() { $.cb.checked.call(this); @@ -2387,7 +2387,7 @@ return Header.scrollToIfNeeded(Index.root); }, getCurrentPage: function() { - return +window.location.pathname.split('/')[2] || 0; + return +window.location.pathname.split('/')[2]; }, userPageNav: function(pageNum) { if (Conf['Refreshed Navigation'] && Conf['Index Mode'] === 'paged') { @@ -2520,7 +2520,7 @@ } } catch (_error) { err = _error; - c.error('Index failure:', err.stack); + c.error('Index failure:', err); if (notice) { notice.setType('error'); notice.el.lastElementChild.textContent = 'Index refresh failed.'; @@ -12765,45 +12765,38 @@ history.pushState(null, '', this.pathname); } view = threadID ? 'thread' : view || 'index'; - if (view === g.VIEW) { - if (view === 'index') { - if (boardID !== g.BOARD.ID) { - Main.clean(); - Main.updateBoard(boardID); - } - Index.update(); - } else { - Main.refresh({ - boardID: boardID, - view: view, - threadID: threadID - }); + if (view !== g.VIEW) { + Main.clean(); + Main.disconnect(view); + } + if (view === 'index') { + if (boardID !== g.BOARD.ID) { + Main.updateBoard(boardID); } - } else { - if (view === 'index') { - Main.disconnect(view); - Main.clean(); - if (boardID !== g.BOARD.ID) { - Main.updateBoard(boardID); - } + if (Index.root) { Index.connect.call(Index); } else { - Main.refresh({ - boardID: boardID, - view: view, - threadID: threadID - }); + Index.update(); } + } else { + c.error('How?'); + Main.refresh({ + boardID: boardID, + view: view, + threadID: threadID + }); } return Header.setBoardList(); }, popstate: function() { - var a; - a = $.el('a', { - href: window.location, - id: 'popState' - }); - return Main.navigate.call(a); + return Main.popstate = function() { + var a; + a = $.el('a', { + href: window.location, + id: 'popState' + }); + return Main.navigate.call(a); + }; }, updateBoard: function(boardID) { var onload, req; @@ -12849,20 +12842,15 @@ return $('.boardTitle').innerHTML = d.title = "/" + board.board + "/ - " + board.title; }, refresh: function(context) { - var boardID, name, threadID, view, _results, _results1; + var boardID, feature, name, threadID, view, _i, _len, _ref, _ref1; + return; boardID = context.boardID, view = context.view, threadID = context.threadID; - if (view === 'thread') { - _results = []; - for (name in Main.features) { - _results.push(Main.features[name].thread()); + _ref = Main.features; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + _ref1 = _ref[_i], name = _ref1[0], feature = _ref1[1]; + if (feature.refresh) { + feature.refresh(); } - return _results; - } else { - _results1 = []; - for (name in Main.features) { - _results1.push(Main.features[name].index()); - } - return _results1; } } }; diff --git a/src/General/Header.coffee b/src/General/Header.coffee index caa03b742..c46a3b663 100755 --- a/src/General/Header.coffee +++ b/src/General/Header.coffee @@ -330,7 +330,7 @@ Header = $.addClass doc, args[0] $.rmClass doc, args[1] Header.bar.parentNode.className = args[2] - $[args[3]] Header.bar, Header.notify + $[args[3]] Header.bar, Header.noticesRoot toggleBarPosition: -> $.cb.checked.call @ diff --git a/src/General/Index.coffee b/src/General/Index.coffee index 5623c4909..d1e139cd8 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -144,7 +144,7 @@ Index = Header.scrollToIfNeeded Index.root getCurrentPage: -> - +window.location.pathname.split('/')[2] or 0 + +window.location.pathname.split('/')[2] userPageNav: (pageNum) -> if Conf['Refreshed Navigation'] and Conf['Index Mode'] is 'paged' Index.update pageNum @@ -245,7 +245,7 @@ Index = else if req.status is 304 and pageNum? Index.pageNav pageNum catch err - c.error 'Index failure:', err.stack + c.error 'Index failure:', err # network error or non-JSON content for example. if notice notice.setType 'error' diff --git a/src/General/Main.coffee b/src/General/Main.coffee index 49aa34864..33bdf3e0e 100755 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -352,7 +352,7 @@ Main = g.VIEW = view navigate: (e) -> - return unless @hostname is 'boards.4chan.org' + return if @hostname isnt 'boards.4chan.org' # Lets have a good idea of what we should we should be expecting for this kind of feature path = @pathname.split '/' path.shift() if path[0] is '' @@ -368,31 +368,26 @@ Main = else view or 'index' # path is "/boardID/". See the problem? - # Moving from thread to thread or index to index. - if view is g.VIEW - if view is 'index' - unless boardID is g.BOARD.ID - Main.clean() - Main.updateBoard boardID + if view isnt g.VIEW + Main.clean() + Main.disconnect view + if view is 'index' + Main.updateBoard boardID unless boardID is g.BOARD.ID + + if Index.root + Index.connect.call Index + else Index.update() - else - Main.refresh {boardID, view, threadID} - + # Moving from thread to thread or index to index. else - if view is 'index' - Main.disconnect view - Main.clean() - Main.updateBoard boardID unless boardID is g.BOARD.ID - Index.connect.call Index - - else - Main.refresh {boardID, view, threadID} + c.error 'How?' + Main.refresh {boardID, view, threadID} Header.setBoardList() - popstate: -> + popstate: -> <% if (type === 'crx') { %> Main.popstate = -> <% } %> # blink/webkit throw a popstate on page load. Not what we want. a = $.el 'a', href: window.location id: 'popState' @@ -430,13 +425,11 @@ Main = $('.boardTitle').innerHTML = d.title = "/#{board.board}/ - #{board.title}" refresh: (context) -> + return {boardID, view, threadID} = context - if view is 'thread' - # Refresh thread features - Main.features[name].thread() for name of Main.features - else - # Refresh index features - Main.features[name].index() for name of Main.features + # Refresh features + feature.refresh() for [name, feature] in Main.features when feature.refresh + return Main.init()