Wednesday, December 31, 2008

[jQuery] Re: Event callback question

Thanks for your response.

Yes I have used that before, but I need to know how to add a callback function which is called after a set of animations are completed.

If I have an array of dom elements which all need the same animation applied to them,
how can I tell when all the animations are complete?

Thanks,
Cam

On Thu, Jan 1, 2009 at 8:19 PM, brian <bally.zijn@gmail.com> wrote:

On Wed, Dec 31, 2008 at 11:26 PM, Cam Spiers <camspiers@gmail.com> wrote:
> Hey,
>
> function closeMainPanels(){
>     jQuery("div.mainLiner div.panel").each(function(){
>         jQuery(this).slideUp(750);
>     });
> }
>
> How can I tell when all panels have finished animation?
>
> As I need to call another function when all have finished.
>

slideUp accepts a callback function you could use

http://docs.jquery.com/Effects/slideUp

[jQuery] Re: Event callback question

On Wed, Dec 31, 2008 at 11:26 PM, Cam Spiers <camspiers@gmail.com> wrote:
> Hey,
>
> function closeMainPanels(){
> jQuery("div.mainLiner div.panel").each(function(){
> jQuery(this).slideUp(750);
> });
> }
>
> How can I tell when all panels have finished animation?
>
> As I need to call another function when all have finished.
>

slideUp accepts a callback function you could use

http://docs.jquery.com/Effects/slideUp

[jQuery] Re: what's wrong with $(":checkbox[checked=true]") ?

On Dec 31, 2008, at 4:58 PM, Ricardo Tomasi wrote:


In XHTML the correct value for the checked attribute is 'checked', not
'true'.

<input type="checkbox" checked="checked" />


Sure, but JavaScript returns true (boolean) for the checked attribute.
Do this in Firebug:

$('input:checked').attr('checked')

or this

$('input:checked')[0].checked

and it'll report true, not 'checked'.


Of course, as you and Dave both pointed out, Andy was trying to match elements with checked attribute equal to the string 'true'. I had missed that. D'oh.


--Karl
____________
Karl Swedberg

[jQuery] Event callback question

Hey,

function closeMainPanels(){
    jQuery("div.mainLiner div.panel").each(function(){
        jQuery(this).slideUp(750);
    });
}

How can I tell when all panels have finished animation?

As I need to call another function when all have finished.

Cheers,
Cam







[jQuery] Re: jQuery UI 1.6rc3 is out

Very nicely done, everyone!

 

Rick

 

From: jquery-en@googlegroups.com [mailto:jquery-en@googlegroups.com] On Behalf Of Richard D. Worth
Sent: Wednesday, December 31, 2008 10:03 PM
To: jquery-ui@googlegroups.com
Cc: jquery-en@googlegroups.com
Subject: [jQuery] jQuery UI 1.6rc3 is out

 

jQuery UI 1.6 release candidate 3 is out.

Blog post:
http://blog.jquery.com/2008/12/31/jquery-ui-16rc3-its-getting-really-close/

Demos:
http://ui.jquery.com/demos

ThemeRoller v2:
http://ui.jquery.com/themeroller

Development Bundle:
http://code.google.com/p/jquery-ui/downloads/detail?name=jquery.ui-1.6rc3.zip

Download Builder:
http://ui.jquery.com/download

A huge thanks to everyone who helped make this release happen.

Note: As mentioned on the blog post, the 1.6 final release (scheduled for 1 week after jQuery 1.3) will ship with and require jQuery 1.3. Please help us test this release with 1.3b1. Thanks.

- Richard

Richard D. Worth
http://rdworth.org/

[jQuery] Re: jQuery UI 1.6rc3 is out

great job guys!

is there going to be an easy way to view the source of the new functional demos?

On Wed, Dec 31, 2008 at 8:03 PM, Richard D. Worth <rdworth@gmail.com> wrote:
jQuery UI 1.6 release candidate 3 is out.

Blog post:
http://blog.jquery.com/2008/12/31/jquery-ui-16rc3-its-getting-really-close/

Demos:
http://ui.jquery.com/demos

ThemeRoller v2:
http://ui.jquery.com/themeroller

Development Bundle:
http://code.google.com/p/jquery-ui/downloads/detail?name=jquery.ui-1.6rc3.zip

Download Builder:
http://ui.jquery.com/download

A huge thanks to everyone who helped make this release happen.

Note: As mentioned on the blog post, the 1.6 final release (scheduled for 1 week after jQuery 1.3) will ship with and require jQuery 1.3. Please help us test this release with 1.3b1. Thanks.

- Richard

Richard D. Worth
http://rdworth.org/


[jQuery] jQuery UI 1.6rc3 is out

jQuery UI 1.6 release candidate 3 is out.

Blog post:
http://blog.jquery.com/2008/12/31/jquery-ui-16rc3-its-getting-really-close/

Demos:
http://ui.jquery.com/demos

ThemeRoller v2:
http://ui.jquery.com/themeroller

Development Bundle:
http://code.google.com/p/jquery-ui/downloads/detail?name=jquery.ui-1.6rc3.zip

Download Builder:
http://ui.jquery.com/download

A huge thanks to everyone who helped make this release happen.

Note: As mentioned on the blog post, the 1.6 final release (scheduled for 1 week after jQuery 1.3) will ship with and require jQuery 1.3. Please help us test this release with 1.3b1. Thanks.

- Richard

Richard D. Worth
http://rdworth.org/

[jQuery] White circle appears before message box loads...

Hi,

When loading the message box for the first time I get a white circle
appear before my white box appears.

I wonder if it is to do with the fact I am using rounded corners and
the circle may be a mask, anyone else experience this?

Code below:

function showdiv()
{
$.blockUI({
message: $('img#displayBox'),
css: {
border: 'none',
padding: '5px',
backgroundColor: '#fff',
'-webkit-border-radius': '10px',
'-moz-border-radius': '10px',
opacity: '0.9',
color: '#000',
width: '150'
}
});
}

Ta

[jQuery] How to select one ID from multiple auto generated id?

Dear All...

I'am new to jquery....
I have some problem. I have some link that have Id that auto generated
from mysql query, till now I could not figure out how jQuery know what
ID that i have clicked . For example:

// The FORM
$query = mysql_query("SELECT id,title FROM book ORDER BY id DESC");
<div id='result'></div>
<div id='operation'/>
while $fetch = mysql_fetch_array($query); {
$id = $fetch ['id'];
$title = $fetch ['id'];
echo "$title
| <a id='link_del$id' href = "process.php?do=dell&id=
$id' /> <img id='img_del$id' scr='images/delete_icon.gif'/> </a>
| <a id='link_edit$id' href = "process.php?do=edit&id=
$id' /> <img id='img_edit$id' scr='images/edit_icon.gif'/> </a>
";
}
</div>

In jquery I try to do this, but fail

// jQuery
$(document).ready(function(){

('.operation a').click(function(){
$.ajax({
type: 'GET',
url: $(this).attr('href'),
data: $(this).serialize(),
success: function(data) {
$('#result').html(data);
}
});
return false;
});

});

// PHP Process.php
$id=$_GET['id'];
$delete = mysql_query ("DELETE FROM book WHERE id='$id'");
if ($delete) { echo "YES"; }
else {echo "FAIL";}

any advice would be appreciated
Thank You...

[jQuery] How do I delete the content of a cloned filefield?

Hi, all... and Happy New Year (a little early. US East Coast, 8pm)!

I'm cloning a filefield, and, we'll assume, the user has already
used the browse button to locate a file.

When this filefield is cloned, the file path from the previous field
is still in the new field. I want to empty the filefield.

I tried this:

