diff --git a/controllers/profile/comment_paragraph_plugin_profile_controller.rb b/controllers/profile/comment_paragraph_plugin_profile_controller.rb index 42133c7..a87b1fc 100644 --- a/controllers/profile/comment_paragraph_plugin_profile_controller.rb +++ b/controllers/profile/comment_paragraph_plugin_profile_controller.rb @@ -11,7 +11,6 @@ class CommentParagraphPluginProfileController < ProfileController @comments = article.comments.without_spam.in_paragraph(@paragraph_id) @comments_count = @comments.count @comments = @comments.without_reply.paginate(:per_page => per_page, :page => @paragraph_comment_page ) - @no_more_pages = @comments_count <= @paragraph_comment_page * per_page end diff --git a/lib/comment_paragraph_plugin.rb b/lib/comment_paragraph_plugin.rb index 7ee7591..bb2993a 100644 --- a/lib/comment_paragraph_plugin.rb +++ b/lib/comment_paragraph_plugin.rb @@ -23,6 +23,13 @@ class CommentParagraphPlugin < Noosfero::Plugin arr } end + + def comment_extra_contents(args) + comment = args[:comment] + proc { + render :file => 'comment/comment_extra', :locals => {:comment => comment} + } + end def js_files ['comment_paragraph_macro', 'rangy-core', 'rangy-cssclassapplier', 'rangy-serializer'] diff --git a/lib/ext/comment.rb b/lib/ext/comment.rb index 9d6319c..b91ac57 100644 --- a/lib/ext/comment.rb +++ b/lib/ext/comment.rb @@ -5,7 +5,7 @@ class Comment scope :without_paragraph, :conditions => {:paragraph_id => nil } settings_items :comment_paragraph_selected_area, :type => :string - + scope :in_paragraph, proc { |paragraph_id| { :conditions => ['paragraph_id = ?', paragraph_id] } diff --git a/public/comment_paragraph_macro.js b/public/comment_paragraph_macro.js index bbe40e4..a17368e 100644 --- a/public/comment_paragraph_macro.js +++ b/public/comment_paragraph_macro.js @@ -1,4 +1,7 @@ var comment_paragraph_anchor; + +var ParagraphSelectionCache = {}; + jQuery(document).ready(function($) { rangy.init(); cssApplier = rangy.createCssClassApplier("commented-area", {normalize: false}); @@ -7,15 +10,28 @@ jQuery(document).ready(function($) { $(this).find('.commented-area').replaceWith(function() { return $(this).html(); }); + var rootElement = $(this).get(0); + if(ParagraphSelectionCache.last_paragraph){ + rootElement.innerHTML = ParagraphSelectionCache.last_paragraph; + } }); //highlight area from the paragraph $('.comment_paragraph').mouseup(function(){ - rootElement = $(this).get(0); - console.log(rootElement) - cssApplier.toggleSelection(); + var rootElement = $(this).get(0); + + ParagraphSelectionCache.last_paragraph = rootElement.innerHTML; + + console.log(rootElement) ; + var selObj = rangy.getSelection(); var selected_area = rangy.serializeSelection(selObj, true,rootElement); + + cssApplier.toggleSelection(); + + ParagraphSelectionCache.last_selected_area = selected_area; + //cssApplier.toggleSelection(); + form = jQuery(this).parent().find('form'); if (form.find('input.selected_area').length === 0){ jQuery('').attr({ @@ -32,14 +48,14 @@ jQuery(document).ready(function($) { // em
  • colocar um data-paragraph e data-selected-area - //highlight area from the paragraph - $('.article-comment').mouseover(function(){ - rootElement = $('#comment_paragraph_' + this).get(0); - var selObj = rangy.getSelection(); - var se = $('#result').val(); - rangy.deserializeSelection(se, rootElement); - cssApplier.toggleSelection(); - }); +// //highlight area from the paragraph +// $('.article-comment').mouseover(function(){ +// rootElement = $('#comment_paragraph_' + this).get(0); +// var selObj = rangy.getSelection(); +// var se = $('#result').val(); +// rangy.deserializeSelection(se, rootElement); +// cssApplier.toggleSelection(); +// }); function processSomething(){ var anchor = window.location.hash; @@ -64,6 +80,57 @@ jQuery(document).ready(function($) { processSomething(); + $(document).on('mouseover', 'li.article-comment', function(){ + var selected_area = $(this).find('input.paragraph_comment_area').val(); + var paragraph_id = $(this).find('input.paragraph_id').val(); + var rootElement = $('#comment_paragraph_'+ paragraph_id).get(0); + + if(ParagraphSelectionCache.last_paragraph == null || ParagraphSelectionCache.last_paragraph == 'undefined'){ + console.log(rootElement.innerHTML); + ParagraphSelectionCache.last_paragraph = rootElement.innerHTML; + } + else { + rootElement.innerHTML = ParagraphSelectionCache.last_paragraph ; + } + + //console.log(rootElement.innerHTML); + console.log(selected_area); + rangy.deserializeSelection(selected_area, rootElement); + cssApplier.toggleSelection(); + }); + + $(document).on('mouseout', 'li.article-comment', function(){ + var paragraph_id = $(this).find('input.paragraph_id').val(); + var rootElement = $('#comment_paragraph_'+ paragraph_id).get(0); + console.log(ParagraphSelectionCache.last_paragraph); + +// cssApplier.undoToSelection(); +// +// cssApplier.toggleSelection(); + + + if(ParagraphSelectionCache.last_selected_area != null && ParagraphSelectionCache.last_selected_area != 'undefined' ){ + rootElement = $('#comment_paragraph_'+ paragraph_id).get(0); + rootElement.innerHTML = ParagraphSelectionCache.last_paragraph ; + rangy.deserializeSelection(ParagraphSelectionCache.last_selected_area, rootElement); + cssApplier.toggleSelection(); + } else { + cssApplier.toggleSelection(); + var sel = rangy.getSelection(); + sel.removeAllRanges(); + } + +//var selected_area = $(this).find('input.paragraph_comment_area').val(); + //var paragraph_id = $(this).find('input.paragraph_id').val(); + //var rootElement = $('#comment_paragraph_'+ paragraph_id).get(0); + //console.log(rootElement.innerHTML); + //console.log(selected_area); + //rangy.deserializeSelection(selected_area, rootElement); + //cssApplier.toggleSelection(); + //window.last_paragraph + //if(last_selected_area) + }); + }); function selectAreaForComment(paragraph){ diff --git a/views/comment/comment_extra.html.erb b/views/comment/comment_extra.html.erb new file mode 100644 index 0000000..5fb240b --- /dev/null +++ b/views/comment/comment_extra.html.erb @@ -0,0 +1,2 @@ + + diff --git a/views/comment_paragraph_plugin_profile/_comment_paragraph.html.erb b/views/comment_paragraph_plugin_profile/_comment_paragraph.html.erb index 8412fea..52845f1 100644 --- a/views/comment_paragraph_plugin_profile/_comment_paragraph.html.erb +++ b/views/comment_paragraph_plugin_profile/_comment_paragraph.html.erb @@ -28,13 +28,4 @@ - - - - \ No newline at end of file + \ No newline at end of file -- libgit2 0.21.2