[enh] Implements bootstrap modal as confirm dialog.

This commit is contained in:
opi 2014-11-17 13:59:28 +01:00
parent 79542a4b13
commit d1433ab4b6
6 changed files with 97 additions and 12 deletions

View file

@ -209,24 +209,51 @@ body {
* *
*/ */
#popup { #modal {
.modal; .modal;
.fade; .fade;
overflow-y: auto; overflow-y: auto;
& > div { & > div {
.modal-dialog; .modal-dialog;
& > div {
.modal-content; .modal-content;
} }
#popup-title {
.modal-header;
.modal-title;
} }
#popup-body {
header {
.modal-header;
.title {
.modal-title;
font-weight: bold;
text-transform: uppercase;
margin: 0;
}
}
&.no-title header {display: none;}
.content {
.modal-body; .modal-body;
} }
footer {
.modal-footer;
button {
.btn;
&#modal-cancel {.btn-link;}
&#modal-confirm {.btn-primary;}
} }
}
}
@media (min-width: 768px) {
#modal > div > div {
width: 600px;
margin: 30px auto;
}
}
/* /*
* Various styles * Various styles

4
css/style.min.css vendored

File diff suppressed because one or more lines are too long

View file

@ -40,10 +40,23 @@
</div> </div>
<div id="popup" role="dialog"><div> <div id="modal" tabindex="-1" role="dialog" aria-labelledby="modalLabel" aria-hidden="true">
<h2 id="popup-title"></h2> <div><div>
<div id="popup-body"></div> <header>
<button type="button" class="close" data-dismiss="modal">
<span aria-hidden="true">&times;</span>
<span class="sr-only" data-y18n="close">Close</span>
</button>
<h4 class="title" id="modalLabel"></h4>
</header>
<div class="content"></div>
<footer>
<button type="button" id="modal-cancel" data-action="cancel" data-y18n="cancel">Cancel</button>
<button type="button" id="modal-confirm" data-action="confirm" data-y18n="ok">OK</button>
</footer>
</div></div> </div></div>
</div>
<script type="text/javascript" src="js/vendor/jquery-1.10.1.min.js"></script> <script type="text/javascript" src="js/vendor/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="js/vendor/handlebars-v1.3.0.js"></script> <script type="text/javascript" src="js/vendor/handlebars-v1.3.0.js"></script>

View file

@ -228,6 +228,7 @@ app = Sammy('#main', function (sam) {
loaded = true; loaded = true;
$('div.loader').remove(); $('div.loader').remove();
$('#modal').modal('hide');
if (enableSlide) { if (enableSlide) {
function leSwap() { function leSwap() {
@ -279,6 +280,48 @@ app = Sammy('#main', function (sam) {
} }
}, },
confirm: function(title, content, confirmCallback, cancelCallback) {
// Default callbacks
confirmCallback = typeof confirmCallback !== 'undefined' ? confirmCallback : function() {};
cancelCallback = typeof cancelCallback !== 'undefined' ? cancelCallback : function() {};
// Get modal element
box = $('#modal');
// Modal title
if (typeof title === 'string' && title.length) {
$('.title', box).html(title);
}
else {
box.addClass('no-title');
}
// Modal content
$('.content', box).html(content);
// Handle buttons
$('footer button', box)
.click(function(e){
e.preventDefault();
// Reset & Hide modal
box
.removeClass('no-title')
.modal('hide');
// Do corresponding callback
if ($(this).data('action') == 'confirm') {
confirmCallback();
}
else {
cancelCallback();
}
});
// Show modal
return box.modal('show');
},
arraySortById: function(arr) { arraySortById: function(arr) {
arr.sort(function(a, b){ arr.sort(function(a, b){
if (a.id > b.id) { if (a.id > b.id) {

View file

@ -37,6 +37,7 @@
"both" : "Both", "both" : "Both",
"home" : "Home", "home" : "Home",
"read_more" : "Read more", "read_more" : "Read more",
"cancel" : "Cancel",
"installing" : "Installing", "installing" : "Installing",
"installed" : "Installed", "installed" : "Installed",

View file

@ -37,6 +37,7 @@
"both" : "Les deux", "both" : "Les deux",
"home" : "Accueil", "home" : "Accueil",
"read_more" : "En savoir plus", "read_more" : "En savoir plus",
"cancel" : "Annuler",
"installing" : "Installation", "installing" : "Installation",
"installed" : "Installé", "installed" : "Installé",