$('.image-next :last').attr('value', function() {
return this.value.replace("");

(The image filefields have the clas "image-next")

But that didn't work...no errors, but content was still in the field.

Suggestions?

Thanks,

Rick

Tuesday, December 30, 2008

[jQuery] Re: Interesting on document ready question

> > > > Why do I really need so much on ready?

> > > Yes! That's what we're all wondering! Don't keep us
> > > in suspense. :-)

> > When you work with a bunch of morons in a company
> > that uses them throughout the site and when the js are
> > packaged will lead to unnecessary performance loss.

> 5000 is just an exaggeration, it's probably in the realm of 20.

20. Now you tell us. 20 is *nothing*. Like, why were we even having this
discussion? :-)

Next time you ask a question, before I go off and write an optimized custom
function for you, I'm going to have to ask, "Are you exaggerating again, my
friend?" (How do you do that sticking-tongue-out smiley, anyway?)

-Mike

p.s. You do realize that the morons at your company read this list? ;-)

[jQuery] Autocomplete plugin rare behaviour

Hi

I'm using the autocomplete plugin to edit the name of a product in a
CMS. When the name field (with autocomplete) is empty the autocomplete
works perfectly. However when the field is not empty and you remove
the content the suggestions don't appear but the ajax request retrieve
the correct data (I have seen them with firebug).

Any ideas??

[jQuery] Re: HELP: Screening questions for JavaScript developer candidates:

They create exactly the same result.

