From 2f4069ab9948acec08b4a26527ae9261f4ca5234 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 14 Jan 2014 13:50:13 +0100 Subject: [PATCH] =?utf8?q?kivi.popup=5Fdialog():=20Unterst=C3=BCtzung=20f?= =?utf8?q?=C3=BCr=20bereits=20existierende=20DIVs?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Damit muss kein AJAX-Call mehr gemacht werden, sondern man kann den DIV initial versteckt rendern und dann beliebig oft anzeigen (öffnen)/verstecken (schließen). --- js/kivi.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/js/kivi.js b/js/kivi.js index 2c2811027..81a978fc1 100644 --- a/js/kivi.js +++ b/js/kivi.js @@ -59,11 +59,16 @@ namespace("kivi", function(ns) { return namespace(parts[1])[ parts[2] ]; }; - // Open a modal jQuery UI popup dialog. The content is loaded via AJAX. + // Open a modal jQuery UI popup dialog. The content can be either + // loaded via AJAX (if the parameter 'url' is given) or simply + // displayed if it exists in the DOM already (referenced via + // 'id'). If an existing DOM div should be used then the element + // won't be removed upon closing the dialog which allows re-opening + // it later on. // // Parameters: // - id: dialog DIV ID (optional; defaults to 'jqueryui_popup_dialog') - // - url, data, type: passed as the first three arguments to the $.ajax() call + // - url, data, type: passed as the first three arguments to the $.ajax() call if an AJAX call is made, otherwise ignored. // - dialog: an optional object of options passed to the $.dialog() call ns.popup_dialog = function(params) { var dialog; @@ -79,9 +84,15 @@ namespace("kivi", function(ns) { // User supplied options: params.dialog || { }, { // Options that must not be changed: - close: function(event, ui) { dialog.remove(); } + close: function(event, ui) { if (params.url) dialog.remove(); else dialog.dialog('close'); } }); + if (!params.url) { + // Use existing DOM element and show it. No AJAX call. + dialog = $('#' + id).dialog(dialog_params); + return true; + } + $('#' + id).remove(); dialog = $('').appendTo('body'); -- 2.20.1