diff --git a/lib/comment_paragraph_plugin.rb b/lib/comment_paragraph_plugin.rb index ba9c7ff..dc3dfad 100644 --- a/lib/comment_paragraph_plugin.rb +++ b/lib/comment_paragraph_plugin.rb @@ -21,14 +21,13 @@ class CommentParagraphPlugin < Noosfero::Plugin end def js_files - 'comment_paragraph_macro.js' + ['comment_paragraph_macro', 'rangy-core', 'rangy-cssclassapplier', 'rangy-serializer'] end def stylesheet? true end - end require_dependency 'comment_paragraph_plugin/macros/allow_comment' diff --git a/public/comment_paragraph_macro.js b/public/comment_paragraph_macro.js index a7e4c9f..6817bc9 100644 --- a/public/comment_paragraph_macro.js +++ b/public/comment_paragraph_macro.js @@ -1,7 +1,51 @@ var comment_paragraph_anchor; jQuery(document).ready(function($) { - jQuery('.autoexpand-text-area').autosize(); + rangy.init(); + cssApplier = rangy.createCssClassApplier("commented-area", {normalize: false}); + var rootElement; + +// $('.bt-marker').click(function(){ +// console.log($(this).data('paragraph-id')); +// rootElement = $('#' + 'comment_paragraph' + $(this).data('paragraph-id')).get(0); +// cssApplier.toggleSelection(); +// var selObj = rangy.getSelection(); +// var se = rangy.serializeSelection(selObj, true,rootElement); +// //$('#result').val(se); +// }); + + + //Undo previous highlight from the paragraph + $('.comment_paragraph').mousedown(function(){ + $(this).find('.commented-area').replaceWith(function() { + return $(this).html(); + }); + }); + + //highlight area from the paragraph + $('.comment_paragraph').mouseup(function(){ + rootElement = $(this).get(0); + console.log(rootElement) + cssApplier.toggleSelection(); + var selObj = rangy.getSelection(); + var selected_area = rangy.serializeSelection(selObj, true,rootElement); + + alert(selected_area) + + form = jQuery(this).parent().find('form'); + if (form.find('input.selected_area').length === 0){ + jQuery('').attr({ + class: 'selected_area', + name: 'comment[comment_paragraph_selected_area]', + value: selected_area + }).appendTo(form) + }else{ + form.find('input.selected_area').val(selected_area) + } + rootElement.focus(); + }); + + var anchor = window.location.hash; if(anchor.length==0) return; @@ -21,8 +65,20 @@ jQuery(document).ready(function($) { $.scrollTo(button); } }); + + }); +function selectAreaForComment(paragraph){ +// console.log(this) +// alert("Paragrafo " + paragraph) +// cssApplier.toggleSelection(); +// saveSelection(); +// var selObj = rangy.getSelection(); +// var se = rangy.serializeSelection(selObj, true,rootElement); +} + + function toggleParagraph(paragraph) { var div = jQuery('div.comments_list_toggle_paragraph_'+paragraph); var visible = div.is(':visible'); @@ -41,290 +97,19 @@ function loadCompleted(paragraph) { } } + + //Return a string with the beggining and the end of the selection of a text area separated by colon function getSelectionBounderies(textareaId){ - var textarea = document.getElementById(textareaId); - if ('selectionStart' in textarea) { - // check whether some text is selected in the textarea - if (textarea.selectionStart != textarea.selectionEnd) { - alert(textarea.selectionStart + ":" + textarea.selectionEnd) - return textarea.selectionStart + ":" + textarea.selectionEnd; - } - } +// var textarea = document.getElementById(textareaId); +// if ('selectionStart' in textarea) { +// // check whether some text is selected in the textarea +// if (textarea.selectionStart != textarea.selectionEnd) { +// alert(textarea.selectionStart + ":" + textarea.selectionEnd) +// return textarea.selectionStart + ":" + textarea.selectionEnd; +// } +// } return false } - -/*! - Autosize v1.18.9 - 2014-05-27 - Automatically adjust textarea height based on user input. - (c) 2014 Jack Moore - http://www.jacklmoore.com/autosize - license: http://www.opensource.org/licenses/mit-license.php -*/ -(function ($) { - var - defaults = { - className: 'autosizejs', - id: 'autosizejs', - append: '\n', - callback: false, - resizeDelay: 10, - placeholder: true - }, - - // border:0 is unnecessary, but avoids a bug in Firefox on OSX - copy = ' - -
+
+


+
<%= link_to_remote(image_tag("/plugins/comment_paragraph/images/comments.gif"), :url => { :profile => profile_identifier, :controller => 'comment_paragraph_plugin_profile', :action => 'view_comments', :paragraph_id => paragraph_id, :article_id => article_id}, :method => :post, -- libgit2 0.21.2