The object or array literal is likely to be a tiny bit faster than the new
Object/Array, because it avoids a name lookup (or several name lookups if
you're inside a nested function). But of course even if it is faster, it
would make a difference only if you're doing a large number of them.

One advantage of the object/array notations is that they let you simplify
the code even further. You can write this:

var datascape = {
el: $('#datascape'),
ini: function(){
datascape.el.click(function(){
dothis();
dothat();
});
}
}

Instead of:

var datascape = new Object();

datascape.el = $('#datascape');
datascape.ini = function(){
datascape.el.click(function(){
dothis();
dothat();
});
}

Here, the object literal saves even more name lookups (the datascape
references) and is shorter and more convenient too.

BTW, note that there's a semicolon missing in this code:

datascape.ini = function(){
datascape.el.click(function(){
dothis();
dothat();
});
}; // <-- semicolon required here

Because of JavaScript's semicolon insertion, you can often get away without
it, but not always - so get in the habit of putting the semicolon in.

A function declaration does not require a semicolon at the end:

function foo() {}

But an assignment statement using a function expression, just like any other
assignment statement, does require it:

foo = function() {};

-Mike

> From: Alexandre Plennevaux
>
> why? It's just a shorthand, isn't it ? does it affect the
> computer resources in any manner ?
>
> On Wed, Dec 31, 2008 at 3:12 AM, Kean <shenanime@gmail.com> wrote:
> >
> > Just a nitpick.
> >
> > Don't do this
> > var datascape = new Object();
> > var datascape2 = new Array();
> >
> > Instead
> > var datascape = {};
> > var datascape2 = [];
> >
> >
> > On Dec 30, 1:27 pm, "Alexandre Plennevaux" <aplennev...@gmail.com>
> > wrote:
> >> wair, you're all scarrying me:
> >>
> >> i often do things like this:
> >>
> >> var datascape = new Object();
> >>
> >> datascape.el = $('#datascape');
> >> datascape.ini = function(){
> >> datascape.el.click(function(){
> >> dothis();
> >> dothat();
> >> });
> >>
> >> }
> >>
> >> is this pattern causing a potential memory leak problem,
> because the
> >> js object is linked to a DOM element?
> >>
> >> On Tue, Dec 30, 2008 at 10:10 PM, Kean <shenan...@gmail.com> wrote:
> >>
> >> > A good reason why closure is used
> >>
> >> >http://yuiblog.com/blog/2006/06/01/global-domination/
> >>
> >> > On Dec 30, 1:04 pm, Kean <shenan...@gmail.com> wrote:
> >> >> Klaus is right,
> >>
> >> >> Here's an article about closure causing
> >> >>
> leakshttp://www.javascriptkit.com/javatutors/closuresleak/index.sh
> >> >> tml
> >>
> >> >> On Dec 30, 4:38 am, "Alexandre Plennevaux"
> <aplennev...@gmail.com>
> >> >> wrote:
> >>
> >> >> > Klaus, you got me: frankly i have no "real" idea what is the
> >> >> > purpose of enclosure.
> >> >> > That's abstract art to me. i just read in several places that
> >> >> > it's good to use it, so i trust my sources, do it and
> move on.
> >> >> > Not that i'm proud of it, but, to use a metaphor, one
> does not
> >> >> > need to know the internals of a car in order to be
> able to drive
> >> >> > it, although it surely is a valuable knowledge if one
> wants to keep its car in a good state !
> >> >> > Yet, since the car changes every six months, it's just up to
> >> >> > you, wheather you're driven by the pure developer's
> passion or
> >> >> > by consumer pragmatism.
> >>
> >> >> > On Tue, Dec 30, 2008 at 1:28 PM, Klaus Hartl
> <klaus.ha...@googlemail.com> wrote:
> >>
> >> >> > > On 30 Dez., 08:45, "Alexandre Plennevaux"
> >> >> > > <aplennev...@gmail.com>
> >> >> > > wrote:
> >> >> > >> "JavaScript enclosures"?
> >>
> >> >> > >> i think it has to do with encapsulating your code inside a
> >> >> > >> function so that all vars are inside the
> function's scope, so
> >> >> > >> not cluttering the global namespace.
> >> >> > >> This, to avoid memory leak.
> >>
> >> >> > > Are you implying that global variables do leak
> memory? There
> >> >> > > are good reasons to not clutter the global namespace but I
> >> >> > > don't believe avoiding leaks is one of them.
> >>
> >> >> > > Actually you do increase the chance to create leaks
> in IE if
> >> >> > > you use closures under certain circumstances.
> >>
> >> >> > > --Klaus
>

[jQuery] Re: Interesting on document ready question

5000 is just an exaggeration, it's probably in the realm of 20

On Dec 30, 10:42 pm, Kean <shenan...@gmail.com> wrote:
> > >Why do I really need so much on ready?
> > Yes! That's what we're all wondering! Don't keep us in suspense. :-)
>
> When you work with a bunch of morons in a company that uses them
> throughout the site and when the js are packaged will lead to
> unnecessary performance loss.

[jQuery] Re: HELP: Screening questions for JavaScript developer candidates:

As for JS, saving bytes is totally a good thing.

On Dec 30, 10:53 pm, "Alexandre Plennevaux" <aplennev...@gmail.com>
wrote:
> why? It's just a shorthand, isn't it ? does it affect the computer
> resources in any manner ?
>
> On Wed, Dec 31, 2008 at 3:12 AM, Kean <shenan...@gmail.com> wrote:
>
> > Just a nitpick.
>
> > Don't do this
> > var datascape = new Object();
> > var datascape2 = new Array();
>
> > Instead
> > var datascape = {};
> > var datascape2 = [];
>
> > On Dec 30, 1:27 pm, "Alexandre Plennevaux" <aplennev...@gmail.com>
> > wrote:
> >> wair, you're all scarrying me:
>
> >> i often do things like this:
>
> >> var datascape = new Object();
>
> >> datascape.el = $('#datascape');
> >> datascape.ini = function(){
> >>         datascape.el.click(function(){
> >>           dothis();
> >>           dothat();
> >>         });
>
> >> }
>
> >> is this pattern causing a potential memory leak problem, because the
> >> js object is linked to a DOM element?
>
> >> On Tue, Dec 30, 2008 at 10:10 PM, Kean <shenan...@gmail.com> wrote:
>
> >> > A good reason why closure is used
>
> >> >http://yuiblog.com/blog/2006/06/01/global-domination/
>
> >> > On Dec 30, 1:04 pm, Kean <shenan...@gmail.com> wrote:
> >> >> Klaus is right,
>
> >> >> Here's an article about closure causing leakshttp://www.javascriptkit.com/javatutors/closuresleak/index.shtml
>
> >> >> On Dec 30, 4:38 am, "Alexandre Plennevaux" <aplennev...@gmail.com>
> >> >> wrote:
>
> >> >> > Klaus, you got me: frankly i have no "real" idea what is the purpose
> >> >> > of enclosure.
> >> >> > That's abstract art to me. i just read in several places that it's
> >> >> > good to use it, so i trust my sources, do it and move on. Not that i'm
> >> >> > proud of it, but, to use a metaphor, one does not need to know the
> >> >> > internals of a car in order to be able to drive it, although it surely
> >> >> > is a valuable knowledge if one wants to keep its car in a good state !
> >> >> > Yet, since the car changes every six months, it's just up to you,
> >> >> > wheather you're driven by the pure developer's passion or by consumer
> >> >> > pragmatism.
>
> >> >> > On Tue, Dec 30, 2008 at 1:28 PM, Klaus Hartl <klaus.ha...@googlemail.com> wrote:
>
> >> >> > > On 30 Dez., 08:45, "Alexandre Plennevaux" <aplennev...@gmail.com>
> >> >> > > wrote:
> >> >> > >> "JavaScript enclosures"?
>
> >> >> > >> i think it has to do with encapsulating your code inside a function so
> >> >> > >> that all vars are inside the function's scope, so not cluttering the
> >> >> > >> global namespace.
> >> >> > >> This, to avoid memory leak.
>
> >> >> > > Are you implying that global variables do leak memory? There are good
> >> >> > > reasons to not clutter the global namespace but I don't believe
> >> >> > > avoiding leaks is one of them.
>
> >> >> > > Actually you do increase the chance to create leaks in IE if you use
> >> >> > > closures under certain circumstances.
>
> >> >> > > --Klaus

[jQuery] Re: HELP: Screening questions for JavaScript developer candidates:

why? It's just a shorthand, isn't it ? does it affect the computer
resources in any manner ?

On Wed, Dec 31, 2008 at 3:12 AM, Kean <shenanime@gmail.com> wrote:
>
> Just a nitpick.
>
> Don't do this
> var datascape = new Object();
> var datascape2 = new Array();
>
> Instead
> var datascape = {};
> var datascape2 = [];
>
>
> On Dec 30, 1:27 pm, "Alexandre Plennevaux" <aplennev...@gmail.com>
> wrote:
>> wair, you're all scarrying me:
>>
>> i often do things like this:
>>
>> var datascape = new Object();
>>
>> datascape.el = $('#datascape');
>> datascape.ini = function(){
>> datascape.el.click(function(){
>> dothis();
>> dothat();
>> });
>>
>> }
>>
>> is this pattern causing a potential memory leak problem, because the
>> js object is linked to a DOM element?
>>
>> On Tue, Dec 30, 2008 at 10:10 PM, Kean <shenan...@gmail.com> wrote:
>>
>> > A good reason why closure is used
>>
>> >http://yuiblog.com/blog/2006/06/01/global-domination/
>>
>> > On Dec 30, 1:04 pm, Kean <shenan...@gmail.com> wrote:
>> >> Klaus is right,
>>
>> >> Here's an article about closure causing leakshttp://www.javascriptkit.com/javatutors/closuresleak/index.shtml
>>
>> >> On Dec 30, 4:38 am, "Alexandre Plennevaux" <aplennev...@gmail.com>
>> >> wrote:
>>
>> >> > Klaus, you got me: frankly i have no "real" idea what is the purpose
>> >> > of enclosure.
>> >> > That's abstract art to me. i just read in several places that it's
>> >> > good to use it, so i trust my sources, do it and move on. Not that i'm
>> >> > proud of it, but, to use a metaphor, one does not need to know the
>> >> > internals of a car in order to be able to drive it, although it surely
>> >> > is a valuable knowledge if one wants to keep its car in a good state !
>> >> > Yet, since the car changes every six months, it's just up to you,
>> >> > wheather you're driven by the pure developer's passion or by consumer
>> >> > pragmatism.
>>
>> >> > On Tue, Dec 30, 2008 at 1:28 PM, Klaus Hartl <klaus.ha...@googlemail.com> wrote:
>>
>> >> > > On 30 Dez., 08:45, "Alexandre Plennevaux" <aplennev...@gmail.com>
>> >> > > wrote:
>> >> > >> "JavaScript enclosures"?
>>
>> >> > >> i think it has to do with encapsulating your code inside a function so
>> >> > >> that all vars are inside the function's scope, so not cluttering the
>> >> > >> global namespace.
>> >> > >> This, to avoid memory leak.
>>
>> >> > > Are you implying that global variables do leak memory? There are good
>> >> > > reasons to not clutter the global namespace but I don't believe
>> >> > > avoiding leaks is one of them.
>>
>> >> > > Actually you do increase the chance to create leaks in IE if you use
>> >> > > closures under certain circumstances.
>>
>> >> > > --Klaus

[jQuery] Re: Interesting on document ready question

> >Why do I really need so much on ready?
> Yes! That's what we're all wondering! Don't keep us in suspense. :-)

When you work with a bunch of morons in a company that uses them
throughout the site and when the js are packaged will lead to
unnecessary performance loss.

[jQuery] Superfish menu questions/problem

I have just started using superfish on our site http://christianmotorsports.com
I am not a programmer so getting beyond the basic selection options and pasting in custom css code etc. is not clear to me. I have gone through and edited some existing css code for the general template on the site.
This is the initial problem that I cannot seem to get past:
In this screen grab you can see that I am getting a repeated "bullet" graphic after the Extended menu item name and then a » instead of the graphic arrows or a custom arrow that I would rather have pointing downward in this case (since the submenu opens below the parent link).
If you could help me identify how to solve this problem it would be much appreciated.

Also I have another question. Is the menu suppose to show all the submenus (and them they compress back to the hidden state) every time you refresh the page or go to a new page and it "redraws" the  menu for the first time on the new page? Is there any way to keep it from doing that?

My initial intent was to have a vertical menu with the submenus extending out the right side, but I could not seem to get the adjustments to allow this to happen with out cutting of the submenu type. Where and how do I effectively over ride the menu width to accommodate the extended submenu?

Thats for your help with these questions,

Deaven Butler
CMI Creative Director
918-347-5415



[jQuery] Re: Posting multiple values from a checkbox

 

From: Karl Swedberg
Sent: Tuesday, December 30, 2008 7:42 PM
To: jquery-en@googlegroups.com
Subject: [jQuery] Re: Posting multiple values from a checkbox

On Dec 30, 2008, at 8:11 PM, Michael Geary wrote:


Your checkboxes all have the same ID attribute, and they have no NAME
attribute. Give each one a unique ID and NAME. You can use same value for
those two attributes in a single checkbox, or they can be different. But
each ID and each NAME should be unique.

Hey Mike,

Is it necessary to give each one a unique name? I've read this a number of times, but I've also read the contrary, and PHP seems to like the array-like naming convention for checkboxes:

 <input type="checkbox" id="apples" name="food[]" value="apples" />
 <label for="apples">Apples</label>

 <input type="checkbox" id="pizza" name="food[]" value="pizza" />
 <label for="pizza">Pizza</label>

 <input type="checkbox" id="cake" name="food[]" value="cake" />
 <label for="cake">Cake</label>

So, if I check the Apples checkbox and the Pizza checkbox, the $_Post array will look like this:

Array
(
    [food] => Array
        (
            [0] => apples
            [1] => pizza
        )
)

It's pretty handy, but if there is a compelling argument against doing that, I'm willing to be persuaded. 
 
Ah, good point, Karl. I don't know of any reason not to do that. I didn't mean to imply that the unique names was the only way to do it. It's just the approach I'm most familiar with! :-) 

