Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit 0328a76

Browse files
Foxandxsswesleycho
authored andcommitted
feat(accordion): use uib- prefix
Closes #4389
1 parent eb2366f commit 0328a76

File tree

5 files changed

+262
-106
lines changed

5 files changed

+262
-106
lines changed

src/accordion/accordion.js

+120-13
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse'])
22

3-
.constant('accordionConfig', {
3+
.constant('uibAccordionConfig', {
44
closeOthers: true
55
})
66

7-
.controller('AccordionController', ['$scope', '$attrs', 'accordionConfig', function($scope, $attrs, accordionConfig) {
7+
.controller('UibAccordionController', ['$scope', '$attrs', 'uibAccordionConfig', function($scope, $attrs, accordionConfig) {
88
// This array keeps track of the accordion groups
99
this.groups = [];
1010

@@ -43,10 +43,10 @@ angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse'])
4343

4444
// The accordion directive simply sets up the directive controller
4545
// and adds an accordion CSS class to itself element.
46-
.directive('accordion', function() {
46+
.directive('uibAccordion', function() {
4747
return {
4848
restrict: 'EA',
49-
controller: 'AccordionController',
49+
controller: 'UibAccordionController',
5050
controllerAs: 'accordion',
5151
transclude: true,
5252
replace: false,
@@ -57,9 +57,9 @@ angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse'])
5757
})
5858

5959
// The accordion-group directive indicates a block of html that will expand and collapse in an accordion
60-
.directive('accordionGroup', function() {
60+
.directive('uibAccordionGroup', function() {
6161
return {
62-
require: '^accordion', // We need this directive to be inside an accordion
62+
require: '^uibAccordion', // We need this directive to be inside an accordion
6363
restrict: 'EA',
6464
transclude: true, // It transcludes the contents of the directive into the template
6565
replace: true, // The element containing the directive will be replaced with the template
@@ -103,13 +103,13 @@ angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse'])
103103
// <accordion-group>
104104
// <accordion-heading>Heading containing HTML - <img src="..."></accordion-heading>
105105
// </accordion-group>
106-
.directive('accordionHeading', function() {
106+
.directive('uibAccordionHeading', function() {
107107
return {
108108
restrict: 'EA',
109109
transclude: true, // Grab the contents to be used as the heading
110110
template: '', // In effect remove this element!
111111
replace: true,
112-
require: '^accordionGroup',
112+
require: '^uibAccordionGroup',
113113
link: function(scope, element, attr, accordionGroupCtrl, transclude) {
114114
// Pass the heading to the accordion-group controller
115115
// so that it can be transcluded into the right place in the template
@@ -125,18 +125,125 @@ angular.module('ui.bootstrap.accordion', ['ui.bootstrap.collapse'])
125125
// <div class="accordion-heading" ><a ... accordion-transclude="heading">...</a></div>
126126
// ...
127127
// </div>
128-
.directive('accordionTransclude', function() {
128+
.directive('uibAccordionTransclude', function() {
129129
return {
130-
require: '^accordionGroup',
130+
require: ['?^uibAccordionGroup', '?^accordionGroup'],
131131
link: function(scope, element, attr, controller) {
132-
scope.$watch(function() { return controller[attr.accordionTransclude]; }, function(heading) {
132+
controller = controller[0] ? controller[0] : controller[1]; // Delete after we remove deprecation
133+
scope.$watch(function() { return controller[attr.uibAccordionTransclude]; }, function(heading) {
133134
if (heading) {
134135
element.find('span').html('');
135136
element.find('span').append(heading);
136137
}
137138
});
138139
}
139140
};
140-
})
141+
});
142+
143+
/* Deprecated accordion below */
144+
145+
angular.module('ui.bootstrap.accordion')
146+
147+
.value('$accordionSuppressWarning', false)
148+
149+
.directive('accordion', ['$log', '$accordionSuppressWarning', function($log, $accordionSuppressWarning) {
150+
return {
151+
restrict: 'EA',
152+
controller: 'UibAccordionController',
153+
controllerAs: 'accordion',
154+
transclude: true,
155+
replace: false,
156+
templateUrl: function(element, attrs) {
157+
return attrs.templateUrl || 'template/accordion/accordion.html';
158+
},
159+
link: function() {
160+
if (!$accordionSuppressWarning) {
161+
$log.warn('accordion is now deprecated. Use uib-accordion instead.');
162+
}
163+
}
164+
};
165+
}])
166+
167+
.directive('accordionGroup', ['$log', '$accordionSuppressWarning', function($log, $accordionSuppressWarning) {
168+
return {
169+
require: '^accordion', // We need this directive to be inside an accordion
170+
restrict: 'EA',
171+
transclude: true, // It transcludes the contents of the directive into the template
172+
replace: true, // The element containing the directive will be replaced with the template
173+
templateUrl: function(element, attrs) {
174+
return attrs.templateUrl || 'template/accordion/accordion-group.html';
175+
},
176+
scope: {
177+
heading: '@', // Interpolate the heading attribute onto this scope
178+
isOpen: '=?',
179+
isDisabled: '=?'
180+
},
181+
controller: function() {
182+
this.setHeading = function(element) {
183+
this.heading = element;
184+
};
185+
},
186+
link: function(scope, element, attrs, accordionCtrl) {
187+
if (!$accordionSuppressWarning) {
188+
$log.warn('accordion-group is now deprecated. Use uib-accordion-group instead.');
189+
}
190+
191+
accordionCtrl.addGroup(scope);
192+
193+
scope.openClass = attrs.openClass || 'panel-open';
194+
scope.panelClass = attrs.panelClass;
195+
scope.$watch('isOpen', function(value) {
196+
element.toggleClass(scope.openClass, !!value);
197+
if (value) {
198+
accordionCtrl.closeOthers(scope);
199+
}
200+
});
201+
202+
scope.toggleOpen = function($event) {
203+
if (!scope.isDisabled) {
204+
if (!$event || $event.which === 32) {
205+
scope.isOpen = !scope.isOpen;
206+
}
207+
}
208+
};
209+
}
210+
};
211+
}])
212+
213+
.directive('accordionHeading', ['$log', '$accordionSuppressWarning', function($log, $accordionSuppressWarning) {
214+
return {
215+
restrict: 'EA',
216+
transclude: true, // Grab the contents to be used as the heading
217+
template: '', // In effect remove this element!
218+
replace: true,
219+
require: '^accordionGroup',
220+
link: function(scope, element, attr, accordionGroupCtrl, transclude) {
221+
if (!$accordionSuppressWarning) {
222+
$log.warn('accordion-heading is now deprecated. Use uib-accordion-heading instead.');
223+
}
224+
// Pass the heading to the accordion-group controller
225+
// so that it can be transcluded into the right place in the template
226+
// [The second parameter to transclude causes the elements to be cloned so that they work in ng-repeat]
227+
accordionGroupCtrl.setHeading(transclude(scope, angular.noop));
228+
}
229+
};
230+
}])
231+
232+
.directive('accordionTransclude', ['$log', '$accordionSuppressWarning', function($log, $accordionSuppressWarning) {
233+
return {
234+
require: '^accordionGroup',
235+
link: function(scope, element, attr, controller) {
236+
if (!$accordionSuppressWarning) {
237+
$log.warn('accordion-transclude is now deprecated. Use uib-accordion-transclude instead.');
238+
}
239+
240+
scope.$watch(function() { return controller[attr.accordionTransclude]; }, function(heading) {
241+
if (heading) {
242+
element.find('span').html('');
243+
element.find('span').append(heading);
244+
}
245+
});
246+
}
247+
};
248+
}]);
141249

142-
;

src/accordion/docs/demo.html

+19-19
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
<div class="panel {{panelClass || 'panel-default'}}">
44
<div class="panel-heading">
55
<h4 class="panel-title" style="color:#fa39c3">
6-
<a href tabindex="0" class="accordion-toggle" ng-click="toggleOpen()" accordion-transclude="heading"><span
6+
<a href tabindex="0" class="accordion-toggle" ng-click="toggleOpen()" uib-accordion-transclude="heading"><span
77
ng-class="{'text-muted': isDisabled}">{{heading}}</span></a>
88
</h4>
99
</div>
10-
<div class="panel-collapse collapse" collapse="!isOpen">
10+
<div class="panel-collapse collapse" uib-collapse="!isOpen">
1111
<div class="panel-body" style="text-align: right" ng-transclude></div>
1212
</div>
1313
</div>
@@ -24,30 +24,30 @@ <h4 class="panel-title" style="color:#fa39c3">
2424
Open only one at a time
2525
</label>
2626
</div>
27-
<accordion close-others="oneAtATime">
28-
<accordion-group heading="Static Header, initially expanded" is-open="status.isFirstOpen" is-disabled="status.isFirstDisabled">
27+
<uib-accordion close-others="oneAtATime">
28+
<uib-accordion-group heading="Static Header, initially expanded" is-open="status.isFirstOpen" is-disabled="status.isFirstDisabled">
2929
This content is straight in the template.
30-
</accordion-group>
31-
<accordion-group heading="{{group.title}}" ng-repeat="group in groups">
30+
</uib-accordion-group>
31+
<uib-accordion-group heading="{{group.title}}" ng-repeat="group in groups">
3232
{{group.content}}
33-
</accordion-group>
34-
<accordion-group heading="Dynamic Body Content">
35-
<p>The body of the accordion group grows to fit the contents</p>
33+
</uib-accordion-group>
34+
<uib-accordion-group heading="Dynamic Body Content">
35+
<p>The body of the uib-accordion group grows to fit the contents</p>
3636
<button type="button" class="btn btn-default btn-sm" ng-click="addItem()">Add Item</button>
3737
<div ng-repeat="item in items">{{item}}</div>
38-
</accordion-group>
39-
<accordion-group heading="Custom template" template-url="group-template.html">
38+
</uib-accordion-group>
39+
<uib-accordion-group heading="Custom template" template-url="group-template.html">
4040
Hello
41-
</accordion-group>
42-
<accordion-group heading="Delete account" panel-class="panel-danger">
41+
</uib-accordion-group>
42+
<uib-accordion-group heading="Delete account" panel-class="panel-danger">
4343
<p>Please, to delete your account, click the button below</p>
4444
<button class="btn btn-danger">Delete</button>
45-
</accordion-group>
46-
<accordion-group is-open="status.open">
47-
<accordion-heading>
45+
</uib-accordion-group>
46+
<uib-accordion-group is-open="status.open">
47+
<uib-accordion-heading>
4848
I can have markup, too! <i class="pull-right glyphicon" ng-class="{'glyphicon-chevron-down': status.open, 'glyphicon-chevron-right': !status.open}"></i>
49-
</accordion-heading>
49+
</uib-accordion-heading>
5050
This is just some content to illustrate fancy headings.
51-
</accordion-group>
52-
</accordion>
51+
</uib-accordion-group>
52+
</uib-accordion>
5353
</div>

src/accordion/docs/readme.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ The **accordion directive** builds on top of the collapse directive to provide a
22

33
The body of each accordion group is transcluded into the body of the collapsible element.
44

5-
### Accordion Settings
5+
### uib-accordion Settings
66

77
* `close-others` (Defaults: false) :
88
Control whether expanding an item will cause the other items to close
99
* `template-url` (Defaults: `template/accordion/accordion.html`) :
1010
Add the ability to override the template used on the component.
1111

12-
### Accordion Group Settings
12+
### uib-accordion Group Settings
1313

1414
* `is-disabled` <i class="glyphicon glyphicon-eye-open"></i> (Defaults: false) :
1515
Whether the accordion group is disabled or not.
@@ -24,4 +24,4 @@ The body of each accordion group is transcluded into the body of the collapsible
2424

2525
### Accordion heading
2626

27-
Instead of the `heading` attribute on the `accordion-group`, you can use an `accordion-heading` element inside a group that will be used as the group's header.
27+
Instead of the `heading` attribute on the `uib-accordion-group`, you can use an `uib-accordion-heading` element inside a group that will be used as the group's header.

0 commit comments

Comments
 (0)