From 0c118fb984efa709ba0ccc49400f3c0c4a7e087a Mon Sep 17 00:00:00 2001 From: Awilum Date: Fri, 3 Jan 2014 02:17:53 +0200 Subject: [PATCH] bootstrap-confirm.js - Added --- public/assets/js/bootstrap-confirm.js | 90 +++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 public/assets/js/bootstrap-confirm.js diff --git a/public/assets/js/bootstrap-confirm.js b/public/assets/js/bootstrap-confirm.js new file mode 100644 index 0000000..812042d --- /dev/null +++ b/public/assets/js/bootstrap-confirm.js @@ -0,0 +1,90 @@ +(function($) { + $.fn.confirmModal = function(opts) + { + var body = $('body'); + var defaultOptions = { + confirmTitle : 'Please confirm', + confirmMessage : 'Are you sure you want to perform this action ?', + confirmOk : 'Yes', + confirmCancel : 'Cancel', + confirmDirection : 'rtl', + confirmStyle : 'primary', + confirmCallback : defaultCallback + }; + var options = $.extend(defaultOptions, opts); + var time = Date.now(); + + var headModalTemplate = + '' + ; + + return this.each(function(index) + { + var confirmLink = $(this); + var targetData = confirmLink.data(); + + var currentOptions = $.extend(options, targetData); + + var modalId = "confirmModal" + parseInt(time + index); + var modalTemplate = headModalTemplate; + var buttonTemplate = + '' + + '' + ; + + if(options.confirmDirection == 'ltr') + { + buttonTemplate = + '' + + '' + ; + } + + modalTemplate = modalTemplate. + replace('#buttonTemplate#', buttonTemplate). + replace('#modalId#', modalId). + replace('#AriaLabel#', options.confirmTitle). + replace('#Heading#', options.confirmTitle). + replace('#Body#', options.confirmMessage). + replace('#Ok#', options.confirmOk). + replace('#Cancel#', options.confirmCancel). + replace('#Style#', options.confirmStyle) + ; + + body.append(modalTemplate); + + var confirmModal = $('#' + modalId); + + confirmLink.on('click', function(modalEvent) + { + modalEvent.preventDefault(); + confirmModal.modal('show'); + + $('button[data-dismiss="ok"]', confirmModal).on('click', function(event) { + confirmModal.modal('hide'); + options.confirmCallback(confirmLink); + }); + }); + }); + + function defaultCallback(target) + { + window.location = $(target).attr('href'); + } + }; +})(jQuery); \ No newline at end of file