Skip to content

Commit b46cb21

Browse files
author
Tom Kaczocha
committed
added callback fix and updated readme
1 parent 958e5b4 commit b46cb21

2 files changed

Lines changed: 58 additions & 39 deletions

File tree

README.md

Lines changed: 57 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,26 @@
22

33
Bootstrap confirm delete modal dialog jquery plugin
44

5-
65
## Installation
7-
You can install with [bower](http://bower.io/) or [npm](https://www.npmjs.com/).
6+
7+
You can install from [npm](https://www.npmjs.com/package/bootstrap-confirm-delete).
88

99
```sh
10-
$ bower install bootstrap-confirm-delete
10+
$ yarn add bootstrap-confirm-delete
1111
$ npm install --save bootstrap-confirm-delete
1212
```
1313

1414
## Dependencies
15+
1516
This plugin depends on the following:
17+
1618
- jquery >= 1.9.1
1719
- bootstrap >= 3.3.5
1820

1921
NOTE: This plugin has not been tested with versions prior to these.
2022

21-
2223
## Basic Usage
24+
2325
This plugin will intercept the delete event on configured page elements. In this example it will block the deletion click
2426
on any links or buttons that have the 'delete' class on them.
2527

@@ -32,94 +34,111 @@ on any links or buttons that have the 'delete' class on them.
3234
<a href="server.php" class="delete" data-type="post">Delete</a>
3335
```
3436

35-
Initialise the plugin either in <script></script> tags on the html page or in an external .js script.
37+
Initialise the plugin either in <script></script> tags on the html page or in an external .js script.
3638

3739
```js
38-
$( document ).ready( function( )
39-
{
40-
$( '.delete' ).bootstrap_confirm_delete( );
41-
} );
40+
$(document).ready(() => {
41+
$('.delete').bootstrap_confirm_delete();
42+
});
4243
```
4344

4445
Notice the 'data-type' attribute on the link. The plugin will use this attribute if set to show a custom delete message. For example,
4546

46-
Heading: 'Delete Post'
47+
Heading: 'Delete Post'
4748

48-
Message: 'Are you sure you want to delete this post?'
49+
Message: 'Are you sure you want to delete this post?'
4950

5051
### Example
52+
5153
This example shows all the available options:
5254

5355
```js
54-
$( document ).ready( function( )
55-
{
56-
$( '.delete' ).bootstrap_confirm_delete(
57-
{
58-
debug: false,
59-
heading: 'My Custom Delete Heading',
60-
message: 'Are you sure you want to delete this item?',
61-
btn_ok_label: 'Yes',
62-
btn_cancel_label: 'Cancel',
63-
data_type: 'post',
64-
callback: function ( event )
65-
{
66-
// grab original clicked delete button
67-
var button = event.data.originalObject;
68-
// execute delete operation
69-
button.closest( 'tr' ).remove();
70-
},
71-
delete_callback: function() { console.log( 'delete button clicked' ); },
72-
cancel_callback: function() { console.log( 'cancel button clicked' ); }
73-
}
74-
);
75-
} );
56+
$(document).ready(() => {
57+
$('.delete').bootstrap_confirm_delete({
58+
debug: false,
59+
heading: 'My Custom Delete Heading',
60+
message: 'Are you sure you want to delete this item?',
61+
btn_ok_label: 'Yes',
62+
btn_cancel_label: 'Cancel',
63+
data_type: 'post',
64+
callback: (event) => {
65+
// grab original clicked delete button
66+
var button = event.data.originalObject;
67+
// execute delete operation
68+
button.closest('tr').remove();
69+
},
70+
delete_callback: () => {
71+
console.log('delete button clicked');
72+
},
73+
cancel_callback: () => {
74+
console.log('cancel button clicked');
75+
},
76+
});
77+
});
7678
```
7779

7880
### See test directory for a more complete example
7981

8082
## Options
83+
8184
Bootstrap Confirm Delete plugin comes with several optional settings.
8285

8386
### debug
87+
8488
Debug mode will output events and information to the console.
8589

8690
### heading
91+
8792
This is for setting a custom modal heading.
8893

8994
### message
95+
9096
Setting a custom delete message/question.
9197

9298
### btn_ok_label
99+
93100
Set the confirm label text
94101

95102
### btn_cancel_label:
103+
96104
Set the cancel label text
97105

98106
### data_type
107+
99108
Used if heading & message are not provided
100109

101110
### callback
111+
102112
Will fire if responding to a button click that has no href attribute.
103113

104114
Use this callback to do any deletions from a button click.
105115
Parameters:
106-
* data (data.originalObject contains the originally clicked object)
116+
117+
- data (data.originalObject contains the originally clicked object)
107118

108119
### delete_callback
120+
109121
Will fire when the delete button is clicked and a handler is provided.
110122
Parameters:
111-
* data (data.originalObject contains the originally clicked object)
123+
124+
- data (data.originalObject contains the originally clicked object)
112125

113126
### cancel_callback
127+
114128
Will fire when the cancel button is clicked and a handler is provided.
115129
Parameters:
116-
* data (data.originalObject contains the originally clicked object)
117130

131+
- data (data.originalObject contains the originally clicked object)
118132

119133
## License
120-
Copyright &copy; 2015 Tom Kaczocha <tom@rawphp.org>
134+
135+
Copyright &copy; 2015-2019 Tom Kaczocha <tom@rawphp.org>
136+
121137
Licensed under the MIT license.
122138

123139
## Contributors
140+
124141
Special thanks to:
125-
* [mpecan](https://github.com/mpecan)
142+
143+
- [mpecan](https://github.com/mpecan)
144+
- [iwansusanto](https://github.com/iwansusanto)

bootstrap-confirm-delete.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
if ( null === document.getElementById( 'bootstrap-confirm-delete-container' ) )
4242
{
43-
$( '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>' );
43+
$( '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"><a id="bootstrap-confirm-dialog-cancel-delete-btn" type="button" class="btn btn-default pull-left" data-dismiss="modal">Cancel</a><a id="bootstrap-confirm-dialog-delete-btn" href="#" class="btn btn-danger pull-right">Delete</a></div></div></div></div></div>' );
4444
}
4545

4646
$( '#bootstrap-confirm-dialog-heading' ).html( plugin.settings.heading );

0 commit comments

Comments
 (0)