Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Insert , Defer and Is there a better way?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
phegaro  
View profile  
 More options Oct 30, 3:19 am
From: phegaro <pheg...@gmail.com>
Date: Fri, 30 Oct 2009 00:19:24 -0700 (PDT)
Local: Fri, Oct 30 2009 3:19 am
Subject: Insert , Defer and Is there a better way?
Hi all,
  This might be a more generic browser/javascript questions than a
prototype specific quesiton but i thought it would better to ask here
because you all tend to really understand javascript and browsers in a
ton of detail. So here goes.

If i execute the following code:

HTML:

<div id="area"></div>

Javascript:

$('area').insert({bottom: "<div id="inserted"></div>"});

var count = 0;
var f = function() {
      if ($('inserted') == null) {
            console.log("not there");
            count++;
            if (count > 50) {
                  $('area'.insert({bottom: "<div id="inserted"></
div>"});
                  count = 0;
            }
            f.defer();
      } else {
        console.log("there");
     }

};

f();

Result:

Most of the time it just shows:

>> there

but some of the time it does this

>> not there
>> not there
>> not there
>> there

I am assuming because the insert is something that is queued and the
browser then inserts the nodes into the DOM in its next event loop. I
know that webkit is a single threaded so this makes sense that
sometimes its not there and then it gets there, so really i guess i
have to wait till its there before i can do the "next thing" on that
inserted node. What about firefox and IE? Are they all single threaded
in the same way? What happens in Chrome?

Sometimes i see the following happen also which is really concerning
to me:

>> not there
>> not there
>> ... 50 times
>> not there
>> there

It happens every so often on webkit (mac os) and on iPhone webkit and
i can reproduce it pretty easily. I have built something simple that
will do this but all this seems a little crazy to me because when i
look at others code they dont even take this into account. They never
way for DOM elements to show up when inserting HTML text into a DOM
element.

Any answers/suggestions would be super helpful.

Kiran


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
T.J. Crowder  
View profile  
 More options Oct 30, 6:22 am
From: "T.J. Crowder" <t...@crowdersoftware.com>
Date: Fri, 30 Oct 2009 03:22:01 -0700 (PDT)
Local: Fri, Oct 30 2009 6:22 am
Subject: Re: Insert , Defer and Is there a better way?
Hi Kiran,

It sounds like you've already put together a minimalist test case,
would you post it (e.g., to Pastie[1] or similar)?  I haven't run into
a situation where a single defer wasn't sufficient, but I also haven't
tested extensively on Mac OS.

Cheers,
--
T.J. Crowder
Independent Software Consultant
tj / crowder software / com
www.crowdersoftware.com

On Oct 30, 7:19 am, phegaro <pheg...@gmail.com> wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
phegaro  
View profile  
 More options Nov 2, 7:41 pm
From: phegaro <pheg...@gmail.com>
Date: Mon, 2 Nov 2009 16:41:36 -0800 (PST)
Local: Mon, Nov 2 2009 7:41 pm
Subject: Re: Insert , Defer and Is there a better way?
HI T.J,
  I'm sorry but are you asking for more than what is above? I can
write a simple page that puts together the HTML and JS listed above.
Is that what you want?

Kiran

On Oct 30, 2:22 am, "T.J. Crowder" <t...@crowdersoftware.com> wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matt Foster  
View profile  
 More options Nov 5, 3:22 pm
From: Matt Foster <mattfoste...@gmail.com>
Date: Thu, 5 Nov 2009 12:22:05 -0800 (PST)
Local: Thurs, Nov 5 2009 3:22 pm
Subject: Re: Insert , Defer and Is there a better way?
Hey Kiran,

Function.defer is simply delegating the functions execution to
Function.delay which in the end delegates it to a wrapper of
window.setTimeout.
By using defer it enforces the timeout to be a value of 0.01 which is
just enough to hiccup the browser's procedural processing.

If your application relies on this element to be inserted, avoid the
defer and you'll be sure the content is loaded after execution of
insert.

--

http://positionabsolute.net

On Nov 2, 7:41 pm, phegaro <pheg...@gmail.com> wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matt Foster  
View profile  
 More options Nov 5, 3:37 pm
From: Matt Foster <mattfoste...@gmail.com>
Date: Thu, 5 Nov 2009 12:37:52 -0800 (PST)
Local: Thurs, Nov 5 2009 3:37 pm
Subject: Re: Insert , Defer and Is there a better way?
In taking a second look at your code...

Are you using the F function recursively to wait for the DOM to be
loaded and your "area" element to be available?

you can use many other approaches...

Prototype

$(document).observe("dom:loaded", function()...);

Traditional

window.onload = function()...

By executing your code in those methods, you can be sure that DOM
elements are loaded and ready for manipulation via Javascript.

--

http://positionabsolute.net

On Nov 5, 3:22 pm, Matt Foster <mattfoste...@gmail.com> wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
phegaro  
View profile  
 More options Nov 16, 6:33 pm
From: phegaro <pheg...@gmail.com>
Date: Mon, 16 Nov 2009 15:33:18 -0800 (PST)
Local: Mon, Nov 16 2009 6:33 pm
Subject: Re: Insert , Defer and Is there a better way?
This is not during DOM load but post dom load where i am trying to
insert more dom elements into the tree that i am seeing things not
always load.

On Nov 5, 12:37 pm, Matt Foster <mattfoste...@gmail.com> wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
T.J. Crowder  
View profile  
 More options Nov 17, 9:37 am
From: "T.J. Crowder" <t...@crowdersoftware.com>
Date: Tue, 17 Nov 2009 06:37:24 -0800 (PST)
Local: Tues, Nov 17 2009 9:37 am
Subject: Re: Insert , Defer and Is there a better way?
Hi,

>   I'm sorry but are you asking for more than what is above? I can
> write a simple page that puts together the HTML and JS listed above.

Yes, there are a lot of details not included in that post, which may
be relevant. There are lots of good reasons to do a complete, stand-
alone test case, not least that it eliminates that problem (of missing
details). _Your_ doing it (rather than someone who isn't seeing the
problem) ensures that you create a test case that replicates the
behavior. Separately, when I'm seeing behavior that doesn't quite make
sense to me, when I do a separate isolated test case, I frequently
find that I did something _slightly_ wrong in the original. And if I
don't find that, I have something useful I can post here. :-)

So yes, I'd suggest doing that. FWIW, there's a starter page here:
http://proto-scripty.wikidot.com/self-contained-test-page

-- T.J.

On Nov 3, 12:41 am, phegaro <pheg...@gmail.com> wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
phegaro  
View profile  
 More options Nov 17, 5:21 pm
From: phegaro <pheg...@gmail.com>
Date: Tue, 17 Nov 2009 14:21:05 -0800 (PST)
Local: Tues, Nov 17 2009 5:21 pm
Subject: Re: Insert , Defer and Is there a better way?
Hi T.J.,
  I tried out creating a unit test case for this and doing stuff on
page load and i cant seem to reproduce this on Safari on the desktop
anymore. Its odd because i think it might have to do with timing and
how long the browser takes to render the content into the DOM but i
can reproduce in a simple unit test. I'll check that this unit test
works on iPhone and give you an update.

Thanks

Kiran

On Nov 17, 6:37 am, "T.J. Crowder" <t...@crowdersoftware.com> wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google