diff --git a/toastr.js b/toastr.js index 80fcd0fb..12ec0e77 100644 --- a/toastr.js +++ b/toastr.js @@ -7,6 +7,7 @@ * conditions of the MIT license, available at http://www.opensource.org/licenses/mit-license.php * * Author: John Papa and Hans FjÀllemark + * ARIA Support: Greta Krafsig * Project: https://github.com/CodeSeven/toastr */ ; (function (define) { @@ -25,6 +26,7 @@ var toastr = { clear: clear, + remove: remove, error: error, getContainer: getContainer, info: info, @@ -101,6 +103,18 @@ }); } } + + function remove($toastElement) { + var options = getOptions(); + if (!$container) { getContainer(options); } + if ($toastElement && $(':focus', $toastElement).length === 0) { + removeToast($toastElement); + return; + } + if ($container.children().length) { + $container.remove(); + } + } //#endregion //#region Internal Methods @@ -188,7 +202,7 @@ } if (options.closeButton) { - $closeElement.addClass('toast-close-button'); + $closeElement.addClass('toast-close-button').attr("role", "button"); $toastElement.prepend($closeElement); } @@ -277,7 +291,10 @@ } $container = $('
') .attr('id', options.containerId) - .addClass(options.positionClass); + .addClass(options.positionClass) + .attr('aria-live', 'polite') + .attr('role', 'alert'); + $container.appendTo($(options.target)); return $container; } @@ -307,4 +324,4 @@ } else { window['toastr'] = factory(window['jQuery']); } -})); +})); \ No newline at end of file