Comparing version 0.0.5 to 0.0.6
58
index.js
@@ -1,57 +0,1 @@ | ||
var _ = require('underscore'), Backbone = require('backbone'); | ||
var BassView = Backbone.View.extend({ | ||
// Assigns a view to a jquery selector in this view's element. | ||
// the second parameter may be an actual backbone view, or a | ||
// key for a registered subview via the subview() method below. | ||
assign : function (selector, view) { | ||
var selectors; | ||
if (_.isObject(selector)) { | ||
selectors = selector; | ||
} | ||
else { | ||
selectors = {}; | ||
selectors[selector] = view; | ||
} | ||
if (!selectors) return; | ||
_.each(selectors, function (view, selector) { | ||
if (typeof view === "string") view = this.__subviews__[view]; | ||
view.setElement(this.$(selector)).render(); | ||
}, this); | ||
}, | ||
// Triggers a custom event that can be listened for | ||
// by subviews etc. Also unbinds events to prevent | ||
// detached DOM elements. | ||
remove: function () { | ||
this.trigger("clean_up"); | ||
this.unbind(); | ||
Backbone.View.prototype.remove.call(this); | ||
}, | ||
// Registers or retrieves a subview of this view. | ||
// The main thing here is to automate the process of | ||
// having subviews listen to their parents for clean_up. | ||
subview: function(key, view){ | ||
// Set up subview object | ||
var sv = this.__subviews__ = this.__subviews__ || {}; | ||
// Check if getting | ||
if (view === undefined) return sv[key]; | ||
// Add listener for removal event | ||
view.listenToOnce(this, "clean_up", function() { | ||
view.remove(); | ||
delete sv[key]; | ||
}); | ||
// Set the key | ||
sv[key] = view; | ||
// Allow chaining | ||
return view | ||
} | ||
}); | ||
exports = module.exports = BassView | ||
exports = module.exports = require('./bassview'); |
{ | ||
"name": "bassview", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "base view for backbone", | ||
"main": "index.js", | ||
"main": "bassview.js", | ||
"scripts": { | ||
@@ -7,0 +7,0 @@ "test": "echo \"Error: no test specified\" && exit 1" |
Sorry, the diff of this file is not supported yet
2669
6
56