@springernature/global-popup
Advanced tools
Comparing version 4.2.0 to 4.3.0
@@ -24,2 +24,24 @@ import {Popup} from '../js/popup'; | ||
it('should open the popup when the trigger is clicked', () => { | ||
const popup = new Popup(trigger, 'popupContent1'); | ||
const spy = jest.spyOn(popup._expander, 'open'); | ||
expect(spy).not.toHaveBeenCalled(); | ||
trigger.click(); | ||
expect(spy).toHaveBeenCalled(); | ||
}); | ||
it('should open the popup when the open method id called', () => { | ||
const popup = new Popup(trigger, 'popupContent1'); | ||
const spy = jest.spyOn(popup._expander, 'open'); | ||
expect(spy).not.toHaveBeenCalled(); | ||
popup.open(); | ||
expect(spy).toHaveBeenCalled(); | ||
}); | ||
it('should build a popup that includes the arrow and close button html', () => { | ||
@@ -26,0 +48,0 @@ new Popup(trigger, 'popupContent1'); |
# History | ||
## 4.3.0 (2021-03-03) | ||
* Adds an open method to allow lazily creating a popup when the trigger is clicked | ||
## 4.2.0 (2021-02-17) | ||
@@ -4,0 +7,0 @@ * Fixes bug so that popup/arrow is positioned above trigger |
@@ -24,2 +24,6 @@ import {Expander} from '@springernature/global-expander/js/expander'; | ||
open() { | ||
this._expander.open(); | ||
} | ||
_build() { | ||
@@ -26,0 +30,0 @@ this._content.insertAdjacentHTML('beforeend', this._closeButton + this._arrow); |
{ | ||
"name": "@springernature/global-popup", | ||
"version": "4.2.0", | ||
"version": "4.3.0", | ||
"description": "Builds and styles a popup that can be opened and closed", | ||
@@ -12,4 +12,4 @@ "license": "MIT", | ||
"scripts": { | ||
"postinstall": "npm_config_registry=https://registry.npmjs.org/ npx @springernature/util-context-warning@0.0.5 -p @springernature/global-popup@4.2.0 -v 9.0.1 9.0.2 9.0.3 9.0.4 9.0.5 9.0.6 9.1.0 9.1.1" | ||
"postinstall": "npm_config_registry=https://registry.npmjs.org/ npx @springernature/util-context-warning@0.0.5 -p @springernature/global-popup@4.3.0 -v 9.0.1 9.0.2 9.0.3 9.0.4 9.0.5 9.0.6 9.1.0 9.1.1" | ||
} | ||
} |
@@ -59,1 +59,25 @@ # Global Popup | ||
``` | ||
### Lazily | ||
If you wish to lazily create a popup the first time the trigger is clicked - for example if building the html for your popup is an expensive operation that you'd like to defer until needed - you can use this pattern: | ||
```javascript | ||
import {Popup} from 'global-popup/js/popup'; | ||
const trigger = document.querySelector('span'); | ||
trigger.addEventListener('click', function() { | ||
const popup = new Popup(trigger, 'popupContent1'); | ||
popup.open(); | ||
}, {capture: false, once: true}); | ||
``` | ||
```html | ||
<div> | ||
<span>Popup trigger</span> | ||
<div id="popupContent1"> | ||
<p>Some popup text</p> | ||
</div> | ||
</div> | ||
``` |
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
21208
380
83