Skip to content

Commit

Permalink
Partial fix for #1225. Change the dialog and panel handling to look a…
Browse files Browse the repository at this point in the history
…t the mime type returned to determine the content type.
  • Loading branch information
Tim Almdal committed Jul 24, 2010
1 parent 9534a1c commit b1cd0b7
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 19 deletions.
45 changes: 34 additions & 11 deletions lib/gallery.dialog.js
Expand Up @@ -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
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();

$("#g-dialog").dialog("open");
self._set_title();
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);
Expand Down Expand Up @@ -108,7 +131,7 @@
},
success: function(data) {
if (data.form) {
var formData = unescape(data.form);
var formData = unescape(data.content);
$("#g-dialog form").replaceWith(formData);
$("#g-dialog").dialog("option", "position", "center");
$("#g-dialog form :submit").removeClass("ui-state-disabled")
Expand Down
38 changes: 30 additions & 8 deletions lib/gallery.panel.js
Expand Up @@ -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.form);
} 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;
Expand Down

0 comments on commit b1cd0b7

Please sign in to comment.