diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2010-08-01 08:31:09 -0700 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2010-08-01 08:31:09 -0700 |
commit | a4531707274318496bb7a4477d940030d870f133 (patch) | |
tree | 6715be3db83d7f834676a0b2c7a38c9bd58ce1a5 /lib/gallery.dialog.js | |
parent | fc580037e797fad48b49fcffa7aa69dca8761972 (diff) | |
parent | 7607e1f932dda53144792d0b7e8674a34fbc7f9a (diff) |
Merge branch 'dialog' of github.com:gallery/gallery3 into dialog
Diffstat (limited to 'lib/gallery.dialog.js')
-rw-r--r-- | lib/gallery.dialog.js | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/lib/gallery.dialog.js b/lib/gallery.dialog.js index 555e6f47..f1d146ab 100644 --- a/lib/gallery.dialog.js +++ b/lib/gallery.dialog.js @@ -31,8 +31,8 @@ url: sHref, type: "GET", beforeSend: function(xhr) { - // Until we convert to jquery 1.4, we need to save the - // XMLHttpRequest object + // 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) { @@ -122,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").html(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); |