Commit c820a6b382e6bbe6aae5f1fc09e936071366f321
1 parent
1a544709
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
comment_paragraph: minor fixes
Showing
1 changed file
with
20 additions
and
54 deletions
Show diff stats
plugins/comment_paragraph/public/comment_paragraph_macro.js
1 | 1 | var comment_paragraph_anchor; |
2 | -var lastParagraph = []; | |
3 | 2 | var lastSelectedArea = []; |
3 | +var original_paragraphs = []; | |
4 | 4 | |
5 | 5 | function setPlusIfZeroComments($){ |
6 | 6 | $('.comment-count').each(function(){ |
... | ... | @@ -15,6 +15,13 @@ jQuery(document).ready(function($) { |
15 | 15 | if($('.comment_paragraph').size() < 1) |
16 | 16 | return; |
17 | 17 | |
18 | + all_paragraphs = $('.comment_paragraph'); | |
19 | + all_paragraphs.each( function(paragraph) { | |
20 | + var paragraph_id = $( all_paragraphs.get(paragraph) ).attr('data-paragraph'); | |
21 | + var paragraph_content = all_paragraphs.get(paragraph).innerHTML; | |
22 | + original_paragraphs.push( { id: paragraph_id, content: paragraph_content } ); | |
23 | + }); | |
24 | + | |
18 | 25 | $(document).keyup(function(e) { |
19 | 26 | // on press ESC key... |
20 | 27 | if (e.which == 27) { |
... | ... | @@ -124,16 +131,17 @@ jQuery(document).ready(function($) { |
124 | 131 | |
125 | 132 | function setCommentBubblePosition(posX, posY) { |
126 | 133 | $("#comment-bubble").css({ |
127 | - top: (posY - 70), | |
134 | + top: (posY - 80), | |
128 | 135 | left: (posX - 70), |
129 | 136 | position:'absolute' |
130 | 137 | }); |
131 | 138 | } |
132 | 139 | |
133 | - | |
134 | 140 | //highlight area from the paragraph |
135 | 141 | $('.comment_paragraph').mouseup(function(event) { |
136 | 142 | |
143 | + $('#comment-bubble').hide(); | |
144 | + | |
137 | 145 | //Don't do anything if there is no selected text |
138 | 146 | if (getSelectionText().length == 0) { |
139 | 147 | return; |
... | ... | @@ -151,41 +159,15 @@ jQuery(document).ready(function($) { |
151 | 159 | |
152 | 160 | var rootElement = $(this).get(0); |
153 | 161 | |
154 | - //Stores the HTML content of the lastParagraph | |
155 | - var founded = false; | |
156 | - | |
157 | - for (var i=0; i < lastParagraph.length; i++) { | |
158 | - var paragraph = lastParagraph[i]; | |
159 | - if (paragraph.id == paragraphId) { | |
160 | - founded = true | |
161 | - break; | |
162 | - } | |
163 | - } | |
164 | - | |
165 | - if (founded) { | |
166 | - lastParagraph[i].html = rootElement.innerHTML; | |
167 | - } | |
168 | - else { | |
169 | - oLastParagraph = { id: paragraphId, html: rootElement.innerHTML }; | |
170 | - lastParagraph.push( oLastParagraph ); | |
171 | - } | |
172 | - | |
173 | - deselectAll(); | |
174 | - | |
175 | 162 | //Maybe it is needed to handle exceptions here |
176 | 163 | try { |
177 | 164 | var selObj = rangy.getSelection(); |
178 | - var selected_area = rangy.serializeSelection(selObj, true,rootElement); | |
179 | - cssApplier.toggleSelection(); | |
165 | + var selected_area = rangy.serializeSelection(selObj, true, rootElement); | |
180 | 166 | } catch(e) { |
181 | - //Translate this mesage | |
182 | - rangy.init(); | |
183 | - cssApplier = rangy.createCssClassApplier("commented-area", {normalize: false}); | |
184 | 167 | return; |
185 | 168 | } |
186 | 169 | |
187 | 170 | //Register the area the has been selected at input.selected_area |
188 | - //lastSelectedArea[paragraphId] = selected_area; | |
189 | 171 | form = $('#page-comment-form-' + paragraphId).find('form'); |
190 | 172 | if (form.find('input.selected_area').length === 0){ |
191 | 173 | $('<input>').attr({ |
... | ... | @@ -201,10 +183,6 @@ jQuery(document).ready(function($) { |
201 | 183 | |
202 | 184 | }); |
203 | 185 | |
204 | - function deselectAll(){ | |
205 | - $(".commented-area").contents().unwrap(); | |
206 | - } | |
207 | - | |
208 | 186 | function processAnchor(){ |
209 | 187 | var anchor = window.location.hash; |
210 | 188 | if(anchor.length==0) return; |
... | ... | @@ -226,38 +204,26 @@ jQuery(document).ready(function($) { |
226 | 204 | |
227 | 205 | processAnchor(); |
228 | 206 | |
229 | - $(document).on('mouseover', 'li.article-comment', function() { | |
207 | + $(document).on('mouseenter', 'li.article-comment', function() { | |
230 | 208 | var selected_area = $(this).find('input.paragraph_comment_area').val(); |
231 | 209 | var paragraph_id = $(this).find('input.paragraph_id').val(); |
232 | - var rootElement = $('#comment_paragraph_'+ paragraph_id).get(0); | |
210 | + var rootElement = $('#comment_paragraph_' + paragraph_id).get(0); | |
233 | 211 | |
234 | - if(lastParagraph[paragraph_id] == null || lastParagraph[paragraph_id] == 'undefined'){ | |
235 | - lastParagraph[paragraph_id] = rootElement.innerHTML; | |
236 | - } | |
237 | - else { | |
238 | - rootElement.innerHTML = lastParagraph[paragraph_id] ; | |
239 | - } | |
240 | 212 | if(selected_area != ""){ |
241 | 213 | rangy.deserializeSelection(selected_area, rootElement); |
242 | 214 | cssApplier.toggleSelection(); |
243 | 215 | } |
244 | 216 | }); |
245 | 217 | |
246 | - $(document).on('mouseout', 'li.article-comment', function(){ | |
247 | - deselectAll(); | |
218 | + $(document).on('mouseleave', 'li.article-comment', function() { | |
248 | 219 | var paragraph_id = $(this).find('input.paragraph_id').val(); |
249 | 220 | var rootElement = $('#comment_paragraph_'+ paragraph_id).get(0); |
250 | 221 | |
251 | - if(lastSelectedArea[paragraph_id] != null && lastSelectedArea[paragraph_id] != 'undefined' ){ | |
252 | - rootElement = $('#comment_paragraph_'+ paragraph_id).get(0); | |
253 | - rootElement.innerHTML = lastParagraph[paragraph_id]; | |
254 | - rangy.deserializeSelection(lastSelectedArea[paragraph_id], rootElement); | |
255 | - cssApplier.toggleSelection(); | |
256 | - } else { | |
257 | - cssApplier.toggleSelection(); | |
258 | - var sel = rangy.getSelection(); | |
259 | - sel.removeAllRanges(); | |
260 | - } | |
222 | + original_paragraphs.each( function(paragraph) { | |
223 | + if (paragraph.id == paragraph_id) { | |
224 | + rootElement.innerHTML = paragraph.content; | |
225 | + } | |
226 | + }); | |
261 | 227 | }); |
262 | 228 | |
263 | 229 | function toggleParagraph(paragraph) { | ... | ... |