Reflow a ton of navigate and index shit to fix broken shit

This commit is contained in:
Zixaphir 2014-03-02 21:04:14 -07:00
parent e451410ef1
commit 7a7a7facf7
5 changed files with 110 additions and 151 deletions

View File

@ -2517,10 +2517,14 @@
return; return;
} }
this.board = "" + g.BOARD; this.board = "" + g.BOARD;
if (g.VIEW !== 'index') { this.button = $.el('a', {
$.ready(this.setupNavLinks); className: 'index-refresh-shortcut fa fa-refresh',
return; title: 'Refresh',
} href: 'javascript:;',
textContent: 'Refresh Index'
});
$.on(this.button, 'click', this.update);
Header.addShortcut(this.button, 1);
if (g.BOARD.ID === 'f') { if (g.BOARD.ID === 'f') {
return; return;
} }
@ -2533,14 +2537,6 @@
name: 'Catalog Features', name: 'Catalog Features',
cb: this.catalogNode cb: this.catalogNode
}); });
this.button = $.el('a', {
className: 'index-refresh-shortcut fa fa-refresh',
title: 'Refresh',
href: 'javascript:;',
textContent: 'Refresh Index'
});
$.on(this.button, 'click', this.update);
Header.addShortcut(this.button, 1);
modeEntry = { modeEntry = {
el: $.el('span', { el: $.el('span', {
textContent: 'Index mode' textContent: 'Index mode'
@ -2675,17 +2671,16 @@
return $('.board', doc) || d.readyState !== 'loading'; return $('.board', doc) || d.readyState !== 'loading';
}), function() { }), function() {
var board, navLink, _l, _len3, _ref3; var board, navLink, _l, _len3, _ref3;
if (g.VIEW === 'index') {
board = $('.board');
$.replace(board, Index.root);
d.implementation.createDocument(null, null, null).appendChild(board);
}
_ref3 = $$('.navLinks'); _ref3 = $$('.navLinks');
for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) { for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) {
navLink = _ref3[_l]; navLink = _ref3[_l];
$.rm(navLink); $.rm(navLink);
} }
return $.after($.x('child::form/preceding-sibling::hr[1]'), Index.navLinks); $.after($.x('child::form/preceding-sibling::hr[1]'), Index.navLinks);
return g.VIEW !== 'index';
board = $('.board');
$.replace(board, Index.root);
return d.implementation.createDocument(null, null, null).appendChild(board);
}); });
this.cb.toggleCatalogMode(); this.cb.toggleCatalogMode();
return $.asap((function() { return $.asap((function() {
@ -2757,6 +2752,9 @@
} }
}, },
threadNode: function() { threadNode: function() {
if (g.VIEW !== 'index') {
return;
}
if (!Index.db.get({ if (!Index.db.get({
boardID: this.board.ID, boardID: this.board.ID,
threadID: this.ID threadID: this.ID
@ -5825,7 +5823,6 @@
}); });
$.on(sc, 'click', function() { $.on(sc, 'click', function() {
if (Conf['Persistent QR'] || !QR.nodes || QR.nodes.el.hidden) { if (Conf['Persistent QR'] || !QR.nodes || QR.nodes.el.hidden) {
$.event('CloseMenu');
QR.open(); QR.open();
QR.nodes.com.focus(); QR.nodes.com.focus();
return $.rmClass(this, 'disabled'); return $.rmClass(this, 'disabled');
@ -5883,14 +5880,8 @@
$.on(d, 'dragover', QR.dragOver); $.on(d, 'dragover', QR.dragOver);
$.on(d, 'drop', QR.dropFile); $.on(d, 'drop', QR.dropFile);
$.on(d, 'dragstart dragend', QR.drag); $.on(d, 'dragstart dragend', QR.drag);
({ $.on(d, 'IndexRefresh', QR.generatePostableThreadsList);
index: function() { $.on(d, 'ThreadUpdate', QR.statusCheck);
return $.on(d, 'IndexRefresh', QR.generatePostableThreadsList);
},
thread: function() {
return $.on(d, 'ThreadUpdate', QR.statusCheck);
}
})[g.VIEW]();
if (!Conf['Persistent QR']) { if (!Conf['Persistent QR']) {
return; return;
} }
@ -12636,45 +12627,35 @@
]; ];
} }
if (error) { if (error) {
Main.handleErrors(error); return Main.handleErrors(error);
} }
return QR.generatePostableThreadsList();
}, },
updateContext: function(view) { updateContext: function(view) {
var oldView;
g.DEAD = false; g.DEAD = false;
if (view !== g.VIEW) { if (view === 'thread') {
$.rmClass(doc, g.VIEW); g.THREADID = +window.location.pathname.split('/')[3];
$.addClass(doc, view);
} }
oldView = g.VIEW; if (view === g.VIEW) {
g.VIEW = view; return;
return { }
$.rmClass(doc, g.VIEW);
$.addClass(doc, view);
({
index: function() { index: function() {
if (oldView === g.VIEW) {
return;
}
delete g.THREADID; delete g.THREADID;
QR.link.textContent = 'Start a Thread'; QR.link.textContent = 'Start a Thread';
$.off(d, 'ThreadUpdate', QR.statusCheck);
$.on(d, 'IndexRefresh', QR.generatePostableThreadsList);
if (Conf['Index Mode'] === 'catalog') { if (Conf['Index Mode'] === 'catalog') {
return $.addClass(doc, 'catalog-mode'); return $.addClass(doc, 'catalog-mode');
} }
}, },
thread: function() { thread: function() {
g.THREADID = +window.location.pathname.split('/')[3];
if (oldView === g.VIEW) {
return;
}
QR.link.textContent = 'Reply to Thread'; QR.link.textContent = 'Reply to Thread';
$.on(d, 'ThreadUpdate', QR.statusCheck);
$.off(d, 'IndexRefresh', QR.generatePostableThreadsList);
if (Conf['Index Mode'] === 'catalog') { if (Conf['Index Mode'] === 'catalog') {
return $.rmClass(doc, 'catalog-mode'); return $.rmClass(doc, 'catalog-mode');
} }
} }
}[g.VIEW](); })[view]();
return g.VIEW = view;
}, },
updateBoard: function(boardID) { updateBoard: function(boardID) {
var fullBoardList; var fullBoardList;
@ -12718,7 +12699,7 @@
}, },
updateSFW: function(sfw) { updateSFW: function(sfw) {
var findStyle, style; var findStyle, style;
Favicon.el.href = "//s.4cdn.org/image/favicon" + (sfw ? '-ws' : '') + ".ico"; Favicon.el.href = Favicon["default"] = "//s.4cdn.org/image/favicon" + (sfw ? '-ws' : '') + ".ico";
$.add(d.head, Favicon.el); $.add(d.head, Favicon.el);
if (Favicon.SFW === sfw) { if (Favicon.SFW === sfw) {
return; return;
@ -12805,10 +12786,10 @@
return Navigate.updateBoard(boardID); return Navigate.updateBoard(boardID);
}; };
} }
Navigate.updateSFW(Favicon.SFW);
if (view === 'index') { if (view === 'index') {
return Index.update(pageNum); return Index.update(pageNum);
} }
Navigate.updateSFW(Favicon.SFW);
load = Navigate.load; load = Navigate.load;
Navigate.req = $.ajax("//a.4cdn.org/" + boardID + "/res/" + threadID + ".json", { Navigate.req = $.ajax("//a.4cdn.org/" + boardID + "/res/" + threadID + ".json", {
onabort: load, onabort: load,
@ -12886,6 +12867,7 @@
Main.callbackNodes(Post, posts); Main.callbackNodes(Post, posts);
Navigate.ready('Quote Threading', QuoteThreading.force, Conf['Quote Threading'] && !Conf['Unread Count']); Navigate.ready('Quote Threading', QuoteThreading.force, Conf['Quote Threading'] && !Conf['Unread Count']);
Navigate.buildThread(); Navigate.buildThread();
QR.generatePostableThreadsList();
return Header.hashScroll.call(window); return Header.hashScroll.call(window);
}, },
buildThread: function() { buildThread: function() {

View File

@ -2576,10 +2576,14 @@
return; return;
} }
this.board = "" + g.BOARD; this.board = "" + g.BOARD;
if (g.VIEW !== 'index') { this.button = $.el('a', {
$.ready(this.setupNavLinks); className: 'index-refresh-shortcut fa fa-refresh',
return; title: 'Refresh',
} href: 'javascript:;',
textContent: 'Refresh Index'
});
$.on(this.button, 'click', this.update);
Header.addShortcut(this.button, 1);
if (g.BOARD.ID === 'f') { if (g.BOARD.ID === 'f') {
return; return;
} }
@ -2592,14 +2596,6 @@
name: 'Catalog Features', name: 'Catalog Features',
cb: this.catalogNode cb: this.catalogNode
}); });
this.button = $.el('a', {
className: 'index-refresh-shortcut fa fa-refresh',
title: 'Refresh',
href: 'javascript:;',
textContent: 'Refresh Index'
});
$.on(this.button, 'click', this.update);
Header.addShortcut(this.button, 1);
modeEntry = { modeEntry = {
el: $.el('span', { el: $.el('span', {
textContent: 'Index mode' textContent: 'Index mode'
@ -2734,17 +2730,16 @@
return $('.board', doc) || d.readyState !== 'loading'; return $('.board', doc) || d.readyState !== 'loading';
}), function() { }), function() {
var board, navLink, _l, _len3, _ref3; var board, navLink, _l, _len3, _ref3;
if (g.VIEW === 'index') {
board = $('.board');
$.replace(board, Index.root);
d.implementation.createDocument(null, null, null).appendChild(board);
}
_ref3 = $$('.navLinks'); _ref3 = $$('.navLinks');
for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) { for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) {
navLink = _ref3[_l]; navLink = _ref3[_l];
$.rm(navLink); $.rm(navLink);
} }
return $.after($.x('child::form/preceding-sibling::hr[1]'), Index.navLinks); $.after($.x('child::form/preceding-sibling::hr[1]'), Index.navLinks);
return g.VIEW !== 'index';
board = $('.board');
$.replace(board, Index.root);
return d.implementation.createDocument(null, null, null).appendChild(board);
}); });
this.cb.toggleCatalogMode(); this.cb.toggleCatalogMode();
return $.asap((function() { return $.asap((function() {
@ -2816,6 +2811,9 @@
} }
}, },
threadNode: function() { threadNode: function() {
if (g.VIEW !== 'index') {
return;
}
if (!Index.db.get({ if (!Index.db.get({
boardID: this.board.ID, boardID: this.board.ID,
threadID: this.ID threadID: this.ID
@ -5877,7 +5875,6 @@
}); });
$.on(sc, 'click', function() { $.on(sc, 'click', function() {
if (Conf['Persistent QR'] || !QR.nodes || QR.nodes.el.hidden) { if (Conf['Persistent QR'] || !QR.nodes || QR.nodes.el.hidden) {
$.event('CloseMenu');
QR.open(); QR.open();
QR.nodes.com.focus(); QR.nodes.com.focus();
return $.rmClass(this, 'disabled'); return $.rmClass(this, 'disabled');
@ -5936,14 +5933,8 @@
$.on(d, 'dragover', QR.dragOver); $.on(d, 'dragover', QR.dragOver);
$.on(d, 'drop', QR.dropFile); $.on(d, 'drop', QR.dropFile);
$.on(d, 'dragstart dragend', QR.drag); $.on(d, 'dragstart dragend', QR.drag);
({ $.on(d, 'IndexRefresh', QR.generatePostableThreadsList);
index: function() { $.on(d, 'ThreadUpdate', QR.statusCheck);
return $.on(d, 'IndexRefresh', QR.generatePostableThreadsList);
},
thread: function() {
return $.on(d, 'ThreadUpdate', QR.statusCheck);
}
})[g.VIEW]();
if (!Conf['Persistent QR']) { if (!Conf['Persistent QR']) {
return; return;
} }
@ -12650,45 +12641,35 @@
]; ];
} }
if (error) { if (error) {
Main.handleErrors(error); return Main.handleErrors(error);
} }
return QR.generatePostableThreadsList();
}, },
updateContext: function(view) { updateContext: function(view) {
var oldView;
g.DEAD = false; g.DEAD = false;
if (view !== g.VIEW) { if (view === 'thread') {
$.rmClass(doc, g.VIEW); g.THREADID = +window.location.pathname.split('/')[3];
$.addClass(doc, view);
} }
oldView = g.VIEW; if (view === g.VIEW) {
g.VIEW = view; return;
return { }
$.rmClass(doc, g.VIEW);
$.addClass(doc, view);
({
index: function() { index: function() {
if (oldView === g.VIEW) {
return;
}
delete g.THREADID; delete g.THREADID;
QR.link.textContent = 'Start a Thread'; QR.link.textContent = 'Start a Thread';
$.off(d, 'ThreadUpdate', QR.statusCheck);
$.on(d, 'IndexRefresh', QR.generatePostableThreadsList);
if (Conf['Index Mode'] === 'catalog') { if (Conf['Index Mode'] === 'catalog') {
return $.addClass(doc, 'catalog-mode'); return $.addClass(doc, 'catalog-mode');
} }
}, },
thread: function() { thread: function() {
g.THREADID = +window.location.pathname.split('/')[3];
if (oldView === g.VIEW) {
return;
}
QR.link.textContent = 'Reply to Thread'; QR.link.textContent = 'Reply to Thread';
$.on(d, 'ThreadUpdate', QR.statusCheck);
$.off(d, 'IndexRefresh', QR.generatePostableThreadsList);
if (Conf['Index Mode'] === 'catalog') { if (Conf['Index Mode'] === 'catalog') {
return $.rmClass(doc, 'catalog-mode'); return $.rmClass(doc, 'catalog-mode');
} }
} }
}[g.VIEW](); })[view]();
return g.VIEW = view;
}, },
updateBoard: function(boardID) { updateBoard: function(boardID) {
var fullBoardList; var fullBoardList;
@ -12732,7 +12713,7 @@
}, },
updateSFW: function(sfw) { updateSFW: function(sfw) {
var findStyle, style; var findStyle, style;
Favicon.el.href = "//s.4cdn.org/image/favicon" + (sfw ? '-ws' : '') + ".ico"; Favicon.el.href = Favicon["default"] = "//s.4cdn.org/image/favicon" + (sfw ? '-ws' : '') + ".ico";
$.add(d.head, Favicon.el); $.add(d.head, Favicon.el);
if (Favicon.SFW === sfw) { if (Favicon.SFW === sfw) {
return; return;
@ -12819,10 +12800,10 @@
return Navigate.updateBoard(boardID); return Navigate.updateBoard(boardID);
}; };
} }
Navigate.updateSFW(Favicon.SFW);
if (view === 'index') { if (view === 'index') {
return Index.update(pageNum); return Index.update(pageNum);
} }
Navigate.updateSFW(Favicon.SFW);
load = Navigate.load; load = Navigate.load;
Navigate.req = $.ajax("//a.4cdn.org/" + boardID + "/res/" + threadID + ".json", { Navigate.req = $.ajax("//a.4cdn.org/" + boardID + "/res/" + threadID + ".json", {
onabort: load, onabort: load,
@ -12900,6 +12881,7 @@
Main.callbackNodes(Post, posts); Main.callbackNodes(Post, posts);
Navigate.ready('Quote Threading', QuoteThreading.force, Conf['Quote Threading'] && !Conf['Unread Count']); Navigate.ready('Quote Threading', QuoteThreading.force, Conf['Quote Threading'] && !Conf['Unread Count']);
Navigate.buildThread(); Navigate.buildThread();
QR.generatePostableThreadsList();
return Header.hashScroll.call(window); return Header.hashScroll.call(window);
}, },
buildThread: function() { buildThread: function() {

View File

@ -5,9 +5,14 @@ Index =
@board = "#{g.BOARD}" @board = "#{g.BOARD}"
if g.VIEW isnt 'index' @button = $.el 'a',
$.ready @setupNavLinks className: 'index-refresh-shortcut fa fa-refresh'
return title: 'Refresh'
href: 'javascript:;'
textContent: 'Refresh Index'
$.on @button, 'click', @update
Header.addShortcut @button, 1
return if g.BOARD.ID is 'f' return if g.BOARD.ID is 'f'
@db = new DataBoard 'pinnedThreads' @db = new DataBoard 'pinnedThreads'
@ -19,14 +24,6 @@ Index =
name: 'Catalog Features' name: 'Catalog Features'
cb: @catalogNode cb: @catalogNode
@button = $.el 'a',
className: 'index-refresh-shortcut fa fa-refresh'
title: 'Refresh'
href: 'javascript:;'
textContent: 'Refresh Index'
$.on @button, 'click', @update
Header.addShortcut @button, 1
modeEntry = modeEntry =
el: $.el 'span', textContent: 'Index mode' el: $.el 'span', textContent: 'Index mode'
subEntries: [ subEntries: [
@ -124,21 +121,22 @@ Index =
@update() if g.VIEW is 'index' @update() if g.VIEW is 'index'
$.asap (-> $('.board', doc) or d.readyState isnt 'loading'), -> $.asap (-> $('.board', doc) or d.readyState isnt 'loading'), ->
if g.VIEW is 'index'
board = $ '.board'
$.replace board, Index.root
# Hacks:
# - When removing an element from the document during page load,
# its ancestors will still be correctly created inside of it.
# - Creating loadable elements inside of an origin-less document
# will not download them.
# - Combine the two and you get a download canceller!
# Does not work on Firefox unfortunately. bugzil.la/939713
d.implementation.createDocument(null, null, null).appendChild board
$.rm navLink for navLink in $$ '.navLinks' $.rm navLink for navLink in $$ '.navLinks'
$.after $.x('child::form/preceding-sibling::hr[1]'), Index.navLinks $.after $.x('child::form/preceding-sibling::hr[1]'), Index.navLinks
return g.VIEW isnt 'index'
board = $ '.board'
$.replace board, Index.root
# Hacks:
# - When removing an element from the document during page load,
# its ancestors will still be correctly created inside of it.
# - Creating loadable elements inside of an origin-less document
# will not download them.
# - Combine the two and you get a download canceller!
# Does not work on Firefox unfortunately. bugzil.la/939713
d.implementation.createDocument(null, null, null).appendChild board
@cb.toggleCatalogMode() @cb.toggleCatalogMode()
$.asap (-> $('.pagelist', doc) or d.readyState isnt 'loading'), -> $.asap (-> $('.pagelist', doc) or d.readyState isnt 'loading'), ->
@ -187,6 +185,7 @@ Index =
true true
threadNode: -> threadNode: ->
return if g.VIEW isnt 'index'
return unless Index.db.get {boardID: @board.ID, threadID: @ID} return unless Index.db.get {boardID: @board.ID, threadID: @ID}
@pin() @pin()

View File

@ -83,33 +83,28 @@ Navigate =
error: err error: err
] ]
Main.handleErrors error if error Main.handleErrors error if error
QR.generatePostableThreadsList()
updateContext: (view) -> updateContext: (view) ->
g.DEAD = false g.DEAD = false
g.THREADID = +window.location.pathname.split('/')[3] if view is 'thread'
unless view is g.VIEW return if view is g.VIEW
$.rmClass doc, g.VIEW
$.addClass doc, view $.rmClass doc, g.VIEW
$.addClass doc, view
oldView = g.VIEW
g.VIEW = view
{ {
index: -> index: ->
return if oldView is g.VIEW
delete g.THREADID delete g.THREADID
QR.link.textContent = 'Start a Thread' QR.link.textContent = 'Start a Thread'
$.off d, 'ThreadUpdate', QR.statusCheck
$.on d, 'IndexRefresh', QR.generatePostableThreadsList
$.addClass doc, 'catalog-mode' if Conf['Index Mode'] is 'catalog' $.addClass doc, 'catalog-mode' if Conf['Index Mode'] is 'catalog'
thread: -> thread: ->
g.THREADID = +window.location.pathname.split('/')[3]
return if oldView is g.VIEW
QR.link.textContent = 'Reply to Thread' QR.link.textContent = 'Reply to Thread'
$.on d, 'ThreadUpdate', QR.statusCheck
$.off d, 'IndexRefresh', QR.generatePostableThreadsList
$.rmClass doc, 'catalog-mode' if Conf['Index Mode'] is 'catalog' $.rmClass doc, 'catalog-mode' if Conf['Index Mode'] is 'catalog'
}[g.VIEW]() }[view]()
g.VIEW = view
updateBoard: (boardID) -> updateBoard: (boardID) ->
fullBoardList = $ '#full-board-list', Header.boardList fullBoardList = $ '#full-board-list', Header.boardList
@ -139,14 +134,16 @@ Navigate =
Navigate.updateSFW !!board.ws_board Navigate.updateSFW !!board.ws_board
updateSFW: (sfw) -> updateSFW: (sfw) ->
# TODO: think of a better name for this. Changes style, too. Favicon.el.href = Favicon.default = "//s.4cdn.org/image/favicon#{if sfw then '-ws' else ''}.ico"
Favicon.el.href = "//s.4cdn.org/image/favicon#{if sfw then '-ws' else ''}.ico"
$.add d.head, Favicon.el # Changing the href alone doesn't update the icon on Firefox # Changing the href alone doesn't update the icon on Firefox
$.add d.head, Favicon.el
return if Favicon.SFW is sfw # Board SFW status hasn't changed return if Favicon.SFW is sfw # Board SFW status hasn't changed
Favicon.SFW = sfw Favicon.SFW = sfw
Favicon.update() Favicon.update()
findStyle = (type, base) -> findStyle = (type, base) ->
style = d.cookie.match new RegExp "\b#{type}\_style\=([^;]+);\b" style = d.cookie.match new RegExp "\b#{type}\_style\=([^;]+);\b"
return ["#{type}_style", (if style then style[1] else base)] return ["#{type}_style", (if style then style[1] else base)]
@ -217,11 +214,12 @@ Navigate =
g.BOARD = new Board boardID g.BOARD = new Board boardID
Navigate.title = -> Navigate.updateBoard boardID Navigate.title = -> Navigate.updateBoard boardID
Navigate.updateSFW Favicon.SFW
if view is 'index' if view is 'index'
return Index.update pageNum return Index.update pageNum
# Moving from index to thread or thread to thread # Moving from index to thread or thread to thread
Navigate.updateSFW Favicon.SFW
{load} = Navigate {load} = Navigate
Navigate.req = $.ajax "//a.4cdn.org/#{boardID}/res/#{threadID}.json", Navigate.req = $.ajax "//a.4cdn.org/#{boardID}/res/#{threadID}.json",
onabort: load onabort: load
@ -293,6 +291,7 @@ Navigate =
Navigate.ready 'Quote Threading', QuoteThreading.force, Conf['Quote Threading'] and not Conf['Unread Count'] Navigate.ready 'Quote Threading', QuoteThreading.force, Conf['Quote Threading'] and not Conf['Unread Count']
Navigate.buildThread() Navigate.buildThread()
QR.generatePostableThreadsList()
Header.hashScroll.call window Header.hashScroll.call window
buildThread: -> buildThread: ->

View File

@ -17,7 +17,6 @@ QR =
$.on sc, 'click', -> $.on sc, 'click', ->
if Conf['Persistent QR'] or !QR.nodes or QR.nodes.el.hidden if Conf['Persistent QR'] or !QR.nodes or QR.nodes.el.hidden
$.event 'CloseMenu'
QR.open() QR.open()
QR.nodes.com.focus() QR.nodes.com.focus()
$.rmClass @, 'disabled' $.rmClass @, 'disabled'
@ -66,14 +65,12 @@ QR =
$.on d, 'dragover', QR.dragOver $.on d, 'dragover', QR.dragOver
$.on d, 'drop', QR.dropFile $.on d, 'drop', QR.dropFile
$.on d, 'dragstart dragend', QR.drag $.on d, 'dragstart dragend', QR.drag
{
index: ->
$.on d, 'IndexRefresh', QR.generatePostableThreadsList
thread: ->
$.on d, 'ThreadUpdate', QR.statusCheck
}[g.VIEW]()
return unless Conf['Persistent QR'] # We can thread update and index refresh without loading a new page, so...
$.on d, 'IndexRefresh', QR.generatePostableThreadsList
$.on d, 'ThreadUpdate', QR.statusCheck
return if !Conf['Persistent QR']
QR.open() QR.open()
QR.hide() if Conf['Auto-Hide QR'] QR.hide() if Conf['Auto-Hide QR']