diff --git a/.editorconfig b/.editorconfig index 9b73521..6e87a00 100644 --- a/.editorconfig +++ b/.editorconfig @@ -4,7 +4,7 @@ root = true [*] charset = utf-8 indent_style = space -indent_size = 4 +indent_size = 2 insert_final_newline = true trim_trailing_whitespace = true diff --git a/.eslintrc b/.eslintrc index 8e16686..ba9c48e 100644 --- a/.eslintrc +++ b/.eslintrc @@ -14,7 +14,7 @@ "block-spacing": ["error"], "comma-dangle": ["error", "never"], "comma-spacing": ["error", { "before": false, "after": true }], - "indent": ["error", 4], // modify this depending on the project + "indent": ["error", 2], // modify this depending on the project "key-spacing": ["error", { "beforeColon": false }], "keyword-spacing": ["error", { "before": true, "after": true }], "linebreak-style": ["error", "unix"], diff --git a/brochure/js/launchy.js b/brochure/js/launchy.js index 2ba489e..4f63c61 100644 --- a/brochure/js/launchy.js +++ b/brochure/js/launchy.js @@ -16,4 +16,4 @@ var Launchy=function(t){function e(o){if(n[o])return n[o].exports;var i=n[o]={i: * @version 0.8.1 * @license MIT */ -n(1);var a={modalLaunchLink:"launchy__launch-link",modalCloseLink:"launchy__close-link",modalWindow:"launchy__window",modalContent:"launchy__content",modalOverlay:"launchy__overlay",modalTitle:"launchy__title",modalWindowIsVisible:"launchy__window--is-visible",modalOverlayIsVisible:"launchy__overlay--is-visible"},r={launchyText:"data-launchy-text",launchyTitle:"data-launchy-title",launchyButton:"data-launchy-button",launchyCustom:{close:"data-launchy-close",refocus:"data-launchy-refocus"}},s={Escape:27},l={launchyElements:"[data-launchy]",launchyControl:"launchy-control-",launchyDialog:"launchy-dialog-",launchyCloseControl:"launchy-close-control-",modalOverlay:"modal-overlay-",modalBumper:"modal-bumper-",modalTitle:"modal-title-"},d={modalClose:"Close modal window!",modalCloseHTML:'',modalError:"Launchy container must have a `data-launchy-text` attribute!",modalErrorEmpty:"Launchy container `data-launchy-text` attribute cannot be empty!",modalWarning:"Launchy container should have a `data-launchy-title` attribute, or be sure to supply your own heading! (Prefereably an `

