diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gallery.common.js | 30 | ||||
-rw-r--r-- | lib/gallery.form.js | 42 | ||||
-rw-r--r-- | lib/gallery.panel.js | 64 |
3 files changed, 136 insertions, 0 deletions
diff --git a/lib/gallery.common.js b/lib/gallery.common.js new file mode 100644 index 00000000..bb2e75a2 --- /dev/null +++ b/lib/gallery.common.js @@ -0,0 +1,30 @@ +/** + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +(function () { + $.fn.showMessage = function(message) { + return this.each(function(i){ + $(this).effect("highlight", {"color": "white"}, 3000); + $(this).animate({opacity: 1.0}, 6000); + $(this).fadeOut("slow"); + }); + }; +})(jQuery); + +// Vertically align a block element's content +(function () { + $.fn.vAlign = function(container) { + return this.each(function(i){ + if (container == null) { + container = 'div'; + } + $(this).html("<" + container + ">" + $(this).html() + "</" + container + ">"); + var el = $(this).children(container + ":first"); + var elh = $(el).height(); + var ph = $(this).height(); + var nh = (ph - elh) / 2; + $(el).css('margin-top', nh); + }); + }; +})(jQuery); diff --git a/lib/gallery.form.js b/lib/gallery.form.js new file mode 100644 index 00000000..e69be326 --- /dev/null +++ b/lib/gallery.form.js @@ -0,0 +1,42 @@ +/** + * Handle initialization of all short forms + * + * @param shortForms array Array of short form IDs + */ +function handleShortFormEvent(shortForms) { + for (var i in shortForms) { + shortFormInit(shortForms[i]); + } +} + +/** + * Initialize a short form. Short forms may contain only one text input. + * + * @param formID string The form's ID, including # + */ +function shortFormInit(formID) { + $(formID).addClass("gShortForm"); + + // Get the input ID and it's label text + var labelValue = $(formID + " label:first").html(); + var inputID = "#" + $(formID + " input[type=text]:first").attr("id"); + + // Set the input value equal to label text + if ($(inputID).val() == "") { + $(inputID).val(labelValue); + } + + // Attach event listeners to the input + $(inputID).bind("focus blur", function(e){ + var eLabelVal = $(this).siblings("label").html(); + var eInputVal = $(this).val(); + + // Empty input value if it equals it's label + if (eLabelVal == eInputVal) { + $(this).val(""); + // Reset the input value if it's empty + } else if ($(this).val() == "") { + $(this).val(eLabelVal); + } + }); +} 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 = "<tr id=\"gPanel\"><td colspan=\"6\"></td></tr>"; + + 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; +} |