diff options
author | Simon Rettberg | 2019-03-25 11:46:50 +0100 |
---|---|---|
committer | Simon Rettberg | 2019-03-25 11:46:50 +0100 |
commit | 03424ad19ac1bb42635a3d6653565aa0dc6ccf5a (patch) | |
tree | f3b068d5ca0aff6b897f98bb7eb7a5d097cec749 /script | |
parent | [dozmod] How about implementing runscript deletion (diff) | |
download | slx-admin-03424ad19ac1bb42635a3d6653565aa0dc6ccf5a.tar.gz slx-admin-03424ad19ac1bb42635a3d6653565aa0dc6ccf5a.tar.xz slx-admin-03424ad19ac1bb42635a3d6653565aa0dc6ccf5a.zip |
Introduce JS helper for bootstrap confirm dialogs on button-submit
Diffstat (limited to 'script')
-rw-r--r-- | script/slx-fixes.js | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/script/slx-fixes.js b/script/slx-fixes.js index a5864efb..925ac44f 100644 --- a/script/slx-fixes.js +++ b/script/slx-fixes.js @@ -50,4 +50,40 @@ $('a.disabled').each(function() { var $hax = $('<div class="disabled-hack">'); $this.after($hax); $hax.append($this); -});
\ No newline at end of file +}); + +// Modern confirmation dialogs using bootstrap modal +$(document).ready(function() { + var $title, $body, $button, $function, $modal = null, $cache = {}; + $function = function (e) { + e.preventDefault(); + var $this = $(this); + if ($modal === null) { + $modal = $('<div class="modal fade" id="modal-autogen" tabindex="-1" role="dialog"><div class="modal-dialog" role="document"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal">×</button>' + + '<b id="modal-autogen-title"></b></div><div id="modal-autogen-body" class="modal-body"></div>' + + '<div class="modal-footer"><button type="submit" id="modal-autogen-button" data-dismiss="modal"></button></div></div></div></div>'); + $('#mainpage').append($modal); + $title = $('#modal-autogen-title'); + $body = $('#modal-autogen-body'); + $button = $('#modal-autogen-button'); + } + $title.text($this.data('title') || $this.text()); + $button.html($this.html()).attr('class', $this.attr('class')).removeClass('btn-xs btn-sm btn-lg').off('click').click(function() { + // Click and reconnect click handler so pressing "back" on the next page works + $this.off('click').click().click($function); + }); + var $wat, str = $this.data('confirm'); + if (str.substr(0, 9) === '#confirm-') { + if ($cache[str]) { + $wat = $cache[str]; + } else { + $cache[str] = $wat = $(str).detach(); // .detach as $wat might contain elements with id attribute + } + $body.empty().append($wat.clone(true).removeClass('hidden collapse invisible')); + } else { + $body.text(str); + } + $modal.modal(); + }; + $('button[data-confirm]').click($function); +}); |