Skip to content

Commit 90e2335

Browse files
author
Tom Kaczocha
committed
Added a small test project to validate plugin functionality.
1 parent 4d02853 commit 90e2335

8 files changed

Lines changed: 330 additions & 172 deletions

File tree

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
.idea
2-
bower_components
1+
bower_components

README.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ Heading: 'Delete Post'
4747

4848
Message: 'Are you sure you want to delete this post?'
4949

50-
51-
## Options
52-
Bootstrap Confirm Delete plugin comes with several option settings.
53-
5450
### Example
5551
This example shows all the available options:
5652

@@ -63,20 +59,25 @@ $( document ).ready( function( )
6359
heading: 'My Custom Delete Heading',
6460
message: 'Are you sure you want to delete this item?',
6561
data_type: 'post',
66-
callback: function ( event )
67-
{
68-
// grab original clicked delete button
69-
var button = event.data.originalObject;
70-
// execute delete operation
71-
button.closest( 'tr' ).remove();
72-
},
62+
callback: function ( event )
63+
{
64+
// grab original clicked delete button
65+
var button = event.data.originalObject;
66+
// execute delete operation
67+
button.closest( 'tr' ).remove();
68+
},
7369
delete_callback: function() { console.log( 'delete button clicked' ); },
7470
cancel_callback: function() { console.log( 'cancel button clicked' ); }
7571
}
7672
);
7773
} );
7874
```
7975

76+
### See test directory for a more complete example
77+
78+
## Options
79+
Bootstrap Confirm Delete plugin comes with several optional settings.
80+
8081
### debug
8182
Debug mode will output events and information to the console.
8283

@@ -109,4 +110,8 @@ Parameters:
109110

110111
## License
111112
Copyright &copy; 2015 Tom Kaczocha <tom@rawphp.org>
112-
Licensed under the MIT license.
113+
Licensed under the MIT license.
114+
115+
## Contributors
116+
Special thanks to:
117+
* [mpecan](https://github.com/mpecan)

bootstrap-confirm-delete.css

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +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-
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+
5151
}

bootstrap-confirm-delete.js

Lines changed: 107 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,107 @@
1-
/**
2-
* Bootstrap Confirm Delete
3-
* Author: Tom Kaczocha <tom@rawphp.org>
4-
* Licensed under the MIT license
5-
*/
6-
7-
;
8-
( function ( $, window, document, undefined )
9-
{
10-
var bootstrap_confirm_delete = function ( element, options )
11-
{
12-
this.element = $( element );
13-
this.settings = $.extend(
14-
{
15-
debug: false,
16-
heading: 'Delete',
17-
message: 'Are you sure you want to delete this item?',
18-
data_type: null,
19-
callback: null,
20-
delete_callback: null,
21-
cancel_callback: null
22-
}, options || {}
23-
);
24-
25-
this.onDelete = function ( event )
26-
{
27-
event.preventDefault();
28-
29-
var plugin = $( this ).data( 'bootstrap_confirm_delete' );
30-
31-
if ( undefined !== $( this ).attr( 'data-type' ) )
32-
{
33-
var name = $( this ).attr( 'data-type' );
34-
35-
plugin.settings.heading = 'Delete ' + name[ 0 ].toUpperCase() + name.substr( 1 );
36-
plugin.settings.message = 'Are you sure you want to delete this ' + name + '?';
37-
}
38-
39-
if ( null === document.getElementById( 'bootstrap-confirm-delete-container' ) )
40-
{
41-
$( '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>' );
42-
}
43-
44-
$( '#bootstrap-confirm-dialog-heading' ).html( plugin.settings.heading );
45-
$( '#bootstrap-confirm-dialog-text' ).html( plugin.settings.message );
46-
$( '#bootstrap-confirm-dialog' ).modal( 'toggle' );
47-
48-
var deleteBtn = $( 'a#bootstrap-confirm-dialog-delete-btn' );
49-
var cancelBtn = $( 'a#bootstrap-confirm-dialog-cancel-delete-btn' );
50-
var hasCallback = false;
51-
if ( null !== plugin.settings.callback )
52-
{
53-
if ( $.isFunction( plugin.settings.callback ) )
54-
{
55-
deleteBtn.attr( 'data-dismiss', 'modal' ).off('.bs-confirm-delete').on( 'click.bs-confirm-delete', { originalObject: $( this ) }, plugin.settings.callback );
56-
hasCallback = true;
57-
}
58-
else
59-
{
60-
console.log( plugin.settings.callback + ' is not a valid callback' );
61-
}
62-
}
63-
if ( null !== plugin.settings.delete_callback )
64-
{
65-
if ( $.isFunction( plugin.settings.delete_callback ) )
66-
{
67-
deleteBtn.attr( 'data-dismiss', 'modal' ).off('.bs-confirm-delete').on( 'click.bs-confirm-delete', { originalObject: $( this ) }, plugin.settings.delete_callback );
68-
hasCallback = true;
69-
}
70-
else
71-
{
72-
console.log( plugin.settings.delete_callback + ' is not a valid callback' );
73-
}
74-
}
75-
if ( !hasCallback && '' !== event.currentTarget.href )
76-
{
77-
deleteBtn.attr( 'href', event.currentTarget.href );
78-
}
79-
80-
if ( null !== plugin.settings.cancel_callback )
81-
{
82-
cancelBtn.off('.bs-confirm-delete').on( 'click.bs-confirm-delete', { originalObject: $( this ) }, plugin.settings.cancel_callback );
83-
}
84-
};
85-
};
86-
87-
$.fn.bootstrap_confirm_delete = function ( options )
88-
{
89-
return this.each( function ()
90-
{
91-
var element = $( this );
92-
93-
if ( element.data( 'bootstrap_confirm_delete' ) )
94-
{
95-
return element.data( 'bootstrap_confirm_delete' );
96-
}
97-
98-
var plugin = new bootstrap_confirm_delete( this, options );
99-
100-
element.data( 'bootstrap_confirm_delete', plugin );
101-
element.off('.bs-confirm-delete').on( 'click.bs-confirm-delete', plugin.onDelete );
102-
103-
return plugin;
104-
} );
105-
};
106-
}( jQuery, window, document, undefined ));
1+
/**
2+
* Bootstrap Confirm Delete
3+
* Author: Tom Kaczocha <tom@rawphp.org>
4+
* Licensed under the MIT license
5+
*/
6+
7+
;
8+
( function ( $, window, document, undefined )
9+
{
10+
var bootstrap_confirm_delete = function ( element, options )
11+
{
12+
this.element = $( element );
13+
this.settings = $.extend(
14+
{
15+
debug: false,
16+
heading: 'Delete',
17+
message: 'Are you sure you want to delete this item?',
18+
data_type: null,
19+
callback: null,
20+
delete_callback: null,
21+
cancel_callback: null
22+
}, options || {}
23+
);
24+
25+
this.onDelete = function ( event )
26+
{
27+
event.preventDefault();
28+
29+
var plugin = $( this ).data( 'bootstrap_confirm_delete' );
30+
31+
if ( undefined !== $( this ).attr( 'data-type' ) )
32+
{
33+
var name = $( this ).attr( 'data-type' );
34+
35+
plugin.settings.heading = 'Delete ' + name[ 0 ].toUpperCase() + name.substr( 1 );
36+
plugin.settings.message = 'Are you sure you want to delete this ' + name + '?';
37+
}
38+
39+
if ( null === document.getElementById( 'bootstrap-confirm-delete-container' ) )
40+
{
41+
$( '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>' );
42+
}
43+
44+
$( '#bootstrap-confirm-dialog-heading' ).html( plugin.settings.heading );
45+
$( '#bootstrap-confirm-dialog-text' ).html( plugin.settings.message );
46+
$( '#bootstrap-confirm-dialog' ).modal( 'toggle' );
47+
48+
var deleteBtn = $( 'a#bootstrap-confirm-dialog-delete-btn' );
49+
var cancelBtn = $( 'a#bootstrap-confirm-dialog-cancel-delete-btn' );
50+
var hasCallback = false;
51+
52+
if ( null !== plugin.settings.callback )
53+
{
54+
if ( $.isFunction( plugin.settings.callback ) )
55+
{
56+
deleteBtn.attr( 'data-dismiss', 'modal' ).off('.bs-confirm-delete').on( 'click.bs-confirm-delete', { originalObject: $( this ) }, plugin.settings.callback );
57+
hasCallback = true;
58+
}
59+
else
60+
{
61+
console.log( plugin.settings.callback + ' is not a valid callback' );
62+
}
63+
}
64+
if ( null !== plugin.settings.delete_callback )
65+
{
66+
if ( $.isFunction( plugin.settings.delete_callback ) )
67+
{
68+
deleteBtn.attr( 'data-dismiss', 'modal' ).off('.bs-confirm-delete').on( 'click.bs-confirm-delete', { originalObject: $( this ) }, plugin.settings.delete_callback );
69+
hasCallback = true;
70+
}
71+
else
72+
{
73+
console.log( plugin.settings.delete_callback + ' is not a valid callback' );
74+
}
75+
}
76+
if ( !hasCallback && '' !== event.currentTarget.href )
77+
{
78+
deleteBtn.attr( 'href', event.currentTarget.href );
79+
}
80+
81+
if ( null !== plugin.settings.cancel_callback )
82+
{
83+
cancelBtn.off('.bs-confirm-delete').on( 'click.bs-confirm-delete', { originalObject: $( this ) }, plugin.settings.cancel_callback );
84+
}
85+
};
86+
};
87+
88+
$.fn.bootstrap_confirm_delete = function ( options )
89+
{
90+
return this.each( function ()
91+
{
92+
var element = $( this );
93+
94+
if ( element.data( 'bootstrap_confirm_delete' ) )
95+
{
96+
return element.data( 'bootstrap_confirm_delete' );
97+
}
98+
99+
var plugin = new bootstrap_confirm_delete( this, options );
100+
101+
element.data( 'bootstrap_confirm_delete', plugin );
102+
element.off('.bs-confirm-delete').on( 'click.bs-confirm-delete', plugin.onDelete );
103+
104+
return plugin;
105+
} );
106+
};
107+
}( jQuery, window, document, undefined ));

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": "2.0.0",
3+
"version": "2.0.1",
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": "2.0.0",
3+
"version": "2.0.1",
44
"description": "Bootstrap confirm delete modal dialog jquery plugin",
55
"main": "bootstrap-confirm-dialog.js",
66
"scripts": {

0 commit comments

Comments
 (0)