/* eslint-disable */

// Generated by CoffeeScript 1.6.3
/*
jQuery Growl
Copyright 2013 Kevin Sylvestre
1.1.4
*/

(function () {
  let $; let Animation; let Growl;
  const __bind = function (fn, me) { return function () { return fn.apply(me, arguments); }; };

  $ = jQuery;

  Animation = (function () {
    function Animation() {}

    Animation.transitions = {
      webkitTransition: 'webkitTransitionEnd',
      mozTransition: 'mozTransitionEnd',
      oTransition: 'oTransitionEnd',
      transition: 'transitionend',
    };

    Animation.transition = function ($el) {
      let el; let result; let type; let
        _ref;
      el = $el[0];
      _ref = this.transitions;
      for (type in _ref) {
        result = _ref[type];
        if (el.style[type] != null) {
          return result;
        }
      }
    };

    return Animation;
  }());

  Growl = (function () {
    Growl.settings = {
      namespace: 'growl',
      duration: 3200,
      close: '&times;',
      location: 'default',
      style: 'default',
      size: 'medium',
    };

    Growl.growl = function (settings) {
      if (settings == null) {
        settings = {};
      }
      this.initialize();
      return new Growl(settings);
    };

    Growl.initialize = function () {
      return $('body:not(:has(#growls))').append('<div id="growls" />');
    };

    function Growl(settings) {
      if (settings == null) {
        settings = {};
      }
      this.html = __bind(this.html, this);
      this.$growl = __bind(this.$growl, this);
      this.$growls = __bind(this.$growls, this);
      this.animate = __bind(this.animate, this);
      this.remove = __bind(this.remove, this);
      this.dismiss = __bind(this.dismiss, this);
      this.present = __bind(this.present, this);
      this.close = __bind(this.close, this);
      this.cycle = __bind(this.cycle, this);
      this.unbind = __bind(this.unbind, this);
      this.bind = __bind(this.bind, this);
      this.render = __bind(this.render, this);
      this.settings = $.extend({}, Growl.settings, settings);
      this.$growls().attr('class', this.settings.location);
      this.render();
    }

    Growl.prototype.render = function () {
      let $growl;
      $growl = this.$growl();
      this.$growls().append($growl);
      this.cycle($growl);
    };

    Growl.prototype.bind = function ($growl) {
      if ($growl == null) {
        $growl = this.$growl();
      }
      return $growl.find(`.${this.settings.namespace}-close`).on('click', this.close);
    };

    Growl.prototype.unbind = function ($growl) {
      if ($growl == null) {
        $growl = this.$growl();
      }
      return $growl.find(`.${this.settings.namespace - close}`).off('click', this.close);
    };

    Growl.prototype.cycle = function ($growl) {
      if ($growl == null) {
        $growl = this.$growl();
      }
      return $growl.queue(this.present).delay(this.settings.duration).queue(this.dismiss).queue(this.remove);
    };

    Growl.prototype.close = function (event) {
      let $growl;
      event.preventDefault();
      event.stopPropagation();
      $growl = this.$growl();
      return $growl.stop().queue(this.dismiss).queue(this.remove);
    };

    Growl.prototype.present = function (callback) {
      let $growl;
      $growl = this.$growl();
      this.bind($growl);
      return this.animate($growl, `${this.settings.namespace}-incoming`, 'out', callback);
    };

    Growl.prototype.dismiss = function (callback) {
      let $growl;
      $growl = this.$growl();
      this.unbind($growl);
      return this.animate($growl, `${this.settings.namespace}-outgoing`, 'in', callback);
    };

    Growl.prototype.remove = function (callback) {
      this.$growl().remove();
      return callback();
    };

    Growl.prototype.animate = function ($element, name, direction, callback) {
      let transition;

      if (direction == null) {
        direction = 'in';
      }
      transition = Animation.transition($element);
      $element[direction === 'in' ? 'removeClass' : 'addClass'](name);
      $element.offset().position;
      $element[direction === 'in' ? 'addClass' : 'removeClass'](name);
      if (callback == null) {
        return;
      }
      if (transition != null) {
        $element.one(transition, callback);
      } else {
        callback();
      }
    };

    Growl.prototype.$growls = function () {
      return this.$_growls != null ? this.$_growls : this.$_growls = $('#growls');
    };

    Growl.prototype.$growl = function () {
      return this.$_growl != null ? this.$_growl : this.$_growl = $(this.html());
    };

    Growl.prototype.html = function () {
      return `<div class='${this.settings.namespace} ${this.settings.namespace}-${this.settings.style} ${this.settings.namespace}-${this.settings.size}'>\n  <div class='${this.settings.namespace}-close'>${this.settings.close}</div>\n  <div class='${this.settings.namespace}-title'>${this.settings.title}</div>\n  <div class='${this.settings.namespace}-message'>${this.settings.message}</div>\n</div>`;
    };

    return Growl;
  }());

  $.growl = function (options) {
    if (options == null) {
      options = {};
    }
    return Growl.growl(options);
  };

  $.growl.error = function (options) {
    let settings;

    if (options == null) {
      options = {};
    }
    settings = {
      title: 'Error!',
      style: 'error',
    };
    return $.growl($.extend(settings, options));
  };

  $.growl.notice = function (options) {
    let settings;

    if (options == null) {
      options = {};
    }
    settings = {
      title: 'Notice!',
      style: 'notice',
    };
    return $.growl($.extend(settings, options));
  };

  $.growl.warning = function (options) {
    let settings;

    if (options == null) {
      options = {};
    }
    settings = {
      title: 'Warning!',
      style: 'warning',
    };
    return $.growl($.extend(settings, options));
  };
}).call(this);
