transmet/js/jquery.confirm.min.js

14 lines
2.5 KiB
JavaScript
Raw Normal View History

/*!
* jquery.confirm
*
* @version 2.3.1
*
* @author My C-Labs
* @author Matthieu Napoli <matthieu@mnapoli.fr>
* @author Russel Vela
* @author Marcus Schwarz <msspamfang@gmx.de>
*
* @license MIT
* @url http://myclabs.github.io/jquery.confirm/
*/
(function($){$.fn.confirm=function(options){if(typeof options==="undefined"){options={}}this.click(function(e){e.preventDefault();var newOptions=$.extend({button:$(this)},options);$.confirm(newOptions,e)});return this};$.confirm=function(options,e){if($(".confirmation-modal").length>0)return;var dataOptions={};if(options.button){var dataOptionsMapping={title:"title",text:"text","confirm-button":"confirmButton","cancel-button":"cancelButton","confirm-button-class":"confirmButtonClass"};$.each(dataOptionsMapping,function(attributeName,optionName){var value=options.button.data(attributeName);if(value){dataOptions[optionName]=value}})}var settings=$.extend({},$.confirm.options,{confirm:function(){var url=e&&("string"===typeof e&&e||e.currentTarget&&e.currentTarget.attributes["href"].value);if(url){if(options.post){var form=$('<form method="post" class="hide" action="'+url+'"></form>');$("body").append(form);form.submit()}else{window.location=url}}},cancel:function(o){},button:null},dataOptions,options);var modalHeader="";if(settings.title!==""){modalHeader="<div class=modal-header>"+'<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>'+'<h4 class="modal-title">'+settings.title+"</h4>"+"</div>"}var modalHTML='<div class="confirmation-modal modal fade" tabindex="-1" role="dialog">'+'<div class="modal-dialog">'+'<div class="modal-content">'+modalHeader+'<div class="modal-body">'+settings.text+"</div>"+'<div class="modal-footer">'+'<button class="confirm btn '+settings.confirmButtonClass+'" type="button" data-dismiss="modal">'+settings.confirmButton+"</button>"+'<button class="cancel btn btn-default" type="button" data-dismiss="modal">'+settings.cancelButton+"</div>"+"</div>"+"</div>"+"</div>"+"</div>";var modal=$(modalHTML);modal.on("shown.bs.modal",function(){modal.find(".btn-primary:first").focus()});modal.on("hidden.bs.modal",function(){modal.remove()});modal.find(".confirm").click(function(){settings.confirm(settings.button)});modal.find(".cancel").click(function(){settings.cancel(settings.button)});$("body").append(modal);modal.modal("show")};$.confirm.options={text:"Are you sure?",title:"",confirmButton:"Yes",cancelButton:"Cancel",post:false,confirmButtonClass:"btn-primary"}})(jQuery);