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

popup-tools

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

popup-tools - npm Package Compare versions

Comparing version 0.1.5 to 1.0.0

79

lib/PopupTools.js

@@ -16,2 +16,8 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.popupTools = f()}})(function(){var define,module,exports;

/**
* Return options converted to a string
*
* @param {Object} options
* @return {String}
*/
function optionsToString(options) {

@@ -26,2 +32,6 @@ return Object

/**
* Get a unique name on each call
* @return {String}
*/
function defaultPopupName() {

@@ -32,2 +42,9 @@ popupCount += 1;

/**
* Convert "centered: true" key into concrete left and top arguments
* Both can be overwritten
*
* @param {Object} options
* @return {Object}
*/
function optionsResolveCentered(options) {

@@ -46,2 +63,9 @@ var result = options;

/**
* Polyfill Object.assign
*
* @param {Object} target
* @param {Object} source1 ...
* @return {Object}
*/
function assign(target) {

@@ -63,2 +87,12 @@ var sources = Array.prototype.slice.call(arguments, 1);

/**
* Create a form element, add hidden inputs for all the post data
* and post it into a newly opened popup
*
* @param {String} url
* @param {Object} postData
* @param {String} name
* @param {Object} options
* @return {Object}
*/
function openPopupWithPost(url, postData, name, options) {

@@ -93,2 +127,13 @@ var form = document.createElement('form');

/**
* Open a popup using the first argument. Wait for it to close.
* Returns the window object
*
* @param {Function}
* @param {String}
* @param {String}
* @param {Object}
* @param {Function}
* @return {Object}
*/
function popupExecute(execute, url, name, options, callback) {

@@ -127,4 +172,18 @@ var popupName = name || defaultPopupName();

}
return win;
}
/**
* Open a popup using the first argument.
* Wait for it to close and call the callback.
* Set the options string using the options object
* Returns the window object
*
* @param {String} url
* @param {String} name
* @param {Object} options
* @param {Function} callback
* @return {Object}
*/
function popup(url, name, options, callback) {

@@ -134,2 +193,16 @@ return popupExecute(window.open, url, name, options, callback);

/**
* Open a popup using the first argument.
* Post the data into the open popup.
* Wait for it to close and call the callback.
* Set the options string using the options object
* Returns the window object
*
* @param {String} url
* @param {Object} postData
* @param {String} name
* @param {Object} options
* @param {Function} callback
* @return {Object}
*/
function popupWithPost(url, postData, name, options, callback) {

@@ -143,2 +216,8 @@ function openWithPostData(popupUrl, popupName, optionsString) {

/**
* Return html that when executed, will trigger the popup to callback with a response
*
* @param {Object}
* @return {String}
*/
function popupResponse(data) {

@@ -145,0 +224,0 @@ var jsonData = JSON.stringify(data);

5

package.json
{
"name": "popup-tools",
"version": "0.1.5",
"description": "Popups with events, post and callbacks",
"version": "1.0.0",
"description": "Popups with callbacks, post and data response",
"main": "lib/PopupTools.js",

@@ -19,2 +19,3 @@ "repository": {

"express": "^4.14.0",
"uglify-js": "^2.7.4",
"umd": "^3.0.1",

@@ -21,0 +22,0 @@ "wdio-mocha-framework": "^0.4.3",

35

README.md

@@ -1,2 +0,5 @@

# express-braintree-webhooks
# Popup Tools
Several simple tools to handle popups with callbacks. Posting data to popups as well as receiving data from them.
[![Build Status](https://travis-ci.org/enhancv/popup-tools.svg?branch=master)](https://travis-ci.org/enhancv/popup-tools)

@@ -6,7 +9,18 @@ [![Codacy Badge](https://api.codacy.com/project/badge/Grade/55a5fbd27a854788942d5643daf090ff)](https://www.codacy.com/app/ivank/popup-tools)

Tools for handling popups
## Installation
Install the module with: `npm install popup-tools`, or download the [latast release](https://github.com/enhancv/popup-tools/releases/latest).
Its built with UMD so you can include it with any package manager as well as use it directly in the browser.
## Getting Started
Install the module with: `npm install popup-tools`
## Usage
There are 3 methods in this package
| Function | Description |
| -------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| `popup (url, title, options, callback)` | Open a simple popup, and call the callback method on close |
| `popupWithPost (url, post, title, callback)` | Open a popup and post the data into it. Again wait for callback |
| `popupResponse (data)` | Called on the server as a response to the popup, will trigger the callback to be called with that response |
You can open popup windows, and recieve a callback whenever the window was closed. Options are also passed as an object, and not as a string, as is generally required.
```javascript

@@ -24,5 +38,16 @@ var popupTools = require('popup-tools');

If you're including the file directly into your HTML without package managers, it will add `popupTools` to the global window object.
```html
<script src=".../PopupTools.min.js" ></script>
<script>
popupTools.popup('/popup-url.html', 'My Popup', { width: 400, height: 100 }, function (err) {
// this executes when closed
}));
</script>
```
## Data reponse
You can also send data back from the popup to the server
You can also send data back from the popup to the server, by calling the `popupResponse` method on the result for the popup page. This will trigger the closing of the popup, as well as sending the data in the callback function.

@@ -29,0 +54,0 @@ ```javascript

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