Commit ee1e174b5f208215462a9bf453fcf364ab10986f
1 parent
1c60cecf
Exists in
master
Comments being created with all the paragraphs selected
Showing
1 changed file
with
4 additions
and
43 deletions
Show diff stats
public/comment_paragraph.js
1 | -function getNextParagraphId() { | ||
2 | - max = -1; | ||
3 | - paragraphs = jQuery('#article_body_ifr').contents().find('.article_comments'); | ||
4 | - paragraphs.each(function(key, value) { | ||
5 | - value = jQuery(value).attr('data-macro-paragraph_id'); | ||
6 | - if(value>max) max = parseInt(value); | ||
7 | - }); | ||
8 | - return max+1; | ||
9 | -} | ||
10 | - | ||
11 | function makeCommentable() { | 1 | function makeCommentable() { |
12 | - tinyMCE.activeEditor.focus(); | ||
13 | - start = jQuery(tinyMCE.activeEditor.selection.getStart()).closest('p'); | ||
14 | - end = jQuery(tinyMCE.activeEditor.selection.getEnd()).closest('p'); | ||
15 | - | ||
16 | - //text = start.parent().children(); | ||
17 | - text = jQuery('#article_body_ifr').contents().find('*'); | ||
18 | - selection = text.slice(text.index(start), text.index(end)+1); | ||
19 | - | ||
20 | - hasTag = false; | ||
21 | - selection.each(function(key, value) { | ||
22 | - commentTag = jQuery(value).closest('.article_comments'); | ||
23 | - if(commentTag.length) { | ||
24 | - commentTag.children().unwrap('<div class=\"article_comments\"/>'); | ||
25 | - hasTag = true; | ||
26 | - } | 2 | + paragraphsTxt="" |
3 | + jQuery('#article_body_ifr').contents().find('body').children('p').each(function( index ) { | ||
4 | + paragraphsTxt+='<p><div class="macro article_comments" data-macro="comment_paragraph_plugin/allow_comment" data-macro-paragraph_id="' + index + '">' + jQuery(this).html() + '</p></div>' | ||
27 | }); | 5 | }); |
28 | - | ||
29 | - if(!hasTag) { | ||
30 | - tags = start.siblings().add(start); | ||
31 | - tags = tags.slice(tags.index(start), tags.index(end)>=0?tags.index(end)+1:tags.index(start)+1); | ||
32 | - tags.wrapAll('<div class=\"macro article_comments\" data-macro=\"comment_paragraph_plugin/allow_comment\" data-macro-paragraph_id=\"'+getNextParagraphId()+'\"/>'); | ||
33 | - | ||
34 | - contents = jQuery('#article_body_ifr').contents(); | ||
35 | - lastP = contents.find('p.article_comments_last_paragraph'); | ||
36 | - if(lastP.text().trim().length > 0) { | ||
37 | - lastP.removeClass('article_comments_last_paragraph'); | ||
38 | - } else { | ||
39 | - lastP.remove(); | ||
40 | - } | ||
41 | - lastDiv = contents.find('div.article_comments').last(); | ||
42 | - if(lastDiv.next().length==0) { | ||
43 | - lastDiv.after("<p class='article_comments_last_paragraph'> </p>"); | ||
44 | - } | ||
45 | - } | 6 | + tinyMCE.activeEditor.setContent(paragraphsTxt) |
46 | } | 7 | } |
47 | 8 |