From 8ed791b0dbf8e51d80d480acd96f580d4e4e3588 Mon Sep 17 00:00:00 2001 From: DavideTriso Date: Fri, 9 Feb 2018 20:48:38 +0100 Subject: [PATCH] Solved issue #14 --- dist/aria-dialog.js | 26 +------------------------- dist/aria-dialog.min.js | 2 +- docs/aria-dialog.js | 26 +------------------------- package.json | 2 +- src/js/aria-dialog.js | 26 +------------------------- 5 files changed, 5 insertions(+), 77 deletions(-) diff --git a/dist/aria-dialog.js b/dist/aria-dialog.js index 85c48e0..04a80bf 100644 --- a/dist/aria-dialog.js +++ b/dist/aria-dialog.js @@ -217,7 +217,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI firstFocussableElement = focussableElements.first(), lastFocussableElement = focussableElements.last(); - self.elementWithFocus = $(':focus'); //the element with focus just before the dialog is opened + self.elementWithFocus = $(':focus'); //get the element with focus just before the dialog is opened /* @@ -284,23 +284,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI event.stopPropagation(); }); } - //close dialog when escape is pressed - if (settings.closeWithEsc) { - win.on('keydown.' + pluginName, function (event) { - if (event.keyCode === 27 && checkForModifierKeys(event) === 'none') { - self.updateHash('hide'); - } - }); - } - //close dialog if user clicks on bg - if (settings.closeOnBgClick) { - element.on('click.' + pluginName, function () { - self.updateHash('hide'); - }); - dialogWindow.on('click.' + pluginName, function (event) { - event.stopPropagation(); - }); - } //Update dialog state self.elementState = true; @@ -354,13 +337,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI //trigger custom event on window for authors to listen for win.trigger(pluginName + '.hide', [self]); }, - updateHash: function (action) { - if (action === 'show') { - document.location.hash = this.elementId; - } else { - document.location.hash = ''; - } - }, methodCaller: function (methodName) { var self = this; /* diff --git a/dist/aria-dialog.min.js b/dist/aria-dialog.min.js index 669a5b9..76ba862 100644 --- a/dist/aria-dialog.min.js +++ b/dist/aria-dialog.min.js @@ -1 +1 @@ -!function(e){"function"==typeof define&&define.amd?define(["jquery"],e):"object"==typeof exports?module.exports=e(require("jquery")):e(jQuery,window,document)}(function(e,t,n){"use strict";function i(e,t,n){return n=void 0!==n?n:"",e.is("[id]")||e.attr("id",t+n),e.attr("id")}function a(e){return e.shiftKey||e.ctrlKey||e.altKey||e.metaKey?!(!e.shiftKey||e.ctrlKey||e.altKey||e.metaKey)&&"shift":"none"}function s(e){return e.find("a[href], area[href], button:enabled, input:enabled, textarea:enabled, select:enabled, optgroup:enabled, option:enabled, menuitem:enabled, fieldset:enabled")}function o(t,n){var a=this;a.settings=e.extend({},e.fn[l].defaultSettings,n),a.element=e(t),a.elementId=i(a.element,a.settings.dialogIdPrefix,d),a.elementState=!1,a.elements={dialogWindow:a.element.find("."+a.settings.windowClass),container:a.element.find("."+a.settings.containerClass),heading:a.element.find("."+a.settings.headingClass),mainMessage:a.element.find("."+a.settings.mainMessageClass).first()},a.init()}var l="ariaDialog",d=0,c={r:"role",aMo:"aria-modal",aHi:"aria-hidden",aLab:"aria-labelledby",aDes:"aria-describedby",tbI:"tabindex",aLi:"aria-live",t:"true",f:"false"},r=e(t);e.extend(o.prototype,{init:function(){var e=this,t=e.settings,n=e.element,a=e.elements,o=a.dialogWindow;switch(t.cssTransitions||(n.hide(),o.hide()),t.dialogType){case"modal":o.attr(c.r,"dialog").attr(c.aMo,c.t);break;case"alert":o.attr(c.r,"alertdialog").attr(c.aMo,c.t)}if(o.attr(c.aLab,i(a.heading,e.elementId+"__heading")).attr(c.aHi,c.t).attr(c.tbI,"-1"),1===a.mainMessage.length&&o.attr(c.aDes,i(a.mainMessage,e.elementId+"__main-message")),a.focussableElements=s(o),a.elementToFocus=o.find(t.setFocusOn),"object"!=typeof a.elementToFocus||1!==a.elementToFocus.length||1!==a.elementToFocus.closest(e.element).length||a.focussableElements.index(a.elementToFocus)<0)throw new Error("Check value of 'setFocusOn' option.");r.trigger(l+".initialised",[e]),d+=1},show:function(){var t=this,n=t.element,i=t.elements,o=i.dialogWindow,d=t.settings,f=s(o),u=f.first(),g=f.last();t.elementWithFocus=e(":focus"),d.cssTransitions||(n.show(),o.stop().fadeIn(d.fadeSpeed)),n.addClass(d.dialogOpenClass),o.addClass(d.windowOpenClass).attr(c.aHi,c.f),i.elementToFocus.focus(),u.on("keydown."+l,function(e){9===e.keyCode&&"shift"===a(e)&&(e.preventDefault(),g.focus())}),g.first().on("keydown."+l,function(e){9===e.keyCode&&"none"===a(e)&&(e.preventDefault(),u.focus())}),d.closeWithEsc&&r.on("keydown."+l,function(e){27===e.keyCode&&"none"===a(e)&&t.hide()}),d.closeOnBgClick&&(n.on("click."+l,function(){t.hide()}),o.on("click."+l,function(e){e.stopPropagation()})),d.closeWithEsc&&r.on("keydown."+l,function(e){27===e.keyCode&&"none"===a(e)&&t.updateHash("hide")}),d.closeOnBgClick&&(n.on("click."+l,function(){t.updateHash("hide")}),o.on("click."+l,function(e){e.stopPropagation()})),t.elementState=!0,r.trigger(l+".show",[t])},hide:function(){var e=this,t=e.element,n=e.elements.dialogWindow,i=e.settings;t.removeClass(i.dialogOpenClass),n.removeClass(i.windowOpenClass).attr(c.aHi,c.t),i.cssTransitions||n.stop().fadeOut(i.fadeSpeed,function(){t.hide()}),1===e.elementWithFocus.length&&e.elementWithFocus.focus(),r.off("keydown."+l),t.off("click."+l),n.off("click."+l),e.elementState=!1,r.trigger(l+".hide",[e])},updateHash:function(e){n.location.hash="show"===e?this.elementId:""},methodCaller:function(e){var t=this;switch(e){case"show":t.show();break;case"hide":t.elementState&&t.hide()}}}),e.fn[l]=function(t){return this.each(function(){e.data(this,"plugin_"+l)||"object"!=typeof t&&void 0!==t?"string"==typeof t&&e.data(this,"plugin_"+l).methodCaller(t):e.data(this,"plugin_"+l,new o(this,t))})},e.fn[l].defaultSettings={dialogIdPrefix:"dialog--",windowClass:"dialog__window",containerClass:"dialog__container",headingClass:"dialog__heading",mainMessageClass:"dialog__main-message",dialogOpenClass:"dialog_open",windowOpenClass:"dialog__window_open",dialogType:"modal",containerRole:"document",closeWithEsc:!0,closeOnBgClick:!0,fadeSpeed:600,cssTransitions:!1,setFocusOn:"button:first-child"}}); \ No newline at end of file +!function(e){"function"==typeof define&&define.amd?define(["jquery"],e):"object"==typeof exports?module.exports=e(require("jquery")):e(jQuery,window,document)}(function(e,t,n){"use strict";function i(e,t,n){return n=void 0!==n?n:"",e.is("[id]")||e.attr("id",t+n),e.attr("id")}function a(e){return e.shiftKey||e.ctrlKey||e.altKey||e.metaKey?!(!e.shiftKey||e.ctrlKey||e.altKey||e.metaKey)&&"shift":"none"}function s(e){return e.find("a[href], area[href], button:enabled, input:enabled, textarea:enabled, select:enabled, optgroup:enabled, option:enabled, menuitem:enabled, fieldset:enabled")}function o(t,n){var a=this;a.settings=e.extend({},e.fn[l].defaultSettings,n),a.element=e(t),a.elementId=i(a.element,a.settings.dialogIdPrefix,d),a.elementState=!1,a.elements={dialogWindow:a.element.find("."+a.settings.windowClass),container:a.element.find("."+a.settings.containerClass),heading:a.element.find("."+a.settings.headingClass),mainMessage:a.element.find("."+a.settings.mainMessageClass).first()},a.init()}var l="ariaDialog",d=0,r={r:"role",aMo:"aria-modal",aHi:"aria-hidden",aLab:"aria-labelledby",aDes:"aria-describedby",tbI:"tabindex",aLi:"aria-live",t:"true",f:"false"},c=e(t);e.extend(o.prototype,{init:function(){var e=this,t=e.settings,n=e.element,a=e.elements,o=a.dialogWindow;switch(t.cssTransitions||(n.hide(),o.hide()),t.dialogType){case"modal":o.attr(r.r,"dialog").attr(r.aMo,r.t);break;case"alert":o.attr(r.r,"alertdialog").attr(r.aMo,r.t)}if(o.attr(r.aLab,i(a.heading,e.elementId+"__heading")).attr(r.aHi,r.t).attr(r.tbI,"-1"),1===a.mainMessage.length&&o.attr(r.aDes,i(a.mainMessage,e.elementId+"__main-message")),a.focussableElements=s(o),a.elementToFocus=o.find(t.setFocusOn),"object"!=typeof a.elementToFocus||1!==a.elementToFocus.length||1!==a.elementToFocus.closest(e.element).length||a.focussableElements.index(a.elementToFocus)<0)throw new Error("Check value of 'setFocusOn' option.");c.trigger(l+".initialised",[e]),d+=1},show:function(){var t=this,n=t.element,i=t.elements,o=i.dialogWindow,d=t.settings,f=s(o),u=f.first(),g=f.last();t.elementWithFocus=e(":focus"),d.cssTransitions||(n.show(),o.stop().fadeIn(d.fadeSpeed)),n.addClass(d.dialogOpenClass),o.addClass(d.windowOpenClass).attr(r.aHi,r.f),i.elementToFocus.focus(),u.on("keydown."+l,function(e){9===e.keyCode&&"shift"===a(e)&&(e.preventDefault(),g.focus())}),g.first().on("keydown."+l,function(e){9===e.keyCode&&"none"===a(e)&&(e.preventDefault(),u.focus())}),d.closeWithEsc&&c.on("keydown."+l,function(e){27===e.keyCode&&"none"===a(e)&&t.hide()}),d.closeOnBgClick&&(n.on("click."+l,function(){t.hide()}),o.on("click."+l,function(e){e.stopPropagation()})),t.elementState=!0,c.trigger(l+".show",[t])},hide:function(){var e=this,t=e.element,n=e.elements.dialogWindow,i=e.settings;t.removeClass(i.dialogOpenClass),n.removeClass(i.windowOpenClass).attr(r.aHi,r.t),i.cssTransitions||n.stop().fadeOut(i.fadeSpeed,function(){t.hide()}),1===e.elementWithFocus.length&&e.elementWithFocus.focus(),c.off("keydown."+l),t.off("click."+l),n.off("click."+l),e.elementState=!1,c.trigger(l+".hide",[e])},methodCaller:function(e){var t=this;switch(e){case"show":t.show();break;case"hide":t.elementState&&t.hide()}}}),e.fn[l]=function(t){return this.each(function(){e.data(this,"plugin_"+l)||"object"!=typeof t&&void 0!==t?"string"==typeof t&&e.data(this,"plugin_"+l).methodCaller(t):e.data(this,"plugin_"+l,new o(this,t))})},e.fn[l].defaultSettings={dialogIdPrefix:"dialog--",windowClass:"dialog__window",containerClass:"dialog__container",headingClass:"dialog__heading",mainMessageClass:"dialog__main-message",dialogOpenClass:"dialog_open",windowOpenClass:"dialog__window_open",dialogType:"modal",containerRole:"document",closeWithEsc:!0,closeOnBgClick:!0,fadeSpeed:600,cssTransitions:!1,setFocusOn:"button:first-child"}}); \ No newline at end of file diff --git a/docs/aria-dialog.js b/docs/aria-dialog.js index 85c48e0..04a80bf 100644 --- a/docs/aria-dialog.js +++ b/docs/aria-dialog.js @@ -217,7 +217,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI firstFocussableElement = focussableElements.first(), lastFocussableElement = focussableElements.last(); - self.elementWithFocus = $(':focus'); //the element with focus just before the dialog is opened + self.elementWithFocus = $(':focus'); //get the element with focus just before the dialog is opened /* @@ -284,23 +284,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI event.stopPropagation(); }); } - //close dialog when escape is pressed - if (settings.closeWithEsc) { - win.on('keydown.' + pluginName, function (event) { - if (event.keyCode === 27 && checkForModifierKeys(event) === 'none') { - self.updateHash('hide'); - } - }); - } - //close dialog if user clicks on bg - if (settings.closeOnBgClick) { - element.on('click.' + pluginName, function () { - self.updateHash('hide'); - }); - dialogWindow.on('click.' + pluginName, function (event) { - event.stopPropagation(); - }); - } //Update dialog state self.elementState = true; @@ -354,13 +337,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI //trigger custom event on window for authors to listen for win.trigger(pluginName + '.hide', [self]); }, - updateHash: function (action) { - if (action === 'show') { - document.location.hash = this.elementId; - } else { - document.location.hash = ''; - } - }, methodCaller: function (methodName) { var self = this; /* diff --git a/package.json b/package.json index c67b6cb..8eaef95 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "t-aria-dialog", - "version": "2.0.2", + "version": "2.0.3", "description": "HTML, CSS and JS UI-component for user-friendly and accessible dialogs", "license": "MIT", "repository": { diff --git a/src/js/aria-dialog.js b/src/js/aria-dialog.js index 85c48e0..04a80bf 100644 --- a/src/js/aria-dialog.js +++ b/src/js/aria-dialog.js @@ -217,7 +217,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI firstFocussableElement = focussableElements.first(), lastFocussableElement = focussableElements.last(); - self.elementWithFocus = $(':focus'); //the element with focus just before the dialog is opened + self.elementWithFocus = $(':focus'); //get the element with focus just before the dialog is opened /* @@ -284,23 +284,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI event.stopPropagation(); }); } - //close dialog when escape is pressed - if (settings.closeWithEsc) { - win.on('keydown.' + pluginName, function (event) { - if (event.keyCode === 27 && checkForModifierKeys(event) === 'none') { - self.updateHash('hide'); - } - }); - } - //close dialog if user clicks on bg - if (settings.closeOnBgClick) { - element.on('click.' + pluginName, function () { - self.updateHash('hide'); - }); - dialogWindow.on('click.' + pluginName, function (event) { - event.stopPropagation(); - }); - } //Update dialog state self.elementState = true; @@ -354,13 +337,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI //trigger custom event on window for authors to listen for win.trigger(pluginName + '.hide', [self]); }, - updateHash: function (action) { - if (action === 'show') { - document.location.hash = this.elementId; - } else { - document.location.hash = ''; - } - }, methodCaller: function (methodName) { var self = this; /*