text: // Generated by CoffeeScript 1.3.3
  (function() {
    var StackView, StackViewVessel, StackViewVessels, animate, exports, _ref,
      __hasProp = {}.hasOwnProperty,
      __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
      __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
  
    StackViewVessel = (function(_super) {
  
      __extends(StackViewVessel, _super);
  
      function StackViewVessel() {
        return StackViewVessel.__super__.constructor.apply(this, arguments);
      }
  
      return StackViewVessel;
  
    })(Backbone.Model);
  
    StackViewVessels = (function(_super) {
  
      __extends(StackViewVessels, _super);
  
      function StackViewVessels() {
        return StackViewVessels.__super__.constructor.apply(this, arguments);
      }
  
      StackViewVessels.prototype.model = StackViewVessel;
  
      return StackViewVessels;
  
    })(Backbone.Collection);
  
    animate = function($el, animation, direction, callback) {
      var className, eventName;
      className = "" + animation + "-" + direction;
      eventName = "animation-event-" + className;
      $el.one(eventName, function() {
        $el.removeClass(className);
        return typeof callback === "function" ? callback() : void 0;
      });
      if (animation === false) {
        $el.trigger(eventName);
        return;
      }
      $el.on('webkitAnimationEnd animationEnd', function() {
        return $el.trigger(eventName);
      });
      return $el.addClass(className);
    };
  
    StackView = (function(_super) {
  
      __extends(StackView, _super);
  
      function StackView() {
        this.pop = __bind(this.pop, this);
  
        this.push = __bind(this.push, this);
  
        this.render = __bind(this.render, this);
        return StackView.__super__.constructor.apply(this, arguments);
      }
  
      /*
          A stack is a collection of nested views. The views can be pushed and popped
          off the stack. The stack can:
      
            * Transition views with CSS animations
            * Keeps track of which state.
            * Can cache elements in the DOM.
      */
  
  
      StackView.prototype.className = 'jmbo-stack-view';
  
      StackView.prototype.initialize = function() {
        if (!(this.collection != null)) {
          this.collection = new StackViewVessels;
        }
        this.options.pushDefaults = _.extend({
          animation: 'slide-right',
          removeFromDOM: true
        }, this.options.pushDefaults);
        return this.options.popDefaults = _.extend({
          animation: 'slide-left'
        }, this.options.popDefaults);
      };
  
      StackView.prototype.render = function() {
        var viewVessel, viewVessels, _i, _len;
        viewVessels = this.collection.where({
          _cache: true
        });
        if (this.collection.last()) {
          viewVessels.push(this.collection.last());
        }
        this.$el.contents().detach();
        for (_i = 0, _len = viewVessels.length; _i < _len; _i++) {
          viewVessel = viewVessels[_i];
          this.$el.append(viewVessel.get('view').render().el);
        }
        return this;
      };
  
      StackView.prototype.push = function(newView, options) {
        var currentView, currentViewVessel, opts;
        opts = {};
        _.extend(opts, this.options.pushDefaults, options);
        currentViewVessel = this.collection.last();
        if (currentViewVessel != null) {
          currentView = currentViewVessel.get('view');
          animate(currentView.$el, opts.animation, 'out', function() {
            if (!opts.removeFromDOM) {
              return currentViewVessel.set({
                '_cache': !opts.removeFromDOM
              });
            } else {
              return currentView.$el.detach();
            }
          });
        }
        this.collection.add({
          'view': newView
        });
        newView.stackView = this;
        this.$el.append(newView.render().el);
        newView.trigger('stack:focus');
        return animate(newView.$el, opts.animation, 'in', function() {
          return typeof opts.callback === "function" ? opts.callback() : void 0;
        });
      };
  
      StackView.prototype.pop = function(options) {
        var currentView, newView, newViewVessel, opts, _ref;
        opts = {};
        _.extend(opts, this.options.popDefaults, options);
        currentView = (_ref = this.collection.pop()) != null ? _ref.get('view') : void 0;
        animate(currentView.$el, opts.animation, 'out', function() {
          delete currentView.stackView;
          currentView.$el.remove();
          return typeof opts.callback === "function" ? opts.callback() : void 0;
        });
        newViewVessel = this.collection.last();
        if (newViewVessel != null) {
          newView = newViewVessel.get('view');
          if (!newViewVessel.get('_cache')) {
            this.$el.append(newView.render().el);
            newView.trigger('stack:focus');
          }
          return animate(newView.$el, opts.animation, 'in');
        }
      };
  
      return StackView;
  
    })(Backbone.View);
  
    exports = this;
  
    exports.Jmbo = (_ref = exports.Jmbo) != null ? _ref : {};
  
    exports.Jmbo.StackView = StackView;
  
  }).call(this);
  