diff --git a/a11y-dialog.js b/a11y-dialog.js index 9972ad75..0971c79d 100644 --- a/a11y-dialog.js +++ b/a11y-dialog.js @@ -10,7 +10,7 @@ /** * Define the constructor to instantiate a dialog - * + * * @constructor * @param {Element} node * @param {(NodeList | Element | string)} targets @@ -35,7 +35,7 @@ /** * Set up everything necessary for the dialog to be functioning - * + * * @param {(NodeList | Element | string)} targets * @return {this} */ @@ -64,16 +64,16 @@ }.bind(this)); // Execute all callbacks registered for the `create` event - this._fire('create', event); + this._fire('create'); return this; - } + }; /** * Show the dialog element, disable all the targets (siblings), trap the * current focus within it, listen for some specific key presses and fire all * registered callbacks for `show` event - * + * * @param {Event} event * @return {this} */ @@ -201,7 +201,7 @@ */ A11yDialog.prototype.on = function (type, handler) { if (typeof this._listeners[type] === 'undefined') { - this._listeners[type] = []; + this._listeners[type] = []; } this._listeners[type].push(handler); @@ -235,7 +235,7 @@ * @param {Event} event */ A11yDialog.prototype._fire = function (type, event) { - var listeners = this._listeners[type] || []; + var listeners = this._listeners[type] || []; var trigger = event ? event.target : void 0; listeners.forEach(function (listener) { @@ -268,7 +268,7 @@ /** * Private event handler used when making sure the focus stays within the * currently open dialog - * + * * @access private * @param {Event} event */ diff --git a/a11y-dialog.min.js b/a11y-dialog.min.js index a206a14c..51ee3f07 100644 --- a/a11y-dialog.min.js +++ b/a11y-dialog.min.js @@ -1,2 +1,2 @@ /*! a11y-dialog 3.0.0 — © Edenspiekermann */ -!function(t){"use strict";function e(t,e){this._show=this.show.bind(this),this._hide=this.hide.bind(this),this._maintainFocus=this._maintainFocus.bind(this),this._bindKeypress=this._bindKeypress.bind(this),this.node=t,this._listeners={},this.create(e)}function i(t){return Array.prototype.slice.call(t)}function n(t,e){return i((e||document).querySelectorAll(t))}function s(t){return NodeList.prototype.isPrototypeOf(t)?i(t):Element.prototype.isPrototypeOf(t)?[t]:"string"==typeof t?n(t):void 0}function o(t){var e=r(t);e.length&&e[0].focus()}function r(t){return n(c.join(","),t).filter(function(t){return!!(t.offsetWidth||t.offsetHeight||t.getClientRects().length)})}function h(t,e){var i=r(t),n=i.indexOf(document.activeElement);e.shiftKey&&0===n?(i[i.length-1].focus(),e.preventDefault()):e.shiftKey||n!==i.length-1||(i[0].focus(),e.preventDefault())}function d(t){var e=i(t.parentNode.childNodes),n=e.filter(function(t){return 1===t.nodeType});return n.splice(n.indexOf(t),1),n}var a,c=["a[href]","area[href]","input:not([disabled])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","iframe","object","embed","[contenteditable]",'[tabindex]:not([tabindex^="-"])'],u=9,f=27;e.prototype.create=function(t){return this._targets=this._targets||s(t)||d(this.node),this.node.setAttribute("aria-hidden",!0),this.shown=!1,this._openers=n('[data-a11y-dialog-show="'+this.node.id+'"]'),this._openers.forEach(function(t){t.addEventListener("click",this._show)}.bind(this)),this._closers=n("[data-a11y-dialog-hide]",this.node).concat(n('[data-a11y-dialog-hide="'+this.node.id+'"]')),this._closers.forEach(function(t){t.addEventListener("click",this._hide)}.bind(this)),this._fire("create",event),this},e.prototype.show=function(t){return this.shown?this:(this.shown=!0,this.node.removeAttribute("aria-hidden"),this._targets.forEach(function(t){var e=t.getAttribute("aria-hidden");e&&t.setAttribute("data-a11y-dialog-original",e),t.setAttribute("aria-hidden","true")}),a=document.activeElement,o(this.node),document.body.addEventListener("focus",this._maintainFocus,!0),document.addEventListener("keydown",this._bindKeypress),this._fire("show",t),this)},e.prototype.hide=function(t){return this.shown?(this.shown=!1,this.node.setAttribute("aria-hidden","true"),this._targets.forEach(function(t){var e=t.getAttribute("data-a11y-dialog-original");e?(t.setAttribute("aria-hidden",e),t.removeAttribute("data-a11y-dialog-original")):t.removeAttribute("aria-hidden")}),a&&a.focus(),document.body.removeEventListener("focus",this._maintainFocus,!0),document.removeEventListener("keydown",this._bindKeypress),this._fire("hide",t),this):this},e.prototype.destroy=function(){return this.hide(),this._openers.forEach(function(t){t.removeEventListener("click",this._show)}.bind(this)),this._closers.forEach(function(t){t.removeEventListener("click",this._hide)}.bind(this)),this._fire("destroy"),this._listeners={},this},e.prototype.on=function(t,e){return"undefined"==typeof this._listeners[t]&&(this._listeners[t]=[]),this._listeners[t].push(e),this},e.prototype.off=function(t,e){var i=this._listeners[t].indexOf(e);return i>-1&&this._listeners[t].splice(i,1),this},e.prototype._fire=function(t,e){var i=this._listeners[t]||[],n=e?e.target:void 0;i.forEach(function(t){t(this.node,n)}.bind(this))},e.prototype._bindKeypress=function(t){this.shown&&t.which===f&&(t.preventDefault(),this.hide()),this.shown&&t.which===u&&h(this.node,t)},e.prototype._maintainFocus=function(t){this.shown&&!this.node.contains(t.target)&&o(this.node)},"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=e:"function"==typeof define&&define.amd?define("A11yDialog",[],function(){return e}):"object"==typeof t&&(t.A11yDialog=e)}(this); +!function(t){"use strict";function e(t,e){this._show=this.show.bind(this),this._hide=this.hide.bind(this),this._maintainFocus=this._maintainFocus.bind(this),this._bindKeypress=this._bindKeypress.bind(this),this.node=t,this._listeners={},this.create(e)}function i(t){return Array.prototype.slice.call(t)}function n(t,e){return i((e||document).querySelectorAll(t))}function s(t){return NodeList.prototype.isPrototypeOf(t)?i(t):Element.prototype.isPrototypeOf(t)?[t]:"string"==typeof t?n(t):void 0}function o(t){var e=r(t);e.length&&e[0].focus()}function r(t){return n(c.join(","),t).filter(function(t){return!!(t.offsetWidth||t.offsetHeight||t.getClientRects().length)})}function h(t,e){var i=r(t),n=i.indexOf(document.activeElement);e.shiftKey&&0===n?(i[i.length-1].focus(),e.preventDefault()):e.shiftKey||n!==i.length-1||(i[0].focus(),e.preventDefault())}function d(t){var e=i(t.parentNode.childNodes),n=e.filter(function(t){return 1===t.nodeType});return n.splice(n.indexOf(t),1),n}var a,c=["a[href]","area[href]","input:not([disabled])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","iframe","object","embed","[contenteditable]",'[tabindex]:not([tabindex^="-"])'],u=9,f=27;e.prototype.create=function(t){return this._targets=this._targets||s(t)||d(this.node),this.node.setAttribute("aria-hidden",!0),this.shown=!1,this._openers=n('[data-a11y-dialog-show="'+this.node.id+'"]'),this._openers.forEach(function(t){t.addEventListener("click",this._show)}.bind(this)),this._closers=n("[data-a11y-dialog-hide]",this.node).concat(n('[data-a11y-dialog-hide="'+this.node.id+'"]')),this._closers.forEach(function(t){t.addEventListener("click",this._hide)}.bind(this)),this._fire("create"),this},e.prototype.show=function(t){return this.shown?this:(this.shown=!0,this.node.removeAttribute("aria-hidden"),this._targets.forEach(function(t){var e=t.getAttribute("aria-hidden");e&&t.setAttribute("data-a11y-dialog-original",e),t.setAttribute("aria-hidden","true")}),a=document.activeElement,o(this.node),document.body.addEventListener("focus",this._maintainFocus,!0),document.addEventListener("keydown",this._bindKeypress),this._fire("show",t),this)},e.prototype.hide=function(t){return this.shown?(this.shown=!1,this.node.setAttribute("aria-hidden","true"),this._targets.forEach(function(t){var e=t.getAttribute("data-a11y-dialog-original");e?(t.setAttribute("aria-hidden",e),t.removeAttribute("data-a11y-dialog-original")):t.removeAttribute("aria-hidden")}),a&&a.focus(),document.body.removeEventListener("focus",this._maintainFocus,!0),document.removeEventListener("keydown",this._bindKeypress),this._fire("hide",t),this):this},e.prototype.destroy=function(){return this.hide(),this._openers.forEach(function(t){t.removeEventListener("click",this._show)}.bind(this)),this._closers.forEach(function(t){t.removeEventListener("click",this._hide)}.bind(this)),this._fire("destroy"),this._listeners={},this},e.prototype.on=function(t,e){return"undefined"==typeof this._listeners[t]&&(this._listeners[t]=[]),this._listeners[t].push(e),this},e.prototype.off=function(t,e){var i=this._listeners[t].indexOf(e);return i>-1&&this._listeners[t].splice(i,1),this},e.prototype._fire=function(t,e){var i=this._listeners[t]||[],n=e?e.target:void 0;i.forEach(function(t){t(this.node,n)}.bind(this))},e.prototype._bindKeypress=function(t){this.shown&&t.which===f&&(t.preventDefault(),this.hide()),this.shown&&t.which===u&&h(this.node,t)},e.prototype._maintainFocus=function(t){this.shown&&!this.node.contains(t.target)&&o(this.node)},"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=e:"function"==typeof define&&define.amd?define("A11yDialog",[],function(){return e}):"object"==typeof t&&(t.A11yDialog=e)}(this); diff --git a/example/main.js b/example/main.js index 9972ad75..0971c79d 100644 --- a/example/main.js +++ b/example/main.js @@ -10,7 +10,7 @@ /** * Define the constructor to instantiate a dialog - * + * * @constructor * @param {Element} node * @param {(NodeList | Element | string)} targets @@ -35,7 +35,7 @@ /** * Set up everything necessary for the dialog to be functioning - * + * * @param {(NodeList | Element | string)} targets * @return {this} */ @@ -64,16 +64,16 @@ }.bind(this)); // Execute all callbacks registered for the `create` event - this._fire('create', event); + this._fire('create'); return this; - } + }; /** * Show the dialog element, disable all the targets (siblings), trap the * current focus within it, listen for some specific key presses and fire all * registered callbacks for `show` event - * + * * @param {Event} event * @return {this} */ @@ -201,7 +201,7 @@ */ A11yDialog.prototype.on = function (type, handler) { if (typeof this._listeners[type] === 'undefined') { - this._listeners[type] = []; + this._listeners[type] = []; } this._listeners[type].push(handler); @@ -235,7 +235,7 @@ * @param {Event} event */ A11yDialog.prototype._fire = function (type, event) { - var listeners = this._listeners[type] || []; + var listeners = this._listeners[type] || []; var trigger = event ? event.target : void 0; listeners.forEach(function (listener) { @@ -268,7 +268,7 @@ /** * Private event handler used when making sure the focus stays within the * currently open dialog - * + * * @access private * @param {Event} event */