Sha256: 55012a830d0a29b39971315d4073b2e4fe5863abd86f7fc7d239fb11346e4afc

Contents?: true

Size: 1.44 KB

Versions: 3

Compression:

Stored size: 1.44 KB

Contents

controllers.show = function(key) {
  var _this = this;

  var book = _.find(store, function(book) {
    return book.key == key;
  });

  function pageUrl(index) {
    return book.url + "/" + book.pageUrls[index - 1];
  }

  function preloadImage(index) {
    var image = new Image();
    image.src = pageUrl(index);
  }

  function preloadImages() {
    _(book.pageUrls.length).times(function(i) {
      preloadImage(i + 1);
    });
  }

  this.init = function() {
    console.log("starting show");

    $("#image").attr("src", "img/blank.png");

    $(window).bind("keydown.show", function(event)
    {
      if((event.keyCode == 32 || event.keyCode == 13) && utils.scrollDistanceFromBottom() <= 0)
      {
        event.preventDefault();
        utils.page(utils.page() + 1, book.pageUrls.length);
      }
      else if(event.keyCode == 8)
      {
        event.preventDefault();
        history.back();
      }
    });

    $("#view-show").show().addClass("current-view");

    //setTimeout(preloadImages, 5000);
  }

  this.render = function() {
    var index = utils.page();

    window.scrollTo(0, 0);
    _(5).times(function() {
      $("#image").attr('src', pageUrl(index));
    });

    if((index + 1) <= book.pageUrls.length) {
      preloadImage(index + 1);
    }
  }

  this.destroy = function() {
    console.log("destroying show");
    $(window).unbind(".show");
    $("#view-show").unbind("click");
    $("#view-show").hide().removeClass("current-view");
  }
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mangos-0.0.3 app/js/controllers.show.js
mangos-0.0.2 app/js/controllers.show.js
mangos-0.0.1 app/js/controllers.show.js