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

Commit

Permalink
feat(buttons): remove deprecated code
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Remove deprecated non-prefixed directives

Closes #4716
  • Loading branch information
Foxandxss authored and wesleycho committed Oct 23, 2015
1 parent bc004df commit b549263
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 156 deletions.
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.']);
}));
});

0 comments on commit b549263

Please sign in to comment.