-
-
Save vojtech-dobes/bc3fdad7405cef31aced to your computer and use it in GitHub Desktop.
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
/** | |
* Confirm dialog plugin | |
* | |
* @copyright Copyright (c) 2012 Jan Červený | |
* @license BSD | |
* @link confirmdialog.redsoft.cz | |
* @version 1.0 | |
*/ | |
(function ($, undefined) { | |
$.nette.ext({ | |
load: function () { | |
$('[data-confirm]').click(function (event) { | |
var obj = this; | |
var $obj = $(this); | |
var dialog = $('<div class="modal fade"></div>'); | |
var header = $('<div>', { | |
'class': 'modal-header', | |
html: '<a class="close" data-dismiss="modal">×</a>' | |
}).appendTo(dialog); | |
var body = $('<div>', { | |
'class': "modal-body", | |
html: $obj.data('confirm-text') | |
}).appendTo(dialog); | |
var footer = $('<div class="modal-footer"></div>').appendTo(dialog); | |
header.append($('<h3>', { | |
html: $obj.data('confirm-title') | |
})); | |
var ok = $("<a class='btn " + $obj.data('confirm-ok-class') + "' data-dismiss='modal'>Ano</a>").appendTo(footer); | |
var cancel = $("<a class='btn " + $obj.data('confirm-cancel-class') + "' data-dismiss='modal'>Ne</a>").appendTo(footer); | |
if ($obj.data('confirm-header-class')) { | |
header.addClass($obj.data('confirm-header-class')); | |
} | |
if ($obj.data('confirm-ok-text')) { | |
ok.html($obj.data('confirm-ok-text')); | |
} | |
if ($obj.data('confirm-cancel-text')) { | |
cancel.html($obj.data('confirm-cancel-text')); | |
} | |
ok.on('click', function () { | |
if ($obj.is('input')) { | |
$obj.closest('form').submit(); | |
} else { | |
if ($obj.data('ajax') == 'on') { | |
$.nette.ajax({ | |
url: obj.href | |
}); | |
} else { | |
document.location = obj.href; | |
} | |
} | |
}); | |
dialog.on('hidden', function () { | |
dialog.remove(); | |
}); | |
dialog.appendTo('body'); | |
dialog.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-confirm="modal" | |
data-confirm-title="Confirm" | |
data-confirm-text="Delete?" | |
data-confirm-ok-class="btn-danger" | |
data-confirm-ok-text="Delete" | |
data-confirm-cancel-class="btn-success" | |
data-confirm-cancel-text="Cancel" | |
class="btn btn-danger btn-mini pull-right" | |
data-ajax="on" | |
n:href="deleteHandle! $id">Delete</a> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment