Skip to content

Instantly share code, notes, and snippets.

@krusty
Created March 22, 2012 20:58
Show Gist options
  • Save krusty/2164463 to your computer and use it in GitHub Desktop.
Save krusty/2164463 to your computer and use it in GitHub Desktop.
blocking view
View: Backbone.View.extend({
initialize: function (options) {
if (typeof this.smb_initialize === "function") {
this.smb_initialize(options);
}
this.block_options = this.block_options || {};
this.block_options.element = this.block_options.element || this.$el;
this.block_options.object = this.block_options.object ||
this.object;
var object = this[this.block_options.object];
if (object) {
object.on('fetching', this.block, this);
object.on('reset change add done', this.unblock, this);
object.on('post_action:change_class', this.change_class, this);
}
Backbone.View.prototype.initialize.call(this);
},
change_class: function(post_action, original_post_action) {
this.$el
.removeClass(original_post_action.from_class)
.addClass(original_post_action.to_class);
},
block: function () {
this.block_options.element.block();
},
unblock: function () {
this.block_options.element.unblock();
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment