Commit 15eb6db63efbcc83d338c8b38a79a6fa2449e490

Authored by Evandro Jr
1 parent 7082e915

passing the selected area to the view

plugins/comment_paragraph/controllers/public/comment_paragraph_plugin_public_controller.rb
@@ -2,7 +2,8 @@ class CommentParagraphPluginPublicController < PublicController @@ -2,7 +2,8 @@ class CommentParagraphPluginPublicController < PublicController
2 append_view_path File.join(File.dirname(__FILE__) + '/../views') 2 append_view_path File.join(File.dirname(__FILE__) + '/../views')
3 3
4 def comment_paragraph 4 def comment_paragraph
5 - render :json => { :paragraph_id => Comment.find(params[:id]).paragraph_id } 5 + @comment = Comment.find(params[:id])
  6 + render :json => { :paragraph_id => comment.paragraph_id }
6 end 7 end
7 8
8 end 9 end
plugins/comment_paragraph/lib/comment_paragraph_plugin.rb
@@ -16,7 +16,11 @@ class CommentParagraphPlugin < Noosfero::Plugin @@ -16,7 +16,11 @@ class CommentParagraphPlugin < Noosfero::Plugin
16 comment = args[:comment] 16 comment = args[:comment]
17 paragraph_id = comment.paragraph_id || args[:paragraph_id] 17 paragraph_id = comment.paragraph_id || args[:paragraph_id]
18 proc { 18 proc {
19 - hidden_field_tag('comment[paragraph_id]', paragraph_id) if paragraph_id 19 + arr = []
  20 + arr << hidden_field_tag('comment[id]', comment.id)
  21 + arr << hidden_field_tag('comment[paragraph_id]', paragraph_id) if paragraph_id
  22 + arr << hidden_field_tag('comment[comment_paragraph_selected_area]', comment_paragraph_selected_area) if comment_paragraph_selected_area
  23 + arr
20 } 24 }
21 end 25 end
22 26
plugins/comment_paragraph/lib/ext/comment.rb
@@ -11,6 +11,6 @@ class Comment @@ -11,6 +11,6 @@ class Comment
11 } 11 }
12 } 12 }
13 13
14 - attr_accessible :paragraph_id, :comment_paragraph_selected_area 14 + attr_accessible :paragraph_id, :comment_paragraph_selected_area, :id
15 15
16 end 16 end
plugins/comment_paragraph/public/comment_paragraph_macro.js
1 var comment_paragraph_anchor; 1 var comment_paragraph_anchor;
2 jQuery(document).ready(function($) { 2 jQuery(document).ready(function($) {
3 -  
4 rangy.init(); 3 rangy.init();
5 cssApplier = rangy.createCssClassApplier("commented-area", {normalize: false}); 4 cssApplier = rangy.createCssClassApplier("commented-area", {normalize: false});
6 - var rootElement;  
7 -  
8 -// $('.bt-marker').click(function(){  
9 -// console.log($(this).data('paragraph-id'));  
10 -// rootElement = $('#' + 'comment_paragraph' + $(this).data('paragraph-id')).get(0);  
11 -// cssApplier.toggleSelection();  
12 -// var selObj = rangy.getSelection();  
13 -// var se = rangy.serializeSelection(selObj, true,rootElement);  
14 -// //$('#result').val(se);  
15 -// });  
16 -  
17 -  
18 //Undo previous highlight from the paragraph 5 //Undo previous highlight from the paragraph
19 $('.comment_paragraph').mousedown(function(){ 6 $('.comment_paragraph').mousedown(function(){
20 $(this).find('.commented-area').replaceWith(function() { 7 $(this).find('.commented-area').replaceWith(function() {
@@ -22,20 +9,18 @@ jQuery(document).ready(function($) { @@ -22,20 +9,18 @@ jQuery(document).ready(function($) {
22 }); 9 });
23 }); 10 });
24 11
25 - //highlight area from the paragraph 12 + //highlight area from the paragraph
26 $('.comment_paragraph').mouseup(function(){ 13 $('.comment_paragraph').mouseup(function(){
27 rootElement = $(this).get(0); 14 rootElement = $(this).get(0);
28 console.log(rootElement) 15 console.log(rootElement)
29 cssApplier.toggleSelection(); 16 cssApplier.toggleSelection();
30 var selObj = rangy.getSelection(); 17 var selObj = rangy.getSelection();
31 var selected_area = rangy.serializeSelection(selObj, true,rootElement); 18 var selected_area = rangy.serializeSelection(selObj, true,rootElement);
32 -  
33 - alert(selected_area)  
34 -  
35 form = jQuery(this).parent().find('form'); 19 form = jQuery(this).parent().find('form');
36 if (form.find('input.selected_area').length === 0){ 20 if (form.find('input.selected_area').length === 0){
37 jQuery('<input>').attr({ 21 jQuery('<input>').attr({
38 class: 'selected_area', 22 class: 'selected_area',
  23 + type: 'hidden',
39 name: 'comment[comment_paragraph_selected_area]', 24 name: 'comment[comment_paragraph_selected_area]',
40 value: selected_area 25 value: selected_area
41 }).appendTo(form) 26 }).appendTo(form)
@@ -45,27 +30,39 @@ jQuery(document).ready(function($) { @@ -45,27 +30,39 @@ jQuery(document).ready(function($) {
45 rootElement.focus(); 30 rootElement.focus();
46 }); 31 });
47 32
48 -  
49 -  
50 - var anchor = window.location.hash;  
51 - if(anchor.length==0) return;  
52 33
53 - var val = anchor.split('-'); //anchor format = #comment-\d+  
54 - if(val.length!=2 || val[0]!='#comment') return;  
55 - if($('div[data-macro=comment_paragraph_plugin/allow_comment]').length==0) return; //comment_paragraph_plugin/allow_comment div must exists  
56 - var comment_id = val[1];  
57 - if(!/^\d+$/.test(comment_id)) return; //test for integer  
58 -  
59 - comment_paragraph_anchor = anchor;  
60 - var url = '/plugin/comment_paragraph/public/comment_paragraph/'+comment_id;  
61 - $.getJSON(url, function(data) {  
62 - if(data.paragraph_id!=null) {  
63 - var button = $('div.comment_paragraph_'+ data.paragraph_id + ' a');  
64 - button.click();  
65 - $.scrollTo(button);  
66 - } 34 +// em <li id="comment-31" class="article-comment"> colocar um data-paragraph e data-selected-area
  35 + //highlight area from the paragraph
  36 + $('.article-comment').mouseover(function(){
  37 + rootElement = $('#comment_paragraph_' + this).get(0);
  38 + var selObj = rangy.getSelection();
  39 + var se = $('#result').val();
  40 + rangy.deserializeSelection(se, rootElement);
  41 + cssApplier.toggleSelection();
67 }); 42 });
  43 +
  44 + function processSomething(){
  45 + var anchor = window.location.hash;
  46 + if(anchor.length==0) return;
  47 +
  48 + var val = anchor.split('-'); //anchor format = #comment-\d+
  49 + if(val.length!=2 || val[0]!='#comment') return;
  50 + if($('div[data-macro=comment_paragraph_plugin/allow_comment]').length==0) return; //comment_paragraph_plugin/allow_comment div must exists
  51 + var comment_id = val[1];
  52 + if(!/^\d+$/.test(comment_id)) return; //test for integer
  53 +
  54 + comment_paragraph_anchor = anchor;
  55 + var url = '/plugin/comment_paragraph/public/comment_paragraph/'+comment_id;
  56 + $.getJSON(url, function(data) {
  57 + if(data.paragraph_id!=null) {
  58 + var button = $('div.comment_paragraph_'+ data.paragraph_id + ' a');
  59 + button.click();
  60 + $.scrollTo(button);
  61 + }
  62 + });
  63 + }
68 64
  65 + processSomething();
69 66
70 }); 67 });
71 68
plugins/comment_paragraph/public/style.css
@@ -21,5 +21,12 @@ div.article-comments-list-more{ @@ -21,5 +21,12 @@ div.article-comments-list-more{
21 } 21 }
22 22
23 .commented-area { 23 .commented-area {
24 - background-color: yellow; 24 + background-color: #a8d1ff;
  25 +}
  26 +
  27 +::selection {
  28 + background: #a8d1ff; /* WebKit/Blink Browsers */
  29 +}
  30 +::-moz-selection {
  31 + background: #a8d1ff; /* Gecko Browsers */
25 } 32 }
26 \ No newline at end of file 33 \ No newline at end of file
plugins/comment_paragraph/views/comment_paragraph_plugin_profile/_comment_paragraph.html.erb
@@ -24,7 +24,17 @@ @@ -24,7 +24,17 @@
24 </div> 24 </div>
25 <div id="page-comment-form-<%= paragraph_id %>" class='post_comment_box closed'> 25 <div id="page-comment-form-<%= paragraph_id %>" class='post_comment_box closed'>
26 <%= render :partial => 'comment/comment_form', :locals => {:comment => Comment.new, :display_link => true, :cancel_triggers_hide => true, :paragraph_id => paragraph_id}%> 26 <%= render :partial => 'comment/comment_form', :locals => {:comment => Comment.new, :display_link => true, :cancel_triggers_hide => true, :paragraph_id => paragraph_id}%>
  27 + <BR><BR><BR>
27 </div> 28 </div>
28 29
29 </div> 30 </div>
30 </div> 31 </div>
  32 +
  33 +<script>
  34 + jQuery(document).ready(function($) {
  35 + //if($(".article-comment").find("comment-<%#= id %>").length > 0){
  36 + // alert("achou comentario");
  37 + //}
  38 + });
  39 +</script>
  40 +
31 \ No newline at end of file 41 \ No newline at end of file