Commit 600a5c1b7d197fe1c99deacac85140bc15740a7b

Authored by Evandro Jr
2 parents 02686390 ebdc49d6

Merge branch 'AI3205-comment-paragraph' into stable

plugins/comment_paragraph/public/comment_paragraph_macro.js
1 var comment_paragraph_anchor; 1 var comment_paragraph_anchor;
2 -var lastParagraph = [];  
3 var lastSelectedArea = []; 2 var lastSelectedArea = [];
  3 +var original_paragraphs = [];
4 4
5 function setPlusIfZeroComments($){ 5 function setPlusIfZeroComments($){
6 $('.comment-count').each(function(){ 6 $('.comment-count').each(function(){
@@ -15,6 +15,13 @@ jQuery(document).ready(function($) { @@ -15,6 +15,13 @@ jQuery(document).ready(function($) {
15 if($('.comment_paragraph').size() < 1) 15 if($('.comment_paragraph').size() < 1)
16 return; 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 $(document).keyup(function(e) { 25 $(document).keyup(function(e) {
19 // on press ESC key... 26 // on press ESC key...
20 if (e.which == 27) { 27 if (e.which == 27) {
@@ -124,16 +131,17 @@ jQuery(document).ready(function($) { @@ -124,16 +131,17 @@ jQuery(document).ready(function($) {
124 131
125 function setCommentBubblePosition(posX, posY) { 132 function setCommentBubblePosition(posX, posY) {
126 $("#comment-bubble").css({ 133 $("#comment-bubble").css({
127 - top: (posY - 70), 134 + top: (posY - 80),
128 left: (posX - 70), 135 left: (posX - 70),
129 position:'absolute' 136 position:'absolute'
130 }); 137 });
131 } 138 }
132 139
133 -  
134 //highlight area from the paragraph 140 //highlight area from the paragraph
135 $('.comment_paragraph').mouseup(function(event) { 141 $('.comment_paragraph').mouseup(function(event) {
136 142
  143 + $('#comment-bubble').hide();
  144 +
137 //Don't do anything if there is no selected text 145 //Don't do anything if there is no selected text
138 if (getSelectionText().length == 0) { 146 if (getSelectionText().length == 0) {
139 return; 147 return;
@@ -151,41 +159,15 @@ jQuery(document).ready(function($) { @@ -151,41 +159,15 @@ jQuery(document).ready(function($) {
151 159
152 var rootElement = $(this).get(0); 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 //Maybe it is needed to handle exceptions here 162 //Maybe it is needed to handle exceptions here
176 try { 163 try {
177 var selObj = rangy.getSelection(); 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 } catch(e) { 166 } catch(e) {
181 - //Translate this mesage  
182 - rangy.init();  
183 - cssApplier = rangy.createCssClassApplier("commented-area", {normalize: false});  
184 return; 167 return;
185 } 168 }
186 169
187 //Register the area the has been selected at input.selected_area 170 //Register the area the has been selected at input.selected_area
188 - //lastSelectedArea[paragraphId] = selected_area;  
189 form = $('#page-comment-form-' + paragraphId).find('form'); 171 form = $('#page-comment-form-' + paragraphId).find('form');
190 if (form.find('input.selected_area').length === 0){ 172 if (form.find('input.selected_area').length === 0){
191 $('<input>').attr({ 173 $('<input>').attr({
@@ -201,10 +183,6 @@ jQuery(document).ready(function($) { @@ -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 function processAnchor(){ 186 function processAnchor(){
209 var anchor = window.location.hash; 187 var anchor = window.location.hash;
210 if(anchor.length==0) return; 188 if(anchor.length==0) return;
@@ -226,38 +204,26 @@ jQuery(document).ready(function($) { @@ -226,38 +204,26 @@ jQuery(document).ready(function($) {
226 204
227 processAnchor(); 205 processAnchor();
228 206
229 - $(document).on('mouseover', 'li.article-comment', function() { 207 + $(document).on('mouseenter', 'li.article-comment', function() {
230 var selected_area = $(this).find('input.paragraph_comment_area').val(); 208 var selected_area = $(this).find('input.paragraph_comment_area').val();
231 var paragraph_id = $(this).find('input.paragraph_id').val(); 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 if(selected_area != ""){ 212 if(selected_area != ""){
241 rangy.deserializeSelection(selected_area, rootElement); 213 rangy.deserializeSelection(selected_area, rootElement);
242 cssApplier.toggleSelection(); 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 var paragraph_id = $(this).find('input.paragraph_id').val(); 219 var paragraph_id = $(this).find('input.paragraph_id').val();
249 var rootElement = $('#comment_paragraph_'+ paragraph_id).get(0); 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 function toggleParagraph(paragraph) { 229 function toggleParagraph(paragraph) {