diff --git a/controllers/public/comment_paragraph_plugin_public_controller.rb b/controllers/public/comment_paragraph_plugin_public_controller.rb index dc07016..9ee280e 100644 --- a/controllers/public/comment_paragraph_plugin_public_controller.rb +++ b/controllers/public/comment_paragraph_plugin_public_controller.rb @@ -2,7 +2,8 @@ class CommentParagraphPluginPublicController < PublicController append_view_path File.join(File.dirname(__FILE__) + '/../views') def comment_paragraph - render :json => { :paragraph_id => Comment.find(params[:id]).paragraph_id } + @comment = Comment.find(params[:id]) + render :json => { :paragraph_id => comment.paragraph_id } end end diff --git a/lib/comment_paragraph_plugin.rb b/lib/comment_paragraph_plugin.rb index dc3dfad..5f5ad05 100644 --- a/lib/comment_paragraph_plugin.rb +++ b/lib/comment_paragraph_plugin.rb @@ -16,7 +16,11 @@ class CommentParagraphPlugin < Noosfero::Plugin comment = args[:comment] paragraph_id = comment.paragraph_id || args[:paragraph_id] proc { - hidden_field_tag('comment[paragraph_id]', paragraph_id) if paragraph_id + arr = [] + arr << hidden_field_tag('comment[id]', comment.id) + arr << hidden_field_tag('comment[paragraph_id]', paragraph_id) if paragraph_id + arr << hidden_field_tag('comment[comment_paragraph_selected_area]', comment_paragraph_selected_area) if comment_paragraph_selected_area + arr } end diff --git a/lib/ext/comment.rb b/lib/ext/comment.rb index d37d3ca..76e3e46 100644 --- a/lib/ext/comment.rb +++ b/lib/ext/comment.rb @@ -11,6 +11,6 @@ class Comment } } - attr_accessible :paragraph_id, :comment_paragraph_selected_area + attr_accessible :paragraph_id, :comment_paragraph_selected_area, :id end diff --git a/public/comment_paragraph_macro.js b/public/comment_paragraph_macro.js index 6817bc9..bbe40e4 100644 --- a/public/comment_paragraph_macro.js +++ b/public/comment_paragraph_macro.js @@ -1,20 +1,7 @@ var comment_paragraph_anchor; jQuery(document).ready(function($) { - rangy.init(); cssApplier = rangy.createCssClassApplier("commented-area", {normalize: false}); - var rootElement; - -// $('.bt-marker').click(function(){ -// console.log($(this).data('paragraph-id')); -// rootElement = $('#' + 'comment_paragraph' + $(this).data('paragraph-id')).get(0); -// cssApplier.toggleSelection(); -// var selObj = rangy.getSelection(); -// var se = rangy.serializeSelection(selObj, true,rootElement); -// //$('#result').val(se); -// }); - - //Undo previous highlight from the paragraph $('.comment_paragraph').mousedown(function(){ $(this).find('.commented-area').replaceWith(function() { @@ -22,20 +9,18 @@ jQuery(document).ready(function($) { }); }); - //highlight area from the paragraph + //highlight area from the paragraph $('.comment_paragraph').mouseup(function(){ rootElement = $(this).get(0); console.log(rootElement) cssApplier.toggleSelection(); var selObj = rangy.getSelection(); var selected_area = rangy.serializeSelection(selObj, true,rootElement); - - alert(selected_area) - form = jQuery(this).parent().find('form'); if (form.find('input.selected_area').length === 0){ jQuery('').attr({ class: 'selected_area', + type: 'hidden', name: 'comment[comment_paragraph_selected_area]', value: selected_area }).appendTo(form) @@ -45,27 +30,39 @@ jQuery(document).ready(function($) { rootElement.focus(); }); - - - var anchor = window.location.hash; - if(anchor.length==0) return; - var val = anchor.split('-'); //anchor format = #comment-\d+ - if(val.length!=2 || val[0]!='#comment') return; - if($('div[data-macro=comment_paragraph_plugin/allow_comment]').length==0) return; //comment_paragraph_plugin/allow_comment div must exists - var comment_id = val[1]; - if(!/^\d+$/.test(comment_id)) return; //test for integer - - comment_paragraph_anchor = anchor; - var url = '/plugin/comment_paragraph/public/comment_paragraph/'+comment_id; - $.getJSON(url, function(data) { - if(data.paragraph_id!=null) { - var button = $('div.comment_paragraph_'+ data.paragraph_id + ' a'); - button.click(); - $.scrollTo(button); - } +// 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(); }); + + function processSomething(){ + var anchor = window.location.hash; + if(anchor.length==0) return; + + var val = anchor.split('-'); //anchor format = #comment-\d+ + if(val.length!=2 || val[0]!='#comment') return; + if($('div[data-macro=comment_paragraph_plugin/allow_comment]').length==0) return; //comment_paragraph_plugin/allow_comment div must exists + var comment_id = val[1]; + if(!/^\d+$/.test(comment_id)) return; //test for integer + + comment_paragraph_anchor = anchor; + var url = '/plugin/comment_paragraph/public/comment_paragraph/'+comment_id; + $.getJSON(url, function(data) { + if(data.paragraph_id!=null) { + var button = $('div.comment_paragraph_'+ data.paragraph_id + ' a'); + button.click(); + $.scrollTo(button); + } + }); + } + processSomething(); }); diff --git a/public/style.css b/public/style.css index 4677728..d816c09 100644 --- a/public/style.css +++ b/public/style.css @@ -21,5 +21,12 @@ div.article-comments-list-more{ } .commented-area { - background-color: yellow; + background-color: #a8d1ff; +} + +::selection { + background: #a8d1ff; /* WebKit/Blink Browsers */ +} +::-moz-selection { + background: #a8d1ff; /* Gecko Browsers */ } \ No newline at end of file diff --git a/views/comment_paragraph_plugin_profile/_comment_paragraph.html.erb b/views/comment_paragraph_plugin_profile/_comment_paragraph.html.erb index 38fe77d..8412fea 100644 --- a/views/comment_paragraph_plugin_profile/_comment_paragraph.html.erb +++ b/views/comment_paragraph_plugin_profile/_comment_paragraph.html.erb @@ -24,7 +24,17 @@
    <%= render :partial => 'comment/comment_form', :locals => {:comment => Comment.new, :display_link => true, :cancel_triggers_hide => true, :paragraph_id => paragraph_id}%> +


    + + + \ No newline at end of file -- libgit2 0.21.2