Commit 4db8bfd85fcca28f0c3ff203910b08c5896e533c
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Merge branch 'AI3205-comment-paragraph' into stable
Showing
1 changed file
with
48 additions
and
29 deletions
Show diff stats
plugins/comment_paragraph/public/comment_paragraph_macro.js
@@ -111,18 +111,6 @@ jQuery(document).ready(function($) { | @@ -111,18 +111,6 @@ jQuery(document).ready(function($) { | ||
111 | } | 111 | } |
112 | 112 | ||
113 | $("#comment-bubble").hide(); | 113 | $("#comment-bubble").hide(); |
114 | - //Undo previous highlight from the paragraph | ||
115 | - $('.comment_paragraph').mousedown(function(){ | ||
116 | - $("#comment-bubble").hide(); | ||
117 | - var paragraphId = $(this).data('paragraph'); | ||
118 | - $(this).find('.commented-area').replaceWith(function() { | ||
119 | - return $(this).html(); | ||
120 | - }); | ||
121 | - var rootElement = $(this).get(0); | ||
122 | - if(lastParagraph[paragraphId]){ | ||
123 | - rootElement.innerHTML = lastParagraph[paragraphId]; | ||
124 | - } | ||
125 | - }); | ||
126 | 114 | ||
127 | function getSelectionText() { | 115 | function getSelectionText() { |
128 | var text = ""; | 116 | var text = ""; |
@@ -134,40 +122,70 @@ jQuery(document).ready(function($) { | @@ -134,40 +122,70 @@ jQuery(document).ready(function($) { | ||
134 | return text; | 122 | return text; |
135 | } | 123 | } |
136 | 124 | ||
137 | - //highlight area from the paragraph | ||
138 | - $('.comment_paragraph').mouseup(function(event){ | ||
139 | - deselectAll(); | 125 | + function setCommentBubblePosition(posX, posY) { |
126 | + $("#comment-bubble").css({ | ||
127 | + top: (posY - 70), | ||
128 | + left: (posX - 70), | ||
129 | + position:'absolute' | ||
130 | + }); | ||
131 | + } | ||
132 | + | ||
133 | + | ||
134 | + //highlight area from the paragraph | ||
135 | + $('.comment_paragraph').mouseup(function(event) { | ||
136 | + | ||
140 | //Don't do anything if there is no selected text | 137 | //Don't do anything if there is no selected text |
141 | - if(getSelectionText().length == 0) | 138 | + if (getSelectionText().length == 0) { |
142 | return; | 139 | return; |
140 | + } | ||
141 | + | ||
143 | var paragraphId = $(this).data('paragraph'); | 142 | var paragraphId = $(this).data('paragraph'); |
144 | - var currentMousePos = { x: -1, y: -1 }; | ||
145 | - currentMousePos.x = event.pageX; | ||
146 | - currentMousePos.y = event.pageY; | ||
147 | - $("#comment-bubble").css({top: event.pageY-70, left: event.pageX-70, position:'absolute'}); | ||
148 | - //Relates a bubble to the mouse up paragraph | ||
149 | - $("#comment-bubble").data("paragraphId", paragraphId) | 143 | + |
144 | + setCommentBubblePosition( event.pageX, event.pageY ); | ||
145 | + | ||
150 | //Prepare to open the div | 146 | //Prepare to open the div |
151 | var url = $('#link_to_ajax_comments_' + paragraphId).data('url'); | 147 | var url = $('#link_to_ajax_comments_' + paragraphId).data('url'); |
152 | - $("#comment-bubble").data("url", url) | 148 | + $("#comment-bubble").data("url", url); |
149 | + $("#comment-bubble").data("paragraphId", paragraphId); | ||
153 | $("#comment-bubble").show(); | 150 | $("#comment-bubble").show(); |
151 | + | ||
154 | var rootElement = $(this).get(0); | 152 | var rootElement = $(this).get(0); |
153 | + | ||
155 | //Stores the HTML content of the lastParagraph | 154 | //Stores the HTML content of the lastParagraph |
156 | - lastParagraph[paragraphId] = rootElement.innerHTML; | 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 | + | ||
157 | //Maybe it is needed to handle exceptions here | 175 | //Maybe it is needed to handle exceptions here |
158 | - try{ | 176 | + try { |
159 | var selObj = rangy.getSelection(); | 177 | var selObj = rangy.getSelection(); |
160 | var selected_area = rangy.serializeSelection(selObj, true,rootElement); | 178 | var selected_area = rangy.serializeSelection(selObj, true,rootElement); |
161 | cssApplier.toggleSelection(); | 179 | cssApplier.toggleSelection(); |
162 | - }catch(e){ | 180 | + } catch(e) { |
163 | //Translate this mesage | 181 | //Translate this mesage |
164 | - deselectAll(); | ||
165 | rangy.init(); | 182 | rangy.init(); |
166 | cssApplier = rangy.createCssClassApplier("commented-area", {normalize: false}); | 183 | cssApplier = rangy.createCssClassApplier("commented-area", {normalize: false}); |
167 | return; | 184 | return; |
168 | } | 185 | } |
186 | + | ||
169 | //Register the area the has been selected at input.selected_area | 187 | //Register the area the has been selected at input.selected_area |
170 | - lastSelectedArea[paragraphId] = selected_area; | 188 | + //lastSelectedArea[paragraphId] = selected_area; |
171 | form = $('#page-comment-form-' + paragraphId).find('form'); | 189 | form = $('#page-comment-form-' + paragraphId).find('form'); |
172 | if (form.find('input.selected_area').length === 0){ | 190 | if (form.find('input.selected_area').length === 0){ |
173 | $('<input>').attr({ | 191 | $('<input>').attr({ |
@@ -180,6 +198,7 @@ jQuery(document).ready(function($) { | @@ -180,6 +198,7 @@ jQuery(document).ready(function($) { | ||
180 | form.find('input.selected_area').val(selected_area) | 198 | form.find('input.selected_area').val(selected_area) |
181 | } | 199 | } |
182 | rootElement.focus(); | 200 | rootElement.focus(); |
201 | + | ||
183 | }); | 202 | }); |
184 | 203 | ||
185 | function deselectAll(){ | 204 | function deselectAll(){ |
@@ -207,7 +226,7 @@ jQuery(document).ready(function($) { | @@ -207,7 +226,7 @@ jQuery(document).ready(function($) { | ||
207 | 226 | ||
208 | processAnchor(); | 227 | processAnchor(); |
209 | 228 | ||
210 | - $(document).on('mouseover', 'li.article-comment', function(){ | 229 | + $(document).on('mouseover', 'li.article-comment', function() { |
211 | var selected_area = $(this).find('input.paragraph_comment_area').val(); | 230 | var selected_area = $(this).find('input.paragraph_comment_area').val(); |
212 | var paragraph_id = $(this).find('input.paragraph_id').val(); | 231 | var paragraph_id = $(this).find('input.paragraph_id').val(); |
213 | var rootElement = $('#comment_paragraph_'+ paragraph_id).get(0); | 232 | var rootElement = $('#comment_paragraph_'+ paragraph_id).get(0); |