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

feat(buttons): remove deprecated code #4716

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 0 additions & 112 deletions src/buttons/buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,115 +85,3 @@ angular.module('ui.bootstrap.buttons', [])
}
};
});

/* Deprecated buttons below */

angular.module('ui.bootstrap.buttons')

.value('$buttonsSuppressWarning', false)

.controller('ButtonsController', ['$controller', '$log', '$buttonsSuppressWarning', function($controller, $log, $buttonsSuppressWarning) {
if (!$buttonsSuppressWarning) {
$log.warn('ButtonsController is now deprecated. Use UibButtonsController instead.');
}

angular.extend(this, $controller('UibButtonsController'));
}])

.directive('btnRadio', ['$log', '$buttonsSuppressWarning', function($log, $buttonsSuppressWarning) {
return {
require: ['btnRadio', 'ngModel'],
controller: 'ButtonsController',
controllerAs: 'buttons',
link: function(scope, element, attrs, ctrls) {
if (!$buttonsSuppressWarning) {
$log.warn('btn-radio is now deprecated. Use uib-btn-radio instead.');
}

var buttonsCtrl = ctrls[0], ngModelCtrl = ctrls[1];

element.find('input').css({display: 'none'});

//model -> UI
ngModelCtrl.$render = function() {
element.toggleClass(buttonsCtrl.activeClass, angular.equals(ngModelCtrl.$modelValue, scope.$eval(attrs.btnRadio)));
};

//ui->model
element.bind(buttonsCtrl.toggleEvent, function() {
if (attrs.disabled) {
return;
}

var isActive = element.hasClass(buttonsCtrl.activeClass);

if (!isActive || angular.isDefined(attrs.uncheckable)) {
scope.$apply(function() {
ngModelCtrl.$setViewValue(isActive ? null : scope.$eval(attrs.btnRadio));
ngModelCtrl.$render();
});
}
});
}
};
}])

.directive('btnCheckbox', ['$document', '$log', '$buttonsSuppressWarning', function($document, $log, $buttonsSuppressWarning) {
return {
require: ['btnCheckbox', 'ngModel'],
controller: 'ButtonsController',
controllerAs: 'button',
link: function(scope, element, attrs, ctrls) {
if (!$buttonsSuppressWarning) {
$log.warn('btn-checkbox is now deprecated. Use uib-btn-checkbox instead.');
}

var buttonsCtrl = ctrls[0], ngModelCtrl = ctrls[1];

element.find('input').css({display: 'none'});

function getTrueValue() {
return getCheckboxValue(attrs.btnCheckboxTrue, true);
}

function getFalseValue() {
return getCheckboxValue(attrs.btnCheckboxFalse, false);
}

function getCheckboxValue(attributeValue, defaultValue) {
var val = scope.$eval(attributeValue);
return angular.isDefined(val) ? val : defaultValue;
}

//model -> UI
ngModelCtrl.$render = function() {
element.toggleClass(buttonsCtrl.activeClass, angular.equals(ngModelCtrl.$modelValue, getTrueValue()));
};

//ui->model
element.bind(buttonsCtrl.toggleEvent, function() {
if (attrs.disabled) {
return;
}

scope.$apply(function() {
ngModelCtrl.$setViewValue(element.hasClass(buttonsCtrl.activeClass) ? getFalseValue() : getTrueValue());
ngModelCtrl.$render();
});
});

//accessibility
element.on('keypress', function(e) {
if (attrs.disabled || e.which !== 32 || $document[0].activeElement !== element[0]) {
return;
}

scope.$apply(function() {
ngModelCtrl.$setViewValue(element.hasClass(buttonsCtrl.activeClass) ? getFalseValue() : getTrueValue());
ngModelCtrl.$render();
});
});
}
};
}]);

44 changes: 0 additions & 44 deletions src/buttons/test/buttons.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,47 +325,3 @@ describe('buttons', function() {
});
});
});

/* Deprecation tests below */

describe('buttons deprecation', function() {
beforeEach(module('ui.bootstrap.buttons'));

it('should suppress warning', function() {
module(function($provide) {
$provide.value('$buttonsSuppressWarning', true);
});

inject(function($compile, $log, $rootScope) {
spyOn($log, 'warn');

var element = $compile('<button ng-model="model" btn-checkbox>click</button>')($rootScope);
$rootScope.$digest();

expect($log.warn.calls.count()).toBe(0);

element = $compile('<button ng-model="model" btn-radio="1">click1</button><button ng-model="model" btn-radio="2">click2</button>')($rootScope);
$rootScope.$digest();

expect($log.warn.calls.count()).toBe(0);
});
});

it('should give warning by default', inject(function($compile, $log, $rootScope) {
spyOn($log, 'warn');

var element = $compile('<button ng-model="model" btn-checkbox>click</button>')($rootScope);
$rootScope.$digest();

element = $compile('<button ng-model="model" btn-radio="1">click1</button><button ng-model="model" btn-radio="2">click2</button>')($rootScope);
$rootScope.$digest();

expect($log.warn.calls.count()).toBe(6);
expect($log.warn.calls.argsFor(0)).toEqual(['ButtonsController is now deprecated. Use UibButtonsController instead.']);
expect($log.warn.calls.argsFor(1)).toEqual(['btn-checkbox is now deprecated. Use uib-btn-checkbox instead.']);
expect($log.warn.calls.argsFor(2)).toEqual(['ButtonsController is now deprecated. Use UibButtonsController instead.']);
expect($log.warn.calls.argsFor(3)).toEqual(['btn-radio is now deprecated. Use uib-btn-radio instead.']);
expect($log.warn.calls.argsFor(4)).toEqual(['ButtonsController is now deprecated. Use UibButtonsController instead.']);
expect($log.warn.calls.argsFor(5)).toEqual(['btn-radio is now deprecated. Use uib-btn-radio instead.']);
}));
});