Commit 50be5894b6a6407ab21986d8217e124dc24deb3c

Authored by Evandro Jr
1 parent df303518

code cleaned, selection color changed do yellow

plugins/comment_paragraph/controllers/profile/comment_paragraph_plugin_profile_controller.rb
... ... @@ -4,7 +4,7 @@ class CommentParagraphPluginProfileController < ProfileController
4 4 def view_comments
5 5 @article_id = params[:article_id]
6 6 @paragraph_id = params[:paragraph_id]
7   -
  7 +
8 8 article = profile.articles.find(@article_id)
9 9 @paragraph_comment_page = (params[:paragraph_comment_page] || 1).to_i
10 10  
... ...
plugins/comment_paragraph/lib/comment_paragraph_plugin.rb
... ... @@ -16,14 +16,14 @@ class CommentParagraphPlugin < Noosfero::Plugin
16 16 comment = args[:comment]
17 17 paragraph_id = comment.paragraph_id || args[:paragraph_id]
18 18 proc {
19   - arr = []
  19 + arr = []
20 20 arr << hidden_field_tag('comment[id]', comment.id)
21 21 arr << hidden_field_tag('comment[paragraph_id]', paragraph_id) if paragraph_id
22   - arr << hidden_field_tag('comment[comment_paragraph_selected_area]', comment.comment_paragraph_selected_area) if comment.comment_paragraph_selected_area
  22 + arr << hidden_field_tag('comment[comment_paragraph_selected_area]', comment.comment_paragraph_selected_area) if comment.comment_paragraph_selected_area
23 23 arr
24 24 }
25 25 end
26   -
  26 +
27 27 def comment_extra_contents(args)
28 28 comment = args[:comment]
29 29 proc {
... ...
plugins/comment_paragraph/lib/ext/article.rb
... ... @@ -12,6 +12,6 @@ class Article
12 12 errors[:base] << (N_('You are unable to change the body of the article when paragraphs are commented')) unless (paragraphs_with_comments).empty?
13 13 end
14 14 end
15   -
  15 +
16 16 end
17 17  
... ...
plugins/comment_paragraph/lib/ext/comment.rb
... ... @@ -3,9 +3,9 @@ require_dependency &#39;comment&#39;
3 3 class Comment
4 4  
5 5 scope :without_paragraph, :conditions => {:paragraph_id => nil }
6   -
  6 +
7 7 settings_items :comment_paragraph_selected_area, :type => :string
8   -
  8 +
9 9 scope :in_paragraph, proc { |paragraph_id| {
10 10 :conditions => ['paragraph_id = ?', paragraph_id]
11 11 }
... ...
plugins/comment_paragraph/public/comment_paragraph.js
... ... @@ -11,7 +11,7 @@ function makeCommentable() {
11 11 tinyMCE.activeEditor.setContent(paragraphsTxt)
12 12 return;
13 13 }
14   -
  14 +
15 15 jQuery('#article_body_ifr').contents().find('body').children('p').each(function( index ) {
16 16 paragraphsTxt+='<p><div class="macro article_comments" data-macro="comment_paragraph_plugin/allow_comment" data-macro-paragraph_id="' + index + '">' + jQuery(this).html() + '</div></p><br>'
17 17 });
... ...
plugins/comment_paragraph/public/comment_paragraph_macro.js
... ... @@ -20,25 +20,17 @@ jQuery(document).ready(function($) {
20 20 if(lastParagraph[paragraphId]){
21 21 rootElement.innerHTML = lastParagraph[paragraphId];
22 22 }
23   - });
24   -
  23 + });
  24 +
25 25 //highlight area from the paragraph
26 26 $('.comment_paragraph').mouseup(function(){
27 27 var paragraphId = getIdCommentParagraph($(this)[0].id);
28 28 var rootElement = $(this).get(0);
29   -
30 29 lastParagraph[paragraphId] = rootElement.innerHTML;
31   -
32   - console.log(rootElement);
33   -
34 30 var selObj = rangy.getSelection();
35   - var selected_area = rangy.serializeSelection(selObj, true,rootElement);
36   -
  31 + var selected_area = rangy.serializeSelection(selObj, true,rootElement);
37 32 cssApplier.toggleSelection();
38   -
39   - lastSelectedArea[paragraphId] = selected_area;
40   - //cssApplier.toggleSelection();
41   -
  33 + lastSelectedArea[paragraphId] = selected_area;
42 34 form = jQuery(this).parent().find('form');
43 35 if (form.find('input.selected_area').length === 0){
44 36 jQuery('<input>').attr({
... ... @@ -49,20 +41,9 @@ jQuery(document).ready(function($) {
49 41 }).appendTo(form)
50 42 }else{
51 43 form.find('input.selected_area').val(selected_area)
52   - }
  44 + }
53 45 rootElement.focus();
54   - });
55   -
56   -
57   -// em <li id="comment-31" class="article-comment"> colocar um data-paragraph e data-selected-area
58   -// //highlight area from the paragraph
59   -// $('.article-comment').mouseover(function(){
60   -// rootElement = $('#comment_paragraph_' + this).get(0);
61   -// var selObj = rangy.getSelection();
62   -// var se = $('#result').val();
63   -// rangy.deserializeSelection(se, rootElement);
64   -// cssApplier.toggleSelection();
65   -// });
  46 + });
