Permalink
Browse files

Optimize how the the Modalbox is used to do as much of the Ajax reque…

…st as possible in parallel with the Modalbox's animation
  • Loading branch information...
1 parent 3f62b78 commit a1344399d315243a1a1e1534f3a8a7d4cdab6e1b @hlship committed Mar 29, 2011
Showing with 42 additions and 21 deletions.
  1. +42 −21 tapx-core/src/main/resources/com/howardlewisship/tapx/core/tapx-multiselect.js
@@ -82,33 +82,54 @@ Tapx.extendInitializer(function() {
to.fire("tapx:refreshbuttonstate");
}
+ // Re. "Modalbox" vs. "Lightbox". Modalbox is a specific implementation of
+ // the general Lightbox design; we may swap out Modalbox for some other
+ // Lightbox implementation, given how awkward it is to use with Tapestry.
+
function lightbox(title, contentURL) {
- Modalbox.show("<span class='tx-ajax-wait'></span>", {
- title : title,
- afterLoad : function() {
- Tapestry.ajaxRequest(contentURL, function(transport) {
- var reply = transport.responseJSON;
- var inits = reply.inits;
- reply.inits = null;
+ var animationComplete = false;
+ var animationCompleteCallback = null;
+
+ function updateLightboxFromReply(reply) {
+ var inits = reply.inits;
+ reply.inits = null;
+
+ Modalbox.show(reply.content, {
+ title : title,
+ autoFocusing : false,
+ afterLoad : function() {
+ Tapestry.executeInits(inits);
+ },
+ afterUpdate : function() {
+ Modalbox.resizeToContent();
+ }
+ });
+ }
+
+ Tapestry.ajaxRequest(contentURL, function(transport) {
+ var reply = transport.responseJSON;
- Tapestry.loadScriptsInReply(reply, function() {
+ // When the Modalbox animation is complete,
+ // then update its content.
- Modalbox.show(reply.content, {
- title : title,
- autoFocusing : false,
- afterLoad : function() {
+ animationCompleteCallback = function() {
+ updateLightboxFromReply(reply);
+ };
- Tapestry.executeInits(inits);
- },
+ if (animationComplete) {
+ animationCompleteCallback();
+ return;
+ }
+ });
- afterUpdate : function() {
+ Modalbox.show("<span class='tx-ajax-wait'></span>", {
+ title : title,
+ afterLoad : function() {
+
+ animationComplete = true;
- Modalbox.resizeToContent();
- }
- });
- });
- });
+ animationCompleteCallback && animationCompleteCallback();
}
});
}
@@ -180,7 +201,7 @@ Tapx.extendInitializer(function() {
selectedSelect.fire("tapx:refreshbuttonstate");
selectedSelect.focus();
-
+
rebuildHiddenFieldValue();
});
}

0 comments on commit a134439

Please sign in to comment.