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

dialog-promise

Package Overview
Dependencies
Maintainers
2
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.8.9 to 0.9.0

133

lib/dialog-promise.js

@@ -44,3 +44,4 @@ "use strict";

centerDialogEdge('top','offsetHeight','innerHeight');
innerDivDialog.style.height = dialogWindow.offsetHeight-innerDivDialog.offsetTop-2+'px';
// innerDivDialog.style.height = dialogWindow.offsetHeight-innerDivDialog.offsetTop-4+'px';
dialogWindow.style.height = innerDivDialog.offsetHeigth+innerDivDialog.offsetTop+4+'px';
}

@@ -88,2 +89,16 @@

function getRectClient(element){
var rect = {top:0, left:0, width:element.clientWidth, height:element.clientHeight};
while( element != null ) {
rect.top += element.clientTop;
rect.left += element.clientLeft;
element = element.clientParent;
}
rect.bottom=rect.top+rect.height;
rect.rigth=rect.left+rect.width;
return rect;
}
var dialogPromiseIdGenerator=1;
function dialogPromise(dialogConstructor, opts){

@@ -118,2 +133,6 @@ opts = opts||{};

body.removeChild(modalBackground);
delete window.openDialogPromises[dialogWindow.id];
window.openDialogPromises.lastWindows=window.openDialogPromises.lastWindows.filter(function(id){
return id != dialogWindow.id;
});
body.removeChild(dialogWindow);

@@ -144,3 +163,14 @@ if(answer && answer instanceof Error){

body.appendChild(modalBackground);
dialogWindow.id='dialog-promise-'+dialogPromiseIdGenerator;
body.appendChild(dialogWindow);
if(innerDivDialog.firstFocus){
setTimeout(function(){
innerDivDialog.firstFocus.focus();
},20)
}
window.openDialogPromises=window.openDialogPromises||{
lastWindows:[]
};
window.openDialogPromises[dialogWindow.id];
window.openDialogPromises.lastWindows.unshift(dialogWindow.id);
dialogWindow.style.visibility='hidden';

@@ -192,4 +222,56 @@ dialogWindow.style.display='block';

}else if(code>=112 && code<=123){
}else if(event.target!==dialogWindow && !dialogWindow.contains(event.target)){
event.preventDefault();
}else{
var topDialog=document.getElementById(window.openDialogPromises.lastWindows[0]);
if(topDialog){
var tableMenu=topDialog.querySelector('.dialog-menu')
}
var readyToMove=tableMenu && !event.shiftKey && !event.ctrlKey && !event.altKey && !event.metaKey;
var selectTheRow = function selectTheRow(row){
row.setAttribute('key-selected','1')
var container=row;
var contained=row;
var acumTop=container.offsetTop;
while(container=container.parentElement){
if(acumTop>container.clientHeight+container.scrollTop){
contained.scrollTop=acumTop-container.clientHeight
}
acumTop+=container.offsetTop;
contained=container;
}
}
var moveTry = function moveTry(keycode, mover){
if(code==keycode && readyToMove){
var selecteds = topDialog.querySelectorAll('[key-selected="1"]');
var selectedRow=null;
Array.prototype.forEach.call(selecteds, function(row){
row.removeAttribute('key-selected')
selectedRow=row;
});
if(selectedRow){
var nextSelected=selectedRow
while((nextSelected = nextSelected[mover]) && nextSelected.clientWidth==0){
}
selectTheRow(nextSelected||selectedRow);
}else{
selectTheRow(tableMenu.rows[0]);
}
event.preventDefault();
return true;
}
}
if(moveTry(40,'nextElementSibling') || moveTry(38,'previousElementSibling') ){
// ok move
}else if(readyToMove && code==13){
var selectedRow=topDialog.querySelector('[key-selected="1"]');
if(selectedRow){
selectedRow.dialogPromiseRowDone();
event.preventDefault();
}
}else if(event.target!==dialogWindow && !dialogWindow.contains(event.target)){
if(code==9){
dialogWindow.focus();
}else{
event.preventDefault();
}
}
}

@@ -233,7 +315,23 @@ };

var elementsList=opts.elementsList;
var hotkeys={};
return dialogPromise(function(mainElement, done){
elementsList.forEach(function(elementDefinition){
elementsList.forEach(function(elementDefinition, i){
if(typeof elementDefinition=='string'){
var div=document.createElement('div');
div.innerText=elementDefinition;
if(!i){
var button=document.createElement('button')
button.className='dialog-promise-div-button';
button.innerText=elementDefinition;
div.appendChild(button);
mainElement.firstFocus=button;
button.addEventListener('keypress',function(event){
var code = event.keycode||event.which;
var letra=String.fromCharCode(code).toUpperCase();
if(hotkeys[letra]){
hotkeys[letra].click();
}
})
}else{
div.innerText=elementDefinition;
}
mainElement.appendChild(div);

@@ -243,2 +341,6 @@ }else if(elementDefinition instanceof HTMLElement){

mainElement.appendChild(elementDefinition);
if(elementDefinition.firstFocus){
mainElement.firstFocus=elementDefinition;
}
button=elementDefinition;
}else{

@@ -252,2 +354,10 @@ var button=document.createElement('button');

}
if(elementDefinition.hotkey){
hotkeys[elementDefinition.hotkey]=button;
}else{
var letra=button.textContent.substr(0,1).toUpperCase();
if(!(letra in hotkeys)){
hotkeys[letra]=button;
}
}
});

@@ -345,3 +455,3 @@ }, excluding(opts, {elementsList:true}));

var firstKey=true;
input.onkeydown=function(event){
input.addEventListener('keydown',function(event){
if(firstKey && !input.value){

@@ -352,3 +462,3 @@ firstKey=false;

}
};
});
buttonsDef.forEach(function(buttonDef){

@@ -370,4 +480,5 @@ if(buttonDef.value===true){

}
input.focus();
// input.focus();
},24);
input.firstFocus=true;
receiveOpt(opts, 'elementsList', [

@@ -390,2 +501,3 @@ message,

img.src=DialogPromise.path.img+'filter-dialog.png';
img.alt='🔍';
img.style.height='16px';

@@ -415,3 +527,3 @@ div.appendChild(img);

};
span.onkeydown=function(event){
span.addEventListener('keydown', function(event){
var code=event.keyCode || event.which;

@@ -427,3 +539,3 @@ if(code==13 || code==9){

cambiarTimeout=setTimeout(cambiar,200);
};
});
}

@@ -509,2 +621,3 @@ var table=document.createElement('table');

});
row.dialogPromiseRowDone=doDone;
};

6

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

@@ -14,5 +14,5 @@ "repository": "codenautas/dialog-promise",

"devDependencies": {
"@types/mocha": "~5.2.0",
"@types/mocha": "~5.2.1",
"@types/puppeteer": "~1.3.2",
"mocha": "~5.1.1",
"mocha": "~5.2.0",
"puppeteer": "~1.4.0",

@@ -19,0 +19,0 @@ "best-globals": "~0.10.4",

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