You may run into an alternate syntax for using the <label> tags, where you
don't use the for="..." but instead nest the <input> tag inside the <label>.
That is cleaner, but it doesn't work in IE so it's best avoided. Use the
for="..." instead.

There is nothing wrong with doing both -- nesting the <input> inside the <label> and using the "for" attribute. Or is there?
 
Nope, nothing wrong at all with nesting the tags and using the "for" attribute. I used the non-nested tags just for simplicity, since you do need the "for" attribute for IE. I wonder if there would be any advantage to nesting the tags? Maybe it's more semantic?
 
-Mike

[jQuery] Re: Interesting on document ready question

> From: Kean
>
> No, I don't take that as an insult.

I was worried needlessly, then. :-)

> I was just wondering how document ready was coded so it
> really was just a hypothetical question.

Well, there is the source code. :-)

http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js

Just search for "ready" and you'll find the relevant bits. It's not very
complicated, but it does have a lot more overhead than the simplified
version I posted in my previous reply.

In particular, here's the code that adds the function to the readyList
array:

jQuery.readyList.push( function() { return fn.call(this, jQuery); } );

Note that it wraps each of your callback functions in *another* function,
just so it can provide the calling sequence described in the docs:

http://docs.jquery.com/Events/ready

And here's the code that calls the functions:

if ( jQuery.readyList ) {
// Execute all of them
jQuery.each( jQuery.readyList, function(){
this.call( document );
});

// Reset the list of functions
jQuery.readyList = null;
}

Note that this code uses *yet another* wrapper function. So that's three
function calls for each ready function.

Compare that with the code I posted which makes only a single function call
for each ready function:

window.ready = [];
jQuery(function() {
for( var fn, i = -1; fn = ready[++i]; )
fn( jQuery );
});

Now in all fairness, the ready code has been improved in jQuery 1.3 to
remove one of these two wrapper functions, but it still has the other. And
that code could be improved just a bit more by using a direct for loop
instead of jQuery.each() - this would allow the other wrapper function to be
eliminated.

In any case, this shows how you can reduce overhead by rolling your own code
when you need the fastest performance.

Of course, if your thousands of ready functions actually *do* much, this bit
of optimization may be lost in the noise.

> Why do I really need so much on ready?

Yes! That's what we're all wondering! Don't keep us in suspense. :-)

-Mike

[jQuery] Re: HELP: Screening questions for JavaScript developer candidates:



On Dec 31, 2008, at 12:47 AM, Michael Geary wrote:

They use in context like this: "You need to achieve Function
Closure." Not the way I would word it, but at least I can understand what
they mean. :-)

That's pretty funny. Sounds like something you might find in a self-help book. :-)

--Karl

____________
Karl Swedberg





I missed the part about the "JavaScript class" - yeah, massive fail there.

-Mike

From: Ricardo Tomasi

I think Michael wanted to point out that they're called
'closures' and not 'enclosures'. For a hiring questionnary
that's not very bright.

Another one: there's no such thing as a "Javascript class".
You can have "class-like instantiation", but strictly we're
speaking about objects, constructors and prototypes.


[jQuery] Re: HELP: Screening questions for JavaScript developer candidates:

You got it, that's exactly what I was getting at, Ricardo. I assumed that
they actually meant "closures", but who knows, they could have even been
referring to something else.

Actually I've been getting a kick out of (or getting annoyed by, I'm not
sure which) the terminology that's come into use in the Google Maps API
mailing list. Over there they call it "Function Closure" - with the caps and
the singular. They use in context like this: "You need to achieve Function
Closure." Not the way I would word it, but at least I can understand what
they mean. :-)

I missed the part about the "JavaScript class" - yeah, massive fail there.

-Mike

> From: Ricardo Tomasi
>
> I think Michael wanted to point out that they're called
> 'closures' and not 'enclosures'. For a hiring questionnary
> that's not very bright.
>
> Another one: there's no such thing as a "Javascript class".
> You can have "class-like instantiation", but strictly we're
> speaking about objects, constructors and prototypes.

[jQuery] Re: Interesting on document ready question

Excellent analysis, Ricardo. BTW, which browser did you run your timing test
in?

Here's another tip. If you really do need to have thousands of ready
functions, you can speed things up a bit by rolling your own. For example:

window.ready = [];
jQuery(function() {
for( var fn, i = -1; fn = ready[++i]; )
fn( jQuery );
});

Now you can replace each instance of:

$(function() { ... });

With:

ready.push( function() { ... } );

Or, for a bit more of a speedup in IE:

ready[ready.length] = function() { ... };

-Mike

> From: Ricardo Tomasi
>
> Hi Kean,
>
> AFAIK, ready() puts the function you passed into an array of
> functions. Another function is bound to the DOMContentLoaded
> event, which is fired when the DOM is ready on compliant
> browsers. For the others, several methods are in place to
> detect when DOM is loaded.
> When the event fires/DOM load is detected, that function
> starts calling each of the functions in that array.
>
> Was I clear? :D
>
> In short, ready() stacks functions that will get executed
> when DOMContentLoaded fires or the other browser techniques
> detect DOM is complete. The slowness in this comes mostly
> from the overhead of jQuery's methods. When you call $()
> jQuery has to:
> 1. check if you're passing an object/function/array/selector
> string 2. grab the 'document' object (default) 3. return the
> jQuery object with document 4. call the ready() method on
> that object passing your function 5. store the function in an array
>
> that's quite a bit of overhead. this:
>
> (function(){
> console.time('a');
> for (var i=-1;i<5000;i++){
> $(function(){});
> }
> console.timeEnd('a');
> })();
>
> takes around 200 ms here.
>
> $(document).ready() is a bit faster, around 90ms, probably
> because it doesn't run as many conditionals to guess what you want.
>
> hope that was helpful!
>
> cheers,
> -ricardo
>
>
>
> cheers,
> - ricardo
>
> On Dec 31, 1:49 am, Kean <shenan...@gmail.com> wrote:
> > No, I don't take that as an insult.
> >
> > I was just wondering how document ready was coded so it really was
> > just a hypothetical question.
> >
> > Why do I really need so much on ready?
> >
> > Also, MorningZ, I will be very active in the jQuery mailing list in
> > future to learn more js. Perhaps this is not the best
> starting point
> > for us.
> >
> > On Dec 30, 7:23 pm, MorningZ <morni...@gmail.com> wrote:
> >
> > > "There probably is a better way to do it. "
> >
> > > Which is what i was getting at......   i hope "honest"
> isn't/wasn't
> > > taken as "insulting"
> >
> > > On Dec 30, 10:16 pm, "Michael Geary" <m...@mg.to> wrote:
> >
> > > > Come on, MorningZ, there's no need for insults.
> >
> > > > But yes, 5000 of those will be pretty slow - and that's
> before you
> > > > even execute the code inside those functions. How slow?
> It's easy
> > > > to test. The ready functions are run in the order that the $()
> > > > functions are called. So simply do this in a test page:
> >
> > > >     var t1 = +new Date;
> > > >     $(function(){});
> > > >     // ... Repeat above line 5000 times
> > > >     $(function() {
> > > >         var t2 = +new Date;
> > > >         alert( (t2-t1)/1000 + ' seconds' );
> > > >     });
> >
> > > > You can easily generate that file by hand in a text editor. You
> > > > don't have to do 5000 pastes. Start with 10 of them, copy that
> > > > block and paste it 10 times so you have 100, copy
> *that* block and
> > > > paste it 10 times so you have 1000, copy that and five
> more pastes and you're done.
> >
> > > > Test it in IE6 (!), and if you're on your usual development
> > > > machine, triple the time from the alert to take into
> account the
> > > > slower machines that your visitors will have (think a
> slow laptop
> > > > running on battery). If you don't have IE6, try it in
> IE7 and as a
> > > > rough guess, multiply your observed time by six (triple
> for the slow machines, double again for IE6).
> >
> > > > Mind if I ask: why do you need 5000 of these? There
> probably is a
> > > > better way to do it.
> >
> > > > -Mike
> >
> > > > > From: MorningZ
> >
> > > > > If you've got 5000 of those, it's *seriously* time to
> reconsider
> > > > > your coding techniques.....  depending on that much
> JavaScript
> > > > > is just plain old stupid......
> > > > > On Dec 30, 8:59 pm, Kean <shenan...@gmail.com> wrote:
> > > > > > Is document ready "actually" an event handler?
> >
> > > > > > Let's say I have
> >
> > > > > > $(function(){
> >
> > > > > > });
> >
> > > > > > $(function(){
> >
> > > > > > });
> >
> > > > > > $(function(){
> >
> > > > > > });
> >
> > > > > > $(function(){
> >
> > > > > > });
> >
> > > > > > $(function(){
> >
> > > > > > });
> >
> > > > > > etc ..... around 5000 of those.
> >
> > > > > > Will it actually degrade performance like 5000 bind()?
> > > > > > My guess is not much performance penalty, but
> again, it's a guess.
>

