Commit c08a6f9452597b1edcdfd6f998be680abe0214f3
1 parent
50facea9
Exists in
master
and in
29 other branches
Fixing anchor for comments that are inside groups
Showing
6 changed files
with
78 additions
and
6 deletions
Show diff stats
app/views/shared/tiny_mce.rhtml
| @@ -11,10 +11,8 @@ | @@ -11,10 +11,8 @@ | ||
| 11 | <% else %> | 11 | <% else %> |
| 12 | first_line = "print,separator,copy,paste,separator,undo,redo,separator,search,replace,separator,forecolor,fontsizeselect,formatselect" | 12 | first_line = "print,separator,copy,paste,separator,undo,redo,separator,search,replace,separator,forecolor,fontsizeselect,formatselect" |
| 13 | second_line = "bold,italic,underline,strikethrough,separator,bullist,numlist,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,link,unlink,image,table,separator,cleanup,code,macros" | 13 | second_line = "bold,italic,underline,strikethrough,separator,bullist,numlist,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,link,unlink,image,table,separator,cleanup,code,macros" |
| 14 | - <% Environment.macros[environment.id].each do |macro_name, plugin_instance| %> | ||
| 15 | - <% if macro_configuration(macro_name)[:icon_path] %> | ||
| 16 | - second_line += ',<%=macro_name %>' | ||
| 17 | - <% end %> | 14 | + <% macros_with_buttons.each do |macro_name, plugin_instance| %> |
| 15 | + second_line += ',<%=macro_name %>' | ||
| 18 | <% end %> | 16 | <% end %> |
| 19 | <% end %> | 17 | <% end %> |
| 20 | 18 |
plugins/comment_group_macro/controllers/public/comment_group_macro_plugin_public_controller.rb
0 → 100644
plugins/comment_group_macro/lib/comment_group_macro_plugin.rb
plugins/comment_group_macro/public/comment_group_macro.js
0 → 100644
| @@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
| 1 | +var comment_group_anchor; | ||
| 2 | +jQuery(document).ready(function($) { | ||
| 3 | + var anchor = window.location.hash; | ||
| 4 | + if(anchor.length==0) return; | ||
| 5 | + | ||
| 6 | + var val = anchor.split('-'); //anchor format = #comment-\d+ | ||
| 7 | + if(val.length!=2 || val[0]!='#comment') return; | ||
| 8 | + if($('div[data-macro=display_comments]').length==0) return; //display_comments div must exists | ||
| 9 | + var comment_id = val[1]; | ||
| 10 | + if(!/^\d+$/.test(comment_id)) return; //test for integer | ||
| 11 | + | ||
| 12 | + comment_group_anchor = anchor; | ||
| 13 | + var url = '/plugin/comment_group_macro/public/comment_group/'+comment_id; | ||
| 14 | + $.getJSON(url, function(data) { | ||
| 15 | + if(data.group_id!=null) { | ||
| 16 | + var button = $('div.comment_group_'+ data.group_id + ' a'); | ||
| 17 | + button.click(); | ||
| 18 | + $.scrollTo(button); | ||
| 19 | + } | ||
| 20 | + }); | ||
| 21 | +}); |
plugins/comment_group_macro/test/functional/comment_group_macro_plugin_public_controller_test.rb
0 → 100644
| @@ -0,0 +1,33 @@ | @@ -0,0 +1,33 @@ | ||
| 1 | +require File.dirname(__FILE__) + '/../../../../test/test_helper' | ||
| 2 | +require File.dirname(__FILE__) + '/../../controllers/public/comment_group_macro_plugin_public_controller' | ||
| 3 | + | ||
| 4 | +# Re-raise errors caught by the controller. | ||
| 5 | +class CommentGroupMacroPluginPublicController; def rescue_action(e) raise e end; end | ||
| 6 | + | ||
| 7 | +class CommentGroupMacroPluginPublicControllerTest < ActionController::TestCase | ||
| 8 | + | ||
| 9 | + def setup | ||
| 10 | + @controller = CommentGroupMacroPluginPublicController.new | ||
| 11 | + @request = ActionController::TestRequest.new | ||
| 12 | + @response = ActionController::TestResponse.new | ||
| 13 | + | ||
| 14 | + @profile = create_user('testuser').person | ||
| 15 | + @article = profile.articles.build(:name => 'test') | ||
| 16 | + @article.save! | ||
| 17 | + end | ||
| 18 | + attr_reader :article | ||
| 19 | + attr_reader :profile | ||
| 20 | + | ||
| 21 | + should 'be able to return group_id for a comment' do | ||
| 22 | + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :group_id => 0) | ||
| 23 | + xhr :get, :comment_group, :id => comment.id | ||
| 24 | + assert_match /\{\"group_id\":0\}/, @response.body | ||
| 25 | + end | ||
| 26 | + | ||
| 27 | + should 'return group_id=null for a global comment' do | ||
| 28 | + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala' ) | ||
| 29 | + xhr :get, :comment_group, :id => comment.id | ||
| 30 | + assert_match /\{\"group_id\":null\}/, @response.body | ||
| 31 | + end | ||
| 32 | + | ||
| 33 | +end |
plugins/comment_group_macro/views/_comment_group.rhtml
| @@ -6,7 +6,7 @@ | @@ -6,7 +6,7 @@ | ||
| 6 | :loaded => visual_effect(:highlight, "comments_list_group_#{group_id}"), | 6 | :loaded => visual_effect(:highlight, "comments_list_group_#{group_id}"), |
| 7 | :method => :post, | 7 | :method => :post, |
| 8 | :condition => "!groupVisible(#{group_id})", | 8 | :condition => "!groupVisible(#{group_id})", |
| 9 | - :complete => "jQuery('div.comment-group-loading-#{group_id}').removeClass('comment-button-loading')")%> | 9 | + :complete => "loadCompleted(#{group_id})")%> |
| 10 | </div> | 10 | </div> |
| 11 | <!-- FIXME: css file --> | 11 | <!-- FIXME: css file --> |
| 12 | <div id="comments_group_count_<%= group_id %>" style="float: right; vertical-align: middle; padding-left: 3px; padding-right: 5px; color: #5AC1FC"><span id="comment-count-<%= group_id %>" class='comment-count'><%= count %></span></div> | 12 | <div id="comments_group_count_<%= group_id %>" style="float: right; vertical-align: middle; padding-left: 3px; padding-right: 5px; color: #5AC1FC"><span id="comment-count-<%= group_id %>" class='comment-count'><%= count %></span></div> |
| @@ -33,9 +33,17 @@ | @@ -33,9 +33,17 @@ | ||
| 33 | return jQuery('div.comments_list_toggle_group_'+group).is(':visible'); | 33 | return jQuery('div.comments_list_toggle_group_'+group).is(':visible'); |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | + function loadCompleted(group) { | ||
| 37 | + jQuery('div.comment-group-loading-'+group).removeClass('comment-button-loading') | ||
| 38 | + if(comment_group_anchor) { | ||
| 39 | + jQuery.scrollTo(jQuery(comment_group_anchor)); | ||
| 40 | + comment_group_anchor = null; | ||
| 41 | + } | ||
| 42 | + } | ||
| 43 | + | ||
| 36 | (function($) { | 44 | (function($) { |
| 37 | var button = $('div.comment_group_<%= group_id %> a'); | 45 | var button = $('div.comment_group_<%= group_id %> a'); |
| 38 | - button.click(function() { | 46 | + button.live('click', function() { |
| 39 | var div = $('div.comments_list_toggle_group_<%= group_id %>') | 47 | var div = $('div.comments_list_toggle_group_<%= group_id %>') |
| 40 | if(!div.is(':visible')) | 48 | if(!div.is(':visible')) |
| 41 | $('div.comment-group-loading-<%= group_id %>').addClass('comment-button-loading'); | 49 | $('div.comment-group-loading-<%= group_id %>').addClass('comment-button-loading'); |