From d47f34d2ddee7b2b008d59a87a0d573dfb5cd162 Mon Sep 17 00:00:00 2001 From: Tavicu Date: Tue, 18 Feb 2014 03:57:20 -0800 Subject: [PATCH 01/23] Initial commit --- README.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..8273791 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +bootstrap-confirmation +====================== + +Confirmation for Bootstrap 3 From 95b2d579ee775021f2200b07314bd4f6aa33f09d Mon Sep 17 00:00:00 2001 From: Tavicu Date: Tue, 18 Feb 2014 14:00:50 +0200 Subject: [PATCH 02/23] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8273791..3f3bfab 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ bootstrap-confirmation ====================== -Confirmation for Bootstrap 3 +This is a fork of jibe914's [original code](https://github.com/ethaizone/Bootstrap-Confirmation) + +Confirmation plugin compatible with Twitter Bootstrap 3 From aef0441311e328da33315f4ef3b1aaeb239908e2 Mon Sep 17 00:00:00 2001 From: Tavicu Date: Tue, 18 Feb 2014 14:24:24 +0200 Subject: [PATCH 03/23] Update README.md --- README.md | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3f3bfab..1d4aebb 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,66 @@ -bootstrap-confirmation -====================== +# bootstrap-confirmation v1.0 This is a fork of jibe914's [original code](https://github.com/ethaizone/Bootstrap-Confirmation) -Confirmation plugin compatible with Twitter Bootstrap 3 +Confirmation plugin compatible with Twitter Bootstrap 3 extending Popover + +## Usage + +Create your `button or link` with the `data-toggle="confirmation"`. + + Confirmation + +Enable plugin via JavaScript: + + $('[data-toggle="confirmation"]').confirmation(); + +Or if you want to assing to one element + + Confirmation + $('.confirmation').confirmation(); + +## Options + +In addition to the standard bootstrap popover options, you now have access to the following options + ++ **btnOkClass** +Set the Ok button class. `default: btn btn-sm btn-danger` + ++ **btnOkLabel** +Set the Ok button label. `default: Delete` + ++ **btnOkIcon** +Set the Ok button icon. `default: glyphicon glyphicon-ok` + ++ **btnCancelClass** +Set the Ok button class. `default: btn btn-sm btn-default` + ++ **btnCancelLabel** +Set the Ok button label. `default: Cancel` + ++ **btnCancelIcon** +Set the Ok button icon. `default: glyphicon glyphicon-remove` + ++ **singleton** +Set true to allow only one confirmation to show at a time. `default: true` + ++ **popout** +Set true to hide the confirmation when user clicks outside of it. `default: true` + ++ **onConfirm** +Callback for confirm button. `default: function(event){}` + ++ **onCancel** +Callback for cancel button. `default: function(event){}` + +## Copyright and license + +Copyright (C) 2013 bootstrap-confirmation + +Licensed under the MIT license. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. From 8e58c5feddaf6c3e8bab2bac84b35265ef4cc7af Mon Sep 17 00:00:00 2001 From: Tavicu Date: Tue, 18 Feb 2014 14:25:27 +0200 Subject: [PATCH 04/23] Create bootstrap-confirm.php --- bootstrap-confirm.php | 226 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 226 insertions(+) create mode 100644 bootstrap-confirm.php diff --git a/bootstrap-confirm.php b/bootstrap-confirm.php new file mode 100644 index 0000000..edd0014 --- /dev/null +++ b/bootstrap-confirm.php @@ -0,0 +1,226 @@ ++function ($) { + 'use strict'; + + //var for check event at body can have only one. + var event_body = false; + + // CONFIRMATION PUBLIC CLASS DEFINITION + // =============================== + var Confirmation = function (element, options) { + var that = this; + + // remove href attribute of button + $(element).removeAttr('href'); + + this.init('confirmation', element, options); + + $(element).on('show.bs.confirmation', function(e) { + var options = that.options; + var all = options.all_selector; + + if(options.singleton) { + $(all).not(that.$element).confirmation('hide'); + } + }); + + $(element).on('shown.bs.confirmation', function(e) { + var options = that.options; + var all = options.all_selector; + + that.$element.on('click.dismiss.bs.confirmation', '[data-dismiss="confirmation"]', $.proxy(that.hide, that)); + + if(that.isPopout()) { + if(!event_body) { + event_body = $('body').on('click', function (e) { + if($(all).is(e.target)) return; + if($(all).has(e.target).length) return; + if($('.popover').has(e.target).length) return; + + $(all).confirmation('hide'); + + $('body').unbind(e); + + event_body = false; + + return; + }); + } + } + }); + } + + if (!$.fn.popover || !$.fn.tooltip) throw new Error('Confirmation requires popover.js and tooltip.js'); + + Confirmation.DEFAULTS = $.extend({}, $.fn.popover.Constructor.DEFAULTS, { + placement : 'top', + title : 'Are you sure?', + btnOkClass : 'btn btn-sm btn-danger', + btnOkLabel : 'Delete', + btnOkIcon : 'glyphicon glyphicon-ok', + btnCancelClass : 'btn btn-sm btn-default', + btnCancelLabel : 'Cancel', + btnCancelIcon : 'glyphicon glyphicon-remove', + href : '#', + target : '_self', + singleton : true, + popout : true, + onConfirm : function(event){}, + onCancel : function(event){}, + template : '
' + + '

' + + '
' + + 'Yes' + + ' No' + + '
' + + '
' + }); + + + // NOTE: CONFIRMATION EXTENDS popover.js + // ================================ + Confirmation.prototype = $.extend({}, $.fn.popover.Constructor.prototype); + + Confirmation.prototype.constructor = Confirmation; + + Confirmation.prototype.getDefaults = function () { + return Confirmation.DEFAULTS; + } + + Confirmation.prototype.setContent = function () { + var that = this; + var $tip = this.tip(); + var title = this.getTitle(); + var $btnOk = $tip.find('[data-apply="confirmation"]'); + var $btnCancel = $tip.find('[data-dismiss="confirmation"]'); + var options = this.options + + $btnOk.addClass(this.getBtnOkClass()) + .html(this.getBtnOkLabel()) + .prepend($('').addClass(this.getBtnOkIcon()), " ") + .attr('href', this.getHref()) + .attr('target', this.getTarget()) + .one('click', function(event) { + options.onConfirm(event); + + that.$element.confirmation('hide'); + }); + + $btnCancel.addClass(this.getBtnCancelClass()) + .html(this.getBtnCancelLabel()) + .prepend($('').addClass(this.getBtnCancelIcon()), " ") + .one('click', function(event){ + options.onCancel(event); + + that.$element.confirmation('hide'); + }); + + $tip.find('.popover-title')[this.options.html ? 'html' : 'text'](title); + + $tip.removeClass('fade top bottom left right in'); + + // IE8 doesn't accept hiding via the `:empty` pseudo selector, we have to do + // this manually by checking the contents. + if (!$tip.find('.popover-title').html()) $tip.find('.popover-title').hide(); + } + + Confirmation.prototype.getBtnOkClass = function () { + var $e = this.$element; + var o = this.options; + + return $e.attr('data-btnOkClass') || (typeof o.btnOkClass == 'function' ? o.btnOkClass.call($e[0]) : o.btnOkClass); + } + + Confirmation.prototype.getBtnOkLabel = function () { + var $e = this.$element; + var o = this.options; + + return $e.attr('data-btnOkLabel') || (typeof o.btnOkLabel == 'function' ? o.btnOkLabel.call($e[0]) : o.btnOkLabel); + } + + Confirmation.prototype.getBtnOkIcon = function () { + var $e = this.$element; + var o = this.options; + + return $e.attr('data-btnOkIcon') || (typeof o.btnOkIcon == 'function' ? o.btnOkIcon.call($e[0]) : o.btnOkIcon); + } + + Confirmation.prototype.getBtnCancelClass = function () { + var $e = this.$element; + var o = this.options; + + return $e.attr('data-btnCancelClass') || (typeof o.btnCancelClass == 'function' ? o.btnCancelClass.call($e[0]) : o.btnCancelClass); + } + + Confirmation.prototype.getBtnCancelLabel = function () { + var $e = this.$element; + var o = this.options; + + return $e.attr('data-btnCancelLabel') || (typeof o.btnCancelLabel == 'function' ? o.btnCancelLabel.call($e[0]) : o.btnCancelLabel); + } + + Confirmation.prototype.getBtnCancelIcon = function () { + var $e = this.$element; + var o = this.options; + + return $e.attr('data-btnCancelIcon') || (typeof o.btnCancelIcon == 'function' ? o.btnCancelIcon.call($e[0]) : o.btnCancelIcon); + } + + Confirmation.prototype.getHref = function () { + var $e = this.$element; + var o = this.options; + + return $e.attr('data-href') || (typeof o.href == 'function' ? o.href.call($e[0]) : o.href); + } + + Confirmation.prototype.getTarget = function () { + var $e = this.$element; + var o = this.options; + + return $e.attr('data-target') || (typeof o.target == 'function' ? o.target.call($e[0]) : o.target); + } + + Confirmation.prototype.isPopout = function () { + var popout; + var $e = this.$element; + var o = this.options; + + popout = $e.attr('data-popout') || (typeof o.popout == 'function' ? o.popout.call($e[0]) : o.popout); + + if(popout == 'false') popout = false; + + return popout + } + + + // CONFIRMATION PLUGIN DEFINITION + // ========================= + var old = $.fn.confirmation; + + $.fn.confirmation = function (option) { + var that = this; + + return this.each(function () { + var $this = $(this); + var data = $this.data('bs.confirmation'); + var options = typeof option == 'object' && option; + + options = options || {}; + options.all_selector = that.selector; + + if (!data && option == 'destroy') return; + if (!data) $this.data('bs.confirmation', (data = new Confirmation(this, options))); + if (typeof option == 'string') data[option](); + }); + } + + $.fn.confirmation.Constructor = Confirmation + + + // CONFIRMATION NO CONFLICT + // =================== + $.fn.confirmation.noConflict = function () { + $.fn.confirmation = old; + + return this; + } +}(jQuery); From 894a212dc97bc85737ba6941514ad17654d0070b Mon Sep 17 00:00:00 2001 From: Tavicu Date: Tue, 18 Feb 2014 14:26:16 +0200 Subject: [PATCH 05/23] Rename bootstrap-confirm.php to bootstrap-confirmation.php --- bootstrap-confirm.php => bootstrap-confirmation.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename bootstrap-confirm.php => bootstrap-confirmation.php (100%) diff --git a/bootstrap-confirm.php b/bootstrap-confirmation.php similarity index 100% rename from bootstrap-confirm.php rename to bootstrap-confirmation.php From 25cee6fa5c66a4f15857e462d39d708c932e73f1 Mon Sep 17 00:00:00 2001 From: Tavicu Date: Tue, 18 Feb 2014 14:35:47 +0200 Subject: [PATCH 06/23] Update bootstrap-confirmation.php --- bootstrap-confirmation.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bootstrap-confirmation.php b/bootstrap-confirmation.php index edd0014..568a039 100644 --- a/bootstrap-confirmation.php +++ b/bootstrap-confirmation.php @@ -99,7 +99,7 @@ .prepend($('').addClass(this.getBtnOkIcon()), " ") .attr('href', this.getHref()) .attr('target', this.getTarget()) - .one('click', function(event) { + .off('click').on('click', function(event) { options.onConfirm(event); that.$element.confirmation('hide'); @@ -108,7 +108,7 @@ $btnCancel.addClass(this.getBtnCancelClass()) .html(this.getBtnCancelLabel()) .prepend($('').addClass(this.getBtnCancelIcon()), " ") - .one('click', function(event){ + .off('click').on('click', function(event){ options.onCancel(event); that.$element.confirmation('hide'); From 003be0f1bfbc7f40cbaa406983bf3a76835938f8 Mon Sep 17 00:00:00 2001 From: Tavicu Date: Tue, 18 Feb 2014 14:38:22 +0200 Subject: [PATCH 07/23] Create demo.html --- demo.html | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 demo.html diff --git a/demo.html b/demo.html new file mode 100644 index 0000000..ddd10fb --- /dev/null +++ b/demo.html @@ -0,0 +1,46 @@ + + + + Bootstrap-Confirmation Demo + + + + + + +
+
+
+

Default options with datta toggle

+
$('[data-toggle="confirmation"]').confirmation();
+ Click me +
+
+ +
+
+

With callback functions

+
$('.confirmation-callback').confirmation({
+	onConfirm: function(event) { alert('confirm') },
+	onCancel: function(event) { alert('cancel') }
+});
+ + Click me + +
+
+
+ + + + + + + + From 8bf36b08dd5f91c0015b869e3d352601824043db Mon Sep 17 00:00:00 2001 From: Tavicu Date: Tue, 18 Feb 2014 14:39:15 +0200 Subject: [PATCH 08/23] Rename bootstrap-confirmation.php to bootstrap-confirmation.js --- bootstrap-confirmation.php => bootstrap-confirmation.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename bootstrap-confirmation.php => bootstrap-confirmation.js (100%) diff --git a/bootstrap-confirmation.php b/bootstrap-confirmation.js similarity index 100% rename from bootstrap-confirmation.php rename to bootstrap-confirmation.js From 6e31ac6d268109b98fff9cf5b1c9adfd988bd12a Mon Sep 17 00:00:00 2001 From: Tavicu Date: Tue, 18 Feb 2014 14:39:35 +0200 Subject: [PATCH 09/23] Update demo.html --- demo.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/demo.html b/demo.html index ddd10fb..7cf19b0 100644 --- a/demo.html +++ b/demo.html @@ -5,7 +5,7 @@ - +
@@ -31,8 +31,8 @@

With callback functions

- - + +