Skip to content

Commit 57cb5c6

Browse files
author
Tom Kaczocha
committed
Added new options to the modal dialog. Delete by callback.
1 parent 541f801 commit 57cb5c6

5 files changed

Lines changed: 80 additions & 28 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
Bootstrap confirm delete modal dialog jquery plugin
44

55
## Examples
6+
Coming Soon

bootstrap-confirm-delete.css

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
.modal {
2+
3+
}
4+
5+
.fade {
6+
7+
}
8+
9+
.modal-dialog {
10+
11+
}
12+
13+
.modal-content {
14+
15+
}
16+
17+
.modal-header {
18+
19+
}
20+
21+
.modal-body {
22+
23+
}
24+
25+
.modal-footer {
26+
27+
}
28+
29+
#bootstrap-confirm-delete-container {
30+
31+
}
32+
33+
#bootstrap-confirm-dialog {
34+
35+
}
36+
37+
#bootstrap-confirm-dialog-heading {
38+
39+
}
40+
41+
#bootstrap-confirm-dialog-text {
42+
43+
}
44+
45+
#bootstrap-confirm-dialog-cancel-delete-btn {
46+
47+
}
48+
49+
#bootstrap-confirm-dialog-delete-btn {
50+
51+
}

bootstrap-confirm-delete.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,45 @@
66
{
77
$.fn.bootstrap_confirm_delete = function ( options )
88
{
9+
var settings = $.extend(
10+
{
11+
heading: 'Delete',
12+
message: 'Are you sure you want to delete this item?',
13+
data_type: null,
14+
callback: null
15+
}, options );
16+
917
$( this ).on( 'click', function ( event )
1018
{
1119
event.preventDefault();
1220

13-
var heading = 'Delete';
14-
var message = 'Are you sure you want to delete this item?';
15-
16-
if ( undefined !== options )
21+
if ( undefined !== $( this ).attr( 'data-type' ) )
1722
{
18-
if ( undefined !== options.heading )
19-
{
20-
heading = options.heading;
21-
}
22-
23-
if ( undefined !== options.question )
24-
{
25-
message = options.question;
26-
}
27-
}
28-
else
29-
{
30-
if ( undefined !== $( this ).attr( 'data-type' ) )
31-
{
32-
var name = $( this ).attr( 'data-type' );
23+
var name = $( this ).attr( 'data-type' );
3324

34-
heading = 'Delete ' + name[ 0 ].toUpperCase() + name.substr( 1 );
35-
message = 'Are you sure you want to delete this ' + name + '?';
36-
}
25+
settings.heading = 'Delete ' + name[ 0 ].toUpperCase() + name.substr( 1 );
26+
settings.message = 'Are you sure you want to delete this ' + name + '?';
3727
}
3828

3929
if ( null === document.getElementById( 'bootstrap-confirm-delete-container' ) )
4030
{
4131
$( 'body' ).append( '<div id="bootstrap-confirm-delete-container"><div id="bootstrap-confirm-dialog" class="modal fade"><div class="modal-dialog modal-sm"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button><h4 id="bootstrap-confirm-dialog-heading"></h4></div><div class="modal-body"><p id="bootstrap-confirm-dialog-text"></p></div><div class="modal-footer"><button id="bootstrap-confirm-dialog-cancel-delete-btn" type="button" class="btn btn-default pull-left" data-dismiss="modal">Cancel</button><a id="bootstrap-confirm-dialog-delete-btn" href="#" class="btn btn-danger pull-right">Delete</a></div></div></div></div></div>' );
4232
}
4333

44-
$( '#bootstrap-confirm-dialog-heading' ).html( heading );
45-
$( '#bootstrap-confirm-dialog-text' ).html( message );
34+
$( '#bootstrap-confirm-dialog-heading' ).html( settings.heading );
35+
$( '#bootstrap-confirm-dialog-text' ).html( settings.message );
4636
$( '#bootstrap-confirm-dialog' ).modal( 'toggle' );
47-
$( 'a#bootstrap-confirm-dialog-delete-btn' ).attr( 'href', event.currentTarget.href );
37+
38+
if ( null !== settings.callback )
39+
{
40+
$( '#bootstrap-confirm-dialog-delete-btn' ).attr( 'data-dismiss', 'modal');
41+
42+
$( 'a#bootstrap-confirm-dialog-delete-btn' ).on( 'click', settings.callback );
43+
}
44+
else if ( '' !== event.currentTarget.href )
45+
{
46+
$( 'a#bootstrap-confirm-dialog-delete-btn' ).attr( 'href', event.currentTarget.href );
47+
}
4848
} );
4949
};
50-
}( jQuery ) );
50+
}( jQuery ));

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bootstrap-confirm-delete",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"homepage": "https://github.com/rawphp/Bootstrap-Confirm-Delete",
55
"authors": [
66
"Tom Kaczocha <tom@rawphp.org>"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bootstrap-confirm-delete",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "Bootstrap confirm delete modal dialog jquery plugin",
55
"main": "bootstrap-confirm-dialog.js",
66
"scripts": {

0 commit comments

Comments
 (0)