Reflow Navigate.parse

This commit is contained in:
Zixaphir 2014-03-03 01:02:31 -07:00
parent d251177641
commit 393f909d1e
3 changed files with 53 additions and 115 deletions

View File

@ -12620,25 +12620,6 @@
Main.handleErrors(errors); Main.handleErrors(errors);
} }
}, },
ready: function(name, feature, condition) {
var err, error;
try {
if (condition) {
feature();
}
} catch (_error) {
err = _error;
error = [
{
message: "" + name + " Failed.",
error: err
}
];
}
if (error) {
return Main.handleErrors(error);
}
},
updateContext: function(view) { updateContext: function(view) {
g.DEAD = false; g.DEAD = false;
if (view === 'thread') { if (view === 'thread') {
@ -12773,9 +12754,7 @@
$.set('Index Sort', Conf['Index Sort'] = Index.selectSort.value = indexSort); $.set('Index Sort', Conf['Index Sort'] = Index.selectSort.value = indexSort);
Index.cb.sort(); Index.cb.sort();
} }
if (view === g.VIEW && boardID === g.BOARD.ID) { if (!(view === 'index' && 'index' === g.VIEW && boardID === g.BOARD.ID)) {
Navigate.updateContext(view);
} else {
Navigate.disconnect(); Navigate.disconnect();
Navigate.updateContext(view); Navigate.updateContext(view);
Navigate.clean(); Navigate.clean();
@ -12839,12 +12818,12 @@
} }
}, },
parse: function(data) { parse: function(data) {
var OP, board, errors, makePost, obj, post, posts, thread, threadRoot, _i, _len; var OP, board, errors, i, makePost, obj, post, posts, thread, threadRoot;
board = g.BOARD;
Navigate.threadRoot = threadRoot = Build.thread(board, OP = data.shift(), true);
thread = new Thread(OP.no, board);
posts = []; posts = [];
errors = null; errors = null;
board = g.BOARD;
threadRoot = Build.thread(board, OP = data[0], true);
thread = new Thread(OP.no, board);
makePost = function(postNode) { makePost = function(postNode) {
var err; var err;
try { try {
@ -12855,35 +12834,33 @@
errors = []; errors = [];
} }
return errors.push({ return errors.push({
message: "Parsing of Post No." + thread.ID + " failed. Post will be skipped.", message: "Parsing of Post No." + postNode.ID + " failed. Post will be skipped.",
error: err error: err
}); });
} }
}; };
makePost($('.opContainer', threadRoot)); makePost($('.opContainer', threadRoot));
for (_i = 0, _len = data.length; _i < _len; _i++) { i = 0;
obj = data[_i]; while (obj = data[++i]) {
post = Build.postFromObject(obj, board); post = Build.postFromObject(obj, board);
makePost(post); makePost(post);
$.add(threadRoot, post); $.add(threadRoot, post);
} }
if (errors) {
Main.handleErrors(errors);
}
Main.callbackNodes(Thread, [thread]); Main.callbackNodes(Thread, [thread]);
Main.callbackNodes(Post, posts); Main.callbackNodes(Post, posts);
Navigate.ready('Quote Threading', QuoteThreading.force, Conf['Quote Threading'] && !Conf['Unread Count']); if (Conf['Quote Threading'] && !Conf['Unread Count']) {
Navigate.buildThread(); QuoteThreading.force();
QR.generatePostableThreadsList(); }
return Header.hashScroll.call(window);
},
buildThread: function() {
var board;
board = $('.board'); board = $('.board');
$.rmAll(board); $.rmAll(board);
$.add(board, [Navigate.threadRoot, $.el('hr')]); $.add(board, [threadRoot, $.el('hr')]);
if (Conf['Unread Count']) { if (Conf['Unread Count']) {
return Navigate.ready('Unread Count', Unread.ready, Conf['Unread Count']); Unread.ready();
}
QR.generatePostableThreadsList();
Header.hashScroll.call(window);
if (errors) {
return Main.handleErrors(errors);
} }
}, },
popstate: function() { popstate: function() {

View File

@ -12634,25 +12634,6 @@
Main.handleErrors(errors); Main.handleErrors(errors);
} }
}, },
ready: function(name, feature, condition) {
var err, error;
try {
if (condition) {
feature();
}
} catch (_error) {
err = _error;
error = [
{
message: "" + name + " Failed.",
error: err
}
];
}
if (error) {
return Main.handleErrors(error);
}
},
updateContext: function(view) { updateContext: function(view) {
g.DEAD = false; g.DEAD = false;
if (view === 'thread') { if (view === 'thread') {
@ -12787,9 +12768,7 @@
$.set('Index Sort', Conf['Index Sort'] = Index.selectSort.value = indexSort); $.set('Index Sort', Conf['Index Sort'] = Index.selectSort.value = indexSort);
Index.cb.sort(); Index.cb.sort();
} }
if (view === g.VIEW && boardID === g.BOARD.ID) { if (!(view === 'index' && 'index' === g.VIEW && boardID === g.BOARD.ID)) {
Navigate.updateContext(view);
} else {
Navigate.disconnect(); Navigate.disconnect();
Navigate.updateContext(view); Navigate.updateContext(view);
Navigate.clean(); Navigate.clean();
@ -12853,12 +12832,12 @@
} }
}, },
parse: function(data) { parse: function(data) {
var OP, board, errors, makePost, obj, post, posts, thread, threadRoot, _i, _len; var OP, board, errors, i, makePost, obj, post, posts, thread, threadRoot;
board = g.BOARD;
Navigate.threadRoot = threadRoot = Build.thread(board, OP = data.shift(), true);
thread = new Thread(OP.no, board);
posts = []; posts = [];
errors = null; errors = null;
board = g.BOARD;
threadRoot = Build.thread(board, OP = data[0], true);
thread = new Thread(OP.no, board);
makePost = function(postNode) { makePost = function(postNode) {
var err; var err;
try { try {
@ -12869,35 +12848,33 @@
errors = []; errors = [];
} }
return errors.push({ return errors.push({
message: "Parsing of Post No." + thread.ID + " failed. Post will be skipped.", message: "Parsing of Post No." + postNode.ID + " failed. Post will be skipped.",
error: err error: err
}); });
} }
}; };
makePost($('.opContainer', threadRoot)); makePost($('.opContainer', threadRoot));
for (_i = 0, _len = data.length; _i < _len; _i++) { i = 0;
obj = data[_i]; while (obj = data[++i]) {
post = Build.postFromObject(obj, board); post = Build.postFromObject(obj, board);
makePost(post); makePost(post);
$.add(threadRoot, post); $.add(threadRoot, post);
} }
if (errors) {
Main.handleErrors(errors);
}
Main.callbackNodes(Thread, [thread]); Main.callbackNodes(Thread, [thread]);
Main.callbackNodes(Post, posts); Main.callbackNodes(Post, posts);
Navigate.ready('Quote Threading', QuoteThreading.force, Conf['Quote Threading'] && !Conf['Unread Count']); if (Conf['Quote Threading'] && !Conf['Unread Count']) {
Navigate.buildThread(); QuoteThreading.force();
QR.generatePostableThreadsList(); }
return Header.hashScroll.call(window);
},
buildThread: function() {
var board;
board = $('.board'); board = $('.board');
$.rmAll(board); $.rmAll(board);
$.add(board, [Navigate.threadRoot, $.el('hr')]); $.add(board, [threadRoot, $.el('hr')]);
if (Conf['Unread Count']) { if (Conf['Unread Count']) {
return Navigate.ready('Unread Count', Unread.ready, Conf['Unread Count']); Unread.ready();
}
QR.generatePostableThreadsList();
Header.hashScroll.call(window);
if (errors) {
return Main.handleErrors(errors);
} }
}, },
popstate: function() { popstate: function() {

View File

@ -75,16 +75,6 @@ Navigate =
Main.handleErrors errors if errors Main.handleErrors errors if errors
return return
ready: (name, feature, condition) ->
try
feature() if condition
catch err
error = [
message: "#{name} Failed."
error: err
]
Main.handleErrors error if error
updateContext: (view) -> updateContext: (view) ->
g.DEAD = false g.DEAD = false
g.THREADID = +window.location.pathname.split('/')[3] if view is 'thread' g.THREADID = +window.location.pathname.split('/')[3] if view is 'thread'
@ -198,10 +188,7 @@ Navigate =
$.set 'Index Sort', Conf['Index Sort'] = Index.selectSort.value = indexSort $.set 'Index Sort', Conf['Index Sort'] = Index.selectSort.value = indexSort
Index.cb.sort() Index.cb.sort()
if view is g.VIEW and boardID is g.BOARD.ID unless view is 'index' and 'index' is g.VIEW and boardID is g.BOARD.ID
Navigate.updateContext view
else # We've navigated somewhere we weren't before!
Navigate.disconnect() Navigate.disconnect()
Navigate.updateContext view Navigate.updateContext view
Navigate.clean() Navigate.clean()
@ -258,12 +245,11 @@ Navigate =
return return
parse: (data) -> parse: (data) ->
board = g.BOARD posts = []
Navigate.threadRoot = threadRoot = Build.thread board, OP = data.shift(), true errors = null
thread = new Thread OP.no, board board = g.BOARD
threadRoot = Build.thread board, OP = data[0], true
posts = [] thread = new Thread OP.no, board
errors = null
makePost = (postNode) -> makePost = (postNode) ->
try try
@ -272,34 +258,32 @@ Navigate =
# Skip posts that we failed to parse. # Skip posts that we failed to parse.
errors = [] unless errors errors = [] unless errors
errors.push errors.push
message: "Parsing of Post No.#{thread.ID} failed. Post will be skipped." message: "Parsing of Post No.#{postNode.ID} failed. Post will be skipped."
error: err error: err
makePost $('.opContainer', threadRoot) makePost $('.opContainer', threadRoot)
for obj in data i = 0
while obj = data[++i]
post = Build.postFromObject obj, board post = Build.postFromObject obj, board
makePost post makePost post
$.add threadRoot, post $.add threadRoot, post
Main.handleErrors errors if errors
Main.callbackNodes Thread, [thread] Main.callbackNodes Thread, [thread]
Main.callbackNodes Post, posts Main.callbackNodes Post, posts
Navigate.ready 'Quote Threading', QuoteThreading.force, Conf['Quote Threading'] and not Conf['Unread Count'] QuoteThreading.force() if Conf['Quote Threading'] and not Conf['Unread Count']
board = $ '.board'
$.rmAll board
$.add board, [threadRoot, $.el 'hr']
Unread.ready() if Conf['Unread Count']
Navigate.buildThread()
QR.generatePostableThreadsList() QR.generatePostableThreadsList()
Header.hashScroll.call window Header.hashScroll.call window
buildThread: -> Main.handleErrors errors if errors
board = $ '.board'
$.rmAll board
$.add board, [Navigate.threadRoot, $.el 'hr']
if Conf['Unread Count']
Navigate.ready 'Unread Count', Unread.ready, Conf['Unread Count']
popstate: -> popstate: ->
return if window.location.pathname is Navigate.path return if window.location.pathname is Navigate.path