Small reflow to QuoteBacklink I.

I don't like concatenating for temporary data.
This commit is contained in:
Zixaphir 2014-03-02 19:45:54 -07:00
parent 000ca6f9ce
commit e451410ef1
4 changed files with 34 additions and 15 deletions

View File

@ -5185,21 +5185,25 @@
}); });
}, },
firstNode: function() { firstNode: function() {
var container, post, quoteID, _base, _i, _j, _len, _len1, _ref, _ref1; var addNodes, container, post, quoteID, _base, _i, _j, _len, _len1, _ref, _ref1;
if (this.isClone) { if (this.isClone) {
return; return;
} }
addNodes = function(post, that) {
return $.add(post.nodes.backlinkContainer, QuoteBacklink.buildBacklink(post, that));
};
_ref = this.quotes; _ref = this.quotes;
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
quoteID = _ref[_i]; quoteID = _ref[_i];
((_base = QuoteBacklink.map)[quoteID] || (_base[quoteID] = [])).push(this.fullID); ((_base = QuoteBacklink.map)[quoteID] || (_base[quoteID] = [])).push(this.fullID);
if (!((post = g.posts[quoteID]) && (container = post != null ? post.nodes.backlinkContainer : void 0))) { if (!(((post = g.posts[quoteID]) != null) && (container = post.nodes.backlinkContainer))) {
continue; continue;
} }
_ref1 = [post].concat(post.clones); addNodes(post, this);
_ref1 = post.clones;
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
post = _ref1[_j]; post = _ref1[_j];
$.add(post.nodes.backlinkContainer, QuoteBacklink.buildBacklink(post, this)); addNodes(post, this);
} }
} }
}, },
@ -12566,7 +12570,9 @@
g.threads.forEach(function(thread) { g.threads.forEach(function(thread) {
return thread.collect(); return thread.collect();
}); });
QuoteBacklink.containers = {}; if (Conf['Quote Backlinks']) {
QuoteBacklink.map = {};
}
return $.rmAll($('.board')); return $.rmAll($('.board'));
}, },
features: [['Thread Excerpt', ThreadExcerpt], ['Unread Count', Unread], ['Quote Threading', QuoteThreading], ['Thread Stats', ThreadStats], ['Thread Updater', ThreadUpdater], ['Thread Expansion', ExpandThread]], features: [['Thread Excerpt', ThreadExcerpt], ['Unread Count', Unread], ['Quote Threading', QuoteThreading], ['Thread Stats', ThreadStats], ['Thread Updater', ThreadUpdater], ['Thread Expansion', ExpandThread]],

View File

@ -5237,21 +5237,25 @@
}); });
}, },
firstNode: function() { firstNode: function() {
var container, post, quoteID, _base, _i, _j, _len, _len1, _ref, _ref1; var addNodes, container, post, quoteID, _base, _i, _j, _len, _len1, _ref, _ref1;
if (this.isClone) { if (this.isClone) {
return; return;
} }
addNodes = function(post, that) {
return $.add(post.nodes.backlinkContainer, QuoteBacklink.buildBacklink(post, that));
};
_ref = this.quotes; _ref = this.quotes;
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
quoteID = _ref[_i]; quoteID = _ref[_i];
((_base = QuoteBacklink.map)[quoteID] || (_base[quoteID] = [])).push(this.fullID); ((_base = QuoteBacklink.map)[quoteID] || (_base[quoteID] = [])).push(this.fullID);
if (!((post = g.posts[quoteID]) && (container = post != null ? post.nodes.backlinkContainer : void 0))) { if (!(((post = g.posts[quoteID]) != null) && (container = post.nodes.backlinkContainer))) {
continue; continue;
} }
_ref1 = [post].concat(post.clones); addNodes(post, this);
_ref1 = post.clones;
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
post = _ref1[_j]; post = _ref1[_j];
$.add(post.nodes.backlinkContainer, QuoteBacklink.buildBacklink(post, this)); addNodes(post, this);
} }
} }
}, },
@ -12580,7 +12584,9 @@
g.threads.forEach(function(thread) { g.threads.forEach(function(thread) {
return thread.collect(); return thread.collect();
}); });
QuoteBacklink.containers = {}; if (Conf['Quote Backlinks']) {
QuoteBacklink.map = {};
}
return $.rmAll($('.board')); return $.rmAll($('.board'));
}, },
features: [['Thread Excerpt', ThreadExcerpt], ['Unread Count', Unread], ['Quote Threading', QuoteThreading], ['Thread Stats', ThreadStats], ['Thread Updater', ThreadUpdater], ['Thread Expansion', ExpandThread]], features: [['Thread Excerpt', ThreadExcerpt], ['Unread Count', Unread], ['Quote Threading', QuoteThreading], ['Thread Stats', ThreadStats], ['Thread Updater', ThreadUpdater], ['Thread Expansion', ExpandThread]],

View File

@ -36,8 +36,7 @@ Navigate =
clean: -> clean: ->
# Garbage collection # Garbage collection
g.threads.forEach (thread) -> thread.collect() g.threads.forEach (thread) -> thread.collect()
QuoteBacklink.containers = {} QuoteBacklink.map = {} if Conf['Quote Backlinks'] # Containers can get pretty icky.
$.rmAll $ '.board' $.rmAll $ '.board'
features: [ features: [

View File

@ -16,20 +16,27 @@ QuoteBacklink =
@funk = Function 'id', "return '#{format}'" @funk = Function 'id', "return '#{format}'"
@frag = $.nodes [$.tn(' '), $.el 'a', className: 'backlink'] @frag = $.nodes [$.tn(' '), $.el 'a', className: 'backlink']
@map = {} @map = {}
Post.callbacks.push Post.callbacks.push
name: 'Quote Backlinking Part 1' name: 'Quote Backlinking Part 1'
cb: @firstNode cb: @firstNode
Post.callbacks.push Post.callbacks.push
name: 'Quote Backlinking Part 2' name: 'Quote Backlinking Part 2'
cb: @secondNode cb: @secondNode
firstNode: -> firstNode: ->
return if @isClone return if @isClone
addNodes = (post, that) ->
$.add post.nodes.backlinkContainer, QuoteBacklink.buildBacklink post, that
for quoteID in @quotes for quoteID in @quotes
(QuoteBacklink.map[quoteID] or= []).push @fullID (QuoteBacklink.map[quoteID] or= []).push @fullID
continue unless (post = g.posts[quoteID]) and container = post?.nodes.backlinkContainer continue unless (post = g.posts[quoteID])? and container = post.nodes.backlinkContainer
for post in [post].concat post.clones addNodes post, @
$.add post.nodes.backlinkContainer, QuoteBacklink.buildBacklink post, @ for post in post.clones
addNodes post, @
return return
secondNode: -> secondNode: ->
# Don't backlink the OP. # Don't backlink the OP.
return unless @isReply or Conf['OP Backlinks'] return unless @isReply or Conf['OP Backlinks']
@ -46,6 +53,7 @@ QuoteBacklink =
if post = g.posts[quoteID] # Post hasn't been collected since. if post = g.posts[quoteID] # Post hasn't been collected since.
$.add container, QuoteBacklink.buildBacklink @, post $.add container, QuoteBacklink.buildBacklink @, post
$.add @nodes.info, container $.add @nodes.info, container
buildBacklink: (quoted, quoter) -> buildBacklink: (quoted, quoter) ->
frag = QuoteBacklink.frag.cloneNode true frag = QuoteBacklink.frag.cloneNode true
a = frag.lastElementChild a = frag.lastElementChild