Skip to content

Instantly share code, notes, and snippets.

@charlycoste
Forked from brian-mann/FadeTransitionRegion.js
Created September 15, 2013 12:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save charlycoste/6570339 to your computer and use it in GitHub Desktop.
Save charlycoste/6570339 to your computer and use it in GitHub Desktop.
FadeTransitionRegion = Backbone.Marionette.Region.extend
show: (view)->
@ensureEl()
view.render()
@close ->
return if @currentView and @currentView isnt view
@currentView = view
@open view, ->
view.onShow?()
view.trigger "show"
@onShow? view
@trigger "view:show", view
close: (cb) ->
view = @currentView
delete @currentView
if not view
cb?.call @
return
view.fadeOut =>
view.close?()
@trigger "view:closed", view
cb?.call @
open: (view, callback) ->
@$el.html view.$el.hide()
view.fadeIn =>
callback.call @
// Generated by CoffeeScript 1.6.1
var FadeTransitionRegion;
FadeTransitionRegion = Backbone.Marionette.Region.extend({
show: function(view) {
this.ensureEl();
view.render();
return this.close(function() {
if (this.currentView && this.currentView !== view) {
return;
}
this.currentView = view;
return this.open(view, function() {
if (typeof view.onShow === "function") {
view.onShow();
}
view.trigger("show");
if (typeof this.onShow === "function") {
this.onShow(view);
}
return this.trigger("view:show", view);
});
});
},
close: function(cb) {
var view,
_this = this;
view = this.currentView;
delete this.currentView;
if (!view) {
if (cb != null) {
cb.call(this);
}
return;
}
return view.fadeOut(function() {
if (typeof view.close === "function") {
view.close();
}
_this.trigger("view:closed", view);
return cb != null ? cb.call(_this) : void 0;
});
},
open: function(view, callback) {
var _this = this;
this.$el.html(view.$el.hide());
return view.fadeIn(function() {
return callback.call(_this);
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment