From a63502b3c69b59b6246f66d6e7a6f8558033546c Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 6 Jan 2009 08:33:39 +0000 Subject: Refactor the way that dialogs work: 1) Get rid of the resizing behavior; create the dialog in the right place and then show it. 2) Grab the fieldset legend and put it into the title of the dialog, so that we don't have to use title="" params in anchors. 3) Stop using fixed buttons and let the form define its own buttons. 4) Stop suppressing all form buttons. --- lib/gallery.dialog.js | 78 +++++++++++++++++++++++++-------------------------- 1 file changed, 38 insertions(+), 40 deletions(-) (limited to 'lib/gallery.dialog.js') diff --git a/lib/gallery.dialog.js b/lib/gallery.dialog.js index 10ec412a..70f577c5 100644 --- a/lib/gallery.dialog.js +++ b/lib/gallery.dialog.js @@ -26,63 +26,61 @@ function openDialog(element, on_success) { var eDialog = '
'; $("body").append(eDialog); - var buttons = {}; - buttons["Submit"] = function() { - $("#gDialog form").ajaxForm({ - dataType: "json", - success: function(data) { - if (data.form) { - $("#gDialog form").replaceWith(data.form); - } - if (data.result == "success") { - $("#gDialog").dialog("close"); - if (on_success) { - on_success(); - } else if (data.location) { - window.location = data.location; - } else { - window.location.reload(); - } - } - } - }).submit(); - }; - buttons["Reset"] = function() { - $("#gDialog form").resetForm(); - }; - $("#gDialog").dialog({ + autoOpen: false, autoResize: false, draggable: true, - height: $(window).height() - 40, + height: "auto", + width: "auto", modal: true, overlay: { opacity: 0.7, background: "black" }, resizable: true, - title: sTitle, - width: 600, - buttons: buttons, close: function (event, ui) { - $("#gDialog").dialog('destroy').remove(); + $("#gDialog").dialog("destroy").remove(); } }); loading("#gDialog"); - $(".ui-dialog-content").height(400); $("#gDialog").html(sHref); $.get(sHref, function(data) { loading("#gDialog"); - $("#gDialog").html(data).hide().fadeIn(); - // Get dialog and it's contents' height - var contentHt = $(".ui-dialog-titlebar").height() - + $(".ui-dialog-content form").height() - + $(".ui-dialog-buttonpane").height() - + 60; - // Resize height if content's shorter than dialog - if (contentHt < $("#gDialog").data("height.dialog")) { - $(".ui-dialog").animate({height: contentHt}); + $("#gDialog").html(data); + var parent = $("#gDialog").parent().parent(); + parent.css("opacity", "0.0"); + $("#gDialog").dialog("open"); + $("#ui-dialog-title-gDialog").html($("#gDialog fieldset legend:eq(0)").html()); + if (parent.width() < 400) { + parent.css("width", 400); + } + parent.css({"top": $(window).height() / 2 - parent.height() / 2, + "left": $(window).width() / 2 - parent.width() / 2, + "opacity": "1.0" + }); + + ajaxify_dialog = function() { + $("#gDialog form").ajaxForm({ + dataType: "json", + success: function(data) { + if (data.form) { + $("#gDialog form").replaceWith(data.form); + ajaxify_dialog(); + } + if (data.result == "success") { + $("#gDialog").dialog("close"); + if (on_success) { + on_success(); + } else if (data.location) { + window.location = data.location; + } else { + window.location.reload(); + } + } + } + }); }; + ajaxify_dialog(); }); return false; } -- cgit v1.2.3