From 88e1f02c1a250dae7b8dabeeaf9f6209f4c84942 Mon Sep 17 00:00:00 2001 From: Chad Kieffer Date: Tue, 26 May 2009 03:59:35 +0000 Subject: Split out re-used JavaScript for common functions (messages, valign), panel toggle, and forms to external files. --- lib/gallery.panel.js | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 lib/gallery.panel.js (limited to 'lib/gallery.panel.js') diff --git a/lib/gallery.panel.js b/lib/gallery.panel.js new file mode 100644 index 00000000..6ac50615 --- /dev/null +++ b/lib/gallery.panel.js @@ -0,0 +1,64 @@ +/** + * Fire togglePanel() and prevent links from opening + * @see openDialog() + */ +function handlePanelEvent(event) { + togglePanel(event.currentTarget); + event.preventDefault(); +} + +function togglePanel(element, on_success) { + var parent = $(element).parent().parent(); + var sHref = $(element).attr("href"); + var parentClass = $(parent).attr("class"); + var ePanel = ""; + + if ($("#gPanel").length) { + $("#gPanel").slideUp("slow"); + $("#gPanel *").remove(); + $("#gPanel").remove(); + if ($(element).attr("orig_text")) { + $(element).children(".gButtonText").text($(element).attr("orig_text")); + } + console.log("Removing existing #gPanel"); + //togglePanel(element, on_success); + } else { + console.log("Adding #gPanel"); + $(parent).after(ePanel); + //showLoading("#here"); + $("#gPanel td").html(sHref); + $("#gPanel").addClass(parentClass).show().slideDown("slow"); + $.get(sHref, function(data) { + $("#gPanel td").html(data); + ajaxify_panel = function() { + $("#gPanel td form").ajaxForm({ + dataType: "json", + success: function(data) { + if (data.form) { + $("#gPanel td form").replaceWith(data.form); + ajaxify_panel(); + } + if (data.result == "success") { + if (on_success) { + on_success(); + } else if (data.location) { + window.location = data.location; + } else { + window.location.reload(); + } + } + } + }); + if ($("#gPanel td").hasClass("gLoadingLarge")) { + showLoading("#gPanel td"); + } + }; + ajaxify_panel(); + if ($(element).attr("open_text")) { + $(element).attr("orig_text", $(element).children(".gButtonText").text()); + $(element).children(".gButtonText").text($(element).attr("open_text")); + } + }); + } + return false; +} -- cgit v1.2.3