Created
September 21, 2015 20:41
-
-
Save tcitworld/47d86bfa263a2546e26c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* In that case, I don't insert comment in my text. Instead, they are shown on bottom and they have an anchor that | |
* links to the paragraph on which they were created. | |
*/ | |
var paragraphsSelector = $('p'); | |
var commentselector = $('.comment'); | |
var comment = new Array(); | |
var commentdomints = $('.commentdom'); | |
// iteration on each comment coming from commentselector | |
for (var i = 0; i < commentselector.length; i++) { | |
// define paragraph for comment : get the index number for the paragraph stored in database. | |
// It's the same as domPath (see below) | |
comment['dom'] = commentdomints.eq(i).text(); | |
// get paragraph id associated to comment | |
// This is where the problem happens. | |
comment['paragraphid'] = paragraphsSelector.eq(comment['dom']).attr('id'); | |
// set anchor for return button to paragraph | |
commentselector.eq(i).find('.return-to-paragraph').attr('href', '#' + comment['paragraphid']); | |
}; | |
/* | |
* Show comment-adding button when hoovering a paragraph | |
*/ | |
$('article p, article blockquote, article aside').mouseover(function(e) { | |
paragraph = $(this); | |
offsetcom = paragraph.offset(); | |
domPath = $(this).index(); | |
$("#new-comment-button").show(); | |
$("#new-comment-button").offset({ top: offsetcom.top, left: (offsetcom.left + em(55)) }); | |
}); | |
/* | |
* Add the comment input textarea when clicking on button | |
* The index of the paragraph is put in a hidden filed to be sent to server with comment content | |
*/ | |
$('#new-comment-button').click(function(e) { | |
$('.nav-panel-add-comment').show(); | |
$(".nav-panel-add-comment").offset({ top: offsetcom.top, left: offsetcom.left + em(57)}); | |
$("#comment_content").focus(); | |
$(".nav-panel-add-comment #comment_dom").val(domPath); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Quand ça marche si tu veux je peux refaire une passe sur ton JS pour l'opti un peu :)