summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/gallery.dialog.js76
-rw-r--r--lib/gallery.panel.js42
2 files changed, 94 insertions, 24 deletions
diff --git a/lib/gallery.dialog.js b/lib/gallery.dialog.js
index cc35f5cd..f1d146ab 100644
--- a/lib/gallery.dialog.js
+++ b/lib/gallery.dialog.js
@@ -27,19 +27,42 @@
$("#g-dialog").gallery_show_loading();
- $.getJSON(sHref, function(data) {
- $("#g-dialog").html(unescape(data.form)).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"));
+
+ var content = "";
+ if (mimeType[1] == "application/json") {
+ data = JSON.parse(data);
+ content = unescape(data.form);
+ } else {
+ content = data;
+ }
- if ($("#g-dialog form").length) {
- self.form_loaded(null, $("#g-dialog form"));
- }
- self._layout();
+ $("#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();
+ $("#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);
@@ -99,17 +122,42 @@
_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);
diff --git a/lib/gallery.panel.js b/lib/gallery.panel.js
index b94df223..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);
- $.getJSON(sHref, function(data) {
- $("#g-panel td").html(unescape(data.form));
- 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") {