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

Commit b549263

Browse files
Foxandxsswesleycho
authored andcommitted
feat(buttons): remove deprecated code
BREAKING CHANGE: Remove deprecated non-prefixed directives Closes #4716
1 parent bc004df commit b549263

File tree

2 files changed

+0
-156
lines changed

2 files changed

+0
-156
lines changed

src/buttons/buttons.js

-112
Original file line numberDiff line numberDiff line change
@@ -85,115 +85,3 @@ angular.module('ui.bootstrap.buttons', [])
8585
}
8686
};
8787
});
88-
89-
/* Deprecated buttons below */
90-
91-
angular.module('ui.bootstrap.buttons')
92-
93-
.value('$buttonsSuppressWarning', false)
94-
95-
.controller('ButtonsController', ['$controller', '$log', '$buttonsSuppressWarning', function($controller, $log, $buttonsSuppressWarning) {
96-
if (!$buttonsSuppressWarning) {
97-
$log.warn('ButtonsController is now deprecated. Use UibButtonsController instead.');
98-
}
99-
100-
angular.extend(this, $controller('UibButtonsController'));
101-
}])
102-
103-
.directive('btnRadio', ['$log', '$buttonsSuppressWarning', function($log, $buttonsSuppressWarning) {
104-
return {
105-
require: ['btnRadio', 'ngModel'],
106-
controller: 'ButtonsController',
107-
controllerAs: 'buttons',
108-
link: function(scope, element, attrs, ctrls) {
109-
if (!$buttonsSuppressWarning) {
110-
$log.warn('btn-radio is now deprecated. Use uib-btn-radio instead.');
111-
}
112-
113-
var buttonsCtrl = ctrls[0], ngModelCtrl = ctrls[1];
114-
115-
element.find('input').css({display: 'none'});
116-
117-
//model -> UI
118-
ngModelCtrl.$render = function() {
119-
element.toggleClass(buttonsCtrl.activeClass, angular.equals(ngModelCtrl.$modelValue, scope.$eval(attrs.btnRadio)));
120-
};
121-
122-
//ui->model
123-
element.bind(buttonsCtrl.toggleEvent, function() {
124-
if (attrs.disabled) {
125-
return;
126-
}
127-
128-
var isActive = element.hasClass(buttonsCtrl.activeClass);
129-
130-
if (!isActive || angular.isDefined(attrs.uncheckable)) {
131-
scope.$apply(function() {
132-
ngModelCtrl.$setViewValue(isActive ? null : scope.$eval(attrs.btnRadio));
133-
ngModelCtrl.$render();
134-
});
135-
}
136-
});
137-
}
138-
};
139-
}])
140-
141-
.directive('btnCheckbox', ['$document', '$log', '$buttonsSuppressWarning', function($document, $log, $buttonsSuppressWarning) {
142-
return {
143-
require: ['btnCheckbox', 'ngModel'],
144-
controller: 'ButtonsController',
145-
controllerAs: 'button',
146-
link: function(scope, element, attrs, ctrls) {
147-
if (!$buttonsSuppressWarning) {
148-
$log.warn('btn-checkbox is now deprecated. Use uib-btn-checkbox instead.');
149-
}
150-
151-
var buttonsCtrl = ctrls[0], ngModelCtrl = ctrls[1];
152-
153-
element.find('input').css({display: 'none'});
154-
155-
function getTrueValue() {
156-
return getCheckboxValue(attrs.btnCheckboxTrue, true);
157-
}
158-
159-
function getFalseValue() {
160-
return getCheckboxValue(attrs.btnCheckboxFalse, false);
161-
}
162-
163-
function getCheckboxValue(attributeValue, defaultValue) {
164-
var val = scope.$eval(attributeValue);
165-
return angular.isDefined(val) ? val : defaultValue;
166-
}
167-
168-
//model -> UI
169-
ngModelCtrl.$render = function() {
170-
element.toggleClass(buttonsCtrl.activeClass, angular.equals(ngModelCtrl.$modelValue, getTrueValue()));
171-
};
172-
173-
//ui->model
174-
element.bind(buttonsCtrl.toggleEvent, function() {
175-
if (attrs.disabled) {
176-
return;
177-
}
178-
179-
scope.$apply(function() {
180-
ngModelCtrl.$setViewValue(element.hasClass(buttonsCtrl.activeClass) ? getFalseValue() : getTrueValue());
181-
ngModelCtrl.$render();
182-
});
183-
});
184-
185-
//accessibility
186-
element.on('keypress', function(e) {
187-
if (attrs.disabled || e.which !== 32 || $document[0].activeElement !== element[0]) {
188-
return;
189-
}
190-
191-
scope.$apply(function() {
192-
ngModelCtrl.$setViewValue(element.hasClass(buttonsCtrl.activeClass) ? getFalseValue() : getTrueValue());
193-
ngModelCtrl.$render();
194-
});
195-
});
196-
}
197-
};
198-
}]);
199-

src/buttons/test/buttons.spec.js

-44
Original file line numberDiff line numberDiff line change
@@ -325,47 +325,3 @@ describe('buttons', function() {
325325
});
326326
});
327327
});
328-
329-
/* Deprecation tests below */
330-
331-
describe('buttons deprecation', function() {
332-
beforeEach(module('ui.bootstrap.buttons'));
333-
334-
it('should suppress warning', function() {
335-
module(function($provide) {
336-
$provide.value('$buttonsSuppressWarning', true);
337-
});
338-
339-
inject(function($compile, $log, $rootScope) {
340-
spyOn($log, 'warn');
341-
342-
var element = $compile('<button ng-model="model" btn-checkbox>click</button>')($rootScope);
343-
$rootScope.$digest();
344-
345-
expect($log.warn.calls.count()).toBe(0);
346-
347-
element = $compile('<button ng-model="model" btn-radio="1">click1</button><button ng-model="model" btn-radio="2">click2</button>')($rootScope);
348-
$rootScope.$digest();
349-
350-
expect($log.warn.calls.count()).toBe(0);
351-
});
352-
});
353-
354-
it('should give warning by default', inject(function($compile, $log, $rootScope) {
355-
spyOn($log, 'warn');
356-
357-
var element = $compile('<button ng-model="model" btn-checkbox>click</button>')($rootScope);
358-
$rootScope.$digest();
359-
360-
element = $compile('<button ng-model="model" btn-radio="1">click1</button><button ng-model="model" btn-radio="2">click2</button>')($rootScope);
361-
$rootScope.$digest();
362-
363-
expect($log.warn.calls.count()).toBe(6);
364-
expect($log.warn.calls.argsFor(0)).toEqual(['ButtonsController is now deprecated. Use UibButtonsController instead.']);
365-
expect($log.warn.calls.argsFor(1)).toEqual(['btn-checkbox is now deprecated. Use uib-btn-checkbox instead.']);
366-
expect($log.warn.calls.argsFor(2)).toEqual(['ButtonsController is now deprecated. Use UibButtonsController instead.']);
367-
expect($log.warn.calls.argsFor(3)).toEqual(['btn-radio is now deprecated. Use uib-btn-radio instead.']);
368-
expect($log.warn.calls.argsFor(4)).toEqual(['ButtonsController is now deprecated. Use UibButtonsController instead.']);
369-
expect($log.warn.calls.argsFor(5)).toEqual(['btn-radio is now deprecated. Use uib-btn-radio instead.']);
370-
}));
371-
});

0 commit comments

Comments
 (0)