0.10.0 • Published 5 days ago

dialog-promise v0.10.0

Weekly downloads
4
License
MIT
Repository
github
Last release
5 days ago

dialog-promise

Dialog that returns promises

extending npm-version downloads

language: English also available in: Spanish

API

alertPromise, confirmPromise & promptPromise

Implements alert, confirm & prompt functions with Promises

Use

<link rel="stylesheet" type="text/css" href="dialog-promise.css">
<script src="dialog-promise.js"></script>
<button onclick='example2(this)'>example</button>
<script>
function example2(button){
    var theName = "previous Name";
    promptPromise("What's your name?", theName).then(function(name){
        theName = name;
        return confirmPromise("Do you want to know my name?");
    }).then(function(result){
        return alertPromise("Hi "+theName+". My name is DialogPromise");
    }).then(function(){
        button.textContent='try again!';
    },function(err){
        console.log("User Escapes. Don't insist.")
    });
}
</script>

alertPromise, confirmPromise, promptPromise

Recives a mensage (and an object with options). These are versions of the native funcions alert, confirm y prompt

functionreturned value
alerttrue
confirmtrue or false
prompta string with the entered text

If Escape is pressed or the mouse clicked outside the dialog the function returns a rejected promise.

Options

The options could be passed to all of these functions

optiondefuse
underElementnullthe dialog apears below this element. If no element is passed the dialog apears in the center of the window
replacingElementnullhides the specified element and places the window under his father. If father not exists, window hangs from body
withCloseButtontruedisplay the close button
mainAttrs{}attributes (properties) for main dialog window
setAttrs{}DOM attributes for main dialog window
rejecttruetrue if rejects the promise when close by the close button, Esc key or clicking outside of the dialog
closeValueundefinedvalue if rejects the promise when close by the close button, Esc key or clicking outside of the dialog
inputDef{lines:1, attributes:{attrname: 'attrvalue', othername:'othervalue'}}lines option transforms input to textarea with lines rows, attributes is used to set attributes
buttonDef{label:'Ok', value:true}main button of the alertPromise dialog
buttonsDef{label:'Ok', value:true, attributes:{attrname: 'attrvalue', othername:'othervalue'}}button description
askForNoRepeatfalseid (or object) to permits the user to ask to remember de answer

miniMenuPromise(elementsList, opts)

Display a menu

<script src="dialog-promise.js"></script>
<button id=theButton onclick='example3(this)'>example</button>
<script>
function example3(button){
    miniMenuPromise([
        {value:'ar', img:'ar.png', label:'Argentina'},
        {value:'cl', img:'cl.png', label:'Chile'},
        {value:'uy', img:'uy.png', label:'Uruguay'},
    ], {underElement: theButton}).then(function(option){
        return alertPromise("val = "+option);
    });
}
</script>

miniMenuPromise elementList

The options could be passed to all of these functions

optionuse
labeltext to show
valuevalue when click. If not set the row is not clickeable.
imgimage url
startGroupif it starts a group (puts a little line)
imgStyleobject with style attributes for the image
displayFunalternate function to create cells of the row
doneFunalternate function to callback when the option was selected instead of resolving the promise
labelsarray of texts to show (in table)

simpleFormPromise(elements, opts)

Shows a simple form

elements

  • if it is a string it shows the text
  • if it is an HTML elementit shows it
  • otherwise creates a button

Opciones

atributo de elementpredeterminadouso
dialogPromiseDonesee spanish
firstFocusnullsee spanish
labelsee spanish
attributes{}see spanish
valuenullsee spanish
hotkeysee spanish

License

MIT

0.10.0

5 days ago

0.9.15

2 years ago

0.9.14

3 years ago

0.9.12

3 years ago

0.9.10

5 years ago

0.9.9

5 years ago

0.9.8

5 years ago

0.9.7

5 years ago

0.9.6

6 years ago

0.9.5

6 years ago

0.9.4

6 years ago

0.9.3

6 years ago

0.9.2

6 years ago

0.9.1

6 years ago

0.9.0

6 years ago

0.8.9

6 years ago

0.8.8

6 years ago

0.8.7

6 years ago

0.8.6

6 years ago

0.8.5

6 years ago

0.8.4

7 years ago

0.8.3

7 years ago

0.8.2

7 years ago

0.8.0

7 years ago

0.7.1

7 years ago

0.7.0

7 years ago

0.6.5

7 years ago

0.6.4

7 years ago

0.6.3

7 years ago

0.6.2

7 years ago

0.6.1

7 years ago

0.6.0

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.4.0

7 years ago

0.3.5

7 years ago

0.3.3

7 years ago

0.3.2

8 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.0

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago