summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/gallery.common.js30
-rw-r--r--lib/gallery.dialog.js101
-rw-r--r--lib/gallery.panel.js42
-rw-r--r--lib/gallery.show_full_size.js97
4 files changed, 173 insertions, 97 deletions
diff --git a/lib/gallery.common.js b/lib/gallery.common.js
index a9aa6b2c..a8b237bf 100644
--- a/lib/gallery.common.js
+++ b/lib/gallery.common.js
@@ -151,24 +151,24 @@
var width = size.width() - 6,
height = size.height() - 6;
- var ratio = width / imageWidth;
- imageWidth *= ratio;
- imageHeight *= ratio;
-
- /* after scaling the width, check that the height fits */
- if (imageHeight > height) {
- ratio = height / imageHeight;
+ var ratio = width / imageWidth;
imageWidth *= ratio;
imageHeight *= ratio;
- }
- // handle the case where the calculation is almost zero (2.14e-14)
- return {
- top: Number((height - imageHeight) / 2),
- left: Number((width - imageWidth) / 2),
- width: Number(imageWidth),
- height: Number(imageHeight)
- };
+ /* after scaling the width, check that the height fits */
+ if (imageHeight > height) {
+ ratio = height / imageHeight;
+ imageWidth *= ratio;
+ imageHeight *= ratio;
+ }
+
+ // handle the case where the calculation is almost zero (2.14e-14)
+ return {
+ top: Number((height - imageHeight) / 2),
+ left: Number((width - imageWidth) / 2),
+ width: Number(imageWidth),
+ height: Number(imageHeight)
+ };
};
// Initialize a short form. Short forms may contain only one text input.
diff --git a/lib/gallery.dialog.js b/lib/gallery.dialog.js
index 6ec8c634..450f4c88 100644
--- a/lib/gallery.dialog.js
+++ b/lib/gallery.dialog.js
@@ -1,3 +1,4 @@
+
(function($) {
$.widget("ui.gallery_dialog", {
_init: function() {
@@ -26,27 +27,42 @@
$("#g-dialog").gallery_show_loading();
- $.get(sHref, function(data) {
- $("#g-dialog").html(data).gallery_show_loading();
+ $.ajax({
+ url: sHref,
+ type: "GET",
+ beforeSend: function(xhr) {
+ // Until we convert to jquery 1.4, we need to save the XMLHttpRequest object so that we
+ // can detect the mime type of the reply
+ this.xhrData = xhr;
+ },
+ success: function(data, textStatus, xhr) {
+ // Pre jquery 1.4, get the saved XMLHttpRequest object
+ if (xhr == undefined) {
+ xhr = this.xhrData;
+ }
+ var mimeType = /^(\w+\/\w+)\;?/.exec(xhr.getResponseHeader("Content-Type"));
- if ($("#g-dialog form").length) {
- self.form_loaded(null, $("#g-dialog form"));
- }
- self._layout();
-
- $("#g-dialog").dialog("open");
- // Remove titlebar for progress dialogs or set title
- if ($("#g-dialog #g-progress").length) {
- $(".ui-dialog-titlebar").remove();
- } else if ($("#g-dialog h1").length) {
- $("#g-dialog").dialog('option', 'title', $("#g-dialog h1:eq(0)").html());
- $("#g-dialog h1:eq(0)").hide();
- } else if ($("#g-dialog fieldset legend").length) {
- $("#g-dialog").dialog('option', 'title', $("#g-dialog fieldset legend:eq(0)").html());
- }
+ var content = "";
+ if (mimeType[1] == "application/json") {
+ data = JSON.parse(data);
+ content = unescape(data.html);
+ } else {
+ content = data;
+ }
+
+ $("#g-dialog").html(content).gallery_show_loading();
+
+ if ($("#g-dialog form").length) {
+ self.form_loaded(null, $("#g-dialog form"));
+ }
+ self._layout();
+
+ $("#g-dialog").dialog("open");
+ self._set_title();
- if ($("#g-dialog form").length) {
- self._ajaxify_dialog();
+ if ($("#g-dialog form").length) {
+ self._ajaxify_dialog();
+ }
}
});
$("#g-dialog").dialog("option", "self", self);
@@ -106,19 +122,46 @@
_ajaxify_dialog: function() {
var self = this;
$("#g-dialog form").ajaxForm({
- dataType: "json",
beforeSubmit: function(formData, form, options) {
form.find(":submit")
.addClass("ui-state-disabled")
.attr("disabled", "disabled");
return true;
},
+ beforeSend: function(xhr) {
+ // Until we convert to jquery 1.4, we need to save the XMLHttpRequest object so that we
+ // can detect the mime type of the reply
+ this.xhrData = xhr;
+ },
success: function(data) {
- if (data.form) {
- var formData = unescape(data.form);
- $("#g-dialog form").replaceWith(formData);
+ // Pre jquery 1.4, get the saved XMLHttpRequest object
+ xhr = this.xhrData;
+ if (xhr) {
+ var mimeType = /^(\w+\/\w+)\;?/.exec(xhr.getResponseHeader("Content-Type"));
+
+ var content = "";
+ if (mimeType[1] == "application/json") {
+ data = JSON.parse(data);
+ } else {
+ data = {"html": escape(data)};
+ }
+ } else {
+ // Uploading files (eg: watermark) uses a fake xhr in jquery.form.js so
+ // all we have is in the data field, which should be some very simple JSON.
+ // Weirdly enough in Chrome the result gets wrapped in a <pre> element and
+ // looks like this:
+ // <pre style="word-wrap: break-word; white-space: pre-wrap;">{"result":"success",
+ // "location":"\/~bharat\/gallery3\/index.php\/admin\/watermarks"}</pre>
+ // bizarre. Strip that off before parsing.
+ data = JSON.parse(data.match("({.*})")[0]);
+ }
+
+ if (data.html) {
+ $("#g-dialog").html(unescape(data.html));
+ $("#g-dialog").dialog("option", "position", "center");
$("#g-dialog form :submit").removeClass("ui-state-disabled")
.attr("disabled", null);
+ self._set_title();
self._ajaxify_dialog();
self.form_loaded(null, $("#g-dialog form"));
if (typeof data.reset == 'function') {
@@ -136,6 +179,18 @@
});
},
+ _set_title: function() {
+ // Remove titlebar for progress dialogs or set title
+ if ($("#g-dialog #g-progress").length) {
+ $(".ui-dialog-titlebar").remove();
+ } else if ($("#g-dialog h1").length) {
+ $("#g-dialog").dialog('option', 'title', $("#g-dialog h1:eq(0)").html());
+ $("#g-dialog h1:eq(0)").hide();
+ } else if ($("#g-dialog fieldset legend").length) {
+ $("#g-dialog").dialog('option', 'title', $("#g-dialog fieldset legend:eq(0)").html());
+ }
+ },
+
form_closing: function(event, ui) {},
dialog_closing: function(event, ui) {}
});
diff --git a/lib/gallery.panel.js b/lib/gallery.panel.js
index 8d627369..e0605ca3 100644
--- a/lib/gallery.panel.js
+++ b/lib/gallery.panel.js
@@ -31,15 +31,37 @@
if (should_open) {
$(parent).after(ePanel);
$("#g-panel td").html(sHref);
- $.get(sHref, function(data) {
- $("#g-panel td").html(data);
- self._ajaxify_panel();
- if ($(element).attr("open_text")) {
- $(element).attr("orig_text", $(element).children(".g-button-text").text());
- $(element).children(".g-button-text").text($(element).attr("open_text"));
+ $.ajax({
+ url: sHref,
+ type: "GET",
+ beforeSend: function(xhr) {
+ // Until we convert to jquery 1.4, we need to save the
+ // XMLHttpRequest object
+ this.xhrData = xhr;
+ },
+ success: function(data, textStatus, xhr) {
+ // Pre jquery 1.4, get the saved XMLHttpRequest object
+ if (xhr == undefined) {
+ xhr = this.xhrData;
+ }
+ var mimeType = /^(\w+\/\w+)\;?/.exec(xhr.getResponseHeader("Content-Type"));
+ var content = "";
+ if (mimeType[1] == "application/json") {
+ data = JSON.parse(data);
+ content = unescape(data.html);
+ } else {
+ content = data;
+ }
+
+ $("#g-panel td").html(content);
+ self._ajaxify_panel();
+ if ($(element).attr("open_text")) {
+ $(element).attr("orig_text", $(element).children(".g-button-text").text());
+ $(element).children(".g-button-text").text($(element).attr("open_text"));
+ }
+ $("#g-panel").addClass(parentClass).show().slideDown("slow");
}
- $("#g-panel").addClass(parentClass).show().slideDown("slow");
- });
+ });
}
return false;
@@ -57,8 +79,8 @@
return true;
},
success: function(data) {
- if (data.form) {
- $("#g-panel td form").replaceWith(data.form);
+ if (data.html) {
+ $("#g-panel td").html(data.html);
self._ajaxify_panel();
}
if (data.result == "success") {
diff --git a/lib/gallery.show_full_size.js b/lib/gallery.show_full_size.js
index 49dc620a..f617836b 100644
--- a/lib/gallery.show_full_size.js
+++ b/lib/gallery.show_full_size.js
@@ -1,57 +1,56 @@
(function($) {
- /**
- * @todo Move inline CSS out to external style sheet (theme style sheet)
- */
- $.gallery_show_full_size = function(image_url, image_width, image_height) {
- var width = $(document).width();
- var height = $(document).height();
- var size = $.gallery_get_viewport_size();
+ /**
+ * @todo Move inline CSS out to external style sheet (theme style sheet)
+ */
+ $.gallery_show_full_size = function(image_url, image_width, image_height) {
+ var width = $(document).width();
+ var height = $(document).height();
+ var size = $.gallery_get_viewport_size();
- $("body").append('<div id="g-fullsize-overlay" 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="g-fullsize-overlay" 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;
- if (image_width >= size.width() - 6 || image_height >= size.height() - 6) {
- image_size = $.gallery_auto_fit_window(image_width, image_height);
- } else {
- image_size = {
+ var image_size;
+ if (image_width >= size.width() - 6 || image_height >= size.height() - 6) {
+ image_size = $.gallery_auto_fit_window(image_width, image_height);
+ } else {
+ image_size = {
top: Number((height - image_height) / 2), left: Number((width - image_width) / 2),
width: Number(image_width), height: Number(image_height)
- };
- }
+ };
+ }
+ $("body").append('<div id="g-fullsize" 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="g-fullsize-image" src="' + image_url + '"' +
+ 'height="' + image_size.height + '" width="' + image_size.width + '"/></div>');
- $("body").append('<div id="g-fullsize" 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="g-fullsize-image" src="' + image_url + '"' +
- 'height="' + image_size.height + '" width="' + image_size.width + '"/></div>');
-
- $().click(function() {
- $("#g-fullsize-overlay*").remove();
- $("#g-fullsize").remove();
- });
- $().bind("keypress", function() {
- $("#g-fullsize-overlay*").remove();
- $("#g-fullsize").remove();
- });
- $(window).resize(function() {
- $("#g-fullsize-overlay").width($(document).width()).height($(document).height());
- image_size = $.gallery_auto_fit_window(image_width, image_height);
- $("#g-fullsize").height(image_size.height)
- .width(image_size.width)
- .css("top", image_size.top)
- .css("left", image_size.left);
- $("#g-fullsize-image").height(image_size.height).width(image_size.width);
- });
- };
+ $().click(function() {
+ $("#g-fullsize-overlay*").remove();
+ $("#g-fullsize").remove();
+ });
+ $().bind("keypress", function() {
+ $("#g-fullsize-overlay*").remove();
+ $("#g-fullsize").remove();
+ });
+ $(window).resize(function() {
+ $("#g-fullsize-overlay").width($(document).width()).height($(document).height());
+ image_size = $.gallery_auto_fit_window(image_width, image_height);
+ $("#g-fullsize").height(image_size.height)
+ .width(image_size.width)
+ .css("top", image_size.top)
+ .css("left", image_size.left);
+ $("#g-fullsize-image").height(image_size.height).width(image_size.width);
+ });
+ };
})(jQuery);