Commit e497e27ef1a0aae881b29087ed1a6653b0423948
1 parent
c08a6f94
Exists in
master
and in
28 other branches
Refactoring comment group macro javascripts
Showing
2 changed files
with
19 additions
and
26 deletions
Show diff stats
plugins/comment_group_macro/public/comment_group_macro.js
| @@ -19,3 +19,21 @@ jQuery(document).ready(function($) { | @@ -19,3 +19,21 @@ jQuery(document).ready(function($) { | ||
| 19 | } | 19 | } |
| 20 | }); | 20 | }); |
| 21 | }); | 21 | }); |
| 22 | + | ||
| 23 | +function toggleGroup(group) { | ||
| 24 | + var div = jQuery('div.comments_list_toggle_group_'+group); | ||
| 25 | + var visible = div.is(':visible'); | ||
| 26 | + if(!visible) | ||
| 27 | + jQuery('div.comment-group-loading-'+group).addClass('comment-button-loading'); | ||
| 28 | + | ||
| 29 | + div.toggle('fast'); | ||
| 30 | + return visible; | ||
| 31 | +} | ||
| 32 | + | ||
| 33 | +function loadCompleted(group) { | ||
| 34 | + jQuery('div.comment-group-loading-'+group).removeClass('comment-button-loading') | ||
| 35 | + if(comment_group_anchor) { | ||
| 36 | + jQuery.scrollTo(jQuery(comment_group_anchor)); | ||
| 37 | + comment_group_anchor = null; | ||
| 38 | + } | ||
| 39 | +} |
plugins/comment_group_macro/views/_comment_group.rhtml
| @@ -5,7 +5,7 @@ | @@ -5,7 +5,7 @@ | ||
| 5 | :url => { :profile => profile_identifier, :controller => 'comment_group_macro_plugin_profile', :action => 'view_comments', :group_id => group_id, :article_id => article_id}, | 5 | :url => { :profile => profile_identifier, :controller => 'comment_group_macro_plugin_profile', :action => 'view_comments', :group_id => group_id, :article_id => article_id}, |
| 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 => "!toggleGroup(#{group_id})", |
| 9 | :complete => "loadCompleted(#{group_id})")%> | 9 | :complete => "loadCompleted(#{group_id})")%> |
| 10 | </div> | 10 | </div> |
| 11 | <!-- FIXME: css file --> | 11 | <!-- FIXME: css file --> |
| @@ -27,29 +27,4 @@ | @@ -27,29 +27,4 @@ | ||
| 27 | <div id="page-comment-form-<%= group_id %>" class='post_comment_box closed'><%= render :partial => 'comment/comment_form', :locals => {:comment => Comment.new, :display_link => true, :cancel_triggers_hide => true, :group_id => group_id}%></div> | 27 | <div id="page-comment-form-<%= group_id %>" class='post_comment_box closed'><%= render :partial => 'comment/comment_form', :locals => {:comment => Comment.new, :display_link => true, :cancel_triggers_hide => true, :group_id => group_id}%></div> |
| 28 | 28 | ||
| 29 | </div> | 29 | </div> |
| 30 | - | ||
| 31 | - <script type="text/javascript"> | ||
| 32 | - function groupVisible(group) { | ||
| 33 | - return jQuery('div.comments_list_toggle_group_'+group).is(':visible'); | ||
| 34 | - } | ||
| 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 | - | ||
| 44 | - (function($) { | ||
| 45 | - var button = $('div.comment_group_<%= group_id %> a'); | ||
| 46 | - button.live('click', function() { | ||
| 47 | - var div = $('div.comments_list_toggle_group_<%= group_id %>') | ||
| 48 | - if(!div.is(':visible')) | ||
| 49 | - $('div.comment-group-loading-<%= group_id %>').addClass('comment-button-loading'); | ||
| 50 | - div.toggle('fast'); | ||
| 51 | - }); | ||
| 52 | - })(jQuery) | ||
| 53 | - </script> | ||
| 54 | </div> | 30 | </div> |
| 55 | - |