Skip to content

Commit

Permalink
remove prototype.settings
Browse files Browse the repository at this point in the history
set constructor
move namespace and Item to constructor

comment
  • Loading branch information
desandro committed Jan 10, 2014
1 parent bcae797 commit d293f0d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
26 changes: 11 additions & 15 deletions outlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function Outlayer( element, options ) {
// bail out if not proper element
if ( !element || !isElement( element ) ) {
if ( console ) {
console.error( 'Bad ' + this.settings.namespace + ' element: ' + element );
console.error( 'Bad ' + this.constructor.namespace + ' element: ' + element );
}
return;
}
Expand All @@ -135,10 +135,8 @@ function Outlayer( element, options ) {
}

// settings are for internal use only
Outlayer.prototype.settings = {
namespace: 'outlayer',
item: Item
};
Outlayer.namespace = 'outlayer';
Outlayer.Item = Item;

// default options
Outlayer.prototype.options = {
Expand Down Expand Up @@ -202,7 +200,7 @@ Outlayer.prototype.reloadItems = function() {
Outlayer.prototype._itemize = function( elems ) {

var itemElems = this._filterFindItemElements( elems );
var Item = this.settings.item;
var Item = this.constructor.Item;

// create new Outlayer Items for collection
var items = [];
Expand Down Expand Up @@ -849,7 +847,7 @@ Outlayer.prototype.destroy = function() {
delete this.element.outlayerGUID;
// remove data for jQuery
if ( jQuery ) {
jQuery.removeData( this.element, this.settings.namespace );
jQuery.removeData( this.element, this.constructor.namespace );
}

};
Expand All @@ -868,8 +866,7 @@ Outlayer.data = function( elem ) {

// -------------------------- -------------------------- //

// copy an object on the Outlayer prototype
// used in options and settings
// copy an object on the Outlayer prototype to new object
function copyOutlayerProto( obj, property ) {
obj.prototype[ property ] = extend( {}, Outlayer.prototype[ property ] );
}
Expand All @@ -891,14 +888,15 @@ Outlayer.create = function( namespace, options ) {
} else {
extend( Layout.prototype, Outlayer.prototype );
}
// set contructor, used for namespace and Item
Layout.prototype.constructor = Layout;


// copy default options so Outlayer.options don't get touched
copyOutlayerProto( Layout, 'options' );
copyOutlayerProto( Layout, 'settings' );

// apply new options
extend( Layout.prototype.options, options );

Layout.prototype.settings.namespace = namespace;
Layout.namespace = namespace;

Layout.data = Outlayer.data;

Expand All @@ -909,8 +907,6 @@ Outlayer.create = function( namespace, options ) {

Layout.Item.prototype = new Item();

Layout.prototype.settings.item = Layout.Item;

// -------------------------- declarative -------------------------- //

/**
Expand Down
12 changes: 9 additions & 3 deletions test/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@ var CellsByRow = window.CellsByRow;
test( 'create Layouts', function() {

var Leiout = Outlayer.create('leiout');
Leiout.Item.prototype.foo = 'bar';
var elem = document.createElement('div');
var lei = new Leiout( elem );
var outlayr = new Outlayer( elem );

equal( typeof CellsByRow, 'function', 'CellsByRow is a function' );
equal( CellsByRow.prototype.settings.namespace, 'cellsByRow', 'cellsByRow namespace' );
equal( Outlayer.prototype.settings.namespace, 'outlayer', 'Outlayer namespace unchanged' );
equal( Leiout.prototype.settings.namespace, 'leiout', 'Leiout namespace' );
equal( CellsByRow.namespace, 'cellsByRow', 'cellsByRow namespace' );
equal( Outlayer.namespace, 'outlayer', 'Outlayer namespace unchanged' );
equal( Leiout.namespace, 'leiout', 'Leiout namespace' );
equal( CellsByRow.prototype.options.isResizeBound, true, 'isResizeBound option there' );
equal( CellsByRow.prototype.options.columnWidth, 100, 'columnWidth option set' );
strictEqual( Outlayer.prototype.options.columnWidth, undefined, 'Outlayer has no default columnWidth' );
strictEqual( Leiout.prototype.options.columnWidth, undefined, 'Leiout has no default columnWidth' );
equal( lei.constructor.Item, Leiout.Item, 'Leiout.Item is on constructor.Item' );
equal( outlayr.constructor.Item, Outlayer.Item, 'outlayr.Item is still correct Item' );

});

Expand Down

0 comments on commit d293f0d

Please sign in to comment.