updated backbone to 0.9.10

updated marionette 1.0.0-rc5
pull/6/head
Keivan Beigi 12 years ago committed by kay.one
parent eab6abc8c9
commit 78d007791f

File diff suppressed because it is too large Load Diff

@ -1,4 +1,4 @@
// Backbone.Marionette, v1.0.0-rc3 // Backbone.Marionette, v1.0.0-rc5
// Copyright (c)2013 Derick Bailey, Muted Solutions, LLC. // Copyright (c)2013 Derick Bailey, Muted Solutions, LLC.
// Distributed under MIT license // Distributed under MIT license
// http://github.com/marionettejs/backbone.marionette // http://github.com/marionettejs/backbone.marionette
@ -207,12 +207,12 @@ Backbone.ChildViewContainer = (function (Backbone, _) {
return Container; return Container;
})(Backbone, _); })(Backbone, _);
// Backbone.Wreqr, v0.2.0 // Backbone.Wreqr, v0.1.1
// Copyright (c)2012 Derick Bailey, Muted Solutions, LLC. // Copyright (c)2013 Derick Bailey, Muted Solutions, LLC.
// Distributed under MIT license // Distributed under MIT license
// http://github.com/marionettejs/backbone.wreqr // http://github.com/marionettejs/backbone.wreqr
Backbone.Wreqr = (function (Backbone, Marionette, _) { Backbone.Wreqr = (function (Backbone, Marionette, _) {
"option strict"; "use strict";
var Wreqr = {}; var Wreqr = {};
// Handlers // Handlers
@ -220,13 +220,12 @@ Backbone.Wreqr = (function (Backbone, Marionette, _) {
// A registry of functions to call, given a name // A registry of functions to call, given a name
Wreqr.Handlers = (function (Backbone, _) { Wreqr.Handlers = (function (Backbone, _) {
"option strict"; "use strict";
// Constructor // Constructor
// ----------- // -----------
var Handlers = function () { var Handlers = function () {
"use strict";
this._handlers = {}; this._handlers = {};
}; };
@ -284,7 +283,7 @@ Backbone.Wreqr = (function (Backbone, Marionette, _) {
// A simple command pattern implementation. Register a command // A simple command pattern implementation. Register a command
// handler and execute it. // handler and execute it.
Wreqr.Commands = (function (Wreqr) { Wreqr.Commands = (function (Wreqr) {
"option strict"; "use strict";
return Wreqr.Handlers.extend({ return Wreqr.Handlers.extend({
execute: function () { execute: function () {
@ -303,7 +302,7 @@ Backbone.Wreqr = (function (Backbone, Marionette, _) {
// A simple request/response implementation. Register a // A simple request/response implementation. Register a
// request handler, and return a response from it // request handler, and return a response from it
Wreqr.RequestResponse = (function (Wreqr) { Wreqr.RequestResponse = (function (Wreqr) {
"option strict"; "use strict";
return Wreqr.Handlers.extend({ return Wreqr.Handlers.extend({
request: function () { request: function () {
@ -322,32 +321,16 @@ Backbone.Wreqr = (function (Backbone, Marionette, _) {
// of an application through event-driven architecture. // of an application through event-driven architecture.
Wreqr.EventAggregator = (function (Backbone, _) { Wreqr.EventAggregator = (function (Backbone, _) {
"use strict";
var EA = function () { };
// Grab a reference to the original listenTo // Copy the `extend` function used by Backbone's classes
var listenTo = Backbone.Events.listenTo; EA.extend = Backbone.Model.extend;
// Create a version of listenTo that allows contexting binding
function contextBoundListenTo(obj, evtSource, events, callback, context) {
context = context || obj;
return listenTo.call(obj, evtSource, events, _.bind(callback, context));
}
// Define the EventAggregator
function EventAggregator() { }
// Mix Backbone.Events in to it
_.extend(EventAggregator.prototype, Backbone.Events, {
// Override the listenTo so that we can have a version that
// correctly binds context
listenTo: function (evtSource, events, callback, context) {
return contextBoundListenTo(this, evtSource, events, callback, context);
}
});
// Allow it to be extended // Copy the basic Backbone.Events on to the event aggregator
EventAggregator.extend = Backbone.Model.extend; _.extend(EA.prototype, Backbone.Events);
return EventAggregator; return EA;
})(Backbone, _); })(Backbone, _);
@ -381,7 +364,7 @@ var Marionette = (function (Backbone, _, $) {
if (!target || !optionName) { return; } if (!target || !optionName) { return; }
var value; var value;
if (target.options && target.options[optionName]) { if (target.options && (optionName in target.options) && (target.options[optionName] !== undefined)) {
value = target.options[optionName]; value = target.options[optionName];
} else { } else {
value = target[optionName]; value = target[optionName];
@ -509,56 +492,6 @@ var Marionette = (function (Backbone, _, $) {
})(); })();
// addEventBinder
// --------------
//
// Mixes in Backbone.Events to the target object, if it is not present
// already. Also adjusts the listenTo method to accept a 4th parameter
// for the callback context.
(function (Backbone, Marionette, _) {
// grab a reference to the original listenTo
var listenTo = Backbone.Events.listenTo;
// Fix the listenTo method on the target object, allowing the 4th
// context parameter to be specified
Marionette.addEventBinder = function (target) {
// If the target is not already extending Backbone.Events,
// then extend that on to it first
if (!target.on && !target.off && !target.listenTo && !target.stopListening) {
_.extend(target, Backbone.Events);
}
// Override the built-in listenTo method to make sure we
// account for context
target.listenTo = function (evtSource, events, callback, context) {
context = context || this;
return listenTo.call(this, evtSource, events, _.bind(callback, context));
};
};
})(Backbone, Marionette, _);
// Event Aggregator
// ----------------
// A pub-sub object that can be used to decouple various parts
// of an application through event-driven architecture.
//
// Extends [Backbone.Wreqr.EventAggregator](https://github.com/marionettejs/backbone.wreqr)
// and mixes in an EventBinder from [Backbone.EventBinder](https://github.com/marionettejs/backbone.eventbinder).
Marionette.EventAggregator = Backbone.Wreqr.EventAggregator.extend({
constructor: function () {
Marionette.addEventBinder(this);
var args = Array.prototype.slice.apply(arguments);
Backbone.Wreqr.EventAggregator.prototype.constructor.apply(this, args);
}
});
// Marionette.bindEntityEvents & unbindEntityEvents // Marionette.bindEntityEvents & unbindEntityEvents
// --------------------------- // ---------------------------
// //
@ -707,8 +640,6 @@ var Marionette = (function (Backbone, _, $) {
this.triggerMethod = Marionette.triggerMethod; this.triggerMethod = Marionette.triggerMethod;
this.options = options || {}; this.options = options || {};
Marionette.addEventBinder(this);
if (_.isFunction(this.initialize)) { if (_.isFunction(this.initialize)) {
this.initialize(this.options); this.initialize(this.options);
} }
@ -737,8 +668,6 @@ var Marionette = (function (Backbone, _, $) {
Marionette.Region = function (options) { Marionette.Region = function (options) {
this.options = options || {}; this.options = options || {};
Marionette.addEventBinder(this);
this.el = Marionette.getOption(this, "el"); this.el = Marionette.getOption(this, "el");
if (!this.el) { if (!this.el) {
@ -953,7 +882,7 @@ var Marionette = (function (Backbone, _, $) {
// and know whether or not it has been loaded // and know whether or not it has been loaded
_.extend(Marionette.TemplateCache.prototype, { _.extend(Marionette.TemplateCache.prototype, {
// Internal method to load the template asynchronously. // Internal method to load the template
load: function () { load: function () {
var that = this; var that = this;
@ -970,12 +899,12 @@ var Marionette = (function (Backbone, _, $) {
}, },
// Load a template from the DOM, by default. Override // Load a template from the DOM, by default. Override
// this method to provide your own template retrieval, // this method to provide your own template retrieval
// such as asynchronous loading from a server. // For asynchronous loading with AMD/RequireJS, consider
// using a template-loader plugin as described here:
// https://github.com/marionettejs/backbone.marionette/wiki/Using-marionette-with-requirejs
loadTemplate: function (templateId) { loadTemplate: function (templateId) {
var template = $(templateId).html();
var templateEl = $(templateId);
var template = templateEl.html();
if (!template || template.length === 0) { if (!template || template.length === 0) {
var msg = "Could not find template: '" + templateId + "'"; var msg = "Could not find template: '" + templateId + "'";
@ -984,7 +913,6 @@ var Marionette = (function (Backbone, _, $) {
throw err; throw err;
} }
templateEl.remove();
return template; return template;
}, },
@ -1026,7 +954,6 @@ var Marionette = (function (Backbone, _, $) {
constructor: function () { constructor: function () {
_.bindAll(this, "render"); _.bindAll(this, "render");
Marionette.addEventBinder(this);
var args = Array.prototype.slice.apply(arguments); var args = Array.prototype.slice.apply(arguments);
Backbone.View.prototype.constructor.apply(this, args); Backbone.View.prototype.constructor.apply(this, args);
@ -1091,7 +1018,7 @@ var Marionette = (function (Backbone, _, $) {
}; };
// trigger the event // trigger the event
that.trigger(value, args); that.triggerMethod(value, args);
}; };
}); });
@ -1401,15 +1328,15 @@ var Marionette = (function (Backbone, _, $) {
// remove and/or close it later // remove and/or close it later
this.children.add(view); this.children.add(view);
// Render it and show it
this.renderItemView(view, index);
// call the "show" method if the collection view // call the "show" method if the collection view
// has already been shown // has already been shown
if (this._isShown) { if (this._isShown) {
Marionette.triggerMethod.call(view, "show"); Marionette.triggerMethod.call(view, "show");
} }
// Render it and show it
var renderResult = this.renderItemView(view, index);
// this view was added // this view was added
this.triggerMethod("after:item:added", view); this.triggerMethod("after:item:added", view);
}, },
@ -1447,6 +1374,7 @@ var Marionette = (function (Backbone, _, $) {
removeItemView: function (item) { removeItemView: function (item) {
var view = this.children.findByModel(item); var view = this.children.findByModel(item);
this.removeChildView(view); this.removeChildView(view);
this.checkEmpty();
}, },
// Remove the child view and close it // Remove the child view and close it
@ -1464,13 +1392,16 @@ var Marionette = (function (Backbone, _, $) {
this.children.remove(view); this.children.remove(view);
} }
this.triggerMethod("item:removed", view);
},
// helper to show the empty view if the collection is empty
checkEmpty: function () {
// check if we're empty now, and if we are, show the // check if we're empty now, and if we are, show the
// empty view // empty view
if (!this.collection || this.collection.length === 0) { if (!this.collection || this.collection.length === 0) {
this.showEmptyView(); this.showEmptyView();
} }
this.triggerMethod("item:removed", view);
}, },
// Append the HTML to the collection's `el`. // Append the HTML to the collection's `el`.
@ -1505,9 +1436,7 @@ var Marionette = (function (Backbone, _, $) {
this.children.each(function (child) { this.children.each(function (child) {
this.removeChildView(child); this.removeChildView(child);
}, this); }, this);
this.checkEmpty();
// re-initialize to clean up after ourselves
this._initChildViewStorage();
} }
}); });
@ -1845,14 +1774,13 @@ var Marionette = (function (Backbone, _, $) {
// event aggregator as `app.vent` // event aggregator as `app.vent`
Marionette.Application = function (options) { Marionette.Application = function (options) {
this.initCallbacks = new Marionette.Callbacks(); this.initCallbacks = new Marionette.Callbacks();
this.vent = new Marionette.EventAggregator(); this.vent = new Backbone.Wreqr.EventAggregator();
this.commands = new Backbone.Wreqr.Commands(); this.commands = new Backbone.Wreqr.Commands();
this.reqres = new Backbone.Wreqr.RequestResponse(); this.reqres = new Backbone.Wreqr.RequestResponse();
this.submodules = {}; this.submodules = {};
_.extend(this, options); _.extend(this, options);
Marionette.addEventBinder(this);
this.triggerMethod = Marionette.triggerMethod; this.triggerMethod = Marionette.triggerMethod;
}; };
@ -1939,8 +1867,6 @@ var Marionette = (function (Backbone, _, $) {
this.app = app; this.app = app;
this.startWithParent = true; this.startWithParent = true;
// extend this module with an event binder
Marionette.addEventBinder(this);
this.triggerMethod = Marionette.triggerMethod; this.triggerMethod = Marionette.triggerMethod;
}; };
@ -2001,7 +1927,7 @@ var Marionette = (function (Backbone, _, $) {
_.each(this.submodules, function (mod) { mod.stop(); }); _.each(this.submodules, function (mod) { mod.stop(); });
// run the finalizers // run the finalizers
this._finalizerCallbacks.run(); this._finalizerCallbacks.run(undefined, this);
// reset the initializers and finalizers // reset the initializers and finalizers
this._initializerCallbacks.reset(); this._initializerCallbacks.reset();

Loading…
Cancel
Save