$(function () { $.wait = function( callback, seconds){ return window.setTimeout( callback, seconds * 100 ); } //FUNCTIONS //Function to position the comments correctly function positionComment() { $('.comment-wrapper').each(function() { var x=0; var y=0; //find first paragraph above comment in page builder struct var target = $(this).prevAll('.article-text:first'); if (target.length) { //find the comment span (for +) and set data-id for highlight target.find('.comment-span').text('+\xa0').attr('data-highlight',target.attr('data-id')); //set data-highlight on the comment itself $(this).attr('data-highlight',target.attr('data-id')); //find x and y of parent x = target.width() + target.offset().left; var $commentspan=target.find('.comment-span'); if ($commentspan.length) { y = $commentspan.offset().top + $('.wrapper').scrollTop() - 63; if($(this).prevAll('.comment-wrapper:first')){ var prevComment = $(this).prevAll('.comment-wrapper:first'); if(prevComment.length>0){ var prevBottom = $('.wrapper').scrollTop() + prevComment.find('.comment').offset().top + prevComment.find('.comment').height() - 55; if(prevBottom>y){ y = prevBottom ; } } } } else console.error('commentspan not found'); if($(this).parent().prev().children('.comment-wrapper:last')) { var prevComment = $(this).parent().prev().children('.comment-wrapper:last'); if(prevComment.length>0){ var prevBottom = parseInt(prevComment.css('top'),10) + prevComment.height() - 55; if(prevBottom>y){ y = prevBottom; } } } $(this).css('top', y); $(this).css('left', x); //$(this).find('.comment').show(); } else console.error('target not found'); }); }; function hideComments(){ $('.comment-wrapper').each(function(){ $(this).find('.comment').hide(); }); }; //ON INIT RUN: positionComment(); //ATTACH HOOKS //if window is resized, recalculate the position of the comments $(window).resize(function(){ positionComment(); }); /* //Links have title's instead of linktext if title available $('.comment-wrapper a').each(function() { if($(this).attr("title")) { $(this).text(' '+$(this).attr("title")); } }); */ //highlight the comment on hover of the + sign in the article $(".comment-span").hover( //hover in function() { $('.comment-wrapper[data-highlight="'+ $(this).attr('data-highlight') +'"]').addClass('comment-highlighted') }, //hover out function() { $('.comment-wrapper[data-highlight="'+ $(this).attr('data-highlight') +'"]').removeClass('comment-highlighted') } ); //END OF START FUNCTION }); /*******************************************************************/ /* ftrtch dino */ /* [type: JS] [file:comment] [16.404] DESIGN*/ /*******************************************************************/ /* 0.9 D>D */ /* db 191 */