Sha256: d3526da138ca25302e224ee3c995e5999198795984a6e45ca61eaf6bf46974b0

Contents?: true

Size: 1.82 KB

Versions: 13

Compression:

Stored size: 1.82 KB

Contents

// ==========================================================================
// Project:   SproutCore - JavaScript Application Framework
// Copyright: ©2006-2010 Sprout Systems, Inc. and contributors.
//            Portions ©2008-2011 Apple Inc. All rights reserved.
// License:   Licensed under MIT license (see license.js)
// ==========================================================================

sc_require("system/task_queue");

/** @ignore */
SC.chance = {

  preload_task: SC.Task.create({
    run: function(queue) {
      var bank = SC.chance.bank, idx, len = bank.length, images = SC.chance.images;
      for (idx = 0; idx < len; idx++) {
        if (images.length < 1) {
          return SC.chance.didPreloadImages();
        }

        var img = images.pop();
        bank[idx].className = img;
      }

      // to force a break:
      setTimeout(function(){
        SC.run(function() {
          SC.backgroundTaskQueue.push(SC.chance.preload_task);
        });
      }, 0);
    }
  }),


  images: [],
  bank: [],
  PRELOAD_CONCURRENCY: 50,

  preloadImages: function() {
    if (window.CHANCE_SLICES) {
      this.images = window.CHANCE_SLICES;
    }

    var bank = this.bank, idx, con = this.PRELOAD_CONCURRENCY;
    for (idx = 0; idx < con; idx++) {
      var img = document.createElement('div');
      document.body.appendChild(img);
      bank.push(img);
    }

    SC.run(function(){
      SC.backgroundTaskQueue.push(SC.chance.preload_task);
    });
  },

  didPreloadImages: function() {
    var bank = this.bank, idx, len = bank.length;
    for (idx = 0; idx < len; idx++) {
      document.body.removeChild(bank[idx]);
      bank[idx] = undefined;
    }
  }
};


// Disabling image proloading in the mean time temporarly. 
// If you want to enable it in your
// app add the following line.
//SC.ready(SC.chance, 'preloadImages');

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
sproutcore-1.7.1.beta-java lib/frameworks/sproutcore/frameworks/foundation/system/chance.js
sproutcore-1.7.1.beta lib/frameworks/sproutcore/frameworks/foundation/system/chance.js
sproutcore-1.6.0.1-java lib/frameworks/sproutcore/frameworks/foundation/system/chance.js
sproutcore-1.6.0.1 lib/frameworks/sproutcore/frameworks/foundation/system/chance.js
sproutcore-1.6.0.1-x86-mingw32 lib/frameworks/sproutcore/frameworks/foundation/system/chance.js
sproutcore-1.6.0 lib/frameworks/sproutcore/frameworks/foundation/system/chance.js
sproutcore-1.6.0-java lib/frameworks/sproutcore/frameworks/foundation/system/chance.js
sproutcore-1.6.0.rc.2-x86-mingw32 lib/frameworks/sproutcore/frameworks/foundation/system/chance.js
sproutcore-1.6.0.rc.2 lib/frameworks/sproutcore/frameworks/foundation/system/chance.js
sproutcore-1.6.0.rc.2-java lib/frameworks/sproutcore/frameworks/foundation/system/chance.js
sproutcore-1.6.0.rc.1-x86-mingw32 lib/frameworks/sproutcore/frameworks/foundation/system/chance.js
sproutcore-1.6.0.rc.1 lib/frameworks/sproutcore/frameworks/foundation/system/chance.js
sproutcore-1.6.0.rc.1-java lib/frameworks/sproutcore/frameworks/foundation/system/chance.js