Start working on getting index navigation from a thread working

This commit is contained in:
Zixaphir 2014-01-08 09:30:23 -07:00
parent 9368cbb232
commit 41e3fa05ad
6 changed files with 220 additions and 89 deletions

View File

@ -1,5 +1,5 @@
/*
* 4chan X - Version 1.2.45 - 2014-01-07
* 4chan X - Version 1.2.45 - 2014-01-08
*
* Licensed under the MIT license.
* https://github.com/seaweedchan/4chan-x/blob/master/LICENSE

View File

@ -22,7 +22,7 @@
// ==/UserScript==
/*
* 4chan X - Version 1.2.45 - 2014-01-07
* 4chan X - Version 1.2.45 - 2014-01-08
*
* Licensed under the MIT license.
* https://github.com/seaweedchan/4chan-x/blob/master/LICENSE
@ -2146,7 +2146,7 @@
Index = {
init: function() {
var anchorEntry, input, label, modeEntry, name, refNavEntry, repliesEntry, sortEntry, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2;
if (g.VIEW !== 'index' || g.BOARD.ID === 'f') {
if (g.BOARD.ID === 'f') {
return;
}
this.button = $.el('a', {
@ -2257,6 +2257,12 @@
order: 90,
subEntries: [repliesEntry, anchorEntry, refNavEntry, modeEntry, sortEntry]
});
if (g.VIEW !== 'index') {
return;
}
return this.connect.call(this);
},
connect: function() {
$.addClass(doc, 'index-loading');
this.update();
this.root = $.el('div', {
@ -2280,13 +2286,13 @@
return $.asap((function() {
return $('.board', doc) || d.readyState !== 'loading';
}), function() {
var board, navLink, _l, _len3, _ref3;
var board, navLink, _i, _len, _ref;
board = $('.board');
$.replace(board, Index.root);
d.implementation.createDocument(null, null, null).appendChild(board);
_ref3 = $$('.navLinks');
for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) {
navLink = _ref3[_l];
_ref = $$('.navLinks');
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
navLink = _ref[_i];
$.rm(navLink);
}
$.after($.x('child::form/preceding-sibling::hr[1]'), Index.navLinks);
@ -2294,7 +2300,12 @@
return $.asap((function() {
return $('.pagelist') || d.readyState !== 'loading';
}), function() {
return $.replace($('.pagelist'), Index.pagelist);
var pagelist;
if (pagelist = $('.pagelist')) {
return $.replace(pagelist, Index.pagelist);
} else {
return $.after($.id('delform'), Index.pagelist);
}
});
});
},
@ -2444,19 +2455,14 @@
if ((_ref1 = Index.notice) != null) {
_ref1.close();
}
if (d.readyState !== 'loading') {
Index.notice = new Notice('info', 'Refreshing index...');
} else {
now = Date.now();
$.ready(function() {
return setTimeout((function() {
if (!(Index.req && !Index.notice)) {
return;
}
now = Date.now();
$.ready(function() {
return setTimeout((function() {
if (Index.req && !Index.notice) {
return Index.notice = new Notice('info', 'Refreshing index...');
}), 5 * $.SECOND - (Date.now() - now));
});
}
}
}), 5 * $.SECOND - (Date.now() - now));
});
if (typeof pageNum !== 'number') {
pageNum = null;
}
@ -5023,7 +5029,7 @@
});
input = $('input', this.controls);
$.on(input, 'change', this.toggle);
$.event('AddMenuEntry', {
$.event('AddMenuEntry', this.entry = {
type: 'header',
el: this.controls,
order: 98
@ -5036,6 +5042,16 @@
cb: this.node
});
},
disconnect: function() {
var input;
input = $('input', this.controls);
$.off(input, 'change', this.toggle);
$.event('rmMenuEntry', this.entry);
delete this.enabled;
delete this.controls;
delete this.entry;
return Post.callbacks.rm('Quote Threading');
},
setup: function() {
$.off(d, '4chanXInitFinished', QuoteThreading.setup);
return QuoteThreading.force();
@ -12777,16 +12793,32 @@
return _results;
},
disconnect: function() {
var feature, name, _ref;
_ref = Main.features;
for (name in _ref) {
feature = _ref[name];
if (feature.disconnect) {
feature.disconnect();
var err, errors, feature, features, name;
if (g.VIEW === 'thread') {
features = {
'Thread Updater': ThreadUpdater,
'Unread Count': Unread,
'Quote Threading': QuoteThreading
};
}
for (name in features) {
feature = features[name];
try {
feature.disconnect.call(feature);
} catch (_error) {
err = _error;
if (!errors) {
errors = [];
}
errors.push({
message: "Failed to disconnect feature " + name + ".",
error: err
});
}
if (errors) {
Main.handleErrors(errors);
}
}
Post.callbacks.clear();
Thread.callbacks.clear();
return $.rmAll($('.board'));
},
navigate: function(e) {
@ -12806,11 +12838,10 @@
}
if (view === g.VIEW) {
if (view === 'index') {
if (boardID === g.BOARD.ID) {
return Index.update();
if (boardID !== g.BOARD.ID) {
Main.clean();
Main.updateBoard(boardID);
}
Main.clean();
Main.updateBoard(boardID);
return Index.update();
} else {
return Main.refresh({
@ -12820,7 +12851,21 @@
});
}
} else {
return Main.disconnect();
g.VIEW = view;
if (view === 'index') {
Main.disconnect();
Main.clean();
if (boardID !== g.BOARD.ID) {
Main.updateBoard();
}
return Index.connect.call(Index);
} else {
return Main.refresh({
boardID: boardID,
view: view,
threadID: threadID
});
}
}
},
updateBoard: function(boardID) {

View File

@ -1,6 +1,6 @@
// Generated by CoffeeScript
/*
* 4chan X - Version 1.2.45 - 2014-01-07
* 4chan X - Version 1.2.45 - 2014-01-08
*
* Licensed under the MIT license.
* https://github.com/seaweedchan/4chan-x/blob/master/LICENSE
@ -2156,7 +2156,7 @@
Index = {
init: function() {
var anchorEntry, input, label, modeEntry, name, refNavEntry, repliesEntry, sortEntry, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2;
if (g.VIEW !== 'index' || g.BOARD.ID === 'f') {
if (g.BOARD.ID === 'f') {
return;
}
this.button = $.el('a', {
@ -2267,6 +2267,12 @@
order: 90,
subEntries: [repliesEntry, anchorEntry, refNavEntry, modeEntry, sortEntry]
});
if (g.VIEW !== 'index') {
return;
}
return this.connect.call(this);
},
connect: function() {
$.addClass(doc, 'index-loading');
this.update();
this.root = $.el('div', {
@ -2290,13 +2296,13 @@
return $.asap((function() {
return $('.board', doc) || d.readyState !== 'loading';
}), function() {
var board, navLink, _l, _len3, _ref3;
var board, navLink, _i, _len, _ref;
board = $('.board');
$.replace(board, Index.root);
d.implementation.createDocument(null, null, null).appendChild(board);
_ref3 = $$('.navLinks');
for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) {
navLink = _ref3[_l];
_ref = $$('.navLinks');
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
navLink = _ref[_i];
$.rm(navLink);
}
$.after($.x('child::form/preceding-sibling::hr[1]'), Index.navLinks);
@ -2304,7 +2310,12 @@
return $.asap((function() {
return $('.pagelist') || d.readyState !== 'loading';
}), function() {
return $.replace($('.pagelist'), Index.pagelist);
var pagelist;
if (pagelist = $('.pagelist')) {
return $.replace(pagelist, Index.pagelist);
} else {
return $.after($.id('delform'), Index.pagelist);
}
});
});
},
@ -2454,19 +2465,14 @@
if ((_ref1 = Index.notice) != null) {
_ref1.close();
}
if (d.readyState !== 'loading') {
Index.notice = new Notice('info', 'Refreshing index...');
} else {
now = Date.now();
$.ready(function() {
return setTimeout((function() {
if (!(Index.req && !Index.notice)) {
return;
}
now = Date.now();
$.ready(function() {
return setTimeout((function() {
if (Index.req && !Index.notice) {
return Index.notice = new Notice('info', 'Refreshing index...');
}), 5 * $.SECOND - (Date.now() - now));
});
}
}
}), 5 * $.SECOND - (Date.now() - now));
});
if (typeof pageNum !== 'number') {
pageNum = null;
}
@ -5026,7 +5032,7 @@
});
input = $('input', this.controls);
$.on(input, 'change', this.toggle);
$.event('AddMenuEntry', {
$.event('AddMenuEntry', this.entry = {
type: 'header',
el: this.controls,
order: 98
@ -5039,6 +5045,16 @@
cb: this.node
});
},
disconnect: function() {
var input;
input = $('input', this.controls);
$.off(input, 'change', this.toggle);
$.event('rmMenuEntry', this.entry);
delete this.enabled;
delete this.controls;
delete this.entry;
return Post.callbacks.rm('Quote Threading');
},
setup: function() {
$.off(d, '4chanXInitFinished', QuoteThreading.setup);
return QuoteThreading.force();
@ -12751,16 +12767,32 @@
return _results;
},
disconnect: function() {
var feature, name, _ref;
_ref = Main.features;
for (name in _ref) {
feature = _ref[name];
if (feature.disconnect) {
feature.disconnect();
var err, errors, feature, features, name;
if (g.VIEW === 'thread') {
features = {
'Thread Updater': ThreadUpdater,
'Unread Count': Unread,
'Quote Threading': QuoteThreading
};
}
for (name in features) {
feature = features[name];
try {
feature.disconnect.call(feature);
} catch (_error) {
err = _error;
if (!errors) {
errors = [];
}
errors.push({
message: "Failed to disconnect feature " + name + ".",
error: err
});
}
if (errors) {
Main.handleErrors(errors);
}
}
Post.callbacks.clear();
Thread.callbacks.clear();
return $.rmAll($('.board'));
},
navigate: function(e) {
@ -12780,11 +12812,10 @@
}
if (view === g.VIEW) {
if (view === 'index') {
if (boardID === g.BOARD.ID) {
return Index.update();
if (boardID !== g.BOARD.ID) {
Main.clean();
Main.updateBoard(boardID);
}
Main.clean();
Main.updateBoard(boardID);
return Index.update();
} else {
return Main.refresh({
@ -12794,7 +12825,21 @@
});
}
} else {
return Main.disconnect();
g.VIEW = view;
if (view === 'index') {
Main.disconnect();
Main.clean();
if (boardID !== g.BOARD.ID) {
Main.updateBoard();
}
return Index.connect.call(Index);
} else {
return Main.refresh({
boardID: boardID,
view: view,
threadID: threadID
});
}
}
},
updateBoard: function(boardID) {

View File

@ -1,6 +1,6 @@
Index =
init: ->
return if g.VIEW isnt 'index' or g.BOARD.ID is 'f'
return if g.BOARD.ID is 'f'
@button = $.el 'a',
className: 'index-refresh-shortcut fa fa-refresh'
@ -66,6 +66,11 @@ Index =
order: 90
subEntries: [repliesEntry, anchorEntry, refNavEntry, modeEntry, sortEntry]
return if g.VIEW isnt 'index'
@connect.call @
connect: ->
$.addClass doc, 'index-loading'
@update()
@root = $.el 'div', className: 'board'
@ -99,7 +104,10 @@ Index =
$.after $.x('child::form/preceding-sibling::hr[1]'), Index.navLinks
$.rmClass doc, 'index-loading'
$.asap (-> $('.pagelist') or d.readyState isnt 'loading'), ->
$.replace $('.pagelist'), Index.pagelist
if pagelist = $('.pagelist')
$.replace pagelist, Index.pagelist
else
$.after $.id('delform'), Index.pagelist
cb:
mode: ->
@ -202,17 +210,16 @@ Index =
return unless navigator.onLine
Index.req?.abort()
Index.notice?.close()
if d.readyState isnt 'loading'
Index.notice = new Notice 'info', 'Refreshing index...'
else
# Delay the notice on initial page load
# and only display it for slow connections.
now = Date.now()
$.ready ->
setTimeout (->
return unless Index.req and !Index.notice
# Delay the notice on initial page load
# and only display it for slow connections.
now = Date.now()
$.ready ->
setTimeout (->
if Index.req and !Index.notice
Index.notice = new Notice 'info', 'Refreshing index...'
), 5 * $.SECOND - (Date.now() - now)
), 5 * $.SECOND - (Date.now() - now)
pageNum = null if typeof pageNum isnt 'number' # event
onload = (e) -> Index.load e, pageNum
Index.req = $.ajax "//a.4cdn.org/#{g.BOARD}/catalog.json",

View File

@ -322,12 +322,26 @@ Main =
delete threads[id] for id of threads when threads.hasOwnProperty id
disconnect: ->
# Disconnect active features that _can_ be disconnected
feature.disconnect() for name, feature of Main.features when feature.disconnect
if g.VIEW is 'thread'
features =
'Thread Updater': ThreadUpdater
'Unread Count': Unread
'Quote Threading': QuoteThreading
for name, feature of features
try
feature.disconnect.call feature
catch err
errors = [] unless errors
errors.push
message: "Failed to disconnect feature #{name}."
error: err
Main.handleErrors errors if errors
# Clean Post and Thread callbacks
Post.callbacks.clear()
Thread.callbacks.clear()
# Post.callbacks.clear()
# Thread.callbacks.clear()
# Clean the board, as we'll be dumping shit here
$.rmAll $ '.board'
@ -348,17 +362,25 @@ Main =
# Moving from thread to thread or index to index.
if view is g.VIEW
if view is 'index'
if boardID is g.BOARD.ID
return Index.update()
Main.clean()
Main.updateBoard boardID
unless boardID is g.BOARD.ID
Main.clean()
Main.updateBoard boardID
Index.update()
else
Main.refresh {boardID, view, threadID}
else
Main.disconnect()
g.VIEW = view
if view is 'index'
Main.disconnect()
Main.clean()
Main.updateBoard() unless boardID is g.BOARD.ID
Index.connect.call Index
else
Main.refresh {boardID, view, threadID}
updateBoard: (boardID) ->
g.BOARD = new Board boardID

View File

@ -13,7 +13,7 @@ QuoteThreading =
input = $ 'input', @controls
$.on input, 'change', @toggle
$.event 'AddMenuEntry',
$.event 'AddMenuEntry', @entry =
type: 'header'
el: @controls
order: 98
@ -23,6 +23,18 @@ QuoteThreading =
Post.callbacks.push
name: 'Quote Threading'
cb: @node
disconnect: ->
input = $ 'input', @controls
$.off input, 'change', @toggle
$.event 'rmMenuEntry', @entry
delete @enabled
delete @controls
delete @entry
Post.callbacks.rm 'Quote Threading'
setup: ->
$.off d, '4chanXInitFinished', QuoteThreading.setup