[jQuery] Re: Please help me on a .lt method

Thanks all the same。 I've got it solved. Actually the problem is that .lt and .gt were removed from the newly released jquery.

Thanks.

On Wed, Dec 31, 2008 at 1:10 PM, Kean <shenanime@gmail.com> wrote:

Make a demo page or a html page.

Some common mistakes

1. Did you include jQuery?
2. Did you write something like
var $table =$('table') before using  $table.find() ?


On Dec 30, 7:30 pm, Samuel Wu <Samuel.YH...@gmail.com> wrote:
> Hi, everyone
>
> I started writing jquery from last week with the help from a very good
> book Learning Jquery.
>
> I met a problem when reading the book, which has the script:
>
> <code>
> $table.find('tbody tr').show()
> .lt(2)
> .hide()
> .end()
> .gt(5)
> .end();
> </code>
>
> Where 2 and 5 are different from the book, but I think it has no
> effect to the problem.
>
> I haven't met a lt or gt method before, I can only write
> <code>
>     $table.find('tbody tr:lt(2)').hide();
>     $table.find('tbody tr:gt(5)').hide();
> </code>
>
> I tried the author's code, which didn't work on my browser. the
> browser said
> "TypeError: $("table").find("tbody tr").show().lt is not a function"
>
> I also tried this way:
> <code>
> var $trow=$table.find('tbody tr')
> $trow.lt(2).hide()
> <code>
>
> the problem still exists there.
>
> My question is:
> Is lt or gt a method used as a  selector ?
> If I want to implement the chain actions like the first code, how
> could I do that?
>
> Any help is appreciated. thanks very much. Happy new year.



--
Samuel Wu

[jQuery] Re: Please help me on a .lt method

Hi Karl,

Thanks very much for your quick helps.

Feel very nice to hear from you. You write a very nice book. I can write some simple codes after reading your books for only a week. I'm reading the seventh chapter now.

Actually I'm going to release a website for our Chinese learning English Vocabularies in a month, and I hope my scripts work well on my site.

Thanks again. 

On Wed, Dec 31, 2008 at 1:17 PM, Karl Swedberg <karl@englishrules.com> wrote:
Hi Samuel,

Sorry about the problems you're having with the code. The .lt() and .gt() methods were removed from jQuery shortly after the book was published. In their place, you can use the :lt() and :gt() selectors or the .slice() method. The .slice() method is quite versatile, and takes either one or two arguments. To replicate that code using .slice() you could do this:

$table.find('tbody tr').show()
.slice(0, 2)
.hide()
.end()
.slice(5)
.end();



On Dec 30, 2008, at 10:30 PM, Samuel Wu wrote:


Hi, everyone

I started writing jquery from last week with the help from a very good
book Learning Jquery.

I met a problem when reading the book, which has the script:

<code>
$table.find('tbody tr').show()
.lt(2)
.hide()
.end()
.gt(5)
.end();
</code>

Where 2 and 5 are different from the book, but I think it has no
effect to the problem.

I haven't met a lt or gt method before, I can only write
<code>
   $table.find('tbody tr:lt(2)').hide();
   $table.find('tbody tr:gt(5)').hide();
</code>

I tried the author's code, which didn't work on my browser. the
browser said
"TypeError: $("table").find("tbody tr").show().lt is not a function"

I also tried this way:
<code>
var $trow=$table.find('tbody tr')
$trow.lt(2).hide()
<code>

the problem still exists there.

My question is:
Is lt or gt a method used as a  selector ?
If I want to implement the chain actions like the first code, how
could I do that?

Any help is appreciated. thanks very much. Happy new year.




--
Samuel Wu

[jQuery] Re: Please help me on a .lt method

Hi Samuel,

Sorry about the problems you're having with the code. The .lt() and .gt() methods were removed from jQuery shortly after the book was published. In their place, you can use the :lt() and :gt() selectors or the .slice() method. The .slice() method is quite versatile, and takes either one or two arguments. To replicate that code using .slice() you could do this:

$table.find('tbody tr').show()
.slice(0, 2)
.hide()
.end()
.slice(5)
.end();



On Dec 30, 2008, at 10:30 PM, Samuel Wu wrote:


Hi, everyone

I started writing jquery from last week with the help from a very good
book Learning Jquery.

I met a problem when reading the book, which has the script:

<code>
$table.find('tbody tr').show()
.lt(2)
.hide()
.end()
.gt(5)
.end();
</code>

Where 2 and 5 are different from the book, but I think it has no
effect to the problem.

I haven't met a lt or gt method before, I can only write
<code>
   $table.find('tbody tr:lt(2)').hide();
   $table.find('tbody tr:gt(5)').hide();
</code>

I tried the author's code, which didn't work on my browser. the
browser said
"TypeError: $("table").find("tbody tr").show().lt is not a function"

I also tried this way:
<code>
var $trow=$table.find('tbody tr')
$trow.lt(2).hide()
<code>

the problem still exists there.

My question is:
Is lt or gt a method used as a  selector ?
If I want to implement the chain actions like the first code, how
could I do that?

Any help is appreciated. thanks very much. Happy new year.

[jQuery] Re: Please help me on a .lt method

Make a demo page or a html page.

Some common mistakes

1. Did you include jQuery?
2. Did you write something like
var $table =$('table') before using $table.find() ?


On Dec 30, 7:30 pm, Samuel Wu <Samuel.YH...@gmail.com> wrote:
> Hi, everyone
>
> I started writing jquery from last week with the help from a very good
> book Learning Jquery.
>
> I met a problem when reading the book, which has the script:
>
> <code>
> $table.find('tbody tr').show()
> .lt(2)
> .hide()
> .end()
> .gt(5)
> .end();
> </code>
>
> Where 2 and 5 are different from the book, but I think it has no
> effect to the problem.
>
> I haven't met a lt or gt method before, I can only write
> <code>
>     $table.find('tbody tr:lt(2)').hide();
>     $table.find('tbody tr:gt(5)').hide();
> </code>
>
> I tried the author's code, which didn't work on my browser. the
> browser said
> "TypeError: $("table").find("tbody tr").show().lt is not a function"
>
> I also tried this way:
> <code>
> var $trow=$table.find('tbody tr')
> $trow.lt(2).hide()
> <code>
>
> the problem still exists there.
>
> My question is:
> Is lt or gt a method used as a  selector ?
> If I want to implement the chain actions like the first code, how
> could I do that?
>
> Any help is appreciated. thanks very much. Happy new year.

