Sha256: 85ef0eee2fbde6adcdb865ea03dcf129172b753609910aeb91f686dd980de4eb

Contents?: true

Size: 1.19 KB

Versions: 9

Compression:

Stored size: 1.19 KB

Contents

//= require ./adjacent_pages

pageflow.AdjacentPreparer = pageflow.Object.extend({
  initialize: function(adjacentPages) {
    this.adjacentPages = adjacentPages;
  },

  attach: function(events) {
    this.listenTo(events, 'page:change', this.schedule);
  },

  schedule: function(page) {
    clearTimeout(this.scheduleTimeout);

    var prepare = _.bind(this.prepareAdjacent, this, page.element.page('instance'));
    this.scheduleTimeout = setTimeout(prepare, page.prepareNextPageTimeout());
  },

  prepareAdjacent: function(page) {
    var adjacentPages = this.adjacentPages.of(page);
    var noLongerAdjacentPages = _.difference(this.lastAdjacentPages, adjacentPages, [page]);
    var newAdjacentPages = _.difference(adjacentPages, this.lastAdjacentPages);

    _(noLongerAdjacentPages).each(function(page) {
      page.unprepare();
    });

    _(newAdjacentPages).each(function(adjacentPage) {
      adjacentPage.prepare();
      adjacentPage.preload();
    });

    this.lastAdjacentPages = adjacentPages;
  }
});

pageflow.AdjacentPreparer.create = function(pages, scrollNavigator) {
  return new pageflow.AdjacentPreparer(
    new pageflow.AdjacentPages(
      pages,
      scrollNavigator
    )
  );
};

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
pageflow-0.11.4 app/assets/javascripts/pageflow/slideshow/adjacent_preparer.js
pageflow-0.11.3 app/assets/javascripts/pageflow/slideshow/adjacent_preparer.js
pageflow-0.11.2 app/assets/javascripts/pageflow/slideshow/adjacent_preparer.js
pageflow-0.11.1 app/assets/javascripts/pageflow/slideshow/adjacent_preparer.js
pageflow-0.11.0 app/assets/javascripts/pageflow/slideshow/adjacent_preparer.js
pageflow-0.10.0 app/assets/javascripts/pageflow/slideshow/adjacent_preparer.js
pageflow-0.9.2 app/assets/javascripts/pageflow/slideshow/adjacent_preparer.js
pageflow-0.9.1 app/assets/javascripts/pageflow/slideshow/adjacent_preparer.js
pageflow-0.9.0 app/assets/javascripts/pageflow/slideshow/adjacent_preparer.js