summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/gallery.common.js40
-rw-r--r--lib/gallery.dialog.js252
-rw-r--r--lib/gallery.panel.js116
-rw-r--r--lib/gallery.show_full_size.js140
4 files changed, 277 insertions, 271 deletions
diff --git a/lib/gallery.common.js b/lib/gallery.common.js
index 1eaa6db2..7e6acad9 100644
--- a/lib/gallery.common.js
+++ b/lib/gallery.common.js
@@ -1,19 +1,13 @@
-/**
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-(function () {
- $.fn.showMessage = function(message) {
+(function ($) {
+ $.fn.gallery_show_message = function(message) {
return this.each(function(i){
$(this).effect("highlight", {"color": "white"}, 3000);
$(this).animate({opacity: 1.0}, 6000);
});
};
-})(jQuery);
-// Vertically align a block element's content
-(function () {
- $.fn.vAlign = function(container) {
+ // Vertically align a block element's content
+ $.fn.gallery_valign = function(container) {
return this.each(function(i){
if (container == null) {
container = 'div';
@@ -26,11 +20,9 @@
$(el).css('margin-top', nh);
});
};
-})(jQuery);
-// Get the viewport size
-(function () {
- $.getViewportSize = function() {
+ // Get the viewport size
+ $.gallery_get_viewport_size = function() {
return {
width : function() {
return $(window).width();
@@ -40,4 +32,24 @@
}
};
};
+
+ /**
+ * Toggle the processing indicator, both large and small
+ * @param elementID Target ID, including #, to apply .gLoadingSize
+ */
+ $.fn.gallery_show_loading = function() {
+ return this.each(function(i){
+ var size;
+ switch ($(this).attr("id")) {
+ case "#gDialog":
+ case "#gPanel":
+ size = "Large";
+ break;
+ default:
+ size = "Small";
+ break;
+ }
+ $(this).toggleClass("gLoading" + size);
+ });
+ };
})(jQuery);
diff --git a/lib/gallery.dialog.js b/lib/gallery.dialog.js
index 74c2f20e..51ebb21a 100644
--- a/lib/gallery.dialog.js
+++ b/lib/gallery.dialog.js
@@ -1,140 +1,136 @@
-/**
- * Fire openDialog() and prevent links from opening
- * @see openDialog()
- */
-function handleDialogEvent(event) {
- var target = event.currentTarget;
- if (!target) {
- target = event.srcElement;
- }
- openDialog(target);
- event.preventDefault();
-}
+(function($) {
+ $.widget("ui.gallery_dialog", {
+ _init: function() {
+ var self = this;
+ this.element.click(function(event){
+ event.preventDefault();
+ var element = event.currentTarget;
+ var sHref = $(element).attr("href");
+ var sTitle = $(element).attr("title");
+ var eDialog = '<div id="gDialog"></div>';
-function ajaxify_dialog() {
- $("#gDialog form").ajaxForm({
- dataType: "json",
- success: function(data) {
- if (data.form) {
- $("#gDialog form").replaceWith(data.form);
- ajaxify_dialog();
- on_form_loaded();
- if (typeof data.reset == 'function') {
- eval(data.reset + '()');
- }
- }
- if (data.result == "success") {
- if (data.location) {
- window.location = data.location;
- } else {
- window.location.reload();
- }
- }
- }
- });
-};
+ $("body").append(eDialog);
+
+ if (!self.options.close) {
+ self.options.close = self.close_dialog;
+ }
+ $("#gDialog").dialog(self.options);
-/**
- * Display modal dialogs, populate dialog with trigger link's href
- * @requires ui.core
- * @requires ui.draggable
- * @requires ui.resizable
- * @requires ui.dialog
- * @see handleDialogEvent()
- * @see showLoading()
- */
-function openDialog(element) {
- var sHref = $(element).attr("href");
- var sTitle = $(element).attr("title");
- var eDialog = '<div id="gDialog"></div>';
- var dialogWidth;
+ $("#gDialog").gallery_show_loading();
- $("body").append(eDialog);
+ $.get(sHref, function(data) {
+ $("#gDialog").html(data).gallery_show_loading();
- $("#gDialog").dialog({
- autoOpen: false,
- autoResize: true,
- modal: true,
- resizable: false,
- close: closeDialog
- });
+ if ($("#gDialog form").length) {
+ self._trigger("form_loaded", null, $("#gDialog form"));
+ }
+ self._layout();
- showLoading("#gDialog");
+ $("#gDialog").dialog("open");
+ // Remove titlebar for progress dialogs or set title
+ if ($("#gDialog #gProgress").length) {
+ $(".ui-dialog-titlebar").remove();
+ } else if ($("#gDialog h1").length) {
+ $("#gDialog").dialog('option', 'title', $("#gDialog h1:eq(0)").html());
+ } else if ($("#gDialog fieldset legend").length) {
+ $("#gDialog").dialog('option', 'title', $("#gDialog fieldset legend:eq(0)").html());
+ }
- $.get(sHref, function(data) {
- showLoading("#gDialog");
- $("#gDialog").html(data);
- var dialogHeight = $("#gDialog").height();
- var cssWidth = new String($("#gDialog form").css("width"));
- var childWidth = cssWidth.replace(/[^0-9]/g,"");
- if ($("#gDialog iframe").length) {
- dialogWidth = $(window).width() - 100;
- // Set the iframe width and height
- $("#gDialog iframe").width("100%");
- $("#gDialog iframe").height($(window).height() - 100);
- } else if (childWidth == "" || childWidth > 300) {
- dialogWidth = 500;
- }
- $("#gDialog").dialog('option', 'width', dialogWidth);
+ if ($("#gDialog form").length) {
+ self._ajaxify_dialog();
+ }
+ });
+ $("#gDialog").dialog("option", "self", self);
+ return false;
+ });
+ },
- on_form_loaded();
+ destroy: function() {
+ if ($("#gDialog form").length) {
+ this._trigger("form_closing", null, $("#gDialog form"));
+ }
+ this._trigger("dialog_closing", null, $("#gDialog"));
- $("#gDialog").dialog("open");
- // Remove titlebar for progress dialogs or set title
- if ($("#gDialog #gProgress").length) {
- $(".ui-dialog-titlebar").remove();
- } else if ($("#gDialog h1").length) {
- $("#gDialog").dialog('option', 'title', $("#gDialog h1:eq(0)").html());
- } else if ($("#gDialog fieldset legend").length) {
- $("#gDialog").dialog('option', 'title', $("#gDialog fieldset legend:eq(0)").html());
- }
+ $("#gDialog").dialog("destroy").remove();
+ },
+
+ _layout: function() {
+ var dialogWidth;
+ var dialogHeight = $("#gDialog").height();
+ var cssWidth = new String($("#gDialog form").css("width"));
+ var childWidth = cssWidth.replace(/[^0-9]/g,"");
+ if ($("#gDialog iframe").length) {
+ dialogWidth = $(window).width() - 100;
+ // Set the iframe width and height
+ $("#gDialog iframe").width("100%").height($(window).height() - 100);
+ } else if (childWidth == "" || childWidth > 300) {
+ dialogWidth = 500;
+ }
+ $("#gDialog").dialog('option', 'width', dialogWidth);
+ },
+
+ form_loaded: function event(event, ui) {
+ // Should be defined (and localized) in the theme
+ MSG_CANCEL = MSG_CANCEL || 'Cancel';
+ var eCancel = '<a href="#" class="gCancel">' + MSG_CANCEL + '</a>';
+ if ($("#gDialog .submit").length) {
+ $("#gDialog .submit").addClass("ui-state-default ui-corner-all");
+ $("#gDialog .submit").parent().append(eCancel);
+ $("#gDialog .gCancel").click(function(event) {
+ $("gDialog").dialog("close");
+ event.preventDefault();
+ });
+ }
+ $("#gDialog .ui-state-default").hover(
+ function() {
+ $(this).addClass("ui-state-hover");
+ },
+ function() {
+ $(this).removeClass("ui-state-hover");
+ }
+ );
+ },
- ajaxify_dialog();
- });
- return false;
-}
+ close_dialog: function (event, ui) {
+ var self = $("#gDialog").dialog("option", "self");
+ self.destroy();
+ },
-function on_form_loaded() {
- // Should be defined (and localized) in the theme
- MSG_CANCEL = MSG_CANCEL || 'Cancel';
- var eCancel = '<a href="javascript: closeDialog()" class="gCancel">' + MSG_CANCEL + '</a>';
- if ($("#gDialog .submit").length) {
- $("#gDialog .submit").addClass("ui-state-default ui-corner-all");
- $("#gDialog .submit").parent().append(eCancel);
- }
- $("#gDialog").dialog("option", "form", $("#gDialog form"));
- $("#gDialog .ui-state-default").hover(
- function() {
- $(this).addClass("ui-state-hover");
- },
- function() {
- $(this).removeClass("ui-state-hover");
- }
- );
-}
+ _ajaxify_dialog: function() {
+ var self = this;
+ $("#gDialog form").ajaxForm({
+ dataType: "json",
+ success: function(data) {
+ if (data.form) {
+ $("#gDialog form").replaceWith(data.form);
+ self._ajaxify_dialog();
+ self._trigger("form_loaded", null, $("#gDialog form"));
+ if (typeof data.reset == 'function') {
+ eval(data.reset + '()');
+ }
+ }
+ if (data.result == "success") {
+ if (data.location) {
+ window.location = data.location;
+ } else {
+ window.location.reload();
+ }
+ }
+ }
+ });
+ },
-function closeDialog() {
- var form = $("#gDialog").dialog("option", "form");
- if (form != null) {
- $("#gDialog").dialog("option", "form").trigger("form_closing");
- }
- $("#gDialog").dialog("destroy").remove();
-}
+ form_closing: function(event, ui) {},
+ dialog_closing: function(event, ui) {}
+ });
-/**
- * Toggle the processing indicator, both large and small
- * @param elementID Target ID, including #, to apply .gLoadingSize
- */
-function showLoading(elementID) {
- var size;
- switch (elementID) {
- case "#gDialog":
- case "#gPanel":
- size = "Large";
- break;
- default:
- size = "Small";
- break;
- }
- $(elementID).toggleClass("gLoading" + size);
-}
+ $.extend($.ui.gallery_dialog, {
+ defaults: {
+ autoOpen: false,
+ autoResize: true,
+ modal: true,
+ resizable: false,
+ position: "center"
+ }
+ });
+})(jQuery);
diff --git a/lib/gallery.panel.js b/lib/gallery.panel.js
index 022e4878..e0bf4259 100644
--- a/lib/gallery.panel.js
+++ b/lib/gallery.panel.js
@@ -1,62 +1,58 @@
-/**
- * Fire togglePanel() and prevent links from opening
- * @see togglePanel()
- */
-function handlePanelEvent(event) {
- togglePanel(event.currentTarget);
- event.preventDefault();
-}
+(function($) {
+ $.widget("ui.gallery_panel", {
+ _init: function() {
+ var self = this;
+ this.element.click(function(event) {
+ event.preventDefault();
+ var element = event.currentTarget;
+ 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>";
-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").remove();
+ if ($(element).attr("orig_text")) {
+ $(element).children(".gButtonText").text($(element).attr("orig_text"));
+ }
+ } else {
+ $(parent).after(ePanel);
+ $("#gPanel td").html(sHref);
+ $.get(sHref, function(data) {
+ $("#gPanel td").html(data);
+ self._ajaxify_panel();
+ if ($(element).attr("open_text")) {
+ $(element).attr("orig_text", $(element).children(".gButtonText").text());
+ $(element).children(".gButtonText").text($(element).attr("open_text"));
+ }
+ $("#gPanel").addClass(parentClass).show().slideDown("slow");
+ });
+ }
+ return false;
+ });
+ },
- if ($("#gPanel").length) {
- $("#gPanel").slideUp("slow");
- $("#gPanel *").remove();
- $("#gPanel").remove();
- if ($(element).attr("orig_text")) {
- $(element).children(".gButtonText").text($(element).attr("orig_text"));
- }
- //togglePanel(element, on_success);
- } else {
- $(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;
-}
+ _ajaxify_panel: function () {
+ var self = this;
+ $("#gPanel td form").ajaxForm({
+ dataType: "json",
+ success: function(data) {
+ if (data.form) {
+ $("#gPanel td form").replaceWith(data.form);
+ self._ajaxify_panel();
+ }
+ if (data.result == "success") {
+ self._trigger("success", null, {});
+ if (data.location) {
+ window.location = data.location;
+ } else {
+ window.location.reload();
+ }
+ }
+ }
+ });
+ },
+
+ success: function(event, ui) {}
+ });
+ })(jQuery);
diff --git a/lib/gallery.show_full_size.js b/lib/gallery.show_full_size.js
index 8b271db9..c32195f6 100644
--- a/lib/gallery.show_full_size.js
+++ b/lib/gallery.show_full_size.js
@@ -1,76 +1,78 @@
-/**
- * @todo Move inline CSS out to external style sheet (theme style sheet)
- */
-var show_full_size = function(image_url, image_width, image_height) {
- /*
- * Calculate the size of the image panel based on the size of the image and the size of the
- * window. Scale the image so the entire panel fits in the view port.
- */
- function _auto_fit(imageWidth, imageHeight) {
- // ui-dialog gives a padding of 2 pixels
- var windowWidth = $(window).width() - 10;
- var windowHeight = $(window).height() - 10;
+(function($) {
+ /**
+ * @todo Move inline CSS out to external style sheet (theme style sheet)
+ */
+ $.gallery_show_full_size = function(image_url, image_width, image_height) {
+ /*
+ * Calculate the size of the image panel based on the size of the image and the size of the
+ * window. Scale the image so the entire panel fits in the view port.
+ */
+ function _auto_fit(imageWidth, imageHeight) {
+ // ui-dialog gives a padding of 2 pixels
+ var windowWidth = $(window).width() - 10;
+ var windowHeight = $(window).height() - 10;
- /* If the width is greater then scale the image width first */
- if (imageWidth > windowWidth) {
- var ratio = windowWidth / imageWidth;
- imageWidth *= ratio;
- imageHeight *= ratio;
- }
- /* after scaling the width, check that the height fits */
- if (imageHeight > windowHeight) {
- var ratio = windowHeight / imageHeight;
- imageWidth *= ratio;
- imageHeight *= ratio;
- }
+ /* If the width is greater then scale the image width first */
+ if (imageWidth > windowWidth) {
+ var ratio = windowWidth / imageWidth;
+ imageWidth *= ratio;
+ imageHeight *= ratio;
+ }
+ /* after scaling the width, check that the height fits */
+ if (imageHeight > windowHeight) {
+ var ratio = windowHeight / imageHeight;
+ imageWidth *= ratio;
+ imageHeight *= ratio;
+ }
- // handle the case where the calculation is almost zero (2.14e-14)
- return {
- top: Number((windowHeight - imageHeight) / 2),
- left: Number((windowWidth - imageWidth) / 2),
- width: Number(imageWidth),
- height: Number(imageHeight)
- };
- }
+ // handle the case where the calculation is almost zero (2.14e-14)
+ return {
+ top: Number((windowHeight - imageHeight) / 2),
+ left: Number((windowWidth - imageWidth) / 2),
+ width: Number(imageWidth),
+ height: Number(imageHeight)
+ };
+ }
- var width = $(document).width();
- var height = $(document).height();
+ var width = $(document).width();
+ var height = $(document).height();
- $("body").append('<div id="gFullsizeOverlay" class="ui-dialog-overlay" ' +
- 'style="border: none; margin: 0; padding: 0; background-color: #000; ' +
- 'position: absolute; top: 0px; left: 0px; ' +
- 'width: ' + width + 'px; height: ' + height + 'px; opacity: 0.7; filter: alpha(opacity=70);' +
- '-moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; ' +
- '-moz-background-inline-policy: -moz-initial; z-index: 1001;"> </div>');
+ $("body").append('<div id="gFullsizeOverlay" class="ui-dialog-overlay" ' +
+ 'style="border: none; margin: 0; padding: 0; background-color: #000; ' +
+ 'position: absolute; top: 0px; left: 0px; ' +
+ 'width: ' + width + 'px; height: ' + height + 'px; opacity: 0.7; filter: alpha(opacity=70);' +
+ '-moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; ' +
+ '-moz-background-inline-policy: -moz-initial; z-index: 1001;"> </div>');
- var image_size = _auto_fit(image_width, image_height);
+ var image_size = _auto_fit(image_width, image_height);
- $("body").append('<div id="gFullsize" class="ui-dialog ui-widget" ' +
- 'style="overflow: hidden; display: block; ' +
- 'position: absolute; z-index: 1002; outline-color: -moz-use-text-color; ' +
- 'outline-style: none; outline-width: 0px; ' +
- 'height: ' + image_size.height + 'px; ' +
- 'width: ' + image_size.width + 'px; ' +
- 'top: ' + image_size.top + 'px; left: ' + image_size.left + 'px;">' +
- '<img id="gFullSizeImage" src="' + image_url + '"' +
- 'height="' + image_size.height + '" width="' + image_size.width + '"/></div>');
+ $("body").append('<div id="gFullsize" class="ui-dialog ui-widget" ' +
+ 'style="overflow: hidden; display: block; ' +
+ 'position: absolute; z-index: 1002; outline-color: -moz-use-text-color; ' +
+ 'outline-style: none; outline-width: 0px; ' +
+ 'height: ' + image_size.height + 'px; ' +
+ 'width: ' + image_size.width + 'px; ' +
+ 'top: ' + image_size.top + 'px; left: ' + image_size.left + 'px;">' +
+ '<img id="gFullSizeImage" src="' + image_url + '"' +
+ 'height="' + image_size.height + '" width="' + image_size.width + '"/></div>');
- $("#gFullsize").append('<span id="gFullsizeClose" class="fg-button ui-icon ui-state-default ' +
- 'ui-icon-closethick ui-corner-all" style="z-index: 1003; position: absolute; ' +
- 'right: 1em; top: 1em;"></span>');
- $("#gFullsizeClose").click(function() {
- $("#gFullsizeOverlay*").remove();
- $("#gFullsize").remove();
- });
- $(window).resize(function() {
- $("#gFullsizeOverlay").width($(document).width());
- $("#gFullsizeOverlay").height($(document).height());
- image_size = _auto_fit(image_width, image_height);
- $("#gFullsize").height(image_size.height);
- $("#gFullsize").width(image_size.width);
- $("#gFullsize").css("top", image_size.top);
- $("#gFullsize").css("left", image_size.left);
- $("#gFullSizeImage").height(image_size.height);
- $("#gFullSizeImage").width(image_size.width);
- });
-};
+ $("#gFullsize").append('<span id="gFullsizeClose" class="fg-button ui-icon ui-state-default ' +
+ 'ui-icon-closethick ui-corner-all" style="z-index: 1003; position: absolute; ' +
+ 'right: 1em; top: 1em;"></span>');
+ $("#gFullsizeClose").click(function() {
+ $("#gFullsizeOverlay*").remove();
+ $("#gFullsize").remove();
+ });
+ $(window).resize(function() {
+ $("#gFullsizeOverlay").width($(document).width())
+ .height($(document).height());
+ image_size = _auto_fit(image_width, image_height);
+ $("#gFullsize").height(image_size.height)
+ .width(image_size.width)
+ .css("top", image_size.top)
+ .css("left", image_size.left);
+ $("#gFullSizeImage").height(image_size.height)
+ .width(image_size.width);
+ });
+ };
+})(jQuery);