[jQuery] Re: confusing children() behavior
On Sep 7, 2007, at 18:33 , ScottBruin wrote: In this search, pressing enter when an item is highlighted redirects to a new page. The code from the book reads similar to the following: var redirectPage = function() { var x = $autocomplete.find('li').eq(selectedItem).children()[0]; location.href = x; }; where, from earlier: var $autocomplete = $('ol id=dropbox/ol').hide().insertAfter($ ('some search field')); selectedItem is the currently highlighted list element (li) in the drop down div. Its my understanding, then, that the redirectPage function should find the list item that is currently highlighted, and then find its first child. This first child is a link containing text (a la a href=google.comGoogle/a). To me, it seems that .children()[0] should return the entire string: a href=google.comGoogle/a However, it only returns google.com. It should be returning neither. Using the [0] notation on a jQuery object (which is what the .children() method returns) gives you a DOM node object. It may be that whatever diagnostic technique you are using to inspect the return value is using the href as a label for the object. Further, when I change var x = $autocomplete.find('li').eq(selectedItem).children().html() it does return the HTML inside the anchor, namely Google. In this case, you are in effect calling innerHtml on each of the item's children, and concatenating the results. Because only the string Google is in the anchor, this is what is returned. -- Jonathan Chaffer Technology Officer, Structure Interactive
[jQuery] Re: :eq vs :nth?
On Aug 3, 2007, at 20:24 , John Resig wrote: On 8/3/07, Josh Nathanson [EMAIL PROTECTED] wrote: josh, how is that maintaining backwards compatibility? I assume that you will still be able to use the old selectors, but the underlying method that processes them will be different - thus they will be deprecated. Is that not correct jQuery gurus? They'll be deprecated in 1.1.4, removed in 1.2. And really easy to re-add via a plug-in! -- Jonathan Chaffer Technology Officer, Structure Interactive
[jQuery] Re: Help with book example - alternating row colors
On Jul 30, 2007, at 11:16 , Priest, James (NIH/NIEHS) [C] wrote: Using the book code - I've got the background striped every other row: $(document).ready( function() { // $('table#chemtable tr:odd').addClass('odd'); // $(#chemtable tr:even).addClass(even); var rowClass = even; var rowIndex = 0; $('table#chemtable tr').each(function(index) { if (rowIndex %2==0){ rowClass = (rowClass == even ? odd : even); }; $(this).addClass(rowClass); rowIndex++; }); }); But now I'd like to add a bottom border to each 'set' (like the txt example above) but so far my attempts haven't worked... I either get the bottom border correct - or my striping on each 'set' gets thrown off.. How about this? if (rowIndex % 2 == 1){ $(this).addClass('bottom-border'); }; That will add the bottom-border class to the second (last) item of each group. You could insert this clause right after the existing .addClass() line. -- Jonathan Chaffer Technology Officer, Structure Interactive
[jQuery] Re: book learning jquery appendix C,closure question
Yep, that looks like a mistake in the copy editing. We'll make sure that makes it into the errata list. Thanks for catching that! Here's the original code; our copy editor changed the variable names to match the publisher's style guide. $(document).ready(function() { function f() { var a = 0; function g() { a++; console.log(a); } function h() { a = a + 2; console.log(a); } return {'g': g, 'h': h}; } var m = f(); m.g(); m.h(); m.g(); var n = f(); n.g(); n.h(); n.g(); }); On Jul 13, 2007, at 18:16 , Guapo wrote: the following text if copy from the book,I was confused with the variable globVar in the innerFun2,is it a clerical error or the variable in the statement var globVar = outerFun();? thank you all! Interactions between Closures When more than one inner function exists, closures can have effects that are not as easy to anticipate. Suppose we pair our incrementing function with another function, this time incrementing by two: function outerFun() { var outerVar = 0; function innerFun() { outerVar++; alert(outerVar); } function innerFun2() { outerVar = outerVar + 2; alert(globVar); } return {'innerFun': innerFun, 'outerFun2': outerFun2}; } We return references to both functions, using a map to do so (this illustrates another way in which reference to an inner function can escape its parent). Both functions can be called through the references: var globVar = outerFun(); globVar.innerFun(); // Alerts 1 globVar.innerFun2(); // Alerts 3 globVar.innerFun(); // Alerts 4 var globVar2 = outerFun(); globVar2.innerFun(); // Alerts 1 globVar2.innerFun2(); // Alerts 3 globVar2.innerFun(); // Alerts 4 -- Jonathan Chaffer Technology Officer, Structure Interactive
[jQuery] Re: book learning jquery appendix C,closure question
On Jul 13, 2007, at 20:53 , Stephan Beal wrote: As i understand it, that code is wrong, as globVar.innerFun2() is not available to the caller at this point. IMO, to be legal code, innerFun2() should be replaced with outerFun2(). See: http://javascript.crockford.com/private.html for why innerFun2() can be considered a private variable of globVar. What you're missing here is the return statement of the outer function. A reference to the inner function is returned, so it can be called by the outside code. -- Jonathan Chaffer Technology Officer, Structure Interactive
[jQuery] Re: jquery book
That's right. We're still putting the finishing touches on that one, but it should be ready shortly. On Jul 11, 2007, at 11:22 , AtlantaGeek wrote: So it seems the reference book is not available, yet, correct? On Jul 9, 10:57 am, Karl Swedberg [EMAIL PROTECTED] wrote: 2. jQuery Reference Guide is a 250+ page complete reference to the jQuery API and selector expressions (up to v1.1.2), plus individual chapters on the Dimensions plugin, Form plugin, and creating your own plugin (and 3 appendices). This one should be available beginning of August. -- Jonathan Chaffer Technology Officer, Structure Interactive
[jQuery] Re: Syntactic sugar for checking whether an element exists
On Jul 9, 2007, at 23:57 , Erik Beeson wrote: In fact, if you find yourself doing a lot of if(something exists) { ... } else { ...}, you might want to consider trying to move some of your code into a plugin. Most jQuery functions/plugins already deal with the if(exists)... part by simply not executing if nothing is selected. Along those lines, I especially like using .each() for this kind of logic: $('#myId').each(function() { // do things with this here }); The .each() functions as an if, automatically scales to multiple matches (often without planning for it), and as a bonus creates a little namespace in the function where you can declare local variables. -- Jonathan Chaffer Technology Officer, Structure Interactive
[jQuery] Re: Really removing items from the DOM
On Jul 9, 2007, at 13:45 , Stephan Beal wrote: How do i permanently remove items from the DOM *and* jQuery object? i am aware of jQuery(..).remove(), but the docs for remove() say: This does NOT remove them from the jQuery object, allowing you to use the matched elements further. This feature [snide comment removed] causes me to have to jump through some hoops in my code to set the matched DOM object IDs to null so that i won't pick them up in later queries. I think you're confused about what the jQuery object means here. There isn't a master internal list of objects that is keeping track of the DOM nodes. The docs are talking about the individual jQuery object instance you're working with, so you can have the code: $('#myElement').remove().doSomethingElseWithMyElement(); The chain is not broken, and the object still has access to the element. It is removed from the DOM, though, so a later call to: $('#myElement') will match no elements. It will be an empty jQuery object. -- Jonathan Chaffer Technology Officer, Structure Interactive
[jQuery] Re: jQuery book status?
Fred, We've focused on jQuery from a user perspective, though we do describe how things are implemented when it is necessary in order to use them well. The most in-depth chapter from an implementation standpoint is the one on developing jQuery plug-ins. On Jun 20, 2007, at 9:45 , Fred Janon wrote: Karl, Is the book about using jQuery only or also about how the internal workings of jQuery? Thanks Fred On 6/19/07, Karl Swedberg [EMAIL PROTECTED] wrote: Hi Jim, Thanks for asking! The publisher just changed the expected date from July to June because we're actually ahead of schedule. :-) Jonathan and I are reviewing the final proofs now and are hoping to be finished by the end of this week. The publisher estimates that the hard-copy book will take 3 weeks to produce once we have our final edits in (so that puts the release date back into July. The ways of the publisher are mysterious). I imagine the PDF version will be made available very soon after final edits are in. We're taking great care during this last proofing step to ensure that we eliminate typos and other errors (although I don't expect it to be absolutely perfect. These things never are). The book is already available for pre-order on the publisher's site at http://packtpub.com/jquery/book and on a few booksellers' sites, including amazon.co.uk (not sure why amazon.com doesn't have it up on their site yet). There is also a special deal if you want to buy the hard-copy/pdf bundle. --Karl _ Karl Swedberg www.englishrules.com www.learningjquery.com On Jun 19, 2007, at 8:29 AM, Priest, James (NIH/NIEHS) [C] wrote: Just curious if there are any updates about the jQuery book? The site says Expected June 2007 and June is almost over :) Thanks, Jim -- Jonathan Chaffer Technology Officer, Structure Interactive
[jQuery] Re: The .ready() event
On Jun 8, 2007, at 11:36 , Robert O'Rourke wrote: I'm far from knowing all the facts but I thought .ready() was just a jquery event for 'onload', for whatever element just loaded. Like .bind('onload', function(){ ... } );, Is that right? Mike answered the main question here, but just to clarify: .load() or .bind('load') is the jQuery way to respond to the onload event. This event only gets fired when the element it is attached to is *completely* loaded. That means images, etc. must be completely transferred before the event fires. The .ready() method of jQuery registers code that will run when the DOM is ready, which could well be quite a bit before the onload event occurs for the page. It is possible to attach an onload handler to an individual element (e.g. image) though, which can be useful. -- Jonathan Chaffer Technology Officer, Structure Interactive
[jQuery] Re: table paging and sorting together
On Apr 10, 2007, at 16:05 , Paul Malan wrote: Jonathan, thanks for taking time to reply with an excerpt from the book. I have to assume that for potentially large recordsets my best bet is to hand off to the server for sorting/paging rather than storing thousands of rows browser-side. Would you agree? Absolutely. I think an AJAX solution is the most flexible option, and should probably be the default answer unless you know the data is small enough (or the connection fast enough) that it can all be shoved to the browser. In addition, for large amounts of data the database engine is bound to be much faster on sort operations than JavaScript ever could be. There are all manner of optimizations present in databases for just this type of task, and JavaScript is obviously more general-purpose. -- Jonathan Chaffer Technology Officer, Structure Interactive
[jQuery] Re: ANNOUNCE: New jQuery Book Available for Pre-Order!!
On Apr 6, 2007, at 13:13 , Aaron Heimlich wrote: Sweet! Do you know if there's gonna be an eBook version available? The publisher produces eBook versions of most of their books, so I expect so. We don't know the details yet, but I expect it'll be in line with their other offerings. Here's one with the same cover price: http://www.packtpub.com/drupal/book They tend to offer the eBook either separately or bundled with the print edition at a reduced cost. -- Jonathan Chaffer Technology Officer, Structure Interactive
[jQuery] Re: table paging and sorting together
On Apr 6, 2007, at 13:53 , Paul wrote: I’m curious how you all handle paged tabular data that also needs to be sortable. I would typically rely on ajax to retrieve next 25 / previous 25 rows, but if the user can sort any column they want they effectively change what “next 25” means every time they click a column header. Do I need to abandon the tablesorter plugin and simply use ajax to rebuild the table or is there a better way? Yes, you pretty much have to do both on the browser or both on the server. You can send all the data to the browser and have it paged there, or you can perform the sort on the server. Here's a relevant excerpt from The Good Book (no not that one): Sorting and Paging Go Together Data that is long enough to benefit from sorting is likely long enough to be a candidate for paging. It is not unusual to wish to combine these two techniques for data presentation. Since they both affect the set of data that is present on a page, though, it is important to consider their interactions while implementing them. Both sorting and pagination can be accomplished either on the server or in the web browser. We must keep the strategies for the two tasks in sync, however. Otherwise, we can end up with confusing behavior. Suppose, for example, that both sorting and paging is done on the server: When the table is re-sorted by number, a different set of rows is present on page one of the table. If paging is done by the server and sorting by the browser, though, the entire data set is not available for the sorting routine and so it goes wrong: Only the data already present on the page can be displayed. To prevent this from being a problem, we must either perform both tasks on the server, or both in the browser. -- Jonathan Chaffer Technology Officer, Structure Interactive