Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement: add "class" field to init options #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

whitesunset
Copy link

Hello guys.

I'm using your backbone.collectionView (thanks for it!) with Bootstrap Nav component (demo here: http://getbootstrap.com/components/#nav-tabs)

By default, Bootsrtap active tab has "active" class, but your library adds "selected" class to active model view element. So I just added option for selected model class with default value "selected".

Let me know if I did something wrong, on my local projects it works fine now.
Thanks!

@dgbeck
Copy link
Member

dgbeck commented May 20, 2016

HI @whitesunset , thanks for stopping by!

Couple of thoughts here:

  1. Seems reasonable that you might want to change the selected class name
  2. Seems quite rare
  3. In other rare circumstances you might also want to change the other class names, like 'not-sortable'
  4. If you change these class names for one instance of the collection view, you probably will want to change them for all other instances in your app

In light of these thoughts it might be better to attach a "hard coded" instance property that defines the class names, as opposed to using an option. Then you can derive a BaseCollectionView class for your own use, override that property, and everywhere you use the BaseCollectionView class in your app the class names will be the same.

for instance in collectionView

Backbone.CollectionView = Backbone.View.extend( {
        tagName : "ul",

        internalClassNames : {
                'selected' : 'selected',
                'notVisible' : 'not-visible',
                ...
        },

        events : {
            "mousedown > li, tbody > tr > td" : "_listItem_onMousedown",
            "dblclick > li, tbody > tr > td" : "_listItem_onDoubleClick",
            "click" : "_listBackground_onClick",
            "click ul.collection-view, table.collection-view" : "_listBackground_onClick",
            "keydown" : "_onKeydown"
        },
    ...

Then in your derived class

Backbone.BaseCollectionView = Backbone.CollectionView.extend( {
        internalClassNames : _.extend( {}, Backbone.CollectionView.internalClassNames, {
                'selected' : 'active'
        } ),
        ...
} );

and then just use new Backbone.BaseCollectionView() when you instantiate new collection view.

Would this work for your needs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants