Commit efd5c28fceff5a030f1009f0f0e80050137b1c23

Authored by Evandro Jr
1 parent 5a492549
Exists in master

Fixed selection of tables and images

db/migrate/20140715190748_add_setting_to_comments.rb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +class AddSettingToComments < ActiveRecord::Migration
  2 + def self.up
  3 + add_column :comments, :setting, :text unless column_exists?(:comments, :setting)
  4 + end
  5 +
  6 + def self.down
  7 + remove_column :comments, :setting
  8 + end
  9 +end
... ...
db/migrate/20140715201629_add_paragraph_id_to_comment.rb
1 1 class AddParagraphIdToComment < ActiveRecord::Migration
2 2 def self.up
3   - add_column :comments, :paragraph_id, :integer
  3 + add_column :comments, :paragraph_id, :integer unless column_exists?(:comments, :paragraph_id)
4 4 end
5 5  
6 6 def self.down
... ...
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>&nbsp;</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
... ...
public/style.css
... ... @@ -40,7 +40,12 @@ div.article-comments-list-more{
40 40 }
41 41  
42 42 .comment_paragraph{
43   - padding: 0px;
  43 + padding: 0px;
  44 +
  45 +}
  46 +
  47 +.article-body{
  48 + word-wrap: break-word;
44 49 }
45 50  
46 51 .triangle-right {
... ...