Sha256: af666c94724e9ca54d1b60711e945a17f914973ecb633bbacc1aee456202a2c1

Contents?: true

Size: 817 Bytes

Versions: 8

Compression:

Stored size: 817 Bytes

Contents

/**
 * @class Images
 * This class loads images and keeps them stored.
 */
Images = function () {
  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

8 entries across 8 versions & 1 rubygems

Version Path
vis-rails-1.0.1 vendor/assets/vis/graph/Images.js
vis-rails-1.0.0 vendor/assets/vis/graph/Images.js
vis-rails-0.0.6 vendor/assets/vis/graph/Images.js
vis-rails-0.0.5 vendor/assets/vis/graph/Images.js
vis-rails-0.0.4 vendor/assets/vis/graph/Images.js
vis-rails-0.0.3 vendor/assets/vis/graph/Images.js
vis-rails-0.0.2 vendor/assets/vis/graph/Images.js
vis-rails-0.0.1 vendor/assets/vis/graph/Images.js