dialog-promise
Advanced tools
Comparing version 0.0.2 to 0.1.0
@@ -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}]); | ||
} |
{ | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8160
121