backbone.layoutmanager.js
function(views, options) {
    // Ensure that options is always an object, and clone it so that
    // changes to the original object don't screw up this view.
    options = _.extend({}, options);

    // Set up all Views passed.
    _.each(aConcat.call([], views), function(view) {
      // If the View has already been setup, no need to do it again.
      if (view.__manager__) {
        return;
      }

      var views, declaredViews;
      var proto = LayoutManager.prototype;

      // Ensure necessary properties are set.
      _.defaults(view, {
        // Ensure a view always has a views object.
        views: {},

        // Ensure a view always has a sections object.
        sections: {},

        // Internal state object used to store whether or not a View has been
        // taken over by layout manager and if it has been rendered into the
        // DOM.
        __manager__: {},

        // Add the ability to remove all Views.
        _removeViews: LayoutManager._removeViews,

        // Add the ability to remove itself.
        _removeView: LayoutManager._removeView

      // Mix in all LayoutManager prototype properties as well.
      }, LayoutManager.prototype);

      // Assign passed options.
      view.options = options;

      // Merge the View options into the View.
      _.extend(view, options);

      // By default the original Remove function is the Backbone.View one.
      view._remove = Backbone.View.prototype.remove;

      // Ensure the render is always set correctly.
      view.render = LayoutManager.prototype.render;

      // If the user provided their own remove override, use that instead of
      // the default.
      if (view.remove !== proto.remove) {
        view._remove = view.remove;
        view.remove = proto.remove;
      }

      // Normalize views to exist on either instance or options, default to
      // options.
      views = options.views || view.views;

      // Set the internal views, only if selectors have been provided.
      if (_.keys(views).length) {
        // Keep original object declared containing Views.
        declaredViews = views;

        // Reset the property to avoid duplication or overwritting.
        view.views = {};

        // If any declared view is wrapped in a function, invoke it.
        _.each(declaredViews, function(declaredView, key) {
          if (typeof declaredView === "function") {
            declaredViews[key] = declaredView.call(view, view);
          }
        });

        // Set the declared Views.
        view.setViews(declaredViews);
      }
    });
  }
function(views, options) {
    // Ensure that options is always an object, and clone it so that
    // changes to the original object don't screw up this view.
    options = _.extend({}, options);

    // Set up all Views passed.
    _.each(aConcat.call([], views), function(view) {
      // If the View has already been setup, no need to do it again.
      if (view.__manager__) {
        return;
      }

      var views, declaredViews;
      var proto = LayoutManager.prototype;

      // Ensure necessary properties are set.
      _.defaults(view, {
        // Ensure a view always has a views object.
        views: {},

        // Ensure a view always has a sections object.
        sections: {},

        // Internal state object used to store whether or not a View has been
        // taken over by layout manager and if it has been rendered into the
        // DOM.
        __manager__: {},

        // Add the ability to remove all Views.
        _removeViews: LayoutManager._removeViews,

        // Add the ability to remove itself.
        _removeView: LayoutManager._removeView

      // Mix in all LayoutManager prototype properties as well.
      }, LayoutManager.prototype);

      // Assign passed options.
      view.options = options;

      // Merge the View options into the View.
      _.extend(view, options);

      // By default the original Remove function is the Backbone.View one.
      view._remove = Backbone.View.prototype.remove;

      // Ensure the render is always set correctly.
      view.render = LayoutManager.prototype.render;

      // If the user provided their own remove override, use that instead of
      // the default.
      if (view.remove !== proto.remove) {
        view._remove = view.remove;
        view.remove = proto.remove;
      }

      // Normalize views to exist on either instance or options, default to
      // options.
      views = options.views || view.views;

      // Set the internal views, only if selectors have been provided.
      if (_.keys(views).length) {
        // Keep original object declared containing Views.
        declaredViews = views;

        // Reset the property to avoid duplication or overwritting.
        view.views = {};

        // If any declared view is wrapped in a function, invoke it.
        _.each(declaredViews, function(declaredView, key) {
          if (typeof declaredView === "function") {
            declaredViews[key] = declaredView.call(view, view);
          }
        });

        // Set the declared Views.
        view.setViews(declaredViews);
      }
    });
  }
function ( views , options ) { // Ensure that options is always an object, and clone it so that // changes to the original object don't screw up this view. options = _ . extend ( { } , options ) ; // Set up all Views passed. _ . each ( aConcat . call ( [ ] , views ) , function ( view ) { // If the View has already been setup, no need to do it again. if ( view . __manager__ ) { return ; } var views , declaredViews ; var proto = LayoutManager . prototype ; // Ensure necessary properties are set. _ . defaults ( view , { // Ensure a view always has a views object. views : { } , // Ensure a view always has a sections object. sections : { } , // Internal state object used to store whether or not a View has been // taken over by layout manager and if it has been rendered into the // DOM. __manager__ : { } , // Add the ability to remove all Views. _removeViews : LayoutManager . _removeViews , // Add the ability to remove itself. _removeView : LayoutManager . _removeView // Mix in all LayoutManager prototype properties as well. } , LayoutManager . prototype ) ; // Assign passed options. view . options = options ; // Merge the View options into the View. _ . extend ( view , options ) ; // By default the original Remove function is the Backbone.View one. view . _remove = Backbone . View . prototype . remove ; // Ensure the render is always set correctly. view . render = LayoutManager . prototype . render ; // If the user provided their own remove override, use that instead of // the default. if ( view . remove !== proto . remove ) { view . _remove = view . remove ; view . remove = proto . remove ; } // Normalize views to exist on either instance or options, default to // options. views = options . views || view . views ; // Set the internal views, only if selectors have been provided. if ( _ . keys ( views ) . length ) { // Keep original object declared containing Views. declaredViews = views ; // Reset the property to avoid duplication or overwritting. view . views = { } ; // If any declared view is wrapped in a function, invoke it. _ . each ( declaredViews , function ( declaredView , key ) { if ( typeof declaredView === "function" ) { declaredViews [ key ] = declaredView . call ( view , view ) ; } } ) ; // Set the declared Views. view . setViews ( declaredViews ) ; } } ) ; }
Configure a View to work with the LayoutManager plugin.
Configure a View to work with the LayoutManager plugin .