New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

focus-within-polyfill

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

focus-within-polyfill - npm Package Compare versions

Comparing version 1.3.4 to 1.4.0

dist/focus-within-polyfill.js

12

package.json
{
"name": "focus-within-polyfill",
"version": "1.3.4",
"version": "1.4.0",
"description": "focus-within pseudo selector polyfill",
"main": "dist/focus-within.js",
"main": "dist/focus-within-polyfill.js",
"module": "dist/focus-within-polyfill.mjs",
"jsnext:main": "dist/focus-within-polyfill.mjs",
"scripts": {
"build": "npm run build:dev && npm run build:prod",
"build:dev": "rollup -c rollup.config.js --environment BUILD:development",
"build:prod": "rollup -c rollup.config.js --environment BUILD:production",
"build": "rollup -c rollup.config.js --environment BUILD:production",
"watch": "rollup -c rollup.config.js --environment BUILD:development -w",
"prepublish": "npm run build",
"preversion": "npm test",
"version": "npm run build",
"postversion": "git push && git push --tags",
"prepublish": "npm run build",
"test": "echo \"Error: no test specified\" && exit 0"

@@ -16,0 +16,0 @@ },

@@ -1,42 +0,49 @@

��# `:focus-within` Pseudo-Class Polyfill
[![npm version](https://badge.fury.io/js/focus-within-polyfill.svg)](https://badge.fury.io/js/focus-within-polyfill) [![Build Status](https://travis-ci.org/matteobad/focus-within-polyfill.svg?branch=master)](https://travis-ci.org/matteobad/focus-within-polyfill/)
* [How to use](#hot-to-use)
* [Browser support](#browser-support)
* [:focus-within MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/:focus-within)
The `:focus-within` CSS pseudo-class represents an element that has received focus or contains an element that has received focus. In other words, it represents an element that is itself matched by the :focus pseudo-class or has a descendant that is matched by :focus.
More information on [MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/:focus-within).
## How to use
This package is available both as production ready script and as a package. The script can be downloaded [here](https://unpkg.com/focus-within-polyfill/dist/focus-within.min.js), or installed with a package manager.
```sh
# npm
npm install focus-within-polyfill --save
# yarn
yarn add focus-within-polyfill
```
When the polyfill is included via a script tag it will run immediately after load. On the other hand when imported as a dependency, a call to `polyfill` method is required.
```javascript
import focuswithin from 'focus-within-polyfill'
// kick off!
focuswithin.polyfill()
```
## Browser Support
* _Natively supported in Chrome_
* _Natively supported in Firefox_
* _Natively supported in Safari_
* _Natively supported in Opera_
* IE 11
* Edge
# `:focus-within` Pseudo-Class Polyfill
[![npm version](https://badge.fury.io/js/focus-within-polyfill.svg)](https://badge.fury.io/js/focus-within-polyfill) [![Build Status](https://travis-ci.org/matteobad/focus-within-polyfill.svg?branch=master)](https://travis-ci.org/matteobad/focus-within-polyfill/)
* [How to use](#hot-to-use)
* [Browser support](#browser-support)
* [:focus-within MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/:focus-within)
The `:focus-within` CSS pseudo-class represents an element that has received focus or contains an element that has received focus. In other words, it represents an element that is itself matched by the :focus pseudo-class or has a descendant that is matched by :focus.
More information on [MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/:focus-within).
## How to use
This package is available both as production ready script and as a package. The script can be downloaded [here](https://unpkg.com/focus-within-polyfill/dist/focus-within.min.js), or installed with a package manager.
```sh
# npm
npm install focus-within-polyfill --save
# yarn
yarn add focus-within-polyfill
```
When the polyfill is included via a script tag it will create a `focusWithin` object with a `loadPolyfill` and a `unloadPolyfill` method to initialize the code. On the other hand when imported as a dependency the same methods are exposed.
```javascript
/* ES6 */
import { polyfill, unloadPolyfill } from 'focus-within-polyfill'
polyfill() // load polyfill
unloadPolyfill() // unload polyfill
/* ES5 */
<script src='path/to/focus-within-polyfill.js'></script>
focusWithin.polyfill() // load polyfill
focusWithin.unloadPolyfill() // unload polyfill
```
## Browser Support
* _Natively supported in Chrome_
* _Natively supported in Firefox_
* _Natively supported in Safari_
* _Natively supported in Opera_
* IE 11
* Edge

@@ -1,56 +0,49 @@

'use strict'
import { supportsPseudo } from './supports-pseudo'
function polyfill() {
// Initilize polyfill
if (!supportsPseudo()) {
document.addEventListener('focus', update, true)
document.addEventListener('blur', update, true)
}
/**
* Update focus-within class on focus and blur events
* @param {FocusEvent} e
*/
function update(e) {
var el, element, running
/**
* Check for :focus-within pseudo class support
* @returns {Boolean}
*/
function supportsPseudo() {
try {
document.querySelector(':focus-within')
console.info(':focus-within supported')
return true
} catch (error) {
console.info(':focus-within not supported')
return false
}
}
var action = function() {
element = document.activeElement
running = false
/**
* Update focus-within class on focus and blur events
* @param {FocusEvent} e
*/
function update(e) {
var el, element, running
Array.prototype.slice
.call(document.getElementsByClassName('focus-within'))
.forEach(el => el.classList.remove('focus-within'))
var action = function() {
element = document.activeElement
running = false
if (e.type === 'focus' && element && element !== document.body)
for (el = element; el && el.nodeType === 1; el = el.parentNode)
el.classList.add('focus-within')
}
Array.prototype.slice
.call(document.getElementsByClassName('focus-within'))
.forEach(el => el.classList.remove('focus-within'))
if (!running) {
window.requestAnimationFrame(action)
running = true
}
}
if (e.type === 'focus' && element && element !== document.body)
for (el = element; el && el.nodeType === 1; el = el.parentNode)
el.classList.add('focus-within')
}
if (!running) {
window.requestAnimationFrame(action)
running = true
}
/**
* Load polyfill
*/
export function loadPolyfill() {
if (!supportsPseudo()) {
document.addEventListener('focus', update, true)
document.addEventListener('blur', update, true)
console.info(':focus-within polyfill loaded.')
}
}
if (typeof exports === 'object' && typeof module !== 'undefined') {
module.exports = { polyfill: polyfill }
} else {
polyfill()
/**
* Unload polyfill
*/
export function unloadPolyfill() {
if (!supportsPseudo()) {
document.removeEventListener('focus', update, true)
document.removeEventListener('blur', update, true)
console.info(':focus-within polyfill removed.')
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc