jquery-popup-overlay
Advanced tools
Comparing version 2.0.1 to 2.0.3
// Cypress end-to-end tests | ||
// Debugging tips: | ||
// - If some test fails, you can add (); before and after the assertion. | ||
// - cy.pause() can be placed before and after the assertion. | ||
// - cy.debug() can be useful... cy.get('.ls-btn').click({ force: true }).debug() | ||
// - Also, you can click on Before/After state in Cypress UI. | ||
// - If you want to use a console in Cypress UI dev tools, first click on Inspect Element to get the correct `window` scope. | ||
// TODO: | ||
@@ -17,2 +19,28 @@ // - add tests for rightedge and leftedge, for tooltips | ||
//----------------------------------------------------------------------------- | ||
// Prepare random options | ||
const randomOptions = {}; | ||
const allOptions = { | ||
color: ['blue', 'red'], | ||
opacity: [0, 0.5, 1], | ||
background: [true, false] | ||
} | ||
// Get random value from array | ||
const rand = function (arr) { | ||
return arr[Math.floor(Math.random() * arr.length)]; | ||
} | ||
// Randomize options | ||
Object.keys(allOptions).forEach(function(key) { | ||
const randomValue = rand(allOptions[key]); | ||
randomOptions[key] = randomValue; // extend randomOptions object | ||
}); | ||
//----------------------------------------------------------------------------- | ||
// Tests | ||
describe("jQuery Popup Overlay", () => { | ||
@@ -23,7 +51,15 @@ context("Options", () => { | ||
// jquery ':focus' selector fails when window is not in focus, replace it with our own version. | ||
// Although, this still doesn't solve an issue when testing :focus styles and such tests will fail. | ||
// If that happens, re-run the tests with window in focus, or without Cypress UI (i.e. headless). | ||
// https://github.com/cypress-io/cypress/issues/2176 | ||
cy.window().then(win => { | ||
// Extend plugin's defaults with randomOptions | ||
// UNCOMMENT THIS LINE FOR TESTS WITH RANDOM PLUGIN OPTIONS: | ||
// Object.assign(win.$.fn.popup.defaults, randomOptions); | ||
// Log plugin defaults to console (for debugging) | ||
cy.log('**Defaults:**', JSON.stringify(win.$.fn.popup.defaults)); | ||
win.console.log('**Defaults:**', JSON.stringify(win.$.fn.popup.defaults)); | ||
// jquery ':focus' selector fails when window is not in focus, replace it with our own version. | ||
// Although, this still doesn't solve an issue when testing :focus styles and such tests will fail. | ||
// If that happens, re-run the tests with window in focus, or without Cypress UI (i.e. headless). | ||
// https://github.com/cypress-io/cypress/issues/2176 | ||
win.jQuery.find.selectors.filters.focus = function(elem) { | ||
@@ -30,0 +66,0 @@ const doc = elem.ownerDocument; |
@@ -5,3 +5,3 @@ /*! | ||
* @requires jQuery v1.7.1+ | ||
* @link http://vast-engineering.github.com/jquery-popup-overlay/ | ||
* @link https://vast-engineering.github.com/jquery-popup-overlay/ | ||
*/ | ||
@@ -290,3 +290,3 @@ ;(function ($) { /* eslint-disable-line */ | ||
if (options.background) { | ||
if (zindexvalues[el.id] > 0) { | ||
if (zindexvalues[el.id] >= 0) { | ||
$('#' + el.id + '_background').css({ | ||
@@ -299,3 +299,3 @@ zIndex: (zindexvalues[el.id] + 1) | ||
// Add z-index to the wrapper | ||
if (zindexvalues[el.id] > 0) { | ||
if (zindexvalues[el.id] >= 0) { | ||
$wrapper.css({ | ||
@@ -372,25 +372,23 @@ zIndex: (zindexvalues[el.id] + 2) | ||
// Handler: Keep focus inside dialog box | ||
if (options.keepfocus) { | ||
// Make holder div focusable | ||
$el.attr('tabindex', -1); | ||
// Make holder div programatically focusable with tabindex:-1 (tabindex:0 is keyboard focusable) | ||
$el.attr('tabindex', -1); | ||
// Focus popup or user specified element. | ||
// Initial timeout of 50ms is set to give some time to popup to show after clicking on | ||
// `open` element, and after animation is complete to prevent background scrolling. | ||
setTimeout(function() { | ||
if (options.focuselement === 'closebutton') { | ||
$('#' + el.id + ' .' + el.id + closesuffix + ':first').focus(); | ||
} else if (options.focuselement) { | ||
$(options.focuselement).focus(); | ||
} else { | ||
$el.focus(); | ||
} | ||
}, options.focusdelay); | ||
// Focus the popup or user specified element. | ||
// Initial timeout of 50ms is set to give some time to popup to show after clicking on | ||
// `open` element, and after animation is complete to prevent background scrolling. | ||
setTimeout(function() { | ||
if (options.focuselement === 'closebutton') { // e.g. focuselement:'closebutton' | ||
$('#' + el.id + ' .' + el.id + closesuffix + ':first').focus(); | ||
} else if (options.focuselement) { // e.g. focuselement:'#my-close-button' | ||
$(options.focuselement).focus(); | ||
} else if (options.focuselement === true || options.keepfocus) { // e.g. focuselement:true OR keepfocus:true | ||
$el.focus(); | ||
} | ||
}, options.focusdelay); | ||
// Hide main content from screen readers | ||
if (options.keepfocus) { | ||
$(options.pagecontainer).attr('aria-hidden', true); | ||
} | ||
// Hide main content from screen readers | ||
$(options.pagecontainer).attr('aria-hidden', true); | ||
// Reveal popup content to screen readers | ||
@@ -752,7 +750,12 @@ $el.attr('aria-hidden', false); | ||
if(visiblePopupsArray.length && event.which == 9) { | ||
// If tab or shift-tab pressed | ||
var elementId = visiblePopupsArray[visiblePopupsArray.length - 1]; | ||
var el = document.getElementById(elementId); | ||
var options = $(el).data('popupoptions'); | ||
// If the last opened popup doesn't have `keepfocus` option, ignore the rest and don't lock the focus inside of popup. | ||
if (!options.keepfocus) { | ||
return; | ||
} | ||
// Get list of all children elements in given object | ||
@@ -759,0 +762,0 @@ var popupItems = $(el).find('*'); |
{ | ||
"name": "jquery-popup-overlay", | ||
"version": "2.0.1", | ||
"version": "2.0.3", | ||
"description": "Lightweight modal popup overlay for jquery", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -13,6 +13,6 @@ # jQuery Popup Overlay | ||
## Documentation & demo | ||
[Documentation & demo](http://vast-engineering.github.io/jquery-popup-overlay/) | ||
[Documentation & demo](https://vast-engineering.github.io/jquery-popup-overlay/) | ||
## License | ||
Released under the [MIT license](http://www.opensource.org/licenses/MIT). | ||
Released under the [MIT license](https://github.com/vast-engineering/jquery-popup-overlay/blob/gh-pages/LICENSE). | ||
@@ -19,0 +19,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
124730
16
1424