Add the ability to override the confirm function

This commit is contained in:
Samuel Georges 2014-12-15 17:48:59 +11:00
parent 3d903191ee
commit 986b3a95a8
1 changed files with 21 additions and 1 deletions

View File

@ -32,11 +32,31 @@ if (window.jQuery === undefined)
var isUnloading = false
$(window).on('beforeunload', function() { isUnloading = true })
/*
* Custom function, requests confirmation from the user
*/
function handleConfirmMessage(message) {
var _event = jQuery.Event('ajaxConfirmMessage')
_event.promise = $.Deferred()
if ($(window).triggerHandler(_event, [message]) !== undefined) {
_event.promise.done(function(){
options.confirm = null
new Request(element, handler, options)
})
return false
}
if (_event.isDefaultPrevented()) return
if (message) return confirm(message)
}
/*
* Initiate request
*/
if (options.confirm !== undefined && options.confirm.length && !confirm(options.confirm))
if (options.confirm && !handleConfirmMessage(options.confirm))
return
var