From 3200bc22fac604ed9785c9389dcdf922a43cd74b Mon Sep 17 00:00:00 2001 From: whitesunset Date: Fri, 20 May 2016 21:34:52 +0300 Subject: [PATCH] Improvement: add "class" field to init options --- src/backbone.collectionView.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/backbone.collectionView.js b/src/backbone.collectionView.js index e2250d6..f23deba 100755 --- a/src/backbone.collectionView.js +++ b/src/backbone.collectionView.js @@ -62,7 +62,8 @@ { "sortableOptions" : null }, { "reuseModelViews" : true }, { "detachedRendering" : false }, - { "emptyListCaption" : null } + { "emptyListCaption" : null }, + { "class" : 'selected' } ], initialize : function( options ) { @@ -686,6 +687,8 @@ }, _addSelectedClassToSelectedItems : function( oldItemsIdsWithSelectedClass ) { + var options = this.getOptions(); + if( _.isUndefined( oldItemsIdsWithSelectedClass ) ) oldItemsIdsWithSelectedClass = []; // oldItemsIdsWithSelectedClass is used for optimization purposes only. If this info is supplied then we @@ -695,10 +698,10 @@ itemsIdsFromWhichSelectedClassNeedsToBeRemoved = _.without( itemsIdsFromWhichSelectedClassNeedsToBeRemoved, this.selectedItems ); _.each( itemsIdsFromWhichSelectedClassNeedsToBeRemoved, function( thisItemId ) { - this._getContainerEl().find( "[data-model-cid=" + thisItemId + "]" ).removeClass( "selected" ); + this._getContainerEl().find( "[data-model-cid=" + thisItemId + "]" ).removeClass( options.class ); if( this._isRenderedAsList() ) { - this._getContainerEl().find( "li[data-model-cid=" + thisItemId + "] > *" ).removeClass( "selected" ); + this._getContainerEl().find( "li[data-model-cid=" + thisItemId + "] > *" ).removeClass( options.class ); } }, this ); @@ -706,10 +709,10 @@ itemsIdsFromWhichSelectedClassNeedsToBeAdded = _.without( itemsIdsFromWhichSelectedClassNeedsToBeAdded, oldItemsIdsWithSelectedClass ); _.each( itemsIdsFromWhichSelectedClassNeedsToBeAdded, function( thisItemId ) { - this._getContainerEl().find( "[data-model-cid=" + thisItemId + "]" ).addClass( "selected" ); + this._getContainerEl().find( "[data-model-cid=" + thisItemId + "]" ).addClass( options.class ); if( this._isRenderedAsList() ) { - this._getContainerEl().find( "li[data-model-cid=" + thisItemId + "] > *" ).addClass( "selected" ); + this._getContainerEl().find( "li[data-model-cid=" + thisItemId + "] > *" ).addClass( options.class ); } }, this ); },