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

dialog-promise

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dialog-promise - npm Package Compare versions

Comparing version 0.0.2 to 0.1.0

53

lib/dialog-promise.js

@@ -20,2 +20,3 @@ "use strict";

var closeWindow = function closeWindow(senderAnswerFunction, answer){
window.removeEventListener('keydown', interceptKey);
dialogWindow.style.display = 'none';

@@ -34,17 +35,51 @@ body.removeChild(modalBackground);

});
var interceptKey = function interceptKey(event){
if(event.target!==dialogWindow && !dialogWindow.contains(event.target)){
event.preventDefault();
}
}
window.addEventListener('keydown', interceptKey);
});
}
function alertPromise(message){
function simpleFormPromise(elementsList){
return dialogPromise(function(mainElement, done){
var button=document.createElement('button');
button.textContent='Ok';
button.addEventListener('click', function(){
done(true);
elementsList.forEach(function(elementDefinition){
if(typeof elementDefinition=='string'){
var div=document.createElement('div');
div.innerText=elementDefinition;
mainElement.appendChild(div);
}else if(elementDefinition instanceof HTMLElement){
mainElement.appendChild(elementDefinition);
}else{
var button=document.createElement('button');
button.textContent=elementDefinition.label;
button.addEventListener('click', function(){
done(elementDefinition.value);
});
mainElement.appendChild(button);
}
});
var div=document.createElement('div');
div.innerText=message;
mainElement.appendChild(div);
mainElement.appendChild(button);
});
}
function promptPromise(message){
var input = document.createElement('input');
var okObject = {label:'Ok'};
Object.defineProperty(okObject, 'value', { get: function(){ return input.value; }});
return simpleFormPromise([
message,
input,
document.createElement('br'),
okObject,
{label:'Cancel', value:false}
]);
}
function confirmPromise(message){
return simpleFormPromise([message, {label:'Ok', value:true}, {label:'Cancel', value:false}]);
}
function alertPromise(message){
return simpleFormPromise([message, {label:'Ok', value:true}]);
}

2

package.json
{
"name": "dialog-promise",
"description": "Dialog that returns promises",
"version": "0.0.2",
"version": "0.1.0",
"author": "Codenautas <codenautas@googlegroups.com>",

@@ -6,0 +6,0 @@ "repository": "codenautas/dialog-promise",

# dialog-promise
Dialog that returns promises
![designing](https://img.shields.io/badge/stability-designing-red.svg)
![extending](https://img.shields.io/badge/stability-extending-orange.svg)
[![npm-version](https://img.shields.io/npm/v/dialog-promise.svg)](https://npmjs.org/package/dialog-promise)

@@ -6,0 +6,0 @@ [![downloads](https://img.shields.io/npm/dm/dialog-promise.svg)](https://npmjs.org/package/dialog-promise)

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