Sha256: f5a263cba2d28a871f86639be90901ef8a2d25097aa644315b8cf472b189005c

Contents?: true

Size: 1.37 KB

Versions: 23

Compression:

Stored size: 1.37 KB

Contents

SocialStream.Pagination = (function(SS, $, undefined){

  var show = function(callback) {
    var nav = $('nav.more');

    $('a', nav).each(function(i, btn) {
      $(btn).attr('data-page', "2");
    });

    $('.loading', nav).hide();

    $('a', nav).click(function(event) {
      event.preventDefault();

      $(event.target).hide();
      $(event.target).closest('nav.more').find('.loading').show();

      $.ajax({
        url: $(this).attr('data-path'),
        dataType: 'html',
        data: { page: $(this).attr('data-page') },
        type: 'GET',
        success: function(data) {
          var nav = $(event.target).closest("nav.more"),
              per_page = parseInt($(event.target).attr('data-per_page'), 10),
              remaining = parseInt($(event.target).attr('data-remaining'), 10) - per_page;

          nav.before(data);
          nav.find('.loading').hide();

          // data.length is equal to 1
          if (remaining > 0) {
            $(event.target).attr('data-remaining', remaining);
            $(event.target).attr('data-page', parseInt($(event.target).attr('data-page'), 10) + 1);
            $(event.target).html(I18n.t('layout.more', { count: remaining }));
            $(event.target).show();
          }

          if (callback) {
            callback();
          }
        }
      });
    });
  };


  return {
    show: show
  };
}) (SocialStream, jQuery);

Version data entries

23 entries across 23 versions & 2 rubygems

Version Path
social_stream-2.2.2 base/app/assets/javascripts/social_stream/pagination.js
social_stream-base-2.2.2 app/assets/javascripts/social_stream/pagination.js
social_stream-2.2.1 base/app/assets/javascripts/social_stream/pagination.js
social_stream-base-2.2.1 app/assets/javascripts/social_stream/pagination.js
social_stream-2.2.0 base/app/assets/javascripts/social_stream/pagination.js
social_stream-base-2.2.0 app/assets/javascripts/social_stream/pagination.js
social_stream-2.1.1 base/app/assets/javascripts/social_stream/pagination.js
social_stream-2.1.0 base/app/assets/javascripts/social_stream/pagination.js
social_stream-base-2.1.0 app/assets/javascripts/social_stream/pagination.js
social_stream-2.0.4 base/app/assets/javascripts/social_stream/pagination.js
social_stream-base-2.0.4 app/assets/javascripts/social_stream/pagination.js
social_stream-2.0.3 base/app/assets/javascripts/social_stream/pagination.js
social_stream-base-2.0.3 app/assets/javascripts/social_stream/pagination.js
social_stream-2.0.2 base/app/assets/javascripts/social_stream/pagination.js
social_stream-base-2.0.2 app/assets/javascripts/social_stream/pagination.js
social_stream-2.0.1 base/app/assets/javascripts/social_stream/pagination.js
social_stream-base-2.0.1 app/assets/javascripts/social_stream/pagination.js
social_stream-2.0.0 base/app/assets/javascripts/social_stream/pagination.js
social_stream-base-2.0.0 app/assets/javascripts/social_stream/pagination.js
social_stream-2.0.0.beta3 base/app/assets/javascripts/social_stream/pagination.js