[jQuery] Re: .html() only works on original source?

Two issues at play here:

1. the HTML in most browsers doesn't reflect all recent changes done
via Javascript
2. the browser only saves form values after a submit

What you can do is save the values at the time of removal, and then re-
fill it when you put it back. Use the data() function:

// removal, store the values
var oldform = $('#form').children(':input').each(function(){
var t = $(this);
t.data('value', t.val() );
}).end().remove();

//append and fill
oldform.appendTo('body').children(':input').each(function(){
var t = $(this);
t.val( t.data('value') );
});

- ricardo

On Dec 30, 1:39 pm, the_woodsman <elwood.ca...@gmail.com> wrote:
> Hi all,
>
> I'm trying to save the content of a form into a hidden div, so I can
> bring it back later.
>
> However, I also want to save the user's progress on the form. I
> thought I could just dump $('#form').html() into the hidden div, but
> this seems to only remember the original html, no new value attributes
> exist even after I've entered some text.
>
> I tested with something like this:
>
>                 $('body').find(':input').each(
>
>                 function()
>                 {
>                         alert($(this).attr('name')+": "+$(this).val()+", "+$(this).attr
> ('value'));
>                         //.val() and .attr(val)  are always up to date
> and consistent
>
>                         alert(""+$(this).parent().html());
>                         //inconsistent with .attr(val)  above, seems to
> be the original only
>
>                 }
>                 );
>
> An obvious work around would be to iterate through the inputs
> explicitly setting the value atribute to .val(), which I assume would
> work, but it seems there must be a more elegant way...
>
> Is there something like  .liveHtml()?  Or another solution?
>
> Thanks in advance...

[jQuery] Re: Fastest way to clear child elements from a div

If I read the jQuery source code right, it seems that .html() does not
use this replaceHTML method even in 1.3b1


On Dec 30, 8:21 pm, Ricardo Tomasi <ricardob...@gmail.com> wrote:
> There is a long discussion about better 'innerHTML' methods, see here
> (check the comments also):
>
> http://blog.stevenlevithan.com/archives/faster-than-innerhtmlhttp://ajaxian.com/archives/replacehtml-for-when-innerhtml-dogs-you-down
>
> On Dec 30, 7:00 pm, Adam Guichard <amguich...@gmail.com> wrote:
>
> > It ran in 5ms, but its my understanding if I use the method your
> > suggesting I'll be leaking memory.  If I just set the innerhtml = "",
> > I think the dom element's children aren't disposed.  They just sit
> > around chewing up memory, so I don't think I can use the method your
> > suggesting.
>
> > On Dec 30, 2:42 pm, MorningZ <morni...@gmail.com> wrote:
>
> > > just for laughs...see of
>
> > > document.getElementById("ID of Div Tag").innerHTML = "";
>
> > > is anything of an improvement
>
> > > On Dec 30, 3:02 pm, Adam Guichard <amguich...@gmail.com> wrote:
>
> > > > I'm using jTemplates to create a client grid, but I'm having trouble
> > > > with load times.  When I'm paging through the grid jTemplates is
> > > > taking 4+ seconds to clear the grid and 2+ seconds to load it.  I've
> > > > got some work to do to make the loading time go down, but I'm worried
> > > > about the clearing time.  I've tried a few different methods, but
> > > > nothing seems to be really fast.  I'd like to be able to clear the div
> > > > in less than a second.  Here's what I've tried:
>
> > > > $(selector).empty() and $(selector).html('') both took between  3-4
> > > > seconds
>
> > > > Does anyone know of a faster way to empty the child elements of a div?

[jQuery] Re: Interesting on document ready question

Hi Ricardo,

Sweet, that's what I was expecting for an answer.

[jQuery] Re: Interesting on document ready question

Hi Kean,

AFAIK, ready() puts the function you passed into an array of
functions. Another function is bound to the DOMContentLoaded event,
which is fired when the DOM is ready on compliant browsers. For the
others, several methods are in place to detect when DOM is loaded.
When the event fires/DOM load is detected, that function starts
calling each of the functions in that array.

Was I clear? :D

In short, ready() stacks functions that will get executed when
DOMContentLoaded fires or the other browser techniques detect DOM is
complete. The slowness in this comes mostly from the overhead of
jQuery's methods. When you call $() jQuery has to:
1. check if you're passing an object/function/array/selector string
2. grab the 'document' object (default)
3. return the jQuery object with document
4. call the ready() method on that object passing your function
5. store the function in an array

that's quite a bit of overhead. this:

(function(){
console.time('a');
for (var i=-1;i<5000;i++){
$(function(){});
}
console.timeEnd('a');
})();

takes around 200 ms here.

$(document).ready() is a bit faster, around 90ms, probably because it
doesn't run as many conditionals to guess what you want.

hope that was helpful!

cheers,
-ricardo

cheers,
- ricardo

On Dec 31, 1:49 am, Kean <shenan...@gmail.com> wrote:
> No, I don't take that as an insult.
>
> I was just wondering how document ready was coded so it really was
> just a hypothetical question.
>
> Why do I really need so much on ready?
>
> Also, MorningZ, I will be very active in the jQuery mailing list in
> future to learn more js. Perhaps this is not the best starting point
> for us.
>
> On Dec 30, 7:23 pm, MorningZ <morni...@gmail.com> wrote:
>
> > "There probably is a better way to do it. "
>
> > Which is what i was getting at......   i hope "honest" isn't/wasn't
> > taken as "insulting"
>
> > On Dec 30, 10:16 pm, "Michael Geary" <m...@mg.to> wrote:
>
> > > Come on, MorningZ, there's no need for insults.
>
> > > But yes, 5000 of those will be pretty slow - and that's before you even
> > > execute the code inside those functions. How slow? It's easy to test. The
> > > ready functions are run in the order that the $() functions are called. So
> > > simply do this in a test page:
>
> > >     var t1 = +new Date;
> > >     $(function(){});
> > >     // ... Repeat above line 5000 times
> > >     $(function() {
> > >         var t2 = +new Date;
> > >         alert( (t2-t1)/1000 + ' seconds' );
> > >     });
>
> > > You can easily generate that file by hand in a text editor. You don't have
> > > to do 5000 pastes. Start with 10 of them, copy that block and paste it 10
> > > times so you have 100, copy *that* block and paste it 10 times so you have
> > > 1000, copy that and five more pastes and you're done.
>
> > > Test it in IE6 (!), and if you're on your usual development machine, triple
> > > the time from the alert to take into account the slower machines that your
> > > visitors will have (think a slow laptop running on battery). If you don't
> > > have IE6, try it in IE7 and as a rough guess, multiply your observed time by
> > > six (triple for the slow machines, double again for IE6).
>
> > > Mind if I ask: why do you need 5000 of these? There probably is a better way
> > > to do it.
>
> > > -Mike
>
> > > > From: MorningZ
>
> > > > If you've got 5000 of those, it's *seriously* time to
> > > > reconsider your coding techniques.....  depending on that
> > > > much JavaScript is just plain old stupid......
> > > > On Dec 30, 8:59 pm, Kean <shenan...@gmail.com> wrote:
> > > > > Is document ready "actually" an event handler?
>
> > > > > Let's say I have
>
> > > > > $(function(){
>
> > > > > });
>
> > > > > $(function(){
>
> > > > > });
>
> > > > > $(function(){
>
> > > > > });
>
> > > > > $(function(){
>
> > > > > });
>
> > > > > $(function(){
>
> > > > > });
>
> > > > > etc ..... around 5000 of those.
>
> > > > > Will it actually degrade performance like 5000 bind()?
> > > > > My guess is not much performance penalty, but again, it's a guess.

