Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

makeup-exit-emitter

Package Overview
Dependencies
Maintainers
5
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

makeup-exit-emitter - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

128

index.js
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
var nextID = require('makeup-next-id');
var focusExitEmitters = {};
// requires CustomEvent polyfill for IE9+
var focusExitEmitters = {}; // requires CustomEvent polyfill for IE9+
// https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent
function doFocusExit(el, fromElement, toElement) {
el.dispatchEvent(new CustomEvent('focusExit', {
detail: { fromElement: fromElement, toElement: toElement },
bubbles: false // mirror the native mouseleave event
}));
el.dispatchEvent(new CustomEvent('focusExit', {
detail: {
fromElement: fromElement,
toElement: toElement
},
bubbles: false // mirror the native mouseleave event
}));
}
function onDocumentFocusIn(e) {
var newFocusElement = e.target;
var targetIsDescendant = this.el.contains(newFocusElement);
var newFocusElement = e.target;
var targetIsDescendant = this.el.contains(newFocusElement); // if focus has moved to a focusable descendant
// if focus has moved to a focusable descendant
if (targetIsDescendant === true) {
// set the target as the currently focussed element
this.currentFocusElement = newFocusElement;
} else {
// else focus has not gone to a focusable descendant
window.removeEventListener('blur', this.onWindowBlurListener);
document.removeEventListener('focusin', this.onDocumentFocusInListener);
doFocusExit(this.el, this.currentFocusElement, newFocusElement);
this.currentFocusElement = null;
}
if (targetIsDescendant === true) {
// set the target as the currently focussed element
this.currentFocusElement = newFocusElement;
} else {
// else focus has not gone to a focusable descendant
window.removeEventListener('blur', this.onWindowBlurListener);
document.removeEventListener('focusin', this.onDocumentFocusInListener);
doFocusExit(this.el, this.currentFocusElement, newFocusElement);
this.currentFocusElement = null;
}
}
function onWindowBlur() {
doFocusExit(this.el, this.currentFocusElement, undefined);
doFocusExit(this.el, this.currentFocusElement, undefined);
}
function onWidgetFocusIn() {
// listen for focus moving to anywhere in document
// note that mouse click on buttons, checkboxes and radios does not trigger focus events in all browsers!
document.addEventListener('focusin', this.onDocumentFocusInListener);
// listen for focus leaving the window
window.addEventListener('blur', this.onWindowBlurListener);
// listen for focus moving to anywhere in document
// note that mouse click on buttons, checkboxes and radios does not trigger focus events in all browsers!
document.addEventListener('focusin', this.onDocumentFocusInListener); // listen for focus leaving the window
window.addEventListener('blur', this.onWindowBlurListener);
}
var FocusExitEmitter = function () {
function FocusExitEmitter(el) {
_classCallCheck(this, FocusExitEmitter);
var FocusExitEmitter =
/*#__PURE__*/
function () {
function FocusExitEmitter(el) {
_classCallCheck(this, FocusExitEmitter);
this.el = el;
this.el = el;
this.currentFocusElement = null;
this.onWidgetFocusInListener = onWidgetFocusIn.bind(this);
this.onDocumentFocusInListener = onDocumentFocusIn.bind(this);
this.onWindowBlurListener = onWindowBlur.bind(this);
this.el.addEventListener('focusin', this.onWidgetFocusInListener);
}
this.currentFocusElement = null;
this.onWidgetFocusInListener = onWidgetFocusIn.bind(this);
this.onDocumentFocusInListener = onDocumentFocusIn.bind(this);
this.onWindowBlurListener = onWindowBlur.bind(this);
this.el.addEventListener('focusin', this.onWidgetFocusInListener);
_createClass(FocusExitEmitter, [{
key: "removeEventListeners",
value: function removeEventListeners() {
window.removeEventListener('blur', this.onWindowBlurListener);
document.removeEventListener('focusin', this.onDocumentFocusInListener);
this.el.removeEventListener('focusin', this.onWidgetFocusInListener);
}
}]);
_createClass(FocusExitEmitter, [{
key: 'removeEventListeners',
value: function removeEventListeners() {
window.removeEventListener('blur', this.onWindowBlurListener);
document.removeEventListener('focusin', this.onDocumentFocusInListener);
this.el.removeEventListener('focusin', this.onWidgetFocusInListener);
}
}]);
return FocusExitEmitter;
return FocusExitEmitter;
}();
function addFocusExit(el) {
var exitEmitter = null;
var exitEmitter = null;
nextID(el);
nextID(el);
if (!focusExitEmitters[el.id]) {
exitEmitter = new FocusExitEmitter(el);
focusExitEmitters[el.id] = exitEmitter;
}
if (!focusExitEmitters[el.id]) {
exitEmitter = new FocusExitEmitter(el);
focusExitEmitters[el.id] = exitEmitter;
}
return exitEmitter;
return exitEmitter;
}
function removeFocusExit(el) {
var exitEmitter = focusExitEmitters[el.id];
var exitEmitter = focusExitEmitters[el.id];
if (exitEmitter) {
exitEmitter.removeEventListeners();
delete focusExitEmitters[el.id];
}
if (exitEmitter) {
exitEmitter.removeEventListeners();
delete focusExitEmitters[el.id];
}
}
module.exports = {
addFocusExit: addFocusExit,
removeFocusExit: removeFocusExit
addFocusExit: addFocusExit,
removeFocusExit: removeFocusExit
};
{
"name": "makeup-exit-emitter",
"description": "Emits custom 'focusExit' event when keyboard focus has exited an element and all of it's descendants",
"version": "0.1.0",
"version": "0.1.1",
"main": "index.js",

@@ -11,14 +11,16 @@ "repository": "https://github.com/makeup-js/makeup-exit-emitter.git",

"start": "npm run build && parallelshell \"npm run server\" \"npm run watch\"",
"test": "npm run transpile && npm run lasso:test && npm run clean && karma start --autoWatch false --singleRun true",
"prepublishOnly": "npm run clean && npm run lint && npm run build && npm run test",
"build": "npm run transpile && npm run lasso",
"test": "npm run build:module && npm run lasso:tests && karma start --autoWatch false --singleRun true",
"prepublishOnly": "npm run lint && npm run test && npm run clean:tests && npm run build:docs",
"prep": "npm run prepublishOnly",
"build": "npm run build:module && npm run build:docs",
"build:module": "babel src/index.js --out-file index.js",
"build:docs": "babel docs/src/index.js --out-file docs/index.js && npm run lasso:docs && npm run clean:docs",
"fix": "eslint src/index.js --fix",
"lint": "eslint src/index.js > lint.txt",
"lasso": "lasso require-run:./docs/index.js --out docs/static --inject-into docs/index.html --name bundle && npm run clean:lasso",
"lasso:test": "lasso require-run:./test/index.js --name bundle-test --out test/static --config ./test/lasso-config.json && npm run clean:lasso",
"clean": "rimraf reports .DS_Store test/.DS_Store src/.DS_Store docs/.DS_Store && npm run clean:lasso",
"clean:lasso": "rimraf .cache build",
"lint": "eslint src/index.js > lint.txt && eslint docs/src/index.js > lint.txt",
"lasso:docs": "lasso require-run:nodelist-foreach-polyfill require-run:./docs/index.js --out docs/static --inject-into docs/index.html --name bundle",
"lasso:tests": "npm run clean:tests && lasso require-run:./test/index.js --name bundle-test --out test/static --config ./test/lasso-config.json",
"clean:docs": "rimraf .cache build docs/index.js",
"clean:tests": "rimraf lint.txt reports",
"server": "browser-sync start -s --ss docs --index docs/index.html --files docs/index.html",
"watch": "onchange src/*.js docs/index.js -- npm run build",
"transpile": "babel src/index.js --out-file index.js",
"watch": "onchange src/*.js docs/src/index.js -- npm run build",
"version": "npm run prepublishOnly && git add -A docs/static test/static"

@@ -33,17 +35,22 @@ },

"devDependencies": {
"babel-cli": "^6",
"babel-preset-env": "^1",
"@babel/cli": "^7",
"@babel/core": "^7",
"@babel/preset-env": "^7",
"babel-plugin-transform-object-assign": "^6",
"browser-sync": "^2",
"core-js-pure": "^3",
"coveralls": "^3",
"eslint": "^4",
"eslint-config-ebay": "~0.1",
"jasmine-core": "^2",
"karma": "^1",
"eslint": "^5",
"eslint-config-ebay": "^1",
"jasmine-core": "^3",
"karma": "^4",
"karma-chrome-launcher": "^2",
"karma-coverage": "^1",
"karma-html-reporter": "~0.2",
"karma-jasmine": "^1",
"karma-phantomjs-launcher": "^1",
"karma-jasmine": "^2",
"lasso-cli": "^2",
"onchange": "^3",
"nodelist-foreach-polyfill": "^1",
"onchange": "^5",
"parallelshell": "^3",
"puppeteer": "^1",
"rimraf": "^2"

@@ -53,3 +60,3 @@ },

"custom-event-polyfill": "^1",
"makeup-next-id": "~0.0.2"
"makeup-next-id": "~0.0.3"
},

@@ -56,0 +63,0 @@ "files": [

@@ -56,5 +56,9 @@ # makeup-exit-emitter

* custom-event-polyfill
* makeup-next-id
* [makeup-next-id](https://github.com/makeup-js/makeup-next-id)
## Polyfills
* [custom-event-polyfill](https://github.com/krambuhl/custom-event-polyfill) (for IE11)
* [nodelist-foreach-polyfill](https://github.com/imagitama/nodelist-foreach-polyfill) (docs page only)
## Development

@@ -69,7 +73,2 @@

The following hooks exist, and do not need to be invoked manually:
* `npm prepublish` cleans, lints, tests and builds on every `npm publish` command
* `pre-commit` cleans, lints, tests and builds on every `git commit` command
## Test Reports

@@ -76,0 +75,0 @@

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