Skip to content

Instantly share code, notes, and snippets.

@brian-mann
Created October 24, 2012 16:28
Show Gist options
  • Select an option

  • Save brian-mann/3947145 to your computer and use it in GitHub Desktop.

Select an option

Save brian-mann/3947145 to your computer and use it in GitHub Desktop.

Revisions

  1. brian-mann renamed this gist Oct 24, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. brian-mann created this gist Oct 24, 2012.
    48 changes: 48 additions & 0 deletions FadeTransitionRegion
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    var FadeTransitionRegion = Backbone.Marionette.Region.extend({

    show: function(view){
    this.ensureEl();
    view.render();

    this.close(function() {
    if (this.currentView && this.currentView !== view) { return; }
    this.currentView = view;

    this.open(view, function(){
    if (view.onShow){view.onShow();}
    view.trigger("show");

    if (this.onShow) { this.onShow(view); }
    this.trigger("view:show", view);
    });
    });

    },

    close: function(cb){
    var view = this.currentView;
    delete this.currentView;

    if (!view){
    if (cb){ cb.call(this); }
    return;
    }

    var that = this;
    view.fadeOut(function(){
    if (view.close) { view.close(); }
    that.trigger("view:closed", view);
    if (cb){ cb.call(that); }
    });

    },

    open: function(view, callback){
    var that = this;
    this.$el.html(view.$el.hide());
    view.fadeIn(function(){
    callback.call(that);
    });
    }

    });