[jQuery] Re: HELP: Screening questions for JavaScript developer candidates:

See, that is the kind of feedback I was interested in. I sell my self short and thought I saw some inconsistencies and discrepancies; but, was unsure. 

I appreciate everyones feedback.

Thank you,
Angel

[jQuery] Re: HELP: Screening questions for JavaScript developer candidates:

I think Michael wanted to point out that they're called 'closures' and
not 'enclosures'. For a hiring questionnary that's not very bright.

Another one: there's no such thing as a "Javascript class". You can
have "class-like instantiation", but strictly we're speaking about
objects, constructors and prototypes.

On Dec 30, 10:38 am, "Alexandre Plennevaux" <aplennev...@gmail.com>
wrote:
> Klaus, you got me: frankly i have no "real" idea what is the purpose
> of enclosure.
> That's abstract art to me. i just read in several places that it's
> good to use it, so i trust my sources, do it and move on. Not that i'm
> proud of it, but, to use a metaphor, one does not need to know the
> internals of a car in order to be able to drive it, although it surely
> is a valuable knowledge if one wants to keep its car in a good state !
> Yet, since the car changes every six months, it's just up to you,
> wheather you're driven by the pure developer's passion or by consumer
> pragmatism.
>
> On Tue, Dec 30, 2008 at 1:28 PM, Klaus Hartl <klaus.ha...@googlemail.com> wrote:
>
> > On 30 Dez., 08:45, "Alexandre Plennevaux" <aplennev...@gmail.com>
> > wrote:
> >> "JavaScript enclosures"?
>
> >> i think it has to do with encapsulating your code inside a function so
> >> that all vars are inside the function's scope, so not cluttering the
> >> global namespace.
> >> This, to avoid memory leak.
>
> > Are you implying that global variables do leak memory? There are good
> > reasons to not clutter the global namespace but I don't believe
> > avoiding leaks is one of them.
>
> > Actually you do increase the chance to create leaks in IE if you use
> > closures under certain circumstances.
>
> > --Klaus

[jQuery] Re: Fastest way to clear child elements from a div

There is a long discussion about better 'innerHTML' methods, see here
(check the comments also):

http://blog.stevenlevithan.com/archives/faster-than-innerhtml
http://ajaxian.com/archives/replacehtml-for-when-innerhtml-dogs-you-down

On Dec 30, 7:00 pm, Adam Guichard <amguich...@gmail.com> wrote:
> It ran in 5ms, but its my understanding if I use the method your
> suggesting I'll be leaking memory.  If I just set the innerhtml = "",
> I think the dom element's children aren't disposed.  They just sit
> around chewing up memory, so I don't think I can use the method your
> suggesting.
>
> On Dec 30, 2:42 pm, MorningZ <morni...@gmail.com> wrote:
>
> > just for laughs...see of
>
> > document.getElementById("ID of Div Tag").innerHTML = "";
>
> > is anything of an improvement
>
> > On Dec 30, 3:02 pm, Adam Guichard <amguich...@gmail.com> wrote:
>
> > > I'm using jTemplates to create a client grid, but I'm having trouble
> > > with load times.  When I'm paging through the grid jTemplates is
> > > taking 4+ seconds to clear the grid and 2+ seconds to load it.  I've
> > > got some work to do to make the loading time go down, but I'm worried
> > > about the clearing time.  I've tried a few different methods, but
> > > nothing seems to be really fast.  I'd like to be able to clear the div
> > > in less than a second.  Here's what I've tried:
>
> > > $(selector).empty() and $(selector).html('') both took between  3-4
> > > seconds
>
> > > Does anyone know of a faster way to empty the child elements of a div?

[jQuery] Re: REFACTOR: contents() with index() or indexOf()

The children() in your loop is not counting the textnode either.

index() can't help you in this case, as it ignores nodes that are not
elements even using contents(). But you can use $.each to simplify
your code a bit:

