diff --git a/db/migrate/20140715190748_add_setting_to_comments.rb b/db/migrate/20140715190748_add_setting_to_comments.rb new file mode 100644 index 0000000..b709771 --- /dev/null +++ b/db/migrate/20140715190748_add_setting_to_comments.rb @@ -0,0 +1,9 @@ +class AddSettingToComments < ActiveRecord::Migration + def self.up + add_column :comments, :setting, :text unless column_exists?(:comments, :setting) + end + + def self.down + remove_column :comments, :setting + end +end diff --git a/db/migrate/20140715201629_add_paragraph_id_to_comment.rb b/db/migrate/20140715201629_add_paragraph_id_to_comment.rb index fa72648..639f4ca 100644 --- a/db/migrate/20140715201629_add_paragraph_id_to_comment.rb +++ b/db/migrate/20140715201629_add_paragraph_id_to_comment.rb @@ -1,6 +1,6 @@ class AddParagraphIdToComment < ActiveRecord::Migration def self.up - add_column :comments, :paragraph_id, :integer + add_column :comments, :paragraph_id, :integer unless column_exists?(:comments, :paragraph_id) end def self.down diff --git a/public/comment_paragraph.js b/public/comment_paragraph.js index 1ca7767..eb3bf22 100644 --- a/public/comment_paragraph.js +++ b/public/comment_paragraph.js @@ -1,9 +1,40 @@ +String.prototype.startsWith = function(needle){ + return(this.indexOf(needle) == 0); +}; + function makeCommentable() { - paragraphsTxt=""; - //Add p tag, when opening the editor. For some season it comes without p tag + var paragraphsTxt=""; + var selectedTextCount=0; + var notSelectedTextCount=0; + var text; + + //Search for text that is not selected in the middle of selected text, in this case unselect everything + jQuery('#article_body_ifr').contents().find('body').children().each(function( index ) { + //Check if there are other texts not selected + var element=jQuery(this).prop('outerHTML'); + console.log(element); + if(element.startsWith('

') && ! element.startsWith('

 

') ){ + notSelectedTextCount++; + } + } + }); + + if(selectedTextCount > 0 && notSelectedTextCount>0){ + jQuery('#article_body_ifr').contents().find('body').children('.paragraph_comment').contents().unwrap(); + //Workaround necessary to post the body of the article + tinymce.activeEditor.execCommand('mceInsertContent', false, " "); + return; + } + + //Add p tag, when opening the editor. For some season it appear at the end without p tag foundCommentableParagraph = false; jQuery('#article_body_ifr').contents().find('body').children('div.article_comments').each(function( index ) { - paragraphsTxt+="

" + jQuery(this).html() + "

"; + if(jQuery(this).html()!="" && jQuery(this).html()!=" " && jQuery(this).html()!="
"){ + paragraphsTxt+="

" + jQuery(this).html() + "

"; + } foundCommentableParagraph = true; }); @@ -12,17 +43,16 @@ function makeCommentable() { tinyMCE.activeEditor.setContent(paragraphsTxt); return; } - + //Wraps the paragraph using the chosen class - jQuery('#article_body_ifr').contents().find('body').children('p').each(function( index ) { - text = jQuery(this).html().trim(); + jQuery('#article_body_ifr').contents().find('body').children('p,table,img').each(function( index ) { + text=jQuery(this).prop('outerHTML'); if(text!="" && text!=" " && text!="
"){ - paragraphsTxt+='

' + text + '


' + paragraphsTxt+='
' + text + '

' } }); tinyMCE.activeEditor.setContent(paragraphsTxt); //Workaround necessary to post the body of the article tinymce.activeEditor.execCommand('mceInsertContent', false, " "); -} - +} \ No newline at end of file diff --git a/public/style.css b/public/style.css index 328b448..c899101 100644 --- a/public/style.css +++ b/public/style.css @@ -40,7 +40,12 @@ div.article-comments-list-more{ } .comment_paragraph{ - padding: 0px; + padding: 0px; + +} + +.article-body{ + word-wrap: break-word; } .triangle-right { -- libgit2 0.21.2