@@ -10,13 +10,13 @@ angularIO.directive('apiList', function () {
10
10
' <dd ng-class="{ active: !$ctrl.apiType }" ng-click="$ctrl.apiType = null">All</dd>' +
11
11
' <dd ng-repeat="apiType in $ctrl.apiTypes" ng-class="{ active: $ctrl.apiType === apiType }" ng-click="$ctrl.setType(apiType)" class="{{apiType.cssClass}}">{{apiType.title}}</dd>' +
12
12
' </dl>' +
13
- ' <input placeholder="Filter" ng-model="$ctrl.apiFilter" ng-model-options="{updateOn: \'default blur\', debounce: {\'default\': 400 , \'blur\': 0}}" class="api-filter">' +
13
+ ' <input placeholder="Filter" ng-model="$ctrl.apiFilter" ng-model-options="{updateOn: \'default blur\', debounce: {\'default\': 350 , \'blur\': 0}}" class="api-filter">' +
14
14
'</div>' +
15
15
'<article class="l-content-small grid-fluid docs-content">' +
16
- ' <div ng-repeat="section in $ctrl.filteredSections " ng-cloak="ng-cloak">' +
16
+ ' <div ng-repeat="section in $ctrl.groupedSections" ng-if="$ctrl.isFiltered(section) " ng-cloak="ng-cloak">' +
17
17
' <h3>{{ section.title }}</h3>' +
18
18
' <ul class="api-list">' +
19
- ' <li ng-repeat="item in section.items" class="api-item">' +
19
+ ' <li ng-repeat="item in section.items" ng-show="item.show" class="api-item">' +
20
20
' <a ng-href="{{ item.path }}"><span class="symbol {{ item.docType }}"></span>{{ item.title }}</a>' +
21
21
' </li>' +
22
22
' </ul>' +
@@ -38,15 +38,36 @@ angularIO.directive('apiList', function () {
38
38
39
39
$ctrl . apiFilter = getApiFilterFromLocation ( ) ;
40
40
$ctrl . apiType = getApiTypeFromLocation ( ) ;
41
- $ctrl . filteredSections = [ ] ;
41
+ $ctrl . groupedSections = [ ] ;
42
42
43
43
$ctrl . setType = function ( type ) {
44
44
if ( type === $ctrl . apiType ) $ctrl . apiType = null ;
45
45
else $ctrl . apiType = type ;
46
46
} ;
47
47
48
+ $ctrl . isFiltered = function ( section ) {
49
+ var apiFilter = ( $ctrl . apiFilter || '' ) . toLowerCase ( ) ;
50
+ var matchesModule = $ctrl . apiFilter === '' || $ctrl . apiFilter === null || section . title . toLowerCase ( ) . indexOf ( $ctrl . apiFilter . toLowerCase ( ) ) !== - 1 ;
51
+ var isVisible = false ;
52
+
53
+ section . items . forEach ( function ( item ) {
54
+ var matchesDocType = ! $ctrl . apiType || $ctrl . apiType . matches . indexOf ( item . docType ) !== - 1 ;
55
+ var matchesTitle = ! apiFilter || item . title . toLowerCase ( ) . indexOf ( apiFilter ) !== - 1 ;
56
+ item . show = matchesDocType && ( matchesTitle || matchesModule ) ;
57
+
58
+ if ( item . show ) {
59
+ isVisible = true ;
60
+ }
61
+ } ) ;
62
+
63
+ return isVisible ;
64
+ } ;
65
+
48
66
$http . get ( $attrs . src ) . then ( function ( response ) {
49
67
$ctrl . sections = response . data ;
68
+ $ctrl . groupedSections = Object . keys ( $ctrl . sections ) . map ( function ( title ) {
69
+ return { title : title , items : $ctrl . sections [ title ] } ;
70
+ } ) ;
50
71
} ) ;
51
72
52
73
$scope . $watchGroup (
@@ -56,19 +77,6 @@ angularIO.directive('apiList', function () {
56
77
57
78
$location . search ( API_FILTER_KEY , apiFilter || null ) ;
58
79
$location . search ( API_TYPE_KEY , $ctrl . apiType && $ctrl . apiType . title || null ) ;
59
-
60
- $ctrl . filteredSections . length = 0 ;
61
- angular . forEach ( $ctrl . sections , function ( section , title ) {
62
- var matchesModule = $ctrl . apiFilter === '' || $ctrl . apiFilter === null || title . toLowerCase ( ) . indexOf ( $ctrl . apiFilter . toLowerCase ( ) ) !== - 1 ;
63
- var filteredItems = section . filter ( function ( item ) {
64
- var matchesDocType = ! $ctrl . apiType || $ctrl . apiType . matches . indexOf ( item . docType ) !== - 1 ;
65
- var matchesTitle = ! apiFilter || item . title . toLowerCase ( ) . indexOf ( apiFilter ) !== - 1 ;
66
- return matchesDocType && ( matchesTitle || matchesModule ) ;
67
- } ) ;
68
- if ( filteredItems . length ) {
69
- $ctrl . filteredSections . push ( { title : title , items : filteredItems } ) ;
70
- }
71
- } ) ;
72
80
}
73
81
) ;
74
82
@@ -81,7 +89,7 @@ angularIO.directive('apiList', function () {
81
89
if ( ! apiFilter ) {
82
90
return null ;
83
91
} else if ( ! $ctrl . apiFilter || $ctrl . apiFilter . title != apiFilter ) {
84
- for ( var i = 0 , ii = $ctrl . apiTypes . length ; i < ii ; i ++ ) {
92
+ for ( var i = 0 , ii = $ctrl . apiTypes . length ; i < ii ; i ++ ) {
85
93
if ( $ctrl . apiTypes [ i ] . title == apiFilter ) {
86
94
return $ctrl . apiTypes [ i ] ;
87
95
}
0 commit comments