var $items = $('<items><item>Hello</item><item>world</item>!!<item
id="my_item">Goodnight moon!</item></items>');
$.each($items.contents(), function(i) {
if (this.id == 'my_item') {
console.info(i);
return false; //stop the loop
}
});

- ricardo

On Dec 31, 1:04 am, nachocab <nacho...@gmail.com> wrote:
> Allright, so I guess manually going through the contents() array is
> the only solution.
> The only function that comes close to giving me the index is
> jQuery.inArray() (it's really just the for loop that I'm doing with a
> different condition), but it doesn't let me specify the id or the
> className, so I'm out of luck.
>
> Thanks anyway,
>
> Nacho
>
> On Dec 30, 11:22 pm, Dave Methvin <dave.meth...@gmail.com> wrote:
>
> > > var $items = $('<items><item>Hello</item><item>world</item>...
>
> > jQuery will try to parse that with the browser's HTML parser, but it's
> > not HTML. I don't know if that will cause you sorrow or not.
>
> >http://groups.google.com/group/jquery-en/browse_thread/thread/95718c9...
>
> > As for getting the index, maybe something like this?
>
> >   $items.find('#my_item').prevAll().length

[jQuery] Re: Fastest way to clear child elements from a div

Oops I mean event.

On Dec 30, 8:11 pm, Kean <shenan...@gmail.com> wrote:
> Sounds like your nodes have to much element binded to them.
>
> On Dec 30, 1:00 pm, Adam Guichard <amguich...@gmail.com> wrote:
>
> > It ran in 5ms, but its my understanding if I use the method your
> > suggesting I'll be leaking memory.  If I just set the innerhtml = "",
> > I think the dom element's children aren't disposed.  They just sit
> > around chewing up memory, so I don't think I can use the method your
> > suggesting.
>
> > On Dec 30, 2:42 pm, MorningZ <morni...@gmail.com> wrote:
>
> > > just for laughs...see of
>
> > > document.getElementById("ID of Div Tag").innerHTML = "";
>
> > > is anything of an improvement
>
> > > On Dec 30, 3:02 pm, Adam Guichard <amguich...@gmail.com> wrote:
>
> > > > I'm using jTemplates to create a client grid, but I'm having trouble
> > > > with load times.  When I'm paging through the grid jTemplates is
> > > > taking 4+ seconds to clear the grid and 2+ seconds to load it.  I've
> > > > got some work to do to make the loading time go down, but I'm worried
> > > > about the clearing time.  I've tried a few different methods, but
> > > > nothing seems to be really fast.  I'd like to be able to clear the div
> > > > in less than a second.  Here's what I've tried:
>
> > > > $(selector).empty() and $(selector).html('') both took between  3-4
> > > > seconds
>
> > > > Does anyone know of a faster way to empty the child elements of a div?

[jQuery] Re: Fastest way to clear child elements from a div

Sounds like your nodes have to much element binded to them.


On Dec 30, 1:00 pm, Adam Guichard <amguich...@gmail.com> wrote:
> It ran in 5ms, but its my understanding if I use the method your
> suggesting I'll be leaking memory.  If I just set the innerhtml = "",
> I think the dom element's children aren't disposed.  They just sit
> around chewing up memory, so I don't think I can use the method your
> suggesting.
>
> On Dec 30, 2:42 pm, MorningZ <morni...@gmail.com> wrote:
>
> > just for laughs...see of
>
> > document.getElementById("ID of Div Tag").innerHTML = "";
>
> > is anything of an improvement
>
> > On Dec 30, 3:02 pm, Adam Guichard <amguich...@gmail.com> wrote:
>
> > > I'm using jTemplates to create a client grid, but I'm having trouble
> > > with load times.  When I'm paging through the grid jTemplates is
> > > taking 4+ seconds to clear the grid and 2+ seconds to load it.  I've
> > > got some work to do to make the loading time go down, but I'm worried
> > > about the clearing time.  I've tried a few different methods, but
> > > nothing seems to be really fast.  I'd like to be able to clear the div
> > > in less than a second.  Here's what I've tried:
>
> > > $(selector).empty() and $(selector).html('') both took between  3-4
> > > seconds
>
> > > Does anyone know of a faster way to empty the child elements of a div?

[jQuery] Re: Ajax lists makes the page jump

Rather than set the height, you could set min-height. 

IE6 doesn't recognize min-height, but it treats height as min-height, so you can set height within a conditional comment for IE6 only.

--Karl

____________
Karl Swedberg




On Dec 30, 2008, at 4:25 PM, Loa wrote:


Yo!
Just found this mail group, if I'm in the wrong place just flame on ;)
Hm.. tried to post but it never showed up... hope it doesn't end up in
"double post"

To the business.
So I got a page with this structure:

<body>
<div id="container">
<table id="dalist">
</table>
</div>
</body>

Im just fetching a list of items with xml and inserting them as rows
in the table. And the reason I use ajax is that I want some smooth
paging to the list.

My problem is that if a user change "list page" then the browser
window will jump up as I delete all rows in the table (the page gets
shorter). Do anyone know any good tricks to get around this type of
practical problem?

My own solution was to get the height of the div after inputing the
first page and then set it to that height with css. But then I get
problem if a row is taller (cause of the content) and then "breaks"
the div.

Thanks in advance!
Cheers Loa

[jQuery] jquery autocomplete plugin

Hi list, I need some help with autocomplete plugin.

I have two text field (name and surname) and I need to add to the name
field the autocomplete like this:
When the user start writing on it, it shows the coincidences and when
he select the correct item the surname field most be filled too. For
example:

HTML tags:

<input type="text" id="name" /><br />
<input type="text" id="surname" /><br />

Javascript code:

$().ready(function() {
$("#name").autocomplete(records, {
minChars: 0,
width: 250,
matchContains: 1,
autoFill: true,
onItemSelect: function(row) {
$("#surname").value = row.surname;
},
onFindValue: function(row) {
$("#surname").value = row.surname;
},
formatItem: function(row, i, max) {
return row.name + " " + row.surname;
},
formatMatch: function(row, i, max) {
return row.name;
},
formatResult: function(row) {
return row.name;
}
});
});

*************************
records its a javascript array like:

var records = [
{ name: "John", surname: "Smith"},
{ name: "Ian", surname: "Crawford"},
{ name: "Derek", surname: "Lee"}
];

Thanks!!!

[jQuery] Re: Interesting on document ready question

No, I don't take that as an insult.

I was just wondering how document ready was coded so it really was
just a hypothetical question.

Why do I really need so much on ready?

Also, MorningZ, I will be very active in the jQuery mailing list in
future to learn more js. Perhaps this is not the best starting point
for us.

On Dec 30, 7:23 pm, MorningZ <morni...@gmail.com> wrote:
> "There probably is a better way to do it. "
>
> Which is what i was getting at......   i hope "honest" isn't/wasn't
> taken as "insulting"
>
> On Dec 30, 10:16 pm, "Michael Geary" <m...@mg.to> wrote:
>
> > Come on, MorningZ, there's no need for insults.
>
> > But yes, 5000 of those will be pretty slow - and that's before you even
> > execute the code inside those functions. How slow? It's easy to test. The
> > ready functions are run in the order that the $() functions are called. So
> > simply do this in a test page:
>
> >     var t1 = +new Date;
> >     $(function(){});
> >     // ... Repeat above line 5000 times
> >     $(function() {
> >         var t2 = +new Date;
> >         alert( (t2-t1)/1000 + ' seconds' );
> >     });
>
> > You can easily generate that file by hand in a text editor. You don't have
> > to do 5000 pastes. Start with 10 of them, copy that block and paste it 10
> > times so you have 100, copy *that* block and paste it 10 times so you have
> > 1000, copy that and five more pastes and you're done.
>
> > Test it in IE6 (!), and if you're on your usual development machine, triple
> > the time from the alert to take into account the slower machines that your
> > visitors will have (think a slow laptop running on battery). If you don't
> > have IE6, try it in IE7 and as a rough guess, multiply your observed time by
> > six (triple for the slow machines, double again for IE6).
>
> > Mind if I ask: why do you need 5000 of these? There probably is a better way
> > to do it.
>
> > -Mike
>
> > > From: MorningZ
>
> > > If you've got 5000 of those, it's *seriously* time to
> > > reconsider your coding techniques.....  depending on that
> > > much JavaScript is just plain old stupid......
> > > On Dec 30, 8:59 pm, Kean <shenan...@gmail.com> wrote:
> > > > Is document ready "actually" an event handler?
>
> > > > Let's say I have
>
> > > > $(function(){
>
> > > > });
>
> > > > $(function(){
>
> > > > });
>
> > > > $(function(){
>
> > > > });
>
> > > > $(function(){
>
> > > > });
>
> > > > $(function(){
>
> > > > });
>
> > > > etc ..... around 5000 of those.
>
> > > > Will it actually degrade performance like 5000 bind()?
> > > > My guess is not much performance penalty, but again, it's a guess.

[jQuery] Re: Posting multiple values from a checkbox

On Dec 30, 2008, at 8:11 PM, Michael Geary wrote:


Your checkboxes all have the same ID attribute, and they have no NAME
attribute. Give each one a unique ID and NAME. You can use same value for
those two attributes in a single checkbox, or they can be different. But
each ID and each NAME should be unique.

Hey Mike,

Is it necessary to give each one a unique name? I've read this a number of times, but I've also read the contrary, and PHP seems to like the array-like naming convention for checkboxes:

 <input type="checkbox" id="apples" name="food[]" value="apples" />
 <label for="apples">Apples</label>

 <input type="checkbox" id="pizza" name="food[]" value="pizza" />
 <label for="pizza">Pizza</label>

 <input type="checkbox" id="cake" name="food[]" value="cake" />
 <label for="cake">Cake</label>

So, if I check the Apples checkbox and the Pizza checkbox, the $_Post array will look like this:

Array
(
    [food] => Array
        (
            [0] => apples
            [1] => pizza
        )
)

It's pretty handy, but if there is a compelling argument against doing that, I'm willing to be persuaded.

You may run into an alternate syntax for using the <label> tags, where you
don't use the for="..." but instead nest the <input> tag inside the <label>.
That is cleaner, but it doesn't work in IE so it's best avoided. Use the
for="..." instead.

There is nothing wrong with doing both -- nesting the <input> inside the <label> and using the "for" attribute. Or is there?

--Karl
____________
Karl Swedberg

[jQuery] Please help me on a .lt method

Hi, everyone

I started writing jquery from last week with the help from a very good
book Learning Jquery.

I met a problem when reading the book, which has the script:

<code>
$table.find('tbody tr').show()
.lt(2)
.hide()
.end()
.gt(5)
.end();
</code>

Where 2 and 5 are different from the book, but I think it has no
effect to the problem.

I haven't met a lt or gt method before, I can only write
<code>
$table.find('tbody tr:lt(2)').hide();
$table.find('tbody tr:gt(5)').hide();
</code>

I tried the author's code, which didn't work on my browser. the
browser said
"TypeError: $("table").find("tbody tr").show().lt is not a function"

I also tried this way:
<code>
var $trow=$table.find('tbody tr')
$trow.lt(2).hide()
<code>

the problem still exists there.

My question is:
Is lt or gt a method used as a selector ?
If I want to implement the chain actions like the first code, how
could I do that?

Any help is appreciated. thanks very much. Happy new year.