[Proto-Scripty] Re: Dimensions of dynamic content
Hi, Ajax.Updater is (by default) *asynchronous*, so your code doing the resizing runs before the request completes. Use an onSuccess handler [1] instead. (Don't just make the request synchronous, it locks up the browser UI.) You might also find the "bulletproof ajax requests" page[2] on the unofficial wiki useful. [1] http://prototypejs.org/api/ajax/options [2] http://proto-scripty.wikidot.com/prototype:how-to-bulletproof-ajax-requests HTH, -- T.J. Crowder tj / crowder software / com Independent Software Engineer, consulting services available On Feb 16, 4:41 am, XenoPhage wrote: > Hi there, > > I've tried googling around for an answer to this, but either I'm using > the wrong keywords, or I'm just not getting the answer I'm looking > for.. Anyway, I'll give it a shot here. > > I'm using Ajax.Updater to update a div with dynamic content. Pretty > cut and dry and this works fine, no problem. Once the content has > been updated, I want to place it on the screen based on the new > dimensions of the div. In short, I'm looking to center the div in a > specific area of the screen. > > The problem I seem to be running into, however, is that the first time > this occurs on page load, the width and height of the div return > zero. This is after Ajax.Updater has been called. I'm a bit confused > as to why, though, and I can't seem to find a workaround. > > The code I'm using is as follows : > > function showPopup(myItem, passid) { > myDiv = $('hoverdiv'); > myItem = $(myItem); > > new Ajax.Updater('hoverdiv', 'getinfo.php?pass_id=' + passid, > { method: 'get' }); > > var myOff = myItem.cumulativeOffset(); > > var newX = myOff[0] + (myItem.getWidth() - myDiv.getWidth()) / 2; > var newY = myOff[1] + (myItem.getHeight() - myDiv.getHeight()) / 2; > > myDiv.style.top = newY + 'px'; > myDiv.style.left = newX + 'px'; > > myDiv.appear(); > > } > > This is called via an onclick event in a table. myItem is the tr > element that was clicked and passid is an integer. > > Can anyone point me in the right direction to resolve this? > > Thanks! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Dimensions of dynamic content
T.J. Crowder wrote: > Hi, > > Ajax.Updater is (by default) *asynchronous*, so your code doing the > resizing runs before the request completes. Use an onSuccess handler > [1] instead. (Don't just make the request synchronous, it locks up > the browser UI.) You might also find the "bulletproof ajax requests" > page[2] on the unofficial wiki useful. I actually tried onSuccess before, and had the same results. Is this the correct syntax? new Ajax.Updater('hoverdiv', 'getinfo.php?pass_id=' + passid, { method: 'get', onSuccess: function() { var myOff = myItem.cumulativeOffset(); var newX = myOff[0] + (myItem.getWidth() - myDiv.getWidth()) / 2; var newY = myOff[1] + (myItem.getHeight() - myDiv.getHeight()) / 2; myDiv.style.top = newY + 'px'; myDiv.style.left = newX + 'px'; myDiv.appear(); } }); Thanks for the link to the unofficial wiki, looks quite useful. > HTH, > -- > T.J. Crowder > tj / crowder software / com > Independent Software Engineer, consulting services available -- --- Jason Frisvold xenopha...@gmail.com --- "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Dimensions of dynamic content
Aha. Try using onComplete. onSuccess fires when the Ajax event returns success (naturally) but before you've done anything in the local DOM with your new content. It's the Ajax equivalent of a 200 header from the browser. All it means is "everything worked, now your content is coming!" Walter On Feb 16, 2009, at 9:47 AM, Jason Frisvold wrote: > I actually tried onSuccess before, and had the same results. Is this > the correct syntax? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Dimensions of dynamic content
Jason Frisvold wrote: > I actually tried onSuccess before, and had the same results. Is this > the correct syntax? onComplete makes this work properly. So, I wonder, if I properly check for failures, is it ok to use onComplete for this? -- --- Jason Frisvold xenopha...@gmail.com --- "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Dimensions of dynamic content
Walter Lee Davis wrote: > Aha. Try using onComplete. onSuccess fires when the Ajax event returns > success (naturally) but before you've done anything in the local DOM > with your new content. It's the Ajax equivalent of a 200 header from > the browser. All it means is "everything worked, now your content is > coming!" Yup, just realized this after I sent the previous message. Many thanks! Now I'm off to handle the failures and get this out the door! > Walter -- --- Jason Frisvold xenopha...@gmail.com --- "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---