Skip to content

Commit

Permalink
Convert the gallery.panel.js to use the xhr object that is now part o…
Browse files Browse the repository at this point in the history
…f the success callback.
  • Loading branch information
Tim Almdal committed Oct 16, 2010
1 parent 76bb581 commit 42ced72
Showing 1 changed file with 27 additions and 36 deletions.
63 changes: 27 additions & 36 deletions lib/gallery.panel.js
Expand Up @@ -10,59 +10,50 @@
var parentClass = $(parent).attr("class");
var ePanel = "<tr id=\"g-panel\"><td colspan=\"6\"></td></tr>";

// We keep track of the open vs. closed state by looking to see if there'
// an orig_text attr. If that attr is missing, then the panel is closed
// and we want to open it
var should_open = !$(element).attr("orig_text");
// We keep track of the open vs. closed state by looking to see if there'
// an orig_text attr. If that attr is missing, then the panel is closed
// and we want to open it
var should_open = !$(element).attr("orig_text");

// Close any open panels and reset their button text
// Close any open panels and reset their button text
if ($("#g-panel").length) {
$("#g-panel").slideUp("slow").remove();
$.each($(".g-panel-link"),
function() {
if ($(this).attr("orig_text")) {
$(this).children(".g-button-text").text($(this).attr("orig_text"));
$(this).attr("orig_text", "");
}
}
);
$.each($(".g-panel-link"),
function() {
if ($(this).attr("orig_text")) {
$(this).children(".g-button-text").text($(this).attr("orig_text"));
$(this).attr("orig_text", "");
}
}
);
}

if (should_open) {
$(parent).after(ePanel);
$("#g-panel td").html(sHref);
$.ajax({
if (should_open) {
$(parent).after(ePanel);
$("#g-panel td").html(sHref);
$.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 = "";
// in 1.4.2+ json replies are already converted to an object
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 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");
}
});
}
}

return false;
});
Expand Down

0 comments on commit 42ced72

Please sign in to comment.