Commit 32e196f00e6435c2358cd582c17e29fc555d2f13

Authored by Evandro Jr
1 parent 9e3b375b
Exists in master

Code cleaned

Showing 1 changed file with 26 additions and 56 deletions   Show diff stats
public/comment_paragraph_macro.js
1 var comment_paragraph_anchor; 1 var comment_paragraph_anchor;
2 var lastParagraph = []; 2 var lastParagraph = [];
3 var lastSelectedArea = []; 3 var lastSelectedArea = [];
4 -var sideCommentForm=null;  
5 -var firstTimeOpenParagraph = Array();  
6 -var commentParagraphIds = Array();  
7 -  
8 -function getIdCommentParagraph(paragraphId){  
9 - var idx = paragraphId.lastIndexOf('_');  
10 - return paragraphId.substring(idx+1, paragraphId.length);  
11 -}  
12 4
13 jQuery(document).ready(function($) { 5 jQuery(document).ready(function($) {
14 $('.display-comment-form').unbind(); 6 $('.display-comment-form').unbind();
@@ -28,7 +20,7 @@ jQuery(document).ready(function($) { @@ -28,7 +20,7 @@ jQuery(document).ready(function($) {
28 var page_comment_form = $button.parents('.page-comment-form'); 20 var page_comment_form = $button.parents('.page-comment-form');
29 page_comment_form.find('.errorExplanation').remove(); 21 page_comment_form.find('.errorExplanation').remove();
30 $(this).closest("textarea[name^='comment'").text(""); 22 $(this).closest("textarea[name^='comment'").text("");
31 - $(this).closest("div[class^='side-comment']").hide(); 23 + $(this).closest("div[class^='side-comment']").hide();
32 return false; 24 return false;
33 }); 25 });
34 26
@@ -36,9 +28,9 @@ jQuery(document).ready(function($) { @@ -36,9 +28,9 @@ jQuery(document).ready(function($) {
36 if(div.hasClass('closed')) { 28 if(div.hasClass('closed')) {
37 div.removeClass('closed'); 29 div.removeClass('closed');
38 div.addClass('opened'); 30 div.addClass('opened');
39 - }  
40 - }  
41 - 31 + }
  32 + }
  33 +
42 //Hides old style ballons 34 //Hides old style ballons
43 $("img[alt|=Comments]").hide(); 35 $("img[alt|=Comments]").hide();
44 rangy.init(); 36 rangy.init();
@@ -49,21 +41,6 @@ jQuery(document).ready(function($) { @@ -49,21 +41,6 @@ jQuery(document).ready(function($) {
49 <div align="center" class="triangle-right" >Comentar<br>+</div>\ 41 <div align="center" class="triangle-right" >Comentar<br>+</div>\
50 </a>'); 42 </a>');
51 43
52 - //Creates a side bubble for each paragraph with the amount of comments  
53 - //putSideComments();  
54 -  
55 - $('.comment_paragraph').mouseover(function(){  
56 - var paragraphId = getIdCommentParagraph($(this)[0].id);  
57 - $('#side_comment_counter_' + paragraphId).show();  
58 - });  
59 -  
60 - $('.comment_paragraph').mouseleave(function(){  
61 - var paragraphId = getIdCommentParagraph($(this)[0].id);  
62 -// if($('#side_comment_counter_' + paragraphId).text() == '+'){  
63 -// $('#side_comment_counter_' + paragraphId).hide();  
64 -// }  
65 - });  
66 -  
67 $('.side-comments-counter').click(function(){ 44 $('.side-comments-counter').click(function(){
68 hideAllComments(); 45 hideAllComments();
69 var paragraphId = $(this).data('paragraph') 46 var paragraphId = $(this).data('paragraph')
@@ -71,8 +48,7 @@ jQuery(document).ready(function($) { @@ -71,8 +48,7 @@ jQuery(document).ready(function($) {
71 $('#comments_list_toggle_paragraph_' + paragraphId).show(); 48 $('#comments_list_toggle_paragraph_' + paragraphId).show();
72 console.log(paragraphId); 49 console.log(paragraphId);
73 //Loads the comments 50 //Loads the comments
74 - var url = $('#link_to_ajax_comments_' + paragraphId).data('url');  
75 - firstTimeOpenParagraph[paragraphId]=false; 51 + var url = $('#link_to_ajax_comments_' + paragraphId).data('url');
76 $.ajax({ 52 $.ajax({
77 dataType: "script", 53 dataType: "script",
78 url: url 54 url: url
@@ -82,8 +58,8 @@ jQuery(document).ready(function($) { @@ -82,8 +58,8 @@ jQuery(document).ready(function($) {
82 alignSideComments(paragraphId); 58 alignSideComments(paragraphId);
83 }); 59 });
84 }); 60 });
85 -  
86 - 61 +
  62 +
87 $('#comment-bubble').click(function(event){ 63 $('#comment-bubble').click(function(event){
88 $(this).hide(); 64 $(this).hide();
89 hideAllComments(); 65 hideAllComments();
@@ -97,10 +73,10 @@ jQuery(document).ready(function($) { @@ -97,10 +73,10 @@ jQuery(document).ready(function($) {
97 }).done(function() { 73 }).done(function() {
98 var button = $('#page-comment-form-' + paragraphId + ' a').get(0); 74 var button = $('#page-comment-form-' + paragraphId + ' a').get(0);
99 button.click(); 75 button.click();
100 - alignSideComments(paragraphId); 76 + alignSideComments(paragraphId);
101 }); 77 });
102 - });  
103 - 78 + });
  79 +
104 function alignSideComments(paragraphId){ 80 function alignSideComments(paragraphId){
105 $('.comments_list_toggle_paragraph_' + paragraphId).css('background','#FFFFFF'); 81 $('.comments_list_toggle_paragraph_' + paragraphId).css('background','#FFFFFF');
106 $('label[for|=comment_title]').hide(); 82 $('label[for|=comment_title]').hide();
@@ -108,16 +84,15 @@ jQuery(document).ready(function($) { @@ -108,16 +84,15 @@ jQuery(document).ready(function($) {
108 $('.comment_form p').hide(); 84 $('.comment_form p').hide();
109 $('.comments_list_toggle_paragraph_' + paragraphId).width('350px'); 85 $('.comments_list_toggle_paragraph_' + paragraphId).width('350px');
110 $('.required-field').removeClass("required-field"); 86 $('.required-field').removeClass("required-field");
111 - }  
112 - 87 + }
  88 +
113 function hideAllComments(){ 89 function hideAllComments(){
114 $(".side-comment").hide(); 90 $(".side-comment").hide();
115 - }  
116 - 91 + }
  92 +
117 $("#comment-bubble").hide(); 93 $("#comment-bubble").hide();
118 //Undo previous highlight from the paragraph 94 //Undo previous highlight from the paragraph
119 $('.comment_paragraph').mousedown(function(){ 95 $('.comment_paragraph').mousedown(function(){
120 - //var paragraphId = getIdCommentParagraph($(this)[0].id);  
121 var paragraphId = $(this).data('paragraph'); 96 var paragraphId = $(this).data('paragraph');
122 $(this).find('.commented-area').replaceWith(function() { 97 $(this).find('.commented-area').replaceWith(function() {
123 return $(this).html(); 98 return $(this).html();
@@ -139,7 +114,7 @@ jQuery(document).ready(function($) { @@ -139,7 +114,7 @@ jQuery(document).ready(function($) {
139 //Relates a bubble to the mouse up paragraph 114 //Relates a bubble to the mouse up paragraph
140 $("#comment-bubble").data("paragraphId", paragraphId) 115 $("#comment-bubble").data("paragraphId", paragraphId)
141 //Prepare to open the div 116 //Prepare to open the div
142 - var url = $('#link_to_ajax_comments_' + paragraphId).data('url'); 117 + var url = $('#link_to_ajax_comments_' + paragraphId).data('url');
143 $("#comment-bubble").data("url", url) 118 $("#comment-bubble").data("url", url)
144 $("#comment-bubble").show(); 119 $("#comment-bubble").show();
145 var rootElement = $(this).get(0); 120 var rootElement = $(this).get(0);
@@ -148,15 +123,15 @@ jQuery(document).ready(function($) { @@ -148,15 +123,15 @@ jQuery(document).ready(function($) {
148 //Maybe it is needed to handle exceptions here 123 //Maybe it is needed to handle exceptions here
149 try{ 124 try{
150 var selObj = rangy.getSelection(); 125 var selObj = rangy.getSelection();
151 - var selected_area = rangy.serializeSelection(selObj, true,rootElement); 126 + var selected_area = rangy.serializeSelection(selObj, true,rootElement);
152 cssApplier.toggleSelection(); 127 cssApplier.toggleSelection();
153 }catch(e){ 128 }catch(e){
154 - console.log(e);  
155 - //$.flash("A sele"); 129 + //Translate this mesage
  130 + display_notice("Região não permitida para seleção");
156 return; 131 return;
157 } 132 }
158 //Register the area the has been selected at input.selected_area 133 //Register the area the has been selected at input.selected_area
159 - lastSelectedArea[paragraphId] = selected_area; 134 + lastSelectedArea[paragraphId] = selected_area;
160 form = $('#page-comment-form-' + paragraphId).find('form'); 135 form = $('#page-comment-form-' + paragraphId).find('form');
161 if (form.find('input.selected_area').length === 0){ 136 if (form.find('input.selected_area').length === 0){
162 jQuery('<input>').attr({ 137 jQuery('<input>').attr({
@@ -170,16 +145,11 @@ jQuery(document).ready(function($) { @@ -170,16 +145,11 @@ jQuery(document).ready(function($) {
170 } 145 }
171 rootElement.focus(); 146 rootElement.focus();
172 }); 147 });
173 - 148 +
174 function deselectAll(){ 149 function deselectAll(){
175 $(".commented-area").contents().unwrap(); 150 $(".commented-area").contents().unwrap();
176 } 151 }
177 152
178 -  
179 -// $('.article-body').mousedown(function(event){  
180 -// deselectAll();  
181 -// });  
182 -  
183 function processAnchor(){ 153 function processAnchor(){
184 var anchor = window.location.hash; 154 var anchor = window.location.hash;
185 if(anchor.length==0) return; 155 if(anchor.length==0) return;
@@ -198,17 +168,17 @@ jQuery(document).ready(function($) { @@ -198,17 +168,17 @@ jQuery(document).ready(function($) {
198 }).done(function() { 168 }).done(function() {
199 var button = $('#page-comment-form-' + comment_id + ' a').get(0) 169 var button = $('#page-comment-form-' + comment_id + ' a').get(0)
200 button.click(); 170 button.click();
201 - //alignSideComments(paragraphId); 171 + //alignSideComments(paragraphId);
202 }); 172 });
203 } 173 }
204 - 174 +
205 processAnchor(); 175 processAnchor();
206 - 176 +
207 $(document).on('mouseover', 'li.article-comment', function(){ 177 $(document).on('mouseover', 'li.article-comment', function(){
208 var selected_area = $(this).find('input.paragraph_comment_area').val(); 178 var selected_area = $(this).find('input.paragraph_comment_area').val();
209 var paragraph_id = $(this).find('input.paragraph_id').val(); 179 var paragraph_id = $(this).find('input.paragraph_id').val();
210 var rootElement = $('#comment_paragraph_'+ paragraph_id).get(0); 180 var rootElement = $('#comment_paragraph_'+ paragraph_id).get(0);
211 - 181 +
212 if(lastParagraph[paragraph_id] == null || lastParagraph[paragraph_id] == 'undefined'){ 182 if(lastParagraph[paragraph_id] == null || lastParagraph[paragraph_id] == 'undefined'){
213 lastParagraph[paragraph_id] = rootElement.innerHTML; 183 lastParagraph[paragraph_id] = rootElement.innerHTML;
214 } 184 }
@@ -220,12 +190,12 @@ jQuery(document).ready(function($) { @@ -220,12 +190,12 @@ jQuery(document).ready(function($) {
220 cssApplier.toggleSelection(); 190 cssApplier.toggleSelection();
221 } 191 }
222 }); 192 });
223 - 193 +
224 $(document).on('mouseout', 'li.article-comment', function(){ 194 $(document).on('mouseout', 'li.article-comment', function(){
225 deselectAll(); 195 deselectAll();
226 var paragraph_id = $(this).find('input.paragraph_id').val(); 196 var paragraph_id = $(this).find('input.paragraph_id').val();
227 var rootElement = $('#comment_paragraph_'+ paragraph_id).get(0); 197 var rootElement = $('#comment_paragraph_'+ paragraph_id).get(0);
228 - 198 +
229 if(lastSelectedArea[paragraph_id] != null && lastSelectedArea[paragraph_id] != 'undefined' ){ 199 if(lastSelectedArea[paragraph_id] != null && lastSelectedArea[paragraph_id] != 'undefined' ){
230 rootElement = $('#comment_paragraph_'+ paragraph_id).get(0); 200 rootElement = $('#comment_paragraph_'+ paragraph_id).get(0);
231 rootElement.innerHTML = lastParagraph[paragraph_id]; 201 rootElement.innerHTML = lastParagraph[paragraph_id];