2.0.0 • Published 4 years ago

jquery-bsalert v2.0.0

Weekly downloads
27
License
MIT
Repository
github
Last release
4 years ago

jQuery Bootstrap Alerts v2.0.0

Build status npm version devDependency Status

jQuery plugin to programmatically display bootstrap alerts

Installation

Download

CDN

<script src="https://unpkg.com/jquery-bsalert@2.0.0/dist/jquery.bsAlert.min.js"></script>
<!-- OR -->
<script src="https://unpkg.com/jquery-bsalert@2.0.0/dist/jquery.bsAlert.js"></script>

Package Managers

Install via yarn:

$ yarn add jquery-bsalert

Install via NPM:

$ npm install jquery-bsalert --save

Usage

Standard Usage

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://unpkg.com/jquery-bsalert@2.0.0/dist/jquery.bsAlert.min.js"></script>

<script>
$(function() {
    if(someCheck) {
        $('#form').bsAlert('success', 'It was successful!');
    } else {
        $('#form').bsAlert('danger', 'Check form fields!');
    }

    // With all options
    $('#form').bsAlert({
        type: 'success',
        content: 'Thanks for contacting us!',
        dismissible: true,
        position: 'after'
    });
});
</script>

Webpack and Browserify

$ yarn add jquery-bsalert
var $ = require('jquery');
require('jquery-bsalert');

$('#form').bsAlert('warning', 'This is a warning');

Options

OptionTypeDescriptionDefault
typestringAlert type. See http://getbootstrap.com/components/#alerts for the different types allowed.danger
contentstring or functionThe alert's text or html content. Can also be a function, see below for an example..''
dismissiblebooleanWhether the alert can be dismissed. Displays a close button if truefalse
positionstring or functionWhere to position the alert. Valid options are 'before', 'after', or a function.before

Using the position option as a function:

$('#form').bsAlert({
    // 'this' is bound to the plugin instance
    position: function($alert) {
        $alert.appendTo('.container');
    }
});

Using the content option as a function:

$('#form').bsAlert({
    // 'this' is bound to the plugin instance
    content: function() {
        if(this.options.dismissible) {
            return 'This is a dismissible alert';
        }

        return 'This is not a dismissible alert';
    }
});

Modify the $.fn.bsAlert object to change default option values:

$.fn.bsAlert.dismissible = true;

License

Released under the MIT license

2.0.0

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.3

4 years ago

1.0.0

5 years ago

0.9.4

7 years ago

0.9.3

7 years ago

0.9.2

7 years ago

0.9.1

7 years ago