@@ -6,56 +6,71 @@ define(function(require, exports, module) {
66
77 module . exports = flight . component ( function sidebar ( ) {
88
9+ var potentialSidebarItems = [ 'facets' , 'list' ] ;
10+ var presentItems = [ ] ;
11+
912 this . defaultAttrs ( {
10- listButton : '.select-list' ,
11- facetButton : '.select-facet' ,
12- list : '#list' ,
13- facet : '#facets'
13+ toggleButtons : '.sidebar-action' ,
14+ sidebarItems : '.sidebar-item'
1415 } ) ;
1516
17+ this . configureSidebar = function ( e , config ) {
18+ var configAttr = _ . keys ( config ) ;
19+ presentItems = _ . intersection ( potentialSidebarItems , configAttr ) ;
1620
17- this . showList = function ( e ) {
18- e . preventDefault ( ) ;
19- this . select ( 'list' ) . show ( ) ;
20- this . select ( 'facet' ) . hide ( ) ;
21- this . select ( 'listButton' ) . addClass ( 'active' ) ;
22- this . select ( 'facetButton' ) . removeClass ( 'active' ) ;
21+ var $sidebar = this . $node ;
22+
23+ // add class .sidebar-items-X based on active sidebar items
24+ $sidebar . addClass ( 'sidebar-items-' + presentItems . length ) ;
25+ // activate configured sidebar items
26+ _ . each ( presentItems , function ( item ) {
27+ $sidebar . find ( item ) . show ( ) ;
28+ $sidebar . find ( '[data-select="' + item + '"]' ) . parent ( ) . show ( ) ;
29+ } ) ;
30+
31+ if ( presentItems . length === 1 ) {
32+ $sidebar . find ( '.sidebar-nav' ) . hide ( ) ;
33+ $sidebar . addClass ( 'no-tabs' ) ;
34+ }
2335 } ;
2436
25- this . showFacet = function ( e ) {
37+ this . showItem = function ( e , elemObj ) {
38+ // generic toggle fn for sidebar tabs
2639 e . preventDefault ( ) ;
27- this . select ( 'facet' ) . show ( ) ;
28- this . select ( 'list' ) . hide ( ) ;
29- this . select ( 'facetButton' ) . addClass ( 'active' ) ;
30- this . select ( 'listButton' ) . removeClass ( 'active' ) ;
40+ var $el = $ ( elemObj . el ) ;
41+ var itemTitle = $el . data ( 'select' ) ;
42+ this . select ( 'sidebarItems' ) . hide ( ) ;
43+ this . $node . find ( '#' + itemTitle ) . show ( ) ;
44+ this . select ( 'toggleButtons' ) . removeClass ( 'active' ) ;
45+ $el . addClass ( 'active' ) ;
3146 } ;
3247
3348 this . showFullSidebar = function ( ) {
34- this . select ( 'facet' ) . show ( ) ;
35- this . select ( 'list' ) . show ( ) ;
49+ this . select ( 'sidebarItems' ) . show ( ) ;
3650 } ;
3751
38- this . toggleSidebar = function ( e ) {
52+ this . toggleHiddenSidebar = function ( e ) {
3953 e . preventDefault ( ) ;
4054 this . $node . toggleClass ( 'open' ) ;
4155 $ ( '.sidebar-toggle' ) . toggleClass ( 'active' ) ;
4256 } ;
4357
4458 this . after ( 'initialize' , function ( ) {
59+ this . on ( document , 'config' , this . configureSidebar ) ;
60+
4561 this . on ( 'click' , {
46- listButton : this . showList ,
47- facetButton : this . showFacet
62+ toggleButtons : this . showItem
4863 } ) ;
4964
5065 // This is outside of the component, but it controls it.. perhaps refactor to include within root element?
51- $ ( document ) . on ( 'click' , '.sidebar-toggle' , this . toggleSidebar . bind ( this ) ) ;
66+ $ ( document ) . on ( 'click' , '.sidebar-toggle' , this . toggleHiddenSidebar . bind ( this ) ) ;
67+
5268 $ ( window ) . on ( 'resize' , function ( ) {
5369 if ( document . body . clientWidth > 955 ) {
5470 this . showFullSidebar ( ) ;
5571 }
5672 } . bind ( this ) ) ;
5773
58-
5974 } ) ;
6075 } ) ;
6176} ) ;
0 commit comments