forked from tavicu/bs-confirmation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap-confirmation.min.js
executable file
·5 lines (5 loc) · 5.76 KB
/
bootstrap-confirmation.min.js
1
2
3
4
5
/*!
* Bootstrap Confirmation v1.0.7
* https://github.com/tavicu/bs-confirmation
*/
+function($){"use strict";var event_body=!1,Confirmation=function(t,n){var o=this;this.init("confirmation",t,n),n.selector?$(t).on("click.bs.confirmation",n.selector,function(t){t.preventDefault()}):$(t).on("show.bs.confirmation",function(t){o.runCallback(o.options.onShow,t,o.$element),o.$element.addClass("open"),o.options.singleton&&$(o.options.all_selector).not(o.$element).each(function(){$(this).hasClass("open")&&$(this).confirmation("hide")})}).on("hide.bs.confirmation",function(t){o.runCallback(o.options.onHide,t,o.$element),o.$element.removeClass("open")}).on("shown.bs.confirmation",function(t){(o.isPopout()||event_body)&&(event_body=$("body").on("click",function(t){o.$element.is(t.target)||o.$element.has(t.target).length||$(".popover").has(t.target).length||(o.hide(),o.inState.click=!1,$("body").unbind(t),event_body=!1)}))}).on("click.bs.confirmation",function(t){t.preventDefault()})};if(!$.fn.popover||!$.fn.tooltip)throw new Error("Confirmation requires popover.js and tooltip.js");Confirmation.VERSION="1.0.7",Confirmation.DEFAULTS=$.extend({},$.fn.popover.Constructor.DEFAULTS,{placement:"right",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:!0,popout:!0,onShow:function(t,n){},onHide:function(t,n){},onConfirm:function(t,n){},onCancel:function(t,n){},template:'<div class="popover"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"> <a data-apply="confirmation">Yes</a> <a data-dismiss="confirmation">No</a></div></div>'}),Confirmation.prototype=$.extend({},$.fn.popover.Constructor.prototype),Confirmation.prototype.constructor=Confirmation,Confirmation.prototype.getDefaults=function(){return Confirmation.DEFAULTS},Confirmation.prototype.setContent=function(){var t=this,n=this.tip(),o=this.getTitle(),e=n.find('[data-apply="confirmation"]'),i=n.find('[data-dismiss="confirmation"]');this.options;e.addClass(this.getBtnOkClass()).html(this.getBtnOkLabel()).prepend($("<i></i>").addClass(this.getBtnOkIcon())," ").attr("href",this.getHref()).attr("target",this.getTarget()).off("click").on("click",function(n){if(t.runCallback(t.options.onConfirm,n,t.$element),"submit"==t.$element.attr("type")){var o=t.$element.closest("form"),e=void 0!==o.attr("novalidate");(e||o[0].checkValidity())&&o.submit()}t.hide(),t.inState.click=!1,t.$element.trigger($.Event("confirm.bs.confirmation"))}),i.addClass(this.getBtnCancelClass()).html(this.getBtnCancelLabel()).prepend($("<i></i>").addClass(this.getBtnCancelIcon())," ").off("click").on("click",function(n){t.runCallback(t.options.onCancel,n,t.$element),t.hide(),t.inState.click=!1,t.$element.trigger($.Event("cancel.bs.confirmation"))}),n.find(".popover-title")[this.options.html?"html":"text"](o),n.removeClass("fade top bottom left right in"),n.find(".popover-title").html()||n.find(".popover-title").hide()},Confirmation.prototype.getBtnOkClass=function(){return this.$element.data("btnOkClass")||("function"==typeof this.options.btnOkClass?this.options.btnOkClass.call(this,this.$element):this.options.btnOkClass)},Confirmation.prototype.getBtnOkLabel=function(){return this.$element.data("btnOkLabel")||("function"==typeof this.options.btnOkLabel?this.options.btnOkLabel.call(this,this.$element):this.options.btnOkLabel)},Confirmation.prototype.getBtnOkIcon=function(){return this.$element.data("btnOkIcon")||("function"==typeof this.options.btnOkIcon?this.options.btnOkIcon.call(this,this.$element):this.options.btnOkIcon)},Confirmation.prototype.getBtnCancelClass=function(){return this.$element.data("btnCancelClass")||("function"==typeof this.options.btnCancelClass?this.options.btnCancelClass.call(this,this.$element):this.options.btnCancelClass)},Confirmation.prototype.getBtnCancelLabel=function(){return this.$element.data("btnCancelLabel")||("function"==typeof this.options.btnCancelLabel?this.options.btnCancelLabel.call(this,this.$element):this.options.btnCancelLabel)},Confirmation.prototype.getBtnCancelIcon=function(){return this.$element.data("btnCancelIcon")||("function"==typeof this.options.btnCancelIcon?this.options.btnCancelIcon.call(this,this.$element):this.options.btnCancelIcon)},Confirmation.prototype.getTitle=function(){return this.$element.data("confirmation-title")||this.$element.data("title")||this.$element.attr("title")||("function"==typeof this.options.title?this.options.title.call(this,this.$element):this.options.title)},Confirmation.prototype.getHref=function(){return this.$element.data("href")||this.$element.attr("href")||("function"==typeof this.options.href?this.options.href.call(this,this.$element):this.options.href)},Confirmation.prototype.getTarget=function(){return this.$element.data("target")||this.$element.attr("target")||("function"==typeof this.options.target?this.options.target.call(this,this.$element):this.options.target)},Confirmation.prototype.isPopout=function(){var t=this.$element.data("popout")||("function"==typeof this.options.popout?this.options.popout.call(this,this.$element):this.options.popout);return"false"==t&&(t=!1),t},Confirmation.prototype.runCallback=function(callback,event,element){"function"==typeof callback?callback.call(this,event,element):"string"==typeof callback&&eval(callback)};var old=$.fn.confirmation;$.fn.confirmation=function(t){var n=this;return this.each(function(){var o=$(this),e=o.data("bs.confirmation"),i="object"==typeof t&&t;i=i||{},i.all_selector=n.selector,(e||"destroy"!=t)&&(e||o.data("bs.confirmation",e=new Confirmation(this,i)),"string"==typeof t&&e[t]())})},$.fn.confirmation.Constructor=Confirmation,$.fn.confirmation.noConflict=function(){return $.fn.confirmation=old,this}}(jQuery);