Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: kylefox/jquery-modal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: intellum/jquery-modal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 2 commits
  • 5 files changed
  • 1 contributor

Commits on Jun 4, 2024

  1. Copy the full SHA
    c6ed4bd View commit details
  2. CON-3343 Minify plugin

    aud-tree committed Jun 4, 2024
    Copy the full SHA
    0230b1a View commit details
Showing with 4,426 additions and 1 deletion.
  1. +1 −0 .gitignore
  2. +45 −0 jquery.modal.js
  3. +1 −1 jquery.modal.min.js
  4. +4,376 −0 package-lock.json
  5. +3 −0 package.json
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
*.log
node_modules/*
.idea/*
45 changes: 45 additions & 0 deletions jquery.modal.js
Original file line number Diff line number Diff line change
@@ -85,6 +85,9 @@
open: function() {
var m = this;
this.block();
// Store previous focus
this.previousFocus = document.activeElement;

this.anchor.blur();
if(this.options.doFade) {
setTimeout(function() {
@@ -148,6 +151,7 @@
} else {
this.$elm.css('display', 'inline-block');
}
this.trapFocus();
this.$elm.trigger($.modal.OPEN, [this._ctx()]);
},

@@ -164,6 +168,7 @@
_this.$elm.trigger($.modal.AFTER_CLOSE, [_this._ctx()]);
});
}
this.releaseFocus();
this.$elm.trigger($.modal.CLOSE, [this._ctx()]);
},

@@ -179,6 +184,46 @@
if (this.spinner) this.spinner.remove();
},

// Trap focus in modal for screen readers & keyboard navigation
trapFocus: function() {
// All focusable elements
var focusableElements = 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';

var firstFocusableElement = this.$elm[0].querySelectorAll(focusableElements)[0]; // get first element to be focused inside modal
var focusableContent = this.$elm[0].querySelectorAll(focusableElements);
var lastFocusableElement = focusableContent[focusableContent.length - 1]; // get last element to be focused inside modal


$(this.$elm).on('keydown', function(e) {
var isTabPressed = e.key === 'Tab' || e.keyCode === 9;

if (!isTabPressed) {
return;
}

if (e.shiftKey) { // if shift key pressed for shift + tab combination
if (document.activeElement === firstFocusableElement) {
lastFocusableElement.focus(); // add focus for the last focusable element
e.preventDefault();
}
} else { // if tab key is pressed
if (document.activeElement === lastFocusableElement) { // if focused has reached to last focusable element then focus first focusable element after pressing tab
firstFocusableElement.focus(); // add focus for the first focusable element
e.preventDefault();
}
}
});

firstFocusableElement.focus();
},

releaseFocus: function() {
$(this.$elm).off('keydown');

// Restore previous focus
this.previousFocus.focus();
},

//Return context for custom events
_ctx: function() {
return { elm: this.$elm, $elm: this.$elm, $blocker: this.$blocker, options: this.options, $anchor: this.anchor };
2 changes: 1 addition & 1 deletion jquery.modal.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading