Last active
February 4, 2023 09:10
-
-
Save TOMeeeek/6375100 to your computer and use it in GitHub Desktop.
Confirm dialog for Bootstrap - use nette.ajax.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function ($, undefined) { | |
$.nette.ext({ | |
load: function () { | |
$('[data-nette-confirm]').off('click.nette').click(function (event) { | |
// remove old confirm dialog | |
$("#dConfirmMaster").remove(); | |
var obj = this; | |
event.preventDefault(); | |
event.stopImmediatePropagation(); | |
// modal dialog skeleton | |
$("<div class='modal fade' id='dConfirmMaster' tabindex='-1' role='dialog' aria-labelledby='confirmModalLabel' aria-hidden='true'>" + | |
"<div class='modal-dialog'>" + | |
" <div class='modal-content' id='dConfirm'>" + | |
" <div class='modal-header'>" + | |
" <button type='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button>" + | |
" <h4 class='modal-title' id='confirmModalLabel'>" + $(obj).data('nette-confirm-title') + "</h4>" + | |
" </div>" + | |
" <div class='modal-body'>" + | |
$(obj).data('nette-confirm-text') + | |
" </div>" + | |
" <div class='modal-footer'>" + | |
" <button type='button' id='dConfirmOk' class='btn " + $(obj).data('nette-confirm-ok-class') + "' data-dismiss='modal'>Ano</button>" + | |
" <button type='button' id='dConfirmCancel' class='btn " + $(obj).data('nette-confirm-cancel-class') + "' data-dismiss='modal'>Ne</button>" + | |
" </div>" + | |
" </div>" + | |
"</div>" + | |
"</div>").appendTo('body'); | |
if ($(obj).data('nette-confirm-ok-text')) { | |
$('#dConfirmOk').html($(obj).data('nette-confirm-ok-text')); | |
} | |
if ($(obj).data('nette-confirm-cancel-text')) { | |
$('#dConfirmCancel').html($(obj).data('nette-confirm-cancel-text')); | |
} | |
$('#dConfirmOk').click(function () { | |
var tagName = $(obj).prop("tagName"); | |
if (tagName == 'INPUT') { | |
var form = $(obj).closest('form'); | |
form.submit(); | |
} else { | |
if ($(obj).hasClass('ajax') || $(obj).data('ajax') == 'on') { | |
$.nette.ajax({ | |
url: obj.href | |
}); | |
} else { | |
document.location = obj.href; | |
} | |
} | |
}); | |
$('#dConfirmMaster').modal('show'); | |
return false; | |
}); | |
} | |
}); | |
})(jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<a | |
data-nette-confirm="modal" | |
data-nette-confirm-title="Confirm dialog" | |
data-nette-confirm-text="Delete?" | |
data-nette-confirm-ok-class="btn-danger" | |
data-nette-confirm-ok-text="Yes" | |
data-nette-confirm-cancel-class="btn-success" | |
data-nette-confirm-cancel-text="No" | |
class="btn btn-danger ajax" | |
n:href="deleteHandle! $id">Delete</a> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment