diff --git a/app/views/shared/tiny_mce.rhtml b/app/views/shared/tiny_mce.rhtml index 25d5106..19514fa 100644 --- a/app/views/shared/tiny_mce.rhtml +++ b/app/views/shared/tiny_mce.rhtml @@ -11,10 +11,8 @@ <% else %> first_line = "print,separator,copy,paste,separator,undo,redo,separator,search,replace,separator,forecolor,fontsizeselect,formatselect" second_line = "bold,italic,underline,strikethrough,separator,bullist,numlist,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,link,unlink,image,table,separator,cleanup,code,macros" - <% Environment.macros[environment.id].each do |macro_name, plugin_instance| %> - <% if macro_configuration(macro_name)[:icon_path] %> - second_line += ',<%=macro_name %>' - <% end %> + <% macros_with_buttons.each do |macro_name, plugin_instance| %> + second_line += ',<%=macro_name %>' <% end %> <% end %> diff --git a/plugins/comment_group_macro/controllers/public/comment_group_macro_plugin_public_controller.rb b/plugins/comment_group_macro/controllers/public/comment_group_macro_plugin_public_controller.rb new file mode 100644 index 0000000..ff1f527 --- /dev/null +++ b/plugins/comment_group_macro/controllers/public/comment_group_macro_plugin_public_controller.rb @@ -0,0 +1,8 @@ +class CommentGroupMacroPluginPublicController < PublicController + append_view_path File.join(File.dirname(__FILE__) + '/../views') + + def comment_group + render :json => { :group_id => Comment.find(params[:id]).group_id } + end + +end diff --git a/plugins/comment_group_macro/lib/comment_group_macro_plugin.rb b/plugins/comment_group_macro/lib/comment_group_macro_plugin.rb index 7f8c13c..cb8ce4c 100644 --- a/plugins/comment_group_macro/lib/comment_group_macro_plugin.rb +++ b/plugins/comment_group_macro/lib/comment_group_macro_plugin.rb @@ -43,4 +43,8 @@ class CommentGroupMacroPlugin < Noosfero::Plugin } end + def js_files + 'comment_group_macro.js' + end + end diff --git a/plugins/comment_group_macro/public/comment_group_macro.js b/plugins/comment_group_macro/public/comment_group_macro.js new file mode 100644 index 0000000..c7867c4 --- /dev/null +++ b/plugins/comment_group_macro/public/comment_group_macro.js @@ -0,0 +1,21 @@ +var comment_group_anchor; +jQuery(document).ready(function($) { + var anchor = window.location.hash; + if(anchor.length==0) return; + + var val = anchor.split('-'); //anchor format = #comment-\d+ + if(val.length!=2 || val[0]!='#comment') return; + if($('div[data-macro=display_comments]').length==0) return; //display_comments div must exists + var comment_id = val[1]; + if(!/^\d+$/.test(comment_id)) return; //test for integer + + comment_group_anchor = anchor; + var url = '/plugin/comment_group_macro/public/comment_group/'+comment_id; + $.getJSON(url, function(data) { + if(data.group_id!=null) { + var button = $('div.comment_group_'+ data.group_id + ' a'); + button.click(); + $.scrollTo(button); + } + }); +}); diff --git a/plugins/comment_group_macro/test/functional/comment_group_macro_plugin_public_controller_test.rb b/plugins/comment_group_macro/test/functional/comment_group_macro_plugin_public_controller_test.rb new file mode 100644 index 0000000..24d89b6 --- /dev/null +++ b/plugins/comment_group_macro/test/functional/comment_group_macro_plugin_public_controller_test.rb @@ -0,0 +1,33 @@ +require File.dirname(__FILE__) + '/../../../../test/test_helper' +require File.dirname(__FILE__) + '/../../controllers/public/comment_group_macro_plugin_public_controller' + +# Re-raise errors caught by the controller. +class CommentGroupMacroPluginPublicController; def rescue_action(e) raise e end; end + +class CommentGroupMacroPluginPublicControllerTest < ActionController::TestCase + + def setup + @controller = CommentGroupMacroPluginPublicController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + + @profile = create_user('testuser').person + @article = profile.articles.build(:name => 'test') + @article.save! + end + attr_reader :article + attr_reader :profile + + should 'be able to return group_id for a comment' do + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :group_id => 0) + xhr :get, :comment_group, :id => comment.id + assert_match /\{\"group_id\":0\}/, @response.body + end + + should 'return group_id=null for a global comment' do + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala' ) + xhr :get, :comment_group, :id => comment.id + assert_match /\{\"group_id\":null\}/, @response.body + end + +end diff --git a/plugins/comment_group_macro/views/_comment_group.rhtml b/plugins/comment_group_macro/views/_comment_group.rhtml index 490aba8..71ef7ed 100644 --- a/plugins/comment_group_macro/views/_comment_group.rhtml +++ b/plugins/comment_group_macro/views/_comment_group.rhtml @@ -6,7 +6,7 @@ :loaded => visual_effect(:highlight, "comments_list_group_#{group_id}"), :method => :post, :condition => "!groupVisible(#{group_id})", - :complete => "jQuery('div.comment-group-loading-#{group_id}').removeClass('comment-button-loading')")%> + :complete => "loadCompleted(#{group_id})")%>
<%= count %>
@@ -33,9 +33,17 @@ return jQuery('div.comments_list_toggle_group_'+group).is(':visible'); } + function loadCompleted(group) { + jQuery('div.comment-group-loading-'+group).removeClass('comment-button-loading') + if(comment_group_anchor) { + jQuery.scrollTo(jQuery(comment_group_anchor)); + comment_group_anchor = null; + } + } + (function($) { var button = $('div.comment_group_<%= group_id %> a'); - button.click(function() { + button.live('click', function() { var div = $('div.comments_list_toggle_group_<%= group_id %>') if(!div.is(':visible')) $('div.comment-group-loading-<%= group_id %>').addClass('comment-button-loading'); -- libgit2 0.21.2