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