Commit e34756f0debb9f83f768261db0d4a6e5deb7958e

Authored by Evandro Jr
1 parent e4c235fe
Exists in master

code cleaned, selection color changed do yellow

controllers/profile/comment_paragraph_plugin_profile_controller.rb
@@ -4,7 +4,7 @@ class CommentParagraphPluginProfileController < ProfileController @@ -4,7 +4,7 @@ class CommentParagraphPluginProfileController < ProfileController
4 def view_comments 4 def view_comments
5 @article_id = params[:article_id] 5 @article_id = params[:article_id]
6 @paragraph_id = params[:paragraph_id] 6 @paragraph_id = params[:paragraph_id]
7 - 7 +
8 article = profile.articles.find(@article_id) 8 article = profile.articles.find(@article_id)
9 @paragraph_comment_page = (params[:paragraph_comment_page] || 1).to_i 9 @paragraph_comment_page = (params[:paragraph_comment_page] || 1).to_i
10 10
lib/comment_paragraph_plugin.rb
@@ -16,14 +16,14 @@ class CommentParagraphPlugin < Noosfero::Plugin @@ -16,14 +16,14 @@ 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 - arr = [] 19 + arr = []
20 arr << hidden_field_tag('comment[id]', comment.id) 20 arr << hidden_field_tag('comment[id]', comment.id)
21 arr << hidden_field_tag('comment[paragraph_id]', paragraph_id) if paragraph_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.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 arr 23 arr
24 } 24 }
25 end 25 end
26 - 26 +
27 def comment_extra_contents(args) 27 def comment_extra_contents(args)
28 comment = args[:comment] 28 comment = args[:comment]
29 proc { 29 proc {
lib/ext/article.rb
@@ -12,6 +12,6 @@ class Article @@ -12,6 +12,6 @@ class Article
12 errors[:base] << (N_('You are unable to change the body of the article when paragraphs are commented')) unless (paragraphs_with_comments).empty? 12 errors[:base] << (N_('You are unable to change the body of the article when paragraphs are commented')) unless (paragraphs_with_comments).empty?
13 end 13 end
14 end 14 end
15 - 15 +
16 end 16 end
17 17
lib/ext/comment.rb
@@ -3,9 +3,9 @@ require_dependency &#39;comment&#39; @@ -3,9 +3,9 @@ require_dependency &#39;comment&#39;
3 class Comment 3 class Comment
4 4
5 scope :without_paragraph, :conditions => {:paragraph_id => nil } 5 scope :without_paragraph, :conditions => {:paragraph_id => nil }
6 - 6 +
7 settings_items :comment_paragraph_selected_area, :type => :string 7 settings_items :comment_paragraph_selected_area, :type => :string
8 - 8 +
9 scope :in_paragraph, proc { |paragraph_id| { 9 scope :in_paragraph, proc { |paragraph_id| {
10 :conditions => ['paragraph_id = ?', paragraph_id] 10 :conditions => ['paragraph_id = ?', paragraph_id]
11 } 11 }
public/comment_paragraph.js
@@ -11,7 +11,7 @@ function makeCommentable() { @@ -11,7 +11,7 @@ function makeCommentable() {
11 tinyMCE.activeEditor.setContent(paragraphsTxt) 11 tinyMCE.activeEditor.setContent(paragraphsTxt)
12 return; 12 return;
13 } 13 }
14 - 14 +
15 jQuery('#article_body_ifr').contents().find('body').children('p').each(function( index ) { 15 jQuery('#article_body_ifr').contents().find('body').children('p').each(function( index ) {
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>' 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 });
public/comment_paragraph_macro.js
@@ -20,25 +20,17 @@ jQuery(document).ready(function($) { @@ -20,25 +20,17 @@ jQuery(document).ready(function($) {
20 if(lastParagraph[paragraphId]){ 20 if(lastParagraph[paragraphId]){
21 rootElement.innerHTML = lastParagraph[paragraphId]; 21 rootElement.innerHTML = lastParagraph[paragraphId];
22 } 22 }
23 - });  
24 - 23 + });
  24 +
25 //highlight area from the paragraph 25 //highlight area from the paragraph
26 $('.comment_paragraph').mouseup(function(){ 26 $('.comment_paragraph').mouseup(function(){
27 var paragraphId = getIdCommentParagraph($(this)[0].id); 27 var paragraphId = getIdCommentParagraph($(this)[0].id);
28 var rootElement = $(this).get(0); 28 var rootElement = $(this).get(0);
29 -  
30 lastParagraph[paragraphId] = rootElement.innerHTML; 29 lastParagraph[paragraphId] = rootElement.innerHTML;
31 -  
32 - console.log(rootElement);  
33 -  
34 var selObj = rangy.getSelection(); 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 cssApplier.toggleSelection(); 32 cssApplier.toggleSelection();
38 -  
39 - lastSelectedArea[paragraphId] = selected_area;  
40 - //cssApplier.toggleSelection();  
41 - 33 + lastSelectedArea[paragraphId] = selected_area;
42 form = jQuery(this).parent().find('form'); 34 form = jQuery(this).parent().find('form');
43 if (form.find('input.selected_area').length === 0){ 35 if (form.find('input.selected_area').length === 0){
44 jQuery('<input>').attr({ 36 jQuery('<input>').attr({
@@ -49,20 +41,9 @@ jQuery(document).ready(function($) { @@ -49,20 +41,9 @@ jQuery(document).ready(function($) {
49 }).appendTo(form) 41 }).appendTo(form)
50 }else{ 42 }else{
51 form.find('input.selected_area').val(selected_area) 43 form.find('input.selected_area').val(selected_area)
52 - } 44 + }
53 rootElement.focus(); 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 function processAnchor(){ 48 function processAnchor(){
68 var anchor = window.location.hash; 49 var anchor = window.location.hash;
@@ -84,41 +65,30 @@ jQuery(document).ready(function($) { @@ -84,41 +65,30 @@ jQuery(document).ready(function($) {
84 } 65 }
85 }); 66 });
86 } 67 }
87 - 68 +
88 processAnchor(); 69 processAnchor();
89 - 70 +
90 $(document).on('mouseover', 'li.article-comment', function(){ 71 $(document).on('mouseover', 'li.article-comment', function(){
91 var selected_area = $(this).find('input.paragraph_comment_area').val(); 72 var selected_area = $(this).find('input.paragraph_comment_area').val();
92 var paragraph_id = $(this).find('input.paragraph_id').val(); 73 var paragraph_id = $(this).find('input.paragraph_id').val();
93 var rootElement = $('#comment_paragraph_'+ paragraph_id).get(0); 74 var rootElement = $('#comment_paragraph_'+ paragraph_id).get(0);
94 - 75 +
95 if(lastParagraph[paragraph_id] == null || lastParagraph[paragraph_id] == 'undefined'){ 76 if(lastParagraph[paragraph_id] == null || lastParagraph[paragraph_id] == 'undefined'){
96 - console.log(rootElement.innerHTML);  
97 lastParagraph[paragraph_id] = rootElement.innerHTML; 77 lastParagraph[paragraph_id] = rootElement.innerHTML;
98 } 78 }
99 else { 79 else {
100 rootElement.innerHTML = lastParagraph[paragraph_id] ; 80 rootElement.innerHTML = lastParagraph[paragraph_id] ;
101 } 81 }
102 -  
103 - //console.log(rootElement.innerHTML);  
104 - console.log("selected_area = '" + selected_area + "'");  
105 if(selected_area != ""){ 82 if(selected_area != ""){
106 rangy.deserializeSelection(selected_area, rootElement); 83 rangy.deserializeSelection(selected_area, rootElement);
107 cssApplier.toggleSelection(); 84 cssApplier.toggleSelection();
108 } 85 }
109 }); 86 });
110 - 87 +
111 $(document).on('mouseout', 'li.article-comment', function(){ 88 $(document).on('mouseout', 'li.article-comment', function(){
112 var paragraph_id = $(this).find('input.paragraph_id').val(); 89 var paragraph_id = $(this).find('input.paragraph_id').val();
113 - console.log("mouseout paragraph_id = " + paragraph_id);  
114 var rootElement = $('#comment_paragraph_'+ paragraph_id).get(0); 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 if(lastSelectedArea[paragraph_id] != null && lastSelectedArea[paragraph_id] != 'undefined' ){ 92 if(lastSelectedArea[paragraph_id] != null && lastSelectedArea[paragraph_id] != 'undefined' ){
123 rootElement = $('#comment_paragraph_'+ paragraph_id).get(0); 93 rootElement = $('#comment_paragraph_'+ paragraph_id).get(0);
124 rootElement.innerHTML = lastParagraph[paragraph_id]; 94 rootElement.innerHTML = lastParagraph[paragraph_id];
@@ -129,30 +99,9 @@ jQuery(document).ready(function($) { @@ -129,30 +99,9 @@ jQuery(document).ready(function($) {
129 var sel = rangy.getSelection(); 99 var sel = rangy.getSelection();
130 sel.removeAllRanges(); 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 function toggleParagraph(paragraph) { 105 function toggleParagraph(paragraph) {
157 var div = jQuery('div.comments_list_toggle_paragraph_'+paragraph); 106 var div = jQuery('div.comments_list_toggle_paragraph_'+paragraph);
158 var visible = div.is(':visible'); 107 var visible = div.is(':visible');
@@ -170,20 +119,3 @@ function loadCompleted(paragraph) { @@ -170,20 +119,3 @@ function loadCompleted(paragraph) {
170 comment_paragraph_anchor = null; 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 -}  
public/style.css
@@ -21,12 +21,12 @@ div.article-comments-list-more{ @@ -21,12 +21,12 @@ div.article-comments-list-more{
21 } 21 }
22 22
23 .commented-area { 23 .commented-area {
24 - background-color: #a8d1ff; 24 + background-color: #FFFF66;
25 } 25 }
26 26
27 ::selection { 27 ::selection {
28 - background: #a8d1ff; /* WebKit/Blink Browsers */ 28 + background: #FFFF66; /* WebKit/Blink Browsers */
29 } 29 }
30 ::-moz-selection { 30 ::-moz-selection {
31 - background: #a8d1ff; /* Gecko Browsers */ 31 + background: #FFFF66; /* Gecko Browsers */
32 } 32 }
33 \ No newline at end of file 33 \ No newline at end of file
test/functional/content_viewer_controller_test.rb
@@ -2,9 +2,9 @@ require File.dirname(__FILE__) + &#39;/../test_helper&#39; @@ -2,9 +2,9 @@ require File.dirname(__FILE__) + &#39;/../test_helper&#39;
2 2
3 class ContentViewerController 3 class ContentViewerController
4 append_view_path File.join(File.dirname(__FILE__) + '/../../views') 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 end 8 end
9 9
10 class ContentViewerControllerTest < ActionController::TestCase 10 class ContentViewerControllerTest < ActionController::TestCase