Sha256: bc3b2f4c8cdebdfe302f0f29592fc867ba44cec9b48d2bf1ae9216a426c7dcc2

Contents?: true

Size: 813 Bytes

Versions: 2

Compression:

Stored size: 813 Bytes

Contents

/**
 * @class Images
 * This class loads images and keeps them stored.
 */
function Images() {
  this.images = {};

  this.callback = undefined;
}

/**
 * Set an onload callback function. This will be called each time an image
 * is loaded
 * @param {function} callback
 */
Images.prototype.setOnloadCallback = function(callback) {
  this.callback = callback;
};

/**
 *
 * @param {string} url          Url of the image
 * @return {Image} img          The image object
 */
Images.prototype.load = function(url) {
  var img = this.images[url];
  if (img == undefined) {
    // create the image
    var images = this;
    img = new Image();
    this.images[url] = img;
    img.onload = function() {
      if (images.callback) {
        images.callback(this);
      }
    };
    img.src = url;
  }

  return img;
};

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vis-rails-2.0.0 vendor/assets/vis/graph/Images.js
vis-rails-1.0.2 vendor/assets/vis/graph/Images.js