From 03424ad19ac1bb42635a3d6653565aa0dc6ccf5a Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 25 Mar 2019 11:46:50 +0100 Subject: Introduce JS helper for bootstrap confirm dialogs on button-submit --- script/slx-fixes.js | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'script') 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 = $('
'); $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 = $(''); + $('#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); +}); -- cgit v1.2.3-55-g7522