$('.cs-main-area .list-group').append("<%= escape_javascript render partial: 'package_list', locals: { packages: @packages, page: params[:page] } %>");

var newPagination;
<% if @packages.count > WillPaginate.per_page * ( params[:page] || '1' ).to_i %>
  newPagination = "<%= escape_javascript will_paginate @packages, class: 'pagination cs-full-width cs-no-margin cs-center' %>";
<% else %>
  newPagination = "<div class='pagination cs-full-width cs-no-margin cs-center'>";
  <% if params[:search].present? %>
    newPagination += "<%= escape_javascript link_to 'View all Packages', root_path(sort: params[:sort]) %>";
  <% else %>
    newPagination += "<a href='#top'>Scroll to Top</a>";
  <% end %>
  newPagination += "</div>";
<% end %>

$('.pagination').replaceWith(newPagination);

$("a[href='#top']").click(function() {
  $("html, body").animate({ scrollTop: 0 }, "slow");
  return false;
});

var appendedSelector = '.cs-main-area > .panel:first-child .list-group',
    appendedList = `<%=
      escape_javascript render partial: 'package_list', \
        locals: { packages: @packages, page: params[:page] }
    %>`;

$(appendedSelector).append(appendedList);

var newPagination;
<% if @packages.count > WillPaginate.per_page * ( params[:page] || '1' ).to_i %>
  newPagination = "<%= escape_javascript will_paginate @packages, class: 'pagination cs-full-width cs-no-margin cs-center' %>";
<% else %>
  newPagination = "<div class='pagination cs-full-width cs-no-margin cs-center'>";
  <% if params[:search].present? %>
    newPagination += "<%= escape_javascript link_to 'View all Packages', root_path(sort: params[:sort]) %>";
  <% else %>
    newPagination += "<a href='#top'>Scroll to Top</a>";
  <% end %>
  newPagination += "</div>";
<% end %>

$('.pagination').replaceWith(newPagination);

$("a[href='#top']").click(function() {
  $("html, body").animate({ scrollTop: 0 }, "slow");
  return false;
});

Fix items being appended to wrong panel on mobile
Fix items being appended to wrong panel on mobile