summaryrefslogtreecommitdiff
path: root/lib/gallery.dialog.js
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2010-08-01 10:35:15 -0700
committerBharat Mediratta <bharat@menalto.com>2010-08-01 10:35:15 -0700
commit3b187d7fe9acbe46e38ae824b6374dd3bfd0cfb0 (patch)
tree81af4ec2993f740fb632c9f5ea4572bb2d1efa23 /lib/gallery.dialog.js
parent563afbe6ddf4b4debea87a0cb0b8758c8826f80c (diff)
parentbf7115cf5a732cea2d498971ec94d2ade3b2fcdd (diff)
Merge branch 'dialog'
Diffstat (limited to 'lib/gallery.dialog.js')
-rw-r--r--lib/gallery.dialog.js76
1 files changed, 62 insertions, 14 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);