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

backbone-modal

v1.1.2

Published

Create clean modal windows with sleek transitions and a simple API.

Downloads

11

Readme

Backbone Modal

Version 1.1.0

Create clean modal windows with sleek transitions and a simple API.

screenshot

Demo & Documentation

Native alert views are ugly and very limiting; this plugin was designed to replace native alert() and provide additional features commonly needed in apps.

It has been developed with a simple and extensible API to make using modals easy.

Modal defaults to using cutting-edge css3 flexbox for the layout. This can be turned off if you wish to support older browsers. Flexbox ensures the text is nice and sharp.


General Use

var myModal = new Modal({
    title: '',
    msg: '',
    btns: ['ok'],
    theme: 'ios7',
    w: null,
    effect: 1,
})

Modal Presets

There are several baked in modal types for common actions. Check out the demo

Alert

Modal.alert('Title', 'Message')

Warn

Modal.warn('Heads up', 'You can‘t do that')

screenshot

Error

Modal.error('Sorry', 'You are not allowed to perform that action')

screenshot

Confirm

Modal.confirm('Confirm', 'Are you sure?', confirmed=>{})

Confirm Delete

Similar to confirm above but will have a red button with a trash icon

Modal.confirmDelete('Delete?', 'Are you sure?', confirmed=>{})

Prompt

Modal.prompt('Title', 'Message', {
    placeholder: 'Enter value',
    val: 'Prefilled value'
}, val=>{
    console.log('you entered: ', val)
})

Prompt has some more options available

{
    okBtn: 'Ok',
    password: false,
    placeholder: 'Enter value...',
    val: '',
    prefix: '',
    suffix: '',
    msgAfter: '',
    pattern: null, // a regex
    h: null, // add height for textarea
    w: null,
    autoFocus: true
}

Image

Modal.img('http://i.imgur.com/lu2sHfr.png')

Spinner

Modal.spinner()
Modal.spinner('With a message')
Modal.spinner(false) // closes spinner

Progress

All modals have a progress method for displaying a progress bar. Here's an example

let md = Modal.progress('Uploading', '');

// later...
md.progress(10) // 10%
md.progress(23) // 23%
md.progress(84) // 84%

md.close();

Custom Backbone View

Modal also supports rendering a custom backbone view for the content.

var MyView = Backbone.View.extend({
    className: 'padded', // optional
    render: function(){
        this.$el.html('<p>My modal content here</p>')
        return this
    },
    
    btnAction: function(){
        console.log('take action on the view')
        
        // your view will have a reference to the modal (only while the modal is open)
        this.modal&&this.modal.close() // close modal if exists
    }
})

var myView = new MyView();

new Modal({
    view: myView,
    btns: [
        'cancel',
        {label: 'View Action', onClick: 'btnAction'}
    ]
})

Options

{
    effect: 1, // open/close animation effect
    title: '',
    msg: '',
    headerImg: '',
    icon: '',
    btns: ['close'],
    theme: 'ios7',
    w: null,
    onOpen: null,
    onOpened: null,
    onClose: null,
    onClosed: null,
}

btns - an array of buttons for the modal

In addition to defining your own buttons, there are a few presets that can be used by string name: close, cancel, dismiss, ok, done.

btns: [
    'close',
    {
        label: 'Custom button',
        className: 'blue md-close',
        onClick: function(){
            console.log('custom button clicked')
        }
    }
]

Note: the md-close class will make that button close the modal in addition to calling the onClick method

icon - adds an animated icon to the top of the modal

Expects basic buttons to be installed or a similar CSS icon font installed prefixed with icon-; ex: icon-trash.

new Modal({title: 'Modal Title', icon: 'ok'})
new Modal({title: 'Modal Title', icon: 'trash'})
new Modal({title: 'Modal Title', icon: 'pencil'})

screenshot

headerImg - creates an image header above your title.

new Modal({
    title: 'Title',
    msg: 'The modal content message',
    headerImg: 'https://images.unsplash.com/photo-1469536526925-9b5547cd5d68?auto=format&fit=crop&w=2852&q=80',
    w: 400
})

screenshot

Changelog

v1.0.0

  • better handling of custom backbone views as content
  • btns onClick can be a string of method name on the custom backbone.view
  • new warn and error styling
  • new headerImg option
  • new icon option

License

MIT © Kevin Jantzer – Blackstone Publishing