-
Notifications
You must be signed in to change notification settings - Fork 12
Performing content check using the API
You can trigger accessibility checker check using a following API call:
editor._.a11ychecker.check( { callback: function ( _skip, issues ) {
console.log( 'Done checking. Is the content valid?', issues.count() == 0 ); }
} );
Where editor
is an instance object of CKEditor 4.
You can check it by opening https://ckeditor.com/docs/ckeditor4/latest/examples/accessibilitychecker.html then opening JavaScript console and pasting the following code:
CKEDITOR.instances.editor1._.a11ychecker.check( { callback: function ( _skip, issues ) {
console.log( 'Done checking. Is the content valid?', issues.count() == 0 ); }
} );
It is also possible to skip eventual alert:
// Listener to hide ui for the next check.
CKEDITOR.instances.editor1._.a11ychecker.once( 'checked', function( event ) {
event.stop();
return false;
} );
CKEDITOR.instances.editor1._.a11ychecker.check( { callback: function ( _skip, issues ) {
console.log( 'Done checking. Is the content valid?', issues.count() == 0 );
} } );
Last remark, is loaded asynchronously to reduce the performance impact on CKEditor 4 instance alone. You might face an issue where the full API will not be available.
In this case it means that the Accessibility Checker is not yet fully loaded, and to access it you need to use a following code:
editor._.a11ychecker.on( 'loaded', function() {
var a11ychecker = editor._.a11ychecker;
// Now you can reliably access A11ychecker API.
a11ychecker.check( { callback: function ( _skip, issues ) {
console.log( 'Done checking. Is the content valid?', issues.count() == 0 );
} } );
} );
Accessibility Checker has been created before the promise API was introduced in the CKEditor 4, thus it doesn't at the moment have a promise-based interface for that.