Commit a0fd2411995fa2f5031341ff5b31209b5127e66c
1 parent
7cacfbaa
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Fixed selection of tables and images
Showing
5 changed files
with
55 additions
and
20 deletions
Show diff stats
db/migrate/20140505190748_add_setting_to_comments.rb
plugins/comment_paragraph/db/migrate/20140715190748_add_setting_to_comments.rb
0 → 100644
plugins/comment_paragraph/db/migrate/20140715201629_add_paragraph_id_to_comment.rb
plugins/comment_paragraph/public/comment_paragraph.js
| 1 | +String.prototype.startsWith = function(needle){ | |
| 2 | + return(this.indexOf(needle) == 0); | |
| 3 | +}; | |
| 4 | + | |
| 1 | 5 | function makeCommentable() { |
| 2 | - paragraphsTxt=""; | |
| 3 | - //Add p tag, when opening the editor. For some season it comes without p tag | |
| 6 | + var paragraphsTxt=""; | |
| 7 | + var selectedTextCount=0; | |
| 8 | + var notSelectedTextCount=0; | |
| 9 | + var text; | |
| 10 | + | |
| 11 | + //Search for text that is not selected in the middle of selected text, in this case unselect everything | |
| 12 | + jQuery('#article_body_ifr').contents().find('body').children().each(function( index ) { | |
| 13 | + //Check if there are other texts not selected | |
| 14 | + var element=jQuery(this).prop('outerHTML'); | |
| 15 | + console.log(element); | |
| 16 | + if(element.startsWith('<div')){ | |
| 17 | + selectedTextCount++; | |
| 18 | + }else{ | |
| 19 | + if(! element.startsWith('<p><br></p>') && ! element.startsWith('<p> </p>') ){ | |
| 20 | + notSelectedTextCount++; | |
| 21 | + } | |
| 22 | + } | |
| 23 | + }); | |
| 24 | + | |
| 25 | + if(selectedTextCount > 0 && notSelectedTextCount>0){ | |
| 26 | + jQuery('#article_body_ifr').contents().find('body').children('.paragraph_comment').contents().unwrap(); | |
| 27 | + //Workaround necessary to post the body of the article | |
| 28 | + tinymce.activeEditor.execCommand('mceInsertContent', false, " "); | |
| 29 | + return; | |
| 30 | + } | |
| 31 | + | |
| 32 | + //Add p tag, when opening the editor. For some season it appear at the end without p tag | |
| 4 | 33 | foundCommentableParagraph = false; |
| 5 | 34 | jQuery('#article_body_ifr').contents().find('body').children('div.article_comments').each(function( index ) { |
| 6 | - paragraphsTxt+="<p>" + jQuery(this).html() + "</p>"; | |
| 35 | + if(jQuery(this).html()!="" && jQuery(this).html()!=" " && jQuery(this).html()!="<br>"){ | |
| 36 | + paragraphsTxt+="<p>" + jQuery(this).html() + "</p>"; | |
| 37 | + } | |
| 7 | 38 | foundCommentableParagraph = true; |
| 8 | 39 | }); |
| 9 | 40 | |
| ... | ... | @@ -12,17 +43,16 @@ function makeCommentable() { |
| 12 | 43 | tinyMCE.activeEditor.setContent(paragraphsTxt); |
| 13 | 44 | return; |
| 14 | 45 | } |
| 15 | - | |
| 46 | + | |
| 16 | 47 | //Wraps the paragraph using the chosen class |
| 17 | - jQuery('#article_body_ifr').contents().find('body').children('p').each(function( index ) { | |
| 18 | - text = jQuery(this).html().trim(); | |
| 48 | + jQuery('#article_body_ifr').contents().find('body').children('p,table,img').each(function( index ) { | |
| 49 | + text=jQuery(this).prop('outerHTML'); | |
| 19 | 50 | if(text!="" && text!=" " && text!="<br>"){ |
| 20 | - paragraphsTxt+='<p><div class="macro article_comments" data-macro="comment_paragraph_plugin/allow_comment" data-macro-paragraph_id="' + index + '">' + text + '</div></p><br>' | |
| 51 | + paragraphsTxt+='<div class="macro article_comments paragraph_comment" data-macro="comment_paragraph_plugin/allow_comment" data-macro-paragraph_id="' + index + '">' + text + '</div><br>' | |
| 21 | 52 | } |
| 22 | 53 | }); |
| 23 | 54 | tinyMCE.activeEditor.setContent(paragraphsTxt); |
| 24 | 55 | |
| 25 | 56 | //Workaround necessary to post the body of the article |
| 26 | 57 | tinymce.activeEditor.execCommand('mceInsertContent', false, " "); |
| 27 | -} | |
| 28 | - | |
| 58 | +} | |
| 29 | 59 | \ No newline at end of file | ... | ... |
plugins/comment_paragraph/public/style.css