Skip to content

Commit

Permalink
Add basic ARIA support for toolbars and buttons
Browse files Browse the repository at this point in the history
Fixes #58
  • Loading branch information
jbalsas committed Oct 27, 2014
1 parent c426afc commit 258ce16
Show file tree
Hide file tree
Showing 14 changed files with 247 additions and 13 deletions.
39 changes: 37 additions & 2 deletions src/core/uicore.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,61 @@
* @param {Object} editor The current CKEditor instance.
*/
init: function(editor) {
var handleUI;
var handleUI,
handleAria,
ariaState = [],
ariaStatusElement,
uiTasksTimeout;

ariaStatusElement = this._createAriaStatusElement(editor.id);

uiTasksTimeout = editor.config.uicore ? editor.config.uicore.timeout : 50;

handleAria = CKEDITOR.tools.debounce(
function(event) {
ariaStatusElement.innerHTML = ariaState.join('. ');
},
uiTasksTimeout
);

handleUI = CKEDITOR.tools.debounce(
function(event) {
ariaState = [];

if (event.name !== 'keyup' || event.data.$.keyCode !== 27 || editor.config.allowEsc) {
editor.fire('editorInteraction', {
nativeEvent: event.data.$,
selectionData: editor.getSelectionData()
});
}
},
editor.config.uicore ? editor.config.uicore.timeout : 50
uiTasksTimeout
);

editor.on('ariaUpdate', function(event) {
ariaState.push(event.data.msg);
handleAria();
});

editor.on('contentDom', function() {
var editable = editor.editable();

editable.attachListener(editable, 'mouseup', handleUI);
editable.attachListener(editable, 'keyup', handleUI);
});
},

