2015-08-07 16:37:36 +02:00
|
|
|
|
/**
|
2020-10-22 06:34:13 +02:00
|
|
|
|
* @license AngularJS v1.8.2
|
2020-10-06 06:36:53 +02:00
|
|
|
|
* (c) 2010-2020 Google LLC. http://angularjs.org
|
2015-08-07 16:37:36 +02:00
|
|
|
|
* License: MIT
|
|
|
|
|
*/
|
2016-10-12 08:08:16 +02:00
|
|
|
|
(function(window, angular) {'use strict';
|
2015-08-07 16:37:36 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @ngdoc module
|
|
|
|
|
* @name ngAria
|
|
|
|
|
* @description
|
|
|
|
|
*
|
|
|
|
|
* The `ngAria` module provides support for common
|
|
|
|
|
* [<abbr title="Accessible Rich Internet Applications">ARIA</abbr>](http://www.w3.org/TR/wai-aria/)
|
|
|
|
|
* attributes that convey state or semantic information about the application for users
|
|
|
|
|
* of assistive technologies, such as screen readers.
|
|
|
|
|
*
|
|
|
|
|
* ## Usage
|
|
|
|
|
*
|
|
|
|
|
* For ngAria to do its magic, simply include the module `ngAria` as a dependency. The following
|
|
|
|
|
* directives are supported:
|
2018-06-29 15:43:16 +02:00
|
|
|
|
* `ngModel`, `ngChecked`, `ngReadonly`, `ngRequired`, `ngValue`, `ngDisabled`, `ngShow`, `ngHide`,
|
|
|
|
|
* `ngClick`, `ngDblClick`, and `ngMessages`.
|
2015-08-07 16:37:36 +02:00
|
|
|
|
*
|
|
|
|
|
* Below is a more detailed breakdown of the attributes handled by ngAria:
|
|
|
|
|
*
|
2017-01-12 07:31:09 +01:00
|
|
|
|
* | Directive | Supported Attributes |
|
|
|
|
|
* |---------------------------------------------|-----------------------------------------------------------------------------------------------------|
|
2016-10-12 08:08:16 +02:00
|
|
|
|
* | {@link ng.directive:ngModel ngModel} | aria-checked, aria-valuemin, aria-valuemax, aria-valuenow, aria-invalid, aria-required, input roles |
|
2017-01-12 07:31:09 +01:00
|
|
|
|
* | {@link ng.directive:ngDisabled ngDisabled} | aria-disabled |
|
|
|
|
|
* | {@link ng.directive:ngRequired ngRequired} | aria-required |
|
|
|
|
|
* | {@link ng.directive:ngChecked ngChecked} | aria-checked |
|
|
|
|
|
* | {@link ng.directive:ngReadonly ngReadonly} | aria-readonly |
|
|
|
|
|
* | {@link ng.directive:ngValue ngValue} | aria-checked |
|
|
|
|
|
* | {@link ng.directive:ngShow ngShow} | aria-hidden |
|
|
|
|
|
* | {@link ng.directive:ngHide ngHide} | aria-hidden |
|
|
|
|
|
* | {@link ng.directive:ngDblclick ngDblclick} | tabindex |
|
|
|
|
|
* | {@link module:ngMessages ngMessages} | aria-live |
|
|
|
|
|
* | {@link ng.directive:ngClick ngClick} | tabindex, keydown event, button role |
|
2015-08-07 16:37:36 +02:00
|
|
|
|
*
|
|
|
|
|
* Find out more information about each directive by reading the
|
|
|
|
|
* {@link guide/accessibility ngAria Developer Guide}.
|
|
|
|
|
*
|
2016-10-12 08:08:16 +02:00
|
|
|
|
* ## Example
|
2015-08-07 16:37:36 +02:00
|
|
|
|
* Using ngDisabled with ngAria:
|
|
|
|
|
* ```html
|
|
|
|
|
* <md-checkbox ng-disabled="disabled">
|
|
|
|
|
* ```
|
|
|
|
|
* Becomes:
|
|
|
|
|
* ```html
|
|
|
|
|
* <md-checkbox ng-disabled="disabled" aria-disabled="true">
|
|
|
|
|
* ```
|
|
|
|
|
*
|
2018-06-29 15:43:16 +02:00
|
|
|
|
* ## Disabling Specific Attributes
|
|
|
|
|
* It is possible to disable individual attributes added by ngAria with the
|
2015-08-07 16:37:36 +02:00
|
|
|
|
* {@link ngAria.$ariaProvider#config config} method. For more details, see the
|
|
|
|
|
* {@link guide/accessibility Developer Guide}.
|
2018-06-29 15:43:16 +02:00
|
|
|
|
*
|
|
|
|
|
* ## Disabling `ngAria` on Specific Elements
|
|
|
|
|
* It is possible to make `ngAria` ignore a specific element, by adding the `ng-aria-disable`
|
|
|
|
|
* attribute on it. Note that only the element itself (and not its child elements) will be ignored.
|
2015-08-07 16:37:36 +02:00
|
|
|
|
*/
|
2018-06-29 15:43:16 +02:00
|
|
|
|
var ARIA_DISABLE_ATTR = 'ngAriaDisable';
|
|
|
|
|
|
2015-08-07 16:37:36 +02:00
|
|
|
|
var ngAriaModule = angular.module('ngAria', ['ng']).
|
2020-10-22 06:34:13 +02:00
|
|
|
|
info({ angularVersion: '1.8.2' }).
|
2015-08-07 16:37:36 +02:00
|
|
|
|
provider('$aria', $AriaProvider);
|
|
|
|
|
|
2015-09-22 17:56:33 +02:00
|
|
|
|
/**
|
|
|
|
|
* Internal Utilities
|
|
|
|
|
*/
|
2020-10-06 06:36:53 +02:00
|
|
|
|
var nativeAriaNodeNames = ['BUTTON', 'A', 'INPUT', 'TEXTAREA', 'SELECT', 'DETAILS', 'SUMMARY'];
|
2015-09-22 17:56:33 +02:00
|
|
|
|
|
|
|
|
|
var isNodeOneOf = function(elem, nodeTypeArray) {
|
|
|
|
|
if (nodeTypeArray.indexOf(elem[0].nodeName) !== -1) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
};
|
2015-08-07 16:37:36 +02:00
|
|
|
|
/**
|
|
|
|
|
* @ngdoc provider
|
|
|
|
|
* @name $ariaProvider
|
2016-11-25 08:43:18 +01:00
|
|
|
|
* @this
|
2015-08-07 16:37:36 +02:00
|
|
|
|
*
|
|
|
|
|
* @description
|
|
|
|
|
*
|
|
|
|
|
* Used for configuring the ARIA attributes injected and managed by ngAria.
|
|
|
|
|
*
|
|
|
|
|
* ```js
|
|
|
|
|
* angular.module('myApp', ['ngAria'], function config($ariaProvider) {
|
|
|
|
|
* $ariaProvider.config({
|
|
|
|
|
* ariaValue: true,
|
|
|
|
|
* tabindex: false
|
|
|
|
|
* });
|
|
|
|
|
* });
|
|
|
|
|
*```
|
|
|
|
|
*
|
|
|
|
|
* ## Dependencies
|
|
|
|
|
* Requires the {@link ngAria} module to be installed.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
function $AriaProvider() {
|
|
|
|
|
var config = {
|
|
|
|
|
ariaHidden: true,
|
|
|
|
|
ariaChecked: true,
|
2016-10-12 08:08:16 +02:00
|
|
|
|
ariaReadonly: true,
|
2015-08-07 16:37:36 +02:00
|
|
|
|
ariaDisabled: true,
|
|
|
|
|
ariaRequired: true,
|
|
|
|
|
ariaInvalid: true,
|
|
|
|
|
ariaValue: true,
|
|
|
|
|
tabindex: true,
|
2017-01-12 07:31:09 +01:00
|
|
|
|
bindKeydown: true,
|
2015-08-07 16:37:36 +02:00
|
|
|
|
bindRoleForClick: true
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @ngdoc method
|
|
|
|
|
* @name $ariaProvider#config
|
|
|
|
|
*
|
|
|
|
|
* @param {object} config object to enable/disable specific ARIA attributes
|
|
|
|
|
*
|
|
|
|
|
* - **ariaHidden** – `{boolean}` – Enables/disables aria-hidden tags
|
|
|
|
|
* - **ariaChecked** – `{boolean}` – Enables/disables aria-checked tags
|
2016-10-12 08:08:16 +02:00
|
|
|
|
* - **ariaReadonly** – `{boolean}` – Enables/disables aria-readonly tags
|
2015-08-07 16:37:36 +02:00
|
|
|
|
* - **ariaDisabled** – `{boolean}` – Enables/disables aria-disabled tags
|
|
|
|
|
* - **ariaRequired** – `{boolean}` – Enables/disables aria-required tags
|
|
|
|
|
* - **ariaInvalid** – `{boolean}` – Enables/disables aria-invalid tags
|
2017-01-12 07:31:09 +01:00
|
|
|
|
* - **ariaValue** – `{boolean}` – Enables/disables aria-valuemin, aria-valuemax and
|
|
|
|
|
* aria-valuenow tags
|
2015-08-07 16:37:36 +02:00
|
|
|
|
* - **tabindex** – `{boolean}` – Enables/disables tabindex tags
|
2017-01-12 07:31:09 +01:00
|
|
|
|
* - **bindKeydown** – `{boolean}` – Enables/disables keyboard event binding on non-interactive
|
|
|
|
|
* elements (such as `div` or `li`) using ng-click, making them more accessible to users of
|
|
|
|
|
* assistive technologies
|
|
|
|
|
* - **bindRoleForClick** – `{boolean}` – Adds role=button to non-interactive elements (such as
|
|
|
|
|
* `div` or `li`) using ng-click, making them more accessible to users of assistive
|
|
|
|
|
* technologies
|
2015-08-07 16:37:36 +02:00
|
|
|
|
*
|
|
|
|
|
* @description
|
|
|
|
|
* Enables/disables various ARIA attributes
|
|
|
|
|
*/
|
|
|
|
|
this.config = function(newConfig) {
|
|
|
|
|
config = angular.extend(config, newConfig);
|
|
|
|
|
};
|
|
|
|
|
|
2020-10-06 06:36:53 +02:00
|
|
|
|
function watchExpr(attrName, ariaAttr, nativeAriaNodeNames, negate) {
|
2015-08-07 16:37:36 +02:00
|
|
|
|
return function(scope, elem, attr) {
|
2018-06-29 15:43:16 +02:00
|
|
|
|
if (attr.hasOwnProperty(ARIA_DISABLE_ATTR)) return;
|
|
|
|
|
|
2015-08-07 16:37:36 +02:00
|
|
|
|
var ariaCamelName = attr.$normalize(ariaAttr);
|
2020-10-06 06:36:53 +02:00
|
|
|
|
if (config[ariaCamelName] && !isNodeOneOf(elem, nativeAriaNodeNames) && !attr[ariaCamelName]) {
|
2015-08-07 16:37:36 +02:00
|
|
|
|
scope.$watch(attr[attrName], function(boolVal) {
|
|
|
|
|
// ensure boolean value
|
|
|
|
|
boolVal = negate ? !boolVal : !!boolVal;
|
|
|
|
|
elem.attr(ariaAttr, boolVal);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @ngdoc service
|
|
|
|
|
* @name $aria
|
|
|
|
|
*
|
|
|
|
|
* @description
|
|
|
|
|
*
|
|
|
|
|
* The $aria service contains helper methods for applying common
|
|
|
|
|
* [ARIA](http://www.w3.org/TR/wai-aria/) attributes to HTML directives.
|
|
|
|
|
*
|
|
|
|
|
* ngAria injects common accessibility attributes that tell assistive technologies when HTML
|
|
|
|
|
* elements are enabled, selected, hidden, and more. To see how this is performed with ngAria,
|
|
|
|
|
* let's review a code snippet from ngAria itself:
|
|
|
|
|
*
|
|
|
|
|
*```js
|
|
|
|
|
* ngAriaModule.directive('ngDisabled', ['$aria', function($aria) {
|
2020-10-06 06:36:53 +02:00
|
|
|
|
* return $aria.$$watchExpr('ngDisabled', 'aria-disabled', nativeAriaNodeNames, false);
|
2015-08-07 16:37:36 +02:00
|
|
|
|
* }])
|
|
|
|
|
*```
|
|
|
|
|
* Shown above, the ngAria module creates a directive with the same signature as the
|
|
|
|
|
* traditional `ng-disabled` directive. But this ngAria version is dedicated to
|
2016-10-12 08:08:16 +02:00
|
|
|
|
* solely managing accessibility attributes on custom elements. The internal `$aria` service is
|
|
|
|
|
* used to watch the boolean attribute `ngDisabled`. If it has not been explicitly set by the
|
|
|
|
|
* developer, `aria-disabled` is injected as an attribute with its value synchronized to the
|
|
|
|
|
* value in `ngDisabled`.
|
2015-08-07 16:37:36 +02:00
|
|
|
|
*
|
|
|
|
|
* Because ngAria hooks into the `ng-disabled` directive, developers do not have to do
|
|
|
|
|
* anything to enable this feature. The `aria-disabled` attribute is automatically managed
|
|
|
|
|
* simply as a silent side-effect of using `ng-disabled` with the ngAria module.
|
|
|
|
|
*
|
|
|
|
|
* The full list of directives that interface with ngAria:
|
|
|
|
|
* * **ngModel**
|
2016-10-12 08:08:16 +02:00
|
|
|
|
* * **ngChecked**
|
|
|
|
|
* * **ngReadonly**
|
|
|
|
|
* * **ngRequired**
|
|
|
|
|
* * **ngDisabled**
|
|
|
|
|
* * **ngValue**
|
2015-08-07 16:37:36 +02:00
|
|
|
|
* * **ngShow**
|
|
|
|
|
* * **ngHide**
|
|
|
|
|
* * **ngClick**
|
|
|
|
|
* * **ngDblclick**
|
|
|
|
|
* * **ngMessages**
|
|
|
|
|
*
|
|
|
|
|
* Read the {@link guide/accessibility ngAria Developer Guide} for a thorough explanation of each
|
|
|
|
|
* directive.
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* ## Dependencies
|
|
|
|
|
* Requires the {@link ngAria} module to be installed.
|
|
|
|
|
*/
|
|
|
|
|
this.$get = function() {
|
|
|
|
|
return {
|
|
|
|
|
config: function(key) {
|
|
|
|
|
return config[key];
|
|
|
|
|
},
|
|
|
|
|
$$watchExpr: watchExpr
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ngAriaModule.directive('ngShow', ['$aria', function($aria) {
|
2015-09-22 17:56:33 +02:00
|
|
|
|
return $aria.$$watchExpr('ngShow', 'aria-hidden', [], true);
|
2015-08-07 16:37:36 +02:00
|
|
|
|
}])
|
|
|
|
|
.directive('ngHide', ['$aria', function($aria) {
|
2015-09-22 17:56:33 +02:00
|
|
|
|
return $aria.$$watchExpr('ngHide', 'aria-hidden', [], false);
|
2015-08-07 16:37:36 +02:00
|
|
|
|
}])
|
2016-10-12 08:08:16 +02:00
|
|
|
|
.directive('ngValue', ['$aria', function($aria) {
|
2020-10-06 06:36:53 +02:00
|
|
|
|
return $aria.$$watchExpr('ngValue', 'aria-checked', nativeAriaNodeNames, false);
|
2016-10-12 08:08:16 +02:00
|
|
|
|
}])
|
|
|
|
|
.directive('ngChecked', ['$aria', function($aria) {
|
2020-10-06 06:36:53 +02:00
|
|
|
|
return $aria.$$watchExpr('ngChecked', 'aria-checked', nativeAriaNodeNames, false);
|
2016-10-12 08:08:16 +02:00
|
|
|
|
}])
|
|
|
|
|
.directive('ngReadonly', ['$aria', function($aria) {
|
2020-10-06 06:36:53 +02:00
|
|
|
|
return $aria.$$watchExpr('ngReadonly', 'aria-readonly', nativeAriaNodeNames, false);
|
2016-10-12 08:08:16 +02:00
|
|
|
|
}])
|
|
|
|
|
.directive('ngRequired', ['$aria', function($aria) {
|
2020-10-06 06:36:53 +02:00
|
|
|
|
return $aria.$$watchExpr('ngRequired', 'aria-required', nativeAriaNodeNames, false);
|
2016-10-12 08:08:16 +02:00
|
|
|
|
}])
|
2015-08-07 16:37:36 +02:00
|
|
|
|
.directive('ngModel', ['$aria', function($aria) {
|
|
|
|
|
|
2020-10-06 06:36:53 +02:00
|
|
|
|
function shouldAttachAttr(attr, normalizedAttr, elem, allowNonAriaNodes) {
|
2018-06-29 15:43:16 +02:00
|
|
|
|
return $aria.config(normalizedAttr) &&
|
|
|
|
|
!elem.attr(attr) &&
|
2020-10-06 06:36:53 +02:00
|
|
|
|
(allowNonAriaNodes || !isNodeOneOf(elem, nativeAriaNodeNames)) &&
|
2018-06-29 15:43:16 +02:00
|
|
|
|
(elem.attr('type') !== 'hidden' || elem[0].nodeName !== 'INPUT');
|
2015-08-07 16:37:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function shouldAttachRole(role, elem) {
|
2016-10-12 08:08:16 +02:00
|
|
|
|
// if element does not have role attribute
|
|
|
|
|
// AND element type is equal to role (if custom element has a type equaling shape) <-- remove?
|
2020-10-06 06:36:53 +02:00
|
|
|
|
// AND element is not in nativeAriaNodeNames
|
|
|
|
|
return !elem.attr('role') && (elem.attr('type') === role) && !isNodeOneOf(elem, nativeAriaNodeNames);
|
2015-08-07 16:37:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getShape(attr, elem) {
|
|
|
|
|
var type = attr.type,
|
|
|
|
|
role = attr.role;
|
|
|
|
|
|
|
|
|
|
return ((type || role) === 'checkbox' || role === 'menuitemcheckbox') ? 'checkbox' :
|
|
|
|
|
((type || role) === 'radio' || role === 'menuitemradio') ? 'radio' :
|
2016-10-12 08:08:16 +02:00
|
|
|
|
(type === 'range' || role === 'progressbar' || role === 'slider') ? 'range' : '';
|
2015-08-07 16:37:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
restrict: 'A',
|
2016-10-12 08:08:16 +02:00
|
|
|
|
require: 'ngModel',
|
2015-08-07 16:37:36 +02:00
|
|
|
|
priority: 200, //Make sure watches are fired after any other directives that affect the ngModel value
|
|
|
|
|
compile: function(elem, attr) {
|
2018-06-29 15:43:16 +02:00
|
|
|
|
if (attr.hasOwnProperty(ARIA_DISABLE_ATTR)) return;
|
|
|
|
|
|
2015-08-07 16:37:36 +02:00
|
|
|
|
var shape = getShape(attr, elem);
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
post: function(scope, elem, attr, ngModel) {
|
2016-10-12 08:08:16 +02:00
|
|
|
|
var needsTabIndex = shouldAttachAttr('tabindex', 'tabindex', elem, false);
|
2015-08-07 16:37:36 +02:00
|
|
|
|
|
|
|
|
|
function ngAriaWatchModelValue() {
|
|
|
|
|
return ngModel.$modelValue;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-12 08:08:16 +02:00
|
|
|
|
function getRadioReaction(newVal) {
|
2016-11-25 08:43:18 +01:00
|
|
|
|
// Strict comparison would cause a BC
|
|
|
|
|
// eslint-disable-next-line eqeqeq
|
2016-10-12 08:08:16 +02:00
|
|
|
|
var boolVal = (attr.value == ngModel.$viewValue);
|
|
|
|
|
elem.attr('aria-checked', boolVal);
|
2015-08-07 16:37:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-12 08:08:16 +02:00
|
|
|
|
function getCheckboxReaction() {
|
2015-08-07 16:37:36 +02:00
|
|
|
|
elem.attr('aria-checked', !ngModel.$isEmpty(ngModel.$viewValue));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (shape) {
|
|
|
|
|
case 'radio':
|
|
|
|
|
case 'checkbox':
|
|
|
|
|
if (shouldAttachRole(shape, elem)) {
|
|
|
|
|
elem.attr('role', shape);
|
|
|
|
|
}
|
2016-10-12 08:08:16 +02:00
|
|
|
|
if (shouldAttachAttr('aria-checked', 'ariaChecked', elem, false)) {
|
2015-08-07 16:37:36 +02:00
|
|
|
|
scope.$watch(ngAriaWatchModelValue, shape === 'radio' ?
|
2016-10-12 08:08:16 +02:00
|
|
|
|
getRadioReaction : getCheckboxReaction);
|
2015-08-07 16:37:36 +02:00
|
|
|
|
}
|
2015-09-22 17:56:33 +02:00
|
|
|
|
if (needsTabIndex) {
|
|
|
|
|
elem.attr('tabindex', 0);
|
|
|
|
|
}
|
2015-08-07 16:37:36 +02:00
|
|
|
|
break;
|
|
|
|
|
case 'range':
|
|
|
|
|
if (shouldAttachRole(shape, elem)) {
|
|
|
|
|
elem.attr('role', 'slider');
|
|
|
|
|
}
|
|
|
|
|
if ($aria.config('ariaValue')) {
|
|
|
|
|
var needsAriaValuemin = !elem.attr('aria-valuemin') &&
|
|
|
|
|
(attr.hasOwnProperty('min') || attr.hasOwnProperty('ngMin'));
|
|
|
|
|
var needsAriaValuemax = !elem.attr('aria-valuemax') &&
|
|
|
|
|
(attr.hasOwnProperty('max') || attr.hasOwnProperty('ngMax'));
|
|
|
|
|
var needsAriaValuenow = !elem.attr('aria-valuenow');
|
|
|
|
|
|
|
|
|
|
if (needsAriaValuemin) {
|
|
|
|
|
attr.$observe('min', function ngAriaValueMinReaction(newVal) {
|
|
|
|
|
elem.attr('aria-valuemin', newVal);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (needsAriaValuemax) {
|
|
|
|
|
attr.$observe('max', function ngAriaValueMinReaction(newVal) {
|
|
|
|
|
elem.attr('aria-valuemax', newVal);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (needsAriaValuenow) {
|
|
|
|
|
scope.$watch(ngAriaWatchModelValue, function ngAriaValueNowReaction(newVal) {
|
|
|
|
|
elem.attr('aria-valuenow', newVal);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-09-22 17:56:33 +02:00
|
|
|
|
if (needsTabIndex) {
|
|
|
|
|
elem.attr('tabindex', 0);
|
|
|
|
|
}
|
2015-08-07 16:37:36 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-12 08:08:16 +02:00
|
|
|
|
if (!attr.hasOwnProperty('ngRequired') && ngModel.$validators.required
|
|
|
|
|
&& shouldAttachAttr('aria-required', 'ariaRequired', elem, false)) {
|
|
|
|
|
// ngModel.$error.required is undefined on custom controls
|
|
|
|
|
attr.$observe('required', function() {
|
|
|
|
|
elem.attr('aria-required', !!attr['required']);
|
2015-08-07 16:37:36 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-12 08:08:16 +02:00
|
|
|
|
if (shouldAttachAttr('aria-invalid', 'ariaInvalid', elem, true)) {
|
2015-08-07 16:37:36 +02:00
|
|
|
|
scope.$watch(function ngAriaInvalidWatch() {
|
|
|
|
|
return ngModel.$invalid;
|
|
|
|
|
}, function ngAriaInvalidReaction(newVal) {
|
|
|
|
|
elem.attr('aria-invalid', !!newVal);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}])
|
|
|
|
|
.directive('ngDisabled', ['$aria', function($aria) {
|
2020-10-06 06:36:53 +02:00
|
|
|
|
return $aria.$$watchExpr('ngDisabled', 'aria-disabled', nativeAriaNodeNames, false);
|
2015-08-07 16:37:36 +02:00
|
|
|
|
}])
|
|
|
|
|
.directive('ngMessages', function() {
|
|
|
|
|
return {
|
|
|
|
|
restrict: 'A',
|
|
|
|
|
require: '?ngMessages',
|
|
|
|
|
link: function(scope, elem, attr, ngMessages) {
|
2018-06-29 15:43:16 +02:00
|
|
|
|
if (attr.hasOwnProperty(ARIA_DISABLE_ATTR)) return;
|
|
|
|
|
|
2015-08-07 16:37:36 +02:00
|
|
|
|
if (!elem.attr('aria-live')) {
|
|
|
|
|
elem.attr('aria-live', 'assertive');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
})
|
|
|
|
|
.directive('ngClick',['$aria', '$parse', function($aria, $parse) {
|
|
|
|
|
return {
|
|
|
|
|
restrict: 'A',
|
|
|
|
|
compile: function(elem, attr) {
|
2018-06-29 15:43:16 +02:00
|
|
|
|
if (attr.hasOwnProperty(ARIA_DISABLE_ATTR)) return;
|
|
|
|
|
|
2017-02-08 07:27:36 +01:00
|
|
|
|
var fn = $parse(attr.ngClick);
|
2015-08-07 16:37:36 +02:00
|
|
|
|
return function(scope, elem, attr) {
|
|
|
|
|
|
2020-10-06 06:36:53 +02:00
|
|
|
|
if (!isNodeOneOf(elem, nativeAriaNodeNames)) {
|
2015-08-07 16:37:36 +02:00
|
|
|
|
|
2015-09-22 17:56:33 +02:00
|
|
|
|
if ($aria.config('bindRoleForClick') && !elem.attr('role')) {
|
|
|
|
|
elem.attr('role', 'button');
|
2015-08-07 16:37:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-22 17:56:33 +02:00
|
|
|
|
if ($aria.config('tabindex') && !elem.attr('tabindex')) {
|
|
|
|
|
elem.attr('tabindex', 0);
|
|
|
|
|
}
|
2015-08-07 16:37:36 +02:00
|
|
|
|
|
2017-01-12 07:31:09 +01:00
|
|
|
|
if ($aria.config('bindKeydown') && !attr.ngKeydown && !attr.ngKeypress && !attr.ngKeyup) {
|
|
|
|
|
elem.on('keydown', function(event) {
|
2015-09-22 17:56:33 +02:00
|
|
|
|
var keyCode = event.which || event.keyCode;
|
2018-08-09 06:29:56 +02:00
|
|
|
|
|
|
|
|
|
if (keyCode === 13 || keyCode === 32) {
|
2018-09-08 06:32:23 +02:00
|
|
|
|
// If the event is triggered on a non-interactive element ...
|
2020-10-06 06:36:53 +02:00
|
|
|
|
if (nativeAriaNodeNames.indexOf(event.target.nodeName) === -1 && !event.target.isContentEditable) {
|
2018-09-08 06:32:23 +02:00
|
|
|
|
// ... prevent the default browser behavior (e.g. scrolling when pressing spacebar)
|
|
|
|
|
// See https://github.com/angular/angular.js/issues/16664
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
}
|
2015-09-22 17:56:33 +02:00
|
|
|
|
scope.$apply(callback);
|
|
|
|
|
}
|
2015-08-07 16:37:36 +02:00
|
|
|
|
|
2015-09-22 17:56:33 +02:00
|
|
|
|
function callback() {
|
|
|
|
|
fn(scope, { $event: event });
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2015-08-07 16:37:36 +02:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}])
|
|
|
|
|
.directive('ngDblclick', ['$aria', function($aria) {
|
|
|
|
|
return function(scope, elem, attr) {
|
2018-06-29 15:43:16 +02:00
|
|
|
|
if (attr.hasOwnProperty(ARIA_DISABLE_ATTR)) return;
|
|
|
|
|
|
2020-10-06 06:36:53 +02:00
|
|
|
|
if ($aria.config('tabindex') && !elem.attr('tabindex') && !isNodeOneOf(elem, nativeAriaNodeNames)) {
|
2015-08-07 16:37:36 +02:00
|
|
|
|
elem.attr('tabindex', 0);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
})(window, window.angular);
|