(function() { "use strict"; angular.module('shared') .component('sortHeader', { bindings: { field: '@', orderManager: '<', sortFunction: '&' }, controller: 'SortHeader', templateUrl: '/shared/js/angular/ui/sort-header.html', transclude: true }) .controller('SortHeader', ['$element', '$timeout', function SortHeaderController($element, $timeout) { var ctrl = this; ctrl.isOrderBy = function () { return ctrl.orderManager.isOrderBy(ctrl.field); }; ctrl.orderBy = function () { var x = ctrl.orderManager.orderBy(ctrl.field); ctrl.sortFunction({orderedBy: ctrl.field, sortDirection: ctrl.orderManager.getReverse()}); announceOrderChanges(); return x; }; ctrl.getReverse = function () { return ctrl.orderManager.getReverse(); }; var announceOrderChanges = function () { var sortDirection = ctrl.getReverse() ? 'descending' : 'ascending'; angular.element('#SRmessage') .attr('aria-live', 'assertive') .attr('role', 'alert') .html('
Sorted by ' + $element.text().trim() + ': ' + sortDirection + '
'); $timeout(function(){ angular.element('#SRmessage') .removeAttr('role') .attr('aria-live', 'off'); $timeout(function () { angular.element('#SRmessage') .empty() .attr('aria-live', 'assertive') .attr('role', 'alert'); }, 250); }, 2000); }; }]) })();