Debian Codegraph @

extensions/VisualEditor/modules/ve-mw/ui/ve.ui.MWAriaDescribe.js

raw symbols SCIP
1 /**
2 * Mixin for adding descriptive ARIA support to elements.
3 *
4 * @class
5 * @abstract
6 *
7 * @constructor
8 * @param {Object} [config] Configuration options
9 * @param {jQuery} [config.$ariaDescribedBy]
10 * @param {string} [config.ariaLabel]
11 * @param {jQuery} [config.$describedElement]
12 */
13 ve.ui.MWAriaDescribe = function VeUiMWAriaDescribe( config ) {
14 this.$describedElement = config.$describedElement || this.$element;
15
16 if ( config.$ariaDescribedBy ) {
17 this.setAriaDescribedBy( config.$ariaDescribedBy );
18 }
19
20 if ( config.ariaLabel ) {
21 this.setAriaLabel( config.ariaLabel );
22 }
23 };
24
25 /* Setup */
26
27 OO.initClass( ve.ui.MWAriaDescribe );
28
29 /**
30 * @param {jQuery} [$description]
31 * @chainable
32 * @return {OO.ui.Element} The element, for chaining
33 */
34 ve.ui.MWAriaDescribe.prototype.setAriaDescribedBy = function ( $description ) {
35 if ( !$description ) {
36 this.$describedElement.removeAttr( 'aria-describedby' );
37 return this;
38 }
39
40 if ( !$description.attr( 'id' ) ) {
41 $description.attr( 'id', OO.ui.generateElementId() );
42 }
43 this.$describedElement.attr( 'aria-describedby', $description.attr( 'id' ) );
44 return this;
45 };
46
47 /**
48 * @param {string} label
49 * @chainable
50 * @return {OO.ui.Element} The element, for chaining
51 */
52 ve.ui.MWAriaDescribe.prototype.setAriaLabel = function ( label ) {
53 this.$describedElement.attr( 'aria-label', label );
54 return this;
55 };