_createAriaStatusElement: function(id) {
var statusElement;

statusElement = document.createElement('div');
statusElement.setAttribute('aria-live', 'polite');
statusElement.setAttribute('role', 'status');
statusElement.setAttribute('id', id + '_aria');

document.body.appendChild(statusElement);

return statusElement;
}
}
);
Expand Down
1 change: 0 additions & 1 deletion src/ui/yui/src/adapter/yui.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ YUI.add('alloy-editor', function(Y) {
editor.config.removePlugins = this.get('removePlugins');
editor.config.extraPlugins = this.get('extraPlugins');
editor.config.placeholderClass = this.get('placeholderClass');
editor.config.title = false;

Y.mix(editor.config, config);

Expand Down
29 changes: 21 additions & 8 deletions src/ui/yui/src/buttons/button-a.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,12 +506,18 @@ YUI.add('button-a', function(Y) {
*/
_renderLinkUI: function() {
var contentBox,
linkContainer;
linkContainer,
strings;

strings = this.get('strings');

linkContainer = YNode.create(
Lang.sub(
this.TPL_LINK_CONTAINER, {
placeholder: this.get('strings').placeholder
back: strings.back,
clear: strings.clear,
confirm: strings.confirm,
placeholder: strings.placeholder
}
)
);
Expand Down Expand Up @@ -687,16 +693,16 @@ YUI.add('button-a', function(Y) {
'<div class="pull-left btn-group input-wrapper">' +
'<span class="input-container">' +
'<input class="input-large" type="text" placeholder="{placeholder}"></input>' +
'<span class="input-clear">' +
'<span aria-label="{clear}" class="input-clear">' +
'<i class="alloy-editor-icon-remove"></i>' +
'</span>' +
'</span>' +
'</div>' +
'<div class="pull-left btn-group input-close-container">' +
'<button class="alloy-editor-button btn btn-default close-link"><i class="alloy-editor-icon-ok"></i></button>' +
'<button aria-label="{confirm}" class="alloy-editor-button btn btn-default close-link"><i class="alloy-editor-icon-ok"></i></button>' +
'</div>' +
'<div class="pull-right btn-group show-buttons-container">' +
'<button class="alloy-editor-button btn btn-default switch-to-edit"><i class="alloy-editor-icon-remove"></i></button>' +
'<button aria-label="{back}" class="alloy-editor-button btn btn-default switch-to-edit"><i class="alloy-editor-icon-remove"></i></button>' +
'</div>' +
'</div>'
}, {
Expand All @@ -719,14 +725,21 @@ YUI.add('button-a', function(Y) {

/**
* Collection of strings used to label elements of the button's UI.
* ButtonA provides one string property, to specify the value of link placeholder.
* ButtonA provides string properties to specify the messages for:
* - Link input placeholder
* - Button label
* - Button actions (back, clear and confirm)
*
* @attribute strings
* @default {placeholder: 'Type or paste link here'}
* @type String
* @default {back: 'Back', clear: 'Clear', confirm: 'Confirm', label: 'Link', placeholder: 'Type or paste link here'}
* @type Object
*/
strings: {
value: {
back: 'Back',
clear: 'Clear',
confirm: 'Confirm',
label: 'Link',
placeholder: 'Type or paste link here'
}
}
Expand Down
20 changes: 18 additions & 2 deletions src/ui/yui/src/buttons/button-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ YUI.add('button-base', function(Y) {

btnSrcNode = YNode.create(
Lang.sub(this.TPL_BUTTON, {
content: this.TPL_CONTENT
content: this.TPL_CONTENT,
label: this.get('strings').label
})
);

Expand All @@ -226,10 +227,25 @@ YUI.add('button-base', function(Y) {
});
},

TPL_BUTTON: '<button class="alloy-editor-button btn btn-default">{content}</button>'
TPL_BUTTON: '<button aria-label="{label}" class="alloy-editor-button btn btn-default">{content}</button>'
};

ButtonBase.ATTRS = {
/**
* Collection of strings used to label elements of the button's UI.
* ButtonBase provides string properties to specify the label of the button.
*
* @attribute strings
* @default {label: 'Button'}
* @type Object
*/
strings: {
validator: Lang.isObject,
value: {
label: 'Button'
}
},

/**
* Specifies if the button is toggleable, or not.
* Buttons may be "toggleable" or "push" buttons.
Expand Down
15 changes: 15 additions & 0 deletions src/ui/yui/src/buttons/button-em.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ YUI.add('button-em', function(Y) {
element: {
validator: Lang.isString,
value: 'em'
},

/**
* Collection of strings used to label elements of the button's UI.
* ButtonEm provides string properties to specify the label of the button.
*
* @attribute strings
* @default {label: 'Italic'}
* @type Object
*/
strings: {
validator: Lang.isObject,
value: {
label: 'Italic'
}
}
}
});
Expand Down
15 changes: 15 additions & 0 deletions src/ui/yui/src/buttons/button-h1.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ YUI.add('button-h1', function(Y) {
element: {
validator: Lang.isString,
value: 'h1'
},

/**
* Collection of strings used to label elements of the button's UI.
* ButtonH1 provides string properties to specify the label of the button.
*
* @attribute strings
* @default {label: 'Heading level 1'}
* @type Object
*/
strings: {
validator: Lang.isObject,
value: {
label: 'Heading level 1'
}
}
}
});
Expand Down
15 changes: 15 additions & 0 deletions src/ui/yui/src/buttons/button-h2.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ YUI.add('button-h2', function(Y) {
element: {
validator: Lang.isString,
value: 'h2'
},

/**
* Collection of strings used to label elements of the button's UI.
* ButtonH2 provides string properties to specify the label of the button.
*
* @attribute strings
* @default {label: 'Heading level 2'}
* @type Object
*/
strings: {
validator: Lang.isObject,
value: {
label: 'Heading level 2'
}
}
}
});
Expand Down
15 changes: 15 additions & 0 deletions src/ui/yui/src/buttons/button-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,21 @@ YUI.add('button-image', function(Y) {
NS: 'image',

ATTRS: {
/**
* Collection of strings used to label elements of the button's UI.
* ButtonImage provides string properties to specify the label of the button.
*
* @attribute strings
* @default {label: 'Image'}
* @type Object
*/
strings: {
validator: Lang.isObject,
value: {
label: 'Image'
}
},

/**
* Specifies if this button will be toggleable, or not.
* ButtonImage will be not toggleable by default.
Expand Down
15 changes: 15 additions & 0 deletions src/ui/yui/src/buttons/button-left.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,21 @@ YUI.add('button-left', function(Y) {
element: {
validator: Lang.isString,
value: 'left'
},

/**
* Collection of strings used to label elements of the button's UI.
* ButtonLeft provides string properties to specify the label of the button.
*
* @attribute strings
* @default {label: 'Align left'}
* @type Object
*/
strings: {
validator: Lang.isObject,
value: {
label: 'Align left'
}
}
}
});
Expand Down
15 changes: 15 additions & 0 deletions src/ui/yui/src/buttons/button-right.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,21 @@ YUI.add('button-right', function(Y) {
element: {
validator: Lang.isString,
value: 'right'
},

/**
* Collection of strings used to label elements of the button's UI.
* ButtonRight provides string properties to specify the label of the button.
*
* @attribute strings
* @default {label: 'Align right'}
* @type Object
*/
strings: {
validator: Lang.isObject,
value: {
label: 'Align right'
}
}
}
});
Expand Down
15 changes: 15 additions & 0 deletions src/ui/yui/src/buttons/button-strong.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ YUI.add('button-strong', function(Y) {
element: {
validator: Lang.isString,
value: 'strong'
},

/**
* Collection of strings used to label elements of the button's UI.
* ButtonStrong provides string properties to specify the label of the button.
*
* @attribute strings
* @default {label: 'Bold'}
* @type Object
*/
strings: {
validator: Lang.isObject,
value: {
label: 'Bold'
}
}
}
});
Expand Down
15 changes: 15 additions & 0 deletions src/ui/yui/src/buttons/button-twitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ YUI.add('button-twitter', function(Y) {
NS: 'tweet',

ATTRS: {
/**
* Collection of strings used to label elements of the button's UI.
* ButtonTwitter provides string properties to specify the label of the button.
*
* @attribute strings
* @default {label: 'Tweet'}
* @type Object
*/
strings: {
validator: Lang.isObject,
value: {
label: 'Tweet'
}
},

/**
* Specifies if the button is toggleable, or not. ButtonTwitter will be not toggleable by default.
*
Expand Down
15 changes: 15 additions & 0 deletions src/ui/yui/src/buttons/button-underline.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ YUI.add('button-u', function(Y) {
element: {
validator: Lang.isString,
value: 'u'
},

/**
* Collection of strings used to label elements of the button's UI.
* ButtonU provides string properties to specify the label of the button.
*
* @attribute strings
* @default {label: 'Underline'}
* @type Object
*/
strings: {
validator: Lang.isObject,
value: {
label: 'Underline'
}
}
}
});
Expand Down
Loading

0 comments on commit 258ce16

Please sign in to comment.