Skip to content

Commit

Permalink
🔧 set compatOptions on constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
desandro committed Jan 12, 2016
1 parent 01fa2ec commit e35d1b7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
11 changes: 5 additions & 6 deletions outlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ proto.option = function( opts ) {
* get backwards compatible option value, check old name
*/
proto._getOption = function( option ) {
var oldOption = compatOptions[ option ];
var oldOption = this.constructor.compatOptions[ option ];
return oldOption && this.options[ oldOption ] !== undefined ?
this.options[ oldOption ] !== undefined : this.options[ option ];
this.options[ oldOption ] : this.options[ option ];
};

var compatOptions = {
Outlayer.compatOptions = {
// currentName: oldName
initLayout: 'isInitLayout',
horizontal: 'isHorizontal',
Expand Down Expand Up @@ -850,10 +850,10 @@ Outlayer.data = function( elem ) {
Outlayer.create = function( namespace, options ) {
// sub-class Outlayer
var Layout = subclass( Outlayer );

// apply new options and compatOptions
Layout.defaults = utils.extend( {}, Outlayer.defaults );
// apply new options
utils.extend( Layout.defaults, options );
Layout.compatOptions = utils.extend( {}, Outlayer.compatOptions );

Layout.namespace = namespace;

Expand Down Expand Up @@ -895,4 +895,3 @@ Outlayer.Item = Item;
return Outlayer;

}));

6 changes: 5 additions & 1 deletion test/unit/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ QUnit.test( 'create Layouts', function( assert ) {

var Leiout = Outlayer.create('leiout');
Leiout.Item.prototype.foo = 'bar';
Leiout.compatOptions.fitWidth = 'isFitWidth';
var elem = document.createElement('div');
var lei = new Leiout( elem );
var lei = new Leiout( elem, {
isFitWidth: 300
});
var outlayr = new Outlayer( elem );

assert.equal( typeof CellsByRow, 'function', 'CellsByRow is a function' );
Expand All @@ -15,6 +18,7 @@ QUnit.test( 'create Layouts', function( assert ) {
assert.strictEqual( Outlayer.defaults.columnWidth, undefined, 'Outlayer has no default columnWidth' );
assert.strictEqual( Leiout.defaults.columnWidth, undefined, 'Leiout has no default columnWidth' );
assert.equal( lei.constructor.Item, Leiout.Item, 'Leiout.Item is on constructor.Item' );
assert.equal( lei._getOption('fitWidth'), 300, 'backwards compatible _getOption' );
assert.equal( outlayr.constructor.Item, Outlayer.Item, 'outlayr.Item is still correct Item' );

});

0 comments on commit e35d1b7

Please sign in to comment.