66 47  
67 48 function processAnchor(){
68 49 var anchor = window.location.hash;
... ... @@ -84,41 +65,30 @@ jQuery(document).ready(function($) {
84 65 }
85 66 });
86 67 }
87   -
  68 +
88 69 processAnchor();
89   -
  70 +
90 71 $(document).on('mouseover', 'li.article-comment', function(){
91 72 var selected_area = $(this).find('input.paragraph_comment_area').val();
92 73 var paragraph_id = $(this).find('input.paragraph_id').val();
93 74 var rootElement = $('#comment_paragraph_'+ paragraph_id).get(0);
94   -
  75 +
95 76 if(lastParagraph[paragraph_id] == null || lastParagraph[paragraph_id] == 'undefined'){
96   - console.log(rootElement.innerHTML);
97 77 lastParagraph[paragraph_id] = rootElement.innerHTML;
98 78 }
99 79 else {
100 80 rootElement.innerHTML = lastParagraph[paragraph_id] ;
101 81 }
102   -
103   - //console.log(rootElement.innerHTML);
104   - console.log("selected_area = '" + selected_area + "'");
105 82 if(selected_area != ""){
106 83 rangy.deserializeSelection(selected_area, rootElement);
107 84 cssApplier.toggleSelection();
108 85 }
109 86 });
110   -
  87 +
111 88 $(document).on('mouseout', 'li.article-comment', function(){
112 89 var paragraph_id = $(this).find('input.paragraph_id').val();
113   - console.log("mouseout paragraph_id = " + paragraph_id);
114 90 var rootElement = $('#comment_paragraph_'+ paragraph_id).get(0);
115   - console.log(lastParagraph[paragraph_id]);
116   -
117   -// cssApplier.undoToSelection();
118   -//
119   -// cssApplier.toggleSelection();
120   -
121   -
  91 +
122 92 if(lastSelectedArea[paragraph_id] != null && lastSelectedArea[paragraph_id] != 'undefined' ){
123 93 rootElement = $('#comment_paragraph_'+ paragraph_id).get(0);
124 94 rootElement.innerHTML = lastParagraph[paragraph_id];
... ... @@ -129,30 +99,9 @@ jQuery(document).ready(function($) {
129 99 var sel = rangy.getSelection();
130 100 sel.removeAllRanges();
131 101 }
132   -
133   -//var selected_area = $(this).find('input.paragraph_comment_area').val();
134   - //var paragraph_id = $(this).find('input.paragraph_id').val();
135   - //var rootElement = $('#comment_paragraph_'+ paragraph_id).get(0);
136   - //console.log(rootElement.innerHTML);
137   - //console.log(selected_area);
138   - //rangy.deserializeSelection(selected_area, rootElement);
139   - //cssApplier.toggleSelection();
140   - //window.last_paragraph
141   - //if(last_selected_area)
142 102 });
143   -
144 103 });
145 104  
146   -function selectAreaForComment(paragraph){
147   -// console.log(this)
148   -// alert("Paragrafo " + paragraph)
149   -// cssApplier.toggleSelection();
150   -// saveSelection();
151   -// var selObj = rangy.getSelection();
152   -// var se = rangy.serializeSelection(selObj, true,rootElement);
153   -}
154   -
155   -
156 105 function toggleParagraph(paragraph) {
157 106 var div = jQuery('div.comments_list_toggle_paragraph_'+paragraph);
158 107 var visible = div.is(':visible');
... ... @@ -170,20 +119,3 @@ function loadCompleted(paragraph) {
170 119 comment_paragraph_anchor = null;
171 120 }
172 121 }
173   -
174   -
175   -
176   -//Return a string with the beggining and the end of the selection of a text area separated by colon
177   -function getSelectionBounderies(textareaId){
178   -
179   -// var textarea = document.getElementById(textareaId);
180   -// if ('selectionStart' in textarea) {
181   -// // check whether some text is selected in the textarea
182   -// if (textarea.selectionStart != textarea.selectionEnd) {
183   -// alert(textarea.selectionStart + ":" + textarea.selectionEnd)
184   -// return textarea.selectionStart + ":" + textarea.selectionEnd;
185   -// }
186   -// }
187   -
188   - return false
189   -}
... ...
plugins/comment_paragraph/public/style.css
... ... @@ -21,12 +21,12 @@ div.article-comments-list-more{
21 21 }
22 22  
23 23 .commented-area {
24   - background-color: #a8d1ff;
  24 + background-color: #FFFF66;
25 25 }
26 26  
27 27 ::selection {
28   - background: #a8d1ff; /* WebKit/Blink Browsers */
  28 + background: #FFFF66; /* WebKit/Blink Browsers */
29 29 }
30 30 ::-moz-selection {
31   - background: #a8d1ff; /* Gecko Browsers */
  31 + background: #FFFF66; /* Gecko Browsers */
32 32 }
33 33 \ No newline at end of file
... ...
plugins/comment_paragraph/test/functional/content_viewer_controller_test.rb
... ... @@ -2,9 +2,9 @@ require File.dirname(__FILE__) + &#39;/../test_helper&#39;
2 2  
3 3 class ContentViewerController
4 4 append_view_path File.join(File.dirname(__FILE__) + '/../../views')
5   - def rescue_action(e)
6   - raise e
7   - end
  5 + def rescue_action(e)
  6 + raise e
  7 + end
8 8 end
9 9  
10 10 class ContentViewerControllerTest < ActionController::TestCase
... ...