# HG changeset patch # User ritsufag # Date 2013-08-27 19:20:44 # Node ID ab4d79db4f3aa2ad4c1679a240b29d4234e239ab # Parent 068aac3ccfa2774b4b033ba94eaae13f22098089 Add reflink map diff --git a/boards/static/js/thread.js b/boards/static/js/thread.js --- a/boards/static/js/thread.js +++ b/boards/static/js/thread.js @@ -91,6 +91,47 @@ function addQuickReply(postId) { $("html, body").animate({ scrollTop: $(textAreaId).offset().top }, "slow"); } +function addRefLinkMap() { + var postByNum = [], refMap = []; + + $('.post').each(function() { + var self = $(this); + + var postNum = self.attr('id'); + //add post by id + postByNum[postNum] = self; + //add ref link + self.find('p').children('a').each(function() { + if($(this).text().indexOf('>>') == 0) { + var refNum = $(this).text().match(/\d+/); + + if(postByNum[refNum]) { + if(!refMap[refNum]) + refMap[refNum] = []; + + //if !exist + if((',' + refMap[refNum].toString() + ',').indexOf(',' + postNum + ',') < 0) { + refMap[refNum].push(postNum); + }; + } + } + }); + }); + + for(var pNum in refMap) { + if(typeof refMap[pNum] === 'object') { + var data = 'Ответы:' + refMap[pNum].toString().replace(/(\d+)/g, ' >>$1'); + + //append refmap panel + if(!$("#refmap_"+pNum).length) { + $('#'+pNum+'').find('.message').after($('
'+data+'
')); + } + } + } +} + + $(document).ready(function(){ add_panel('.navigation_panel'); + addRefLinkMap(); });