`.)",refocusElemNotFound:"Refocus element not found!"},u=0,h=function(){function t(e){o(this,t),this.focusable=n(2),this.launchyId=u,this.hasTitle=!!e.title,this.useButton=!!e.button,this.modalIsVisible=!1,this.activeElement=null,this.shiftKeyIsPressed=!1,this.allFocusable=null,this.firstFocusable=null,this.lastFocusable=null,this.domFocusable=null,this.createElements(e),this.insertElements(e),this.setupEventListeners(),u++}return i(t,[{key:"createElements",value:function(t){console.log(this.useButton),this.launchControl=document.createElement(this.useButton?"button":"a"),this.launchControl.id=""+l.launchyControl+this.launchyId,this.useButton?this.launchControl.type="button":this.launchControl.href="#"+l.launchyDialog+this.launchyId,this.launchControl.classList.add(a.modalLaunchLink),this.launchControl.setAttribute("aria-haspopup","dialog"),this.launchControl.textContent=t.text,this.closeControl=document.createElement(this.useButton?"button":"a"),this.closeControl.id=""+l.launchyCloseControl+this.launchyId,this.useButton?this.closeControl.type="button":this.closeControl.href="#"+l.launchyControl+this.launchyId,this.closeControl.classList.add(a.modalCloseLink),this.closeControl.setAttribute("aria-label",d.modalClose),this.closeControl.innerHTML=d.modalCloseHTML,this.modalWindow=document.createElement("div"),this.modalWindow.id=""+l.launchyDialog+this.launchyId,this.modalWindow.classList.add(a.modalWindow),this.modalWindow.setAttribute("tabindex",-1),this.modalWindow.setAttribute("role","dialog"),this.modalWindow.setAttribute("aria-modal",!0),this.hasTitle&&this.modalWindow.setAttribute("aria-labelledby",""+l.modalTitle+this.launchyId),this.modalOverlay=document.createElement("div"),this.modalOverlay.id=""+l.modalOverlay+this.launchyId,this.modalOverlay.classList.add(a.modalOverlay),this.modalOverlay.setAttribute("tabindex",0),this.modalBumper=document.createElement("div"),this.modalBumper.id=""+l.modalBumper+this.launchyId,this.modalBumper.setAttribute("tabindex",0),this.modalContent=document.createElement("div"),this.modalContent.classList.add(a.modalContent),this.hasTitle&&(this.modalTitle=document.createElement("h2"),this.modalTitle.id=""+l.modalTitle+this.launchyId,this.modalTitle.classList.add(a.modalTitle),this.modalTitle.textContent=t.title)}},{key:"insertElements",value:function(t){t.target.parentNode.insertBefore(this.launchControl,t.target),t.target.parentNode.insertBefore(this.modalWindow,t.target),this.modalWindow.appendChild(this.modalContent),this.modalContent.appendChild(this.closeControl),this.hasTitle&&this.modalContent.appendChild(this.modalTitle),this.modalContent.appendChild(t.target),document.body.appendChild(this.modalOverlay),document.body.insertBefore(this.modalBumper,document.body.firstChild)}},{key:"setupEventListeners",value:function(){var t=this.modalContent.querySelectorAll("["+r.launchyCustom.close+"]"),e=this.modalContent.querySelectorAll("["+r.launchyCustom.refocus+"]");this.launchControl.addEventListener("click",this.showModal.bind(this),!1),this.closeControl.addEventListener("click",this.hideModal.bind(this),!1),this.modalOverlay.addEventListener("click",this.hideModal.bind(this),!1),document.addEventListener("focus",this.trapFocus.bind(this),!0),document.addEventListener("keydown",this.checkEsc.bind(this),!1),document.addEventListener("keydown",this.checkShift.bind(this),!1);var n=!0,o=!1,i=void 0;try{for(var a,s=Array.from(t)[Symbol.iterator]();!(n=(a=s.next()).done);n=!0){a.value.addEventListener("click",this.hideModal.bind(this),!1)}}catch(t){o=!0,i=t}finally{try{!n&&s.return&&s.return()}finally{if(o)throw i}}var l=!0,d=!1,u=void 0;try{for(var h,c=Array.from(e)[Symbol.iterator]();!(l=(h=c.next()).done);l=!0){h.value.addEventListener("click",this.hideModalRefocus.bind(this),!1)}}catch(t){d=!0,u=t}finally{try{!l&&c.return&&c.return()}finally{if(d)throw u}}}},{key:"showModal",value:function(t){t.preventDefault(),this.activeElement=document.activeElement,this.modalIsVisible=!0,this.allFocusable=this.modalWindow.querySelectorAll(this.focusable),this.firstFocusable=this.allFocusable[0],this.lastFocusable=this.allFocusable[this.allFocusable.length-1],this.modalWindow.classList.add(a.modalWindowIsVisible),this.modalOverlay.classList.add(a.modalOverlayIsVisible),this.inertElements(!0),this.modalWindow.focus()}},{key:"hideModal",value:function(t){t.preventDefault(),this.modalIsVisible=!1,this.allFocusable=null,this.firstFocusable=null,this.lastFocusable=null,this.modalWindow.classList.remove(a.modalWindowIsVisible),this.modalOverlay.classList.remove(a.modalOverlayIsVisible),this.inertElements(!1),this.activeElement.focus()}},{key:"trapFocus",value:function(t){this.modalIsVisible&&!this.modalWindow.contains(t.target)&&(t.stopPropagation(),this.shiftKeyIsPressed?this.lastFocusable.focus():this.firstFocusable.focus())}},{key:"checkEsc",value:function(t){this.modalIsVisible&&t.keyCode===s.Escape&&this.hideModal(t)}},{key:"checkShift",value:function(t){this.modalIsVisible&&(this.shiftKeyIsPressed=t.shiftKey)}},{key:"hideModalRefocus",value:function(t){var e=t.target.getAttribute(r.launchyCustom.refocus),n=document.querySelector("#"+e);if(null==n)throw Error(d.refocusElemNotFound+": #"+e);this.hideModal(t),n.focus()}},{key:"inertElements",value:function(t){var e=document.querySelectorAll(this.focusable),n=!0,o=!1,i=void 0;try{for(var a,r=Array.from(e)[Symbol.iterator]();!(n=(a=r.next()).done);n=!0){var s=a.value;this.modalOverlay===s||this.modalBumper===s||this.modalWindow.contains(s)||(s.inert=t)}}catch(t){o=!0,i=t}finally{try{!n&&r.return&&r.return()}finally{if(o)throw i}}}}]),t}(),c=function(){var t=document.querySelectorAll(l.launchyElements),e=null,n=null,o=null,i=!0,a=!1,s=void 0;try{for(var u,c=Array.from(t)[Symbol.iterator]();!(i=(u=c.next()).done);i=!0){var y=u.value;if(e=y.getAttribute(r.launchyText),n=y.getAttribute(r.launchyTitle),o=y.hasAttribute(r.launchyButton),!e)throw Error(d.modalError);if(""===e.trim())throw Error(d.modalErrorEmpty);n||console.warn(d.modalWarning);new h({target:y,text:e,title:n,button:o})}}catch(t){a=!0,s=t}finally{try{!i&&c.return&&c.return()}finally{if(a)throw s}}};document.addEventListener("DOMContentLoaded",c,!1),e.Launchy=h},function(t,e,n){!function(t,e){e()}(0,function(){"use strict";function t(t,e){var n=window.Element.prototype,o=n.matches||n.mozMatchesSelector||n.msMatchesSelector||n.oMatchesSelector||n.webkitMatchesSelector;if(!t||1!==t.nodeType)return!1;var i=t.parentNode;if(o)return o.call(t,e);for(var a=i.querySelectorAll(e),r=a.length,s=0;s