npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dialog-promise

v0.10.0

Published

Dialog that returns promises

Downloads

64

Readme

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

function |returned value ----------|--------------------- alert |true confirm |true or false prompt |a 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

option |def |use ------------------|--------------|---------------------------------- underElement |null |the dialog apears below this element. If no element is passed the dialog apears in the center of the window replacingElement|null |hides the specified element and places the window under his father. If father not exists, window hangs from body withCloseButton |true |display the close button mainAttrs |{} |attributes (properties) for main dialog window setAttrs |{} |DOM attributes for main dialog window reject |true |true if rejects the promise when close by the close button, Esc key or clicking outside of the dialog closeValue |undefined |value 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 askForNoRepeat |false |id (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

option |use ------------------|---------------------------------- label |text to show value |value when click. If not set the row is not clickeable. img |image url startGroup |if it starts a group (puts a little line) imgStyle |object with style attributes for the image displayFun |alternate function to create cells of the row doneFun |alternate function to callback when the option was selected instead of resolving the promise labels |array 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 element |predeterminado|uso ---------------------|--------------|------------------------------------- dialogPromiseDone | |see spanish firstFocus |null |see spanish label | |see spanish attributes |{} |see spanish value |null |see spanish hotkey | |see spanish

License

MIT