Commit 74faf5993a9f10d1d452214e4a100bf26dfbda59
1 parent
847b6ddf
Exists in
master
passing the selected area to the view
Showing
6 changed files
with
58 additions
and
39 deletions
Show diff stats
controllers/public/comment_paragraph_plugin_public_controller.rb
| ... | ... | @@ -2,7 +2,8 @@ class CommentParagraphPluginPublicController < PublicController |
| 2 | 2 | append_view_path File.join(File.dirname(__FILE__) + '/../views') |
| 3 | 3 | |
| 4 | 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 | 7 | end |
| 7 | 8 | |
| 8 | 9 | end | ... | ... |
lib/comment_paragraph_plugin.rb
| ... | ... | @@ -16,7 +16,11 @@ class CommentParagraphPlugin < Noosfero::Plugin |
| 16 | 16 | comment = args[:comment] |
| 17 | 17 | paragraph_id = comment.paragraph_id || args[:paragraph_id] |
| 18 | 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 | 25 | end |
| 22 | 26 | ... | ... |
lib/ext/comment.rb
public/comment_paragraph_macro.js
| 1 | 1 | var comment_paragraph_anchor; |
| 2 | 2 | jQuery(document).ready(function($) { |
| 3 | - | |
| 4 | 3 | rangy.init(); |
| 5 | 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 | 5 | //Undo previous highlight from the paragraph |
| 19 | 6 | $('.comment_paragraph').mousedown(function(){ |
| 20 | 7 | $(this).find('.commented-area').replaceWith(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 | 13 | $('.comment_paragraph').mouseup(function(){ |
| 27 | 14 | rootElement = $(this).get(0); |
| 28 | 15 | console.log(rootElement) |
| 29 | 16 | cssApplier.toggleSelection(); |
| 30 | 17 | var selObj = rangy.getSelection(); |
| 31 | 18 | var selected_area = rangy.serializeSelection(selObj, true,rootElement); |
| 32 | - | |
| 33 | - alert(selected_area) | |
| 34 | - | |
| 35 | 19 | form = jQuery(this).parent().find('form'); |
| 36 | 20 | if (form.find('input.selected_area').length === 0){ |
| 37 | 21 | jQuery('<input>').attr({ |
| 38 | 22 | class: 'selected_area', |
| 23 | + type: 'hidden', | |
| 39 | 24 | name: 'comment[comment_paragraph_selected_area]', |
| 40 | 25 | value: selected_area |
| 41 | 26 | }).appendTo(form) |
| ... | ... | @@ -45,27 +30,39 @@ jQuery(document).ready(function($) { |
| 45 | 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 | ... | ... |
public/style.css
| ... | ... | @@ -21,5 +21,12 @@ div.article-comments-list-more{ |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 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 | 33 | \ No newline at end of file | ... | ... |
views/comment_paragraph_plugin_profile/_comment_paragraph.html.erb
| ... | ... | @@ -24,7 +24,17 @@ |
| 24 | 24 | </div> |
| 25 | 25 | <div id="page-comment-form-<%= paragraph_id %>" class='post_comment_box closed'> |
| 26 | 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 | 28 | </div> |
| 28 | 29 | |
| 29 | 30 | </div> |
| 30 | 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 | 41 | \ No newline at end of file | ... | ... |