diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index de698e0e..c7b8a360 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -815,29 +815,6 @@ $(document).ready(function(){ } }); - $('.hub_feed_more_control,.republished_feed_more_control').live({ - click: function(e){ - e.preventDefault(); - if($(this).hasClass('more_details_included')){ - $(this).closest('li').find('.metadata').remove(); - $(this).removeClass('more_details_included'); - $(this).find('.fa').removeClass('fa-caret-down'); - $(this).find('.fa').addClass('fa-caret-right'); - return; - } - var elem = this; - $.ajax({ - url: $(this).attr('href'), - success: function(html){ - $(elem).addClass('more_details_included'); - $(elem).closest('li').find('.media-body').append(html); - $(elem).find('.fa').removeClass('fa-caret-right'); - $(elem).find('.fa').addClass('fa-caret-down'); - } - }); - } - }); - if($('.ui-widget-content').length > 0){ $('#hub_search_form,#hub_tag_search_form').live({ submit: function(e){ diff --git a/app/assets/javascripts/hubs/bookmark_collections.js b/app/assets/javascripts/hubs/bookmark_collections.js new file mode 100644 index 00000000..d6f178ed --- /dev/null +++ b/app/assets/javascripts/hubs/bookmark_collections.js @@ -0,0 +1,32 @@ +/* globals $ */ +$('.hub_feed_more_control, .republished_feed_more_control') + .live({ click: toggleListItemMetadata }) + +function toggleListItemMetadata (e) { + e.preventDefault() + + var element = $(this) + + if (element.hasClass('more_details_included')) { + hideListItemMetadata(element) + } else { + showListItemMetadata(element) + } +} + +function hideListItemMetadata (element) { + element.removeClass('more_details_included') + element.closest('li').find('.metadata').empty() + element.find('.fa').removeClass('fa-caret-down').addClass('fa-caret-right') +} + +function showListItemMetadata (element) { + $.ajax({ + url: element.attr('href'), + success: function (html) { + element.addClass('more_details_included') + element.closest('li').find('.metadata').replaceWith(html) + element.find('.fa').removeClass('fa-caret-right').addClass('fa-caret-down') + } + }) +} diff --git a/app/views/hub_feeds/_list_item.html.haml b/app/views/hub_feeds/_list_item.html.haml index 6a4d33bb..0929a727 100644 --- a/app/views/hub_feeds/_list_item.html.haml +++ b/app/views/hub_feeds/_list_item.html.haml @@ -14,6 +14,7 @@ - else = link_to hub_hub_feed_path(@hub, hub_feed) do %h2= raw(strip_tags(hub_feed.to_s)) + .metadata - if defined?(show_hubs) && show_hubs == true %span.smaller in #{link_to(hub_feed.hub, hub_path(hub_feed.hub))} diff --git a/app/views/republished_feeds/_list_item.html.haml b/app/views/republished_feeds/_list_item.html.haml index d95105d8..ea5e49e0 100644 --- a/app/views/republished_feeds/_list_item.html.haml +++ b/app/views/republished_feeds/_list_item.html.haml @@ -20,3 +20,4 @@ \#{link_to('RSS', remix_items_path(republished_feed.url_key, format: :rss))}  \#{link_to('ATOM', remix_items_path(republished_feed.url_key, format: :atom))}  \#{link_to('JSON', remix_items_path(republished_feed.url_key, format: :json, callback: 'callback'))} + .metadata