Sha256: 9f55f604336440084f4d83d1428f76f5406bb6d7d9e3eec3ece9db58247cabb6

Contents?: true

Size: 1.63 KB

Versions: 80

Compression:

Stored size: 1.63 KB

Contents

/**
 * Module dependencies.
 */

var Emitter = require('emitter');
var tmpl = require('./template');
var o = require('dom');

/**
 * Expose `overlay()`.
 */

exports = module.exports = overlay;

/**
 * Expose `Overlay`.
 */

exports.Overlay = Overlay;

/**
 * Return a new `Overlay` with the given `options`.
 *
 * @param {Object|Element} options
 * @return {Overlay}
 * @api public
 */

function overlay(options){
  options = options || {};

  // element
  if (options.nodeName) {
    options = { target: options };
  }

  return new Overlay(options);
};

/**
 * Initialize a new `Overlay`.
 *
 * @param {Object} options
 * @api public
 */

function Overlay(options) {
  Emitter.call(this);
  options = options || {};
  this.target = options.target || 'body';
  this.closable = options.closable;
  this.el = o(tmpl);
  this.el.appendTo(this.target);
  if (this.closable) this.el.on('click', this.hide.bind(this));
}

/**
 * Mixin emitter.
 */

Emitter(Overlay.prototype);

/**
 * Show the overlay.
 *
 * Emits "show" event.
 *
 * @return {Overlay}
 * @api public
 */

Overlay.prototype.show = function(){
  this.emit('show');
  this.el.removeClass('hide');
  return this;
};

/**
 * Hide the overlay.
 *
 * Emits "hide" event.
 *
 * @return {Overlay}
 * @api public
 */

Overlay.prototype.hide = function(){
  this.emit('hide');
  return this.remove();
};

/**
 * Hide the overlay without emitting "hide".
 *
 * Emits "close" event.
 *
 * @return {Overlay}
 * @api public
 */

Overlay.prototype.remove = function(){
  var self = this;
  this.emit('close');
  this.el.addClass('hide');
  setTimeout(function(){
    self.el.remove();
  }, 2000);
  return this;
};

Version data entries

80 entries across 80 versions & 1 rubygems

Version Path
ende-0.5.22 components/component/overlay/0.1.1/index.js
ende-0.5.21 components/component/overlay/0.1.1/index.js
ende-0.5.20 components/component/overlay/0.1.1/index.js
ende-0.5.19 components/component/overlay/0.1.1/index.js
ende-0.5.18 components/component/overlay/0.1.1/index.js
ende-0.5.17 components/component/overlay/0.1.1/index.js
ende-0.5.16 components/component/overlay/0.1.1/index.js
ende-0.5.15 components/component/overlay/0.1.1/index.js
ende-0.5.14 components/component/overlay/0.1.1/index.js
ende-0.5.13 components/component/overlay/0.1.1/index.js
ende-0.5.12 components/component/overlay/0.1.1/index.js
ende-0.5.10 components/component/overlay/0.1.1/index.js
ende-0.5.9 components/component/overlay/0.1.1/index.js
ende-0.5.8 components/component/overlay/0.1.1/index.js
ende-0.5.7 components/component/overlay/0.1.1/index.js
ende-0.5.6 components/component/overlay/0.1.1/index.js
ende-0.4.25 vendor/components/component-overlay/index.js
ende-0.5.5 components/component/overlay/0.1.1/index.js
ende-0.5.4 components/component/overlay/0.1.1/index.js
ende-0.5.3 components/component/overlay/0.1.1/index.js