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

ngbootbox

v0.2.0

Published

AngularJS wrapper for bootbox.js

Downloads

2,079

Readme

ngBootbox

AngularJS wrapper for Bootbox.js. Bootbox.js allowes you to easily make use of Twitter Bootstrap modals for javascript alerts, confirms and prompts. ngBootbox includes three directives, one for each of alert, confirm and prompt.

Installation

bower install ngBootbox

npm install ngbootbox

Development mode

<head>
    <script src="bower_components/jquery/dist/jquery.js"></script>
    <script src="bower_components/angular/angular.js"></script>
    <script src="bower_components/bootstrap/dist/js/bootstrap.js"></script>
    <script src="bower_components/bootbox/bootbox.js"></script>
    <script src="bower_components/ngBootbox/dist/ngBootbox.js"></script>
</head>

Production mode

<head>
    <script src="bower_components/jquery/dist/jquery.min.js"></script>
    <script src="bower_components/angular/angular.min.js"></script>
    <script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
    <script src="bower_components/bootbox/bootbox.js"></script>
    <script src="bower_components/ngBootbox/dist/ngBootbox.min.js"></script>
</head>

Initialize module

angular.module('yourApp', ['ngBootbox']);

Minification

ngBootbox is minification safe, so to minify your own development files, use Gulp or Grunt with ngAnnotate (gulp-ng-annotate or grunt-ng-annotate).

Demo

Visit this page for a working demo.

Directives

ng-bootbox-alert

<button class="btn btn-default" ng-bootbox-alert="Alert message!">
    Alert
</button>

ng-bootbox-confirm

<button class="btn btn-lg btn-primary" ng-bootbox-confirm="Are you sure you want to confirm this?"
        ng-bootbox-confirm-action="confirmCallbackMethod(attr1, attr2)" ng-bootbox-confirm-action-cancel="confirmCallbackCancel(attr1, attr2)">
    Confirm
</button>

ng-bootbox-prompt

<button class="btn btn-lg btn-primary" ng-bootbox-prompt="Please type in your name"
        ng-bootbox-prompt-action="promptCallback(result)" ng-bootbox-prompt-action-cancel="promptCallbackCancelled(result)">
    Prompt
</button>

ng-bootbox-custom-dialog

<button class="btn btn-lg btn-primary"
        ng-bootbox-title="A cool title!"
        ng-bootbox-custom-dialog="Some custom text"
        ng-bootbox-buttons="customDialogButtons"
        ng-bootbox-class-name="some-class">
    Custom dialog
</button>

<script>
    $scope.customDialogButtons = {
        warning: {
            label: "Warning!",
            className: "btn-warning",
            callback: function() { $scope.addAction('Warning', false); }
        },
        success: {
            label: "Success!",
            className: "btn-success",
            callback: function() { $scope.addAction('Success!', true) }
        },
        danger: {
            label: "Danger!",
            className: "btn-danger",
            callback: function() { $scope.addAction('Danger!', false) }
        },
        main: {
            label: "Click ME!",
            className: "btn-primary",
            callback: function() { $scope.addAction('Main...!', true) }
        }
    };
    </script>

Custom dialog with HTML Template

<button class="btn btn-lg btn-primary"
        ng-bootbox-title="A cool title!"
        ng-bootbox-custom-dialog
        ng-bootbox-custom-dialog-template="custom-dialog.tpl.html"
        ng-bootbox-buttons="customDialogButtons">
    Custom dialog with template
</button>

Custom dialog options

An options object can also be used to configure a custom dialog. A full list of available options can be found in the official Bootbox.js documentation.

<button class="btn btn-lg btn-success"
        ng-bootbox-custom-dialog
        ng-bootbox-options="customDialogOptions">
    Custom dialog options
</button>

<script>
    $scope.customDialogOptions = {
        message: 'This is a message!',
        title: 'The best title!',
        onEscape: function() {
          $log.info('Escape was pressed');
        },
        show: true,
        backdrop: false,
        closeButton: true,
        animate: true,
        className: 'test-class',
        buttons: {
            warning: {
                label: "Cancel",
                className: "btn-warning",
                callback: function() { ... }
            },
            success: {
                label: "Ok",
                className: "btn-success",
                callback: function() { ... }
            }
        }
    };
</script>

Scope passing to custom dialog

You can pass $scope to a custom dialog by specifying the scope parameter in options.

<script>
    $scope.customDialogOptions = {
        templateUrl: 'customModal.html',
        scope: $scope,
        title: 'The best title!',
        buttons: {
            warning: {
                label: "Cancel",
                className: "btn-warning",
                callback: function() { ... }
            },
            success: {
                label: "Ok",
                className: "btn-success",
                callback: function() { ... }
            }
        }
    };
</script>

This allows your modal to interact with your controller's scope and bind data in a custom template.

$ngBootbox service

The $ngBootbox service can be used to utilize bootbox.js from within your angular code.

Usage

Inject the $ngBootbox service in your own angular controller, service, directive, etc.

angular.module('yourApp')
    .controller('yourCtrl', function($ngBootbox) { ... });

Methods

$ngBootbox.alert(msg)

Returns a promise that is resolved when the dialog is closed.

Example

$ngBootbox.alert('An important message!')
    .then(function() {
        console.log('Alert closed');
    });
    
$ngBootbox.alert({message:'Another important message!', title:'Ops!'})
    .then(function() {
        console.log('Alert closed');
    });

$ngBootbox.confirm(msg)

Returns a promise that is resolved when if confirmed and rejected if dismissed.

Example

$ngBootbox.confirm('A question?')
    .then(function() {
        console.log('Confirmed!');
    }, function() {
        console.log('Confirm dismissed!');
    });
    
$ngBootbox.confirm({message:"Another question?", title:'Please answer'})
    .then(function() {
        console.log('Confirmed!');
    }, function() {
        console.log('Confirm dismissed!');
    });
    

$ngBootbox.prompt(msg)

Returns a promise that is resolved when submitted and rejected if dismissed.

Example

$ngBootbox.prompt('Enter something')
    .then(function(result) {
        console.log('Prompt returned: ' + result);
    }, function() {
        console.log('Prompt dismissed!');
    });

$ngBootbox.customDialog(options)

Example

var options = {
        message: 'This is a message!',
        title: 'The title!',
        className: 'test-class',
        buttons: {
             warning: {
                 label: "Cancel",
                 className: "btn-warning",
                 callback: function() { ... }
             },
             success: {
                 label: "Ok",
                 className: "btn-success",
                 callback: function() { ... }
             }
        }
    };

$ngBootbox.customDialog(options);

A full list of available options can be found in the official Bootbox.js documentation.

Update

New in 0.0.4: There is now support for specifying a HTML template also when using the $ngBootbox service for displaying custom dialogs.

$scope.customDialogOptions = {
templateUrl: 'custom-dialog.tpl.html',
scope: $scope,
     title: 'The title!',
     buttons: $scope.customDialogButtons
};

When doing this, the message property will be overwritten by the content of the HTML template.

$ngBootbox.setDefaults(options)

Used to set default values for all your Bootbox alerts, confirms, prompts and dialogs.

Example

$ngBootbox.setDefaults({
    animate: false,
    backdrop: false
});

A full list of available options can be found in the official Bootbox.js documentation.

$ngBootbox.hideAll()

Hide all currently active bootbox dialogs.

Example

$ngBootbox.hideAll();

$ngBootbox.addLocale(String name, object values)

Allows the user to add a custom translation for each of the built-in command buttons. The values object should be in this format:

{
    OK : '',
    CANCEL : '',
    CONFIRM : ''
}

$ngBootbox.removeLocale(String name)

Allows the user to remove a locale from the available locale settings.

$ngBootbox.setLocale(String name)

Allows the user to select a locale rather than using setDefaults("locale", ...).

Configuration

$ngBootboxConfigProvider

angular.module('yourApp')
    .config(function($ngBootboxConfigProvider) {
        $ngBootboxConfigProvider.setDefaultLocale('sv');
        
        $ngBootboxConfigProvider.addLocale('ex', { OK: 'OK', CANCEL: 'Avbryt', CONFIRM: 'Bekräfta' });
        
        $ngBootboxConfigProvider.removeLocale('ex');
     })
     .controller('TestCtrl', function($ngBootboxConfig) {
        var defaultLocale = $ngBootboxConfig.getDefaultLocale();  
     });