[jquery-dev] Re: What would you call jQuery's design patterns / principals?
Chaining is a design pattern jQuery uses. $(selector).foo().bar().baz() It can be used object oriented, but it doesn't have to be. var foo = { 'something': $(selector) } You can use closures, but don't have to var foo = 3 $(selector).click( function() { alert(foo); }); Unobtrusive Javascript: http://en.wikipedia.org/wiki/Unobtrusive_Javascript On Aug 30, 12:54 pm, Buddy buddywilli...@gmail.com wrote: I am familiar with KISS and DRY but not PE and Unobtrusive JavaScript . PE sounds interesting, I'll look into it. What do you mean by Unobtrusive JavaScript? Sounds like anti-framework? On Aug 28, 5:49 am, Richard D. Worth rdwo...@gmail.com wrote: Here's a few that come to my mind: - Find things. Do stuff.- Write less. Do more. - KISS - DRY - PE (Progressive Enhancement) - Unobtrusive JavaScript - Richard On Thu, Aug 27, 2009 at 4:29 PM, Buddy buddywilli...@gmail.com wrote: What would you call jQuery's design pattern / principals? - Closures - OO - etc. Everything is helpful. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups jQuery Development group. To post to this group, send email to jquery-dev@googlegroups.com To unsubscribe from this group, send email to jquery-dev+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en -~--~~~~--~~--~--~---
[jquery-dev] Re: new $
DBJDBJ - I'd be interested in hearing all of the gotchas that the engineers have run into using jQuery. It's interesting that they'd try to do new $, as there is no logical reason for it and it isn't in the examples, but for some reason they used it. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups jQuery Development group. To post to this group, send email to jquery-dev@googlegroups.com To unsubscribe from this group, send email to jquery-dev+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en -~--~~~~--~~--~--~---
[jquery-dev] Re: Selectors in Live Method
@Zach - Chaining is very powerful, I like the existing functionality as is. There are performance issues like you mention, but I haven't run into a selector on a page that has caused me difficulty yet. *fingers crossed*. If I did, I would either just roll my own by putting the click event on the document and testing for a match to a selector or create a plugin doing what you suggest. Having both in the core might just create confusion, $.live(selector, 'click', function () { }); vs. $(selector).live('click', function () { }); And the latter is more 'jQuery-ish', at least in my mind. On May 12, 9:49 pm, Jed Schmidt t...@nslator.jp wrote: I'm not convinced you're sacrificing that much performance. One of the great things about .live() is that it can be called before the DOM is even ready. The lack of nodes to search means that selection should return almost immediately. Jed Schmidt On May 12, 9:31 am, Zach Leatherman zachleather...@gmail.com wrote: Sure, but you're sacrificing quite a bit in performance to get chaining. I think it would be helpful to have an alternative option, so that devs are aware of the tradeoff (I'm not asking to change $.fn.live), and my suggestion was to use $.live. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups jQuery Development group. To post to this group, send email to jquery-dev@googlegroups.com To unsubscribe from this group, send email to jquery-dev+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en -~--~~~~--~~--~--~---
[jquery-dev] Re: Selectors in Live Method
I'm curious why the selector even needs to be executed prior to calling the live method... Probably so you can chain it. $('p').live('click', function() { console.log('clicked!')}).css ({'color':'red'}); On May 9, 8:47 am, Zach Leatherman zachleather...@gmail.com wrote: Since we're using Event Delegation on the document object, I'm curious why the selector even needs to be executed prior to calling the live method. Why not make it a jQuery function instead? $.live = function(selector, type, fn) { var r = $([]); r.selector = selector; if(type fn) { r.live(type, fn); } return r; }; There might be some confusion with this approach, since the jQuery object being returned does not actually contain any nodes, but it's something to think about. Thanks, Zach Leathermanhttp://www.zachleat.com/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups jQuery Development group. To post to this group, send email to jquery-dev@googlegroups.com To unsubscribe from this group, send email to jquery-dev+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en -~--~~~~--~~--~--~---
[jquery-dev] Re: Bug in IE 7 with 'find' method
You are right, it has to do with setTimeout. In IE, setTimeout does not allow you to pass parameters like this, and in fact it is against the spec to do so. http://www.claws-and-paws.com/node/1252 On May 3, 12:34 am, Luke Bayes lba...@patternpark.com wrote: Hey Josh, Thanks so much for taking the time to go through this. You are absolutely right in that I didn't test my distilled example - Sorry about that! I dug a little deeper, and it seems my problem is somehow related to IE's handling of setTimeout. As I said, I'm working with Google Maps and of course that is incredibly slow with larger collections, so I threw the call into a setTimeout and let it happen over time. Following is a distilled example that illustrates the problem in a more accurate representation and actually reproduces properly: div id=list div class=foo div class=barone/div /div div class=foo div class=bartwo/div /div div class=foo div class=barthree/div /div div class=foo div class=barfour/div /div /div script function render(item) { text = $(item).find('.bar').text(); console.log('text: ' + text); } var text; var foos = $('#list .foo'); foos.each(function(index, foo) { setTimeout(render, 1, foo);}); /script Thanks, Luke Bayes --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups jQuery Development group. To post to this group, send email to jquery-dev@googlegroups.com To unsubscribe from this group, send email to jquery-dev+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en -~--~~~~--~~--~--~---
[jquery-dev] Re: Bug in IE 7 with 'find' method
I tested the code you gave, and it worked fine in IE7. I got one two three four I'm suspecting that you've distilled the example down from some real code (good practice!) and it was the real code that wasn't working and you didn't test the distilled code. I suspect that in the real code, this was done: text = $('.foo').find('.bar').text(); instead of text = $(foo).find('.bar').text(); inside of the loop which would cause the text to be set to iterating through all of the elements with a class of foo and getting its descendant with a class of bar and return its text. But testing that, it works the same in IE and Firefox and always returns onetwothreefour... so I'm still not sure what the deal is. Hope this helped. Josh Powell On May 1, 11:14 pm, Luke Bayes lba...@patternpark.com wrote: I was able to reproduce this bug in JQuery 1.2.6, 1.3, and 1.3.1 on Windows XP with Internet Explorer 7. The use case is that I have a collection of items in a page of HTML, and I'm using JQuery to build up a JavaScript model (and insert these list items into Google Maps). So, I'm selecting on a class and then iterating over all the items in that class - and performing a find on each item. The following example should illustrate the bug: div class=foo div class=barone/div /div div class=foo div class=bartwo/div /div div class=foo div class=barthree/div /div div class=foo div class=barfour/div /div var text; var foos = $('.foo'); foos.each(function(index, foo) { text = $(foo).find('.bar').text(); console.log('text: ' + text); }); In Safari and Firefox on Win and Mac, text is based only on the descendants of the currently-selected .foo: one two three four In IE 7, text is: onetwothreefour onetwothreefour onetwothreefour onetwothreefour It seems as if the .find is not respecting the current selection that it's hanging off of, and is instead traversing the entire document. These queries are also extremely slow in IE as compared to the alternatives. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups jQuery Development group. To post to this group, send email to jquery-dev@googlegroups.com To unsubscribe from this group, send email to jquery-dev+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en -~--~~~~--~~--~--~---
[jquery-dev] Re: how to convert a string to json structure
If the string is in javascript, there are the two ways already mentioned, though if you built the string in javascript you should probably just build the json object instead. If the string is in PHP/ JSP/or some other server side language, then just print it out into the javascipt and save it into a variable. script var foo = %= jsonString % /script To get data from the object, just use normal object and array references as if it were any other object/array: foo[0].carePacks[0].description On Apr 27, 6:06 am, Remon Oldenbeuving r.s.oldenbeuv...@gmail.com wrote: You could also use: var myobj = (new Function(return + JSONString))() http://yuiblog.com/blog/2006/11/13/javascript-we-hardly-new-ya/#comme... On Mon, Apr 27, 2009 at 2:30 PM, Remon Oldenbeuving r.s.oldenbeuv...@gmail.com wrote: If your completly sure that it is save, you could just use eval: eval(var myJSON = [{carePacks: [{businessCode:J1PS,description:HP 1}],coveragePeriod:12},{carePacks:[{businessCode:J1PS,description:HP s}],coveragePeriod:13}];); On Mon, Apr 27, 2009 at 10:13 AM, gaohk cnga...@gmail.com wrote: I have a string that is like [{carePacks: [{businessCode:J1PS,description:HP 1}],coveragePeriod:12}, {carePacks:[{businessCode:J1PS,description:HP s}],coveragePeriod:13}]. can you give me some advice on how to convert it to a json structure, and how to get data from the data structure, like get HP 1. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups jQuery Development group. To post to this group, send email to jquery-dev@googlegroups.com To unsubscribe from this group, send email to jquery-dev+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en -~--~~~~--~~--~--~---
[jquery-dev] Re: How to return an array object from each()?
Don't do: var playlist = new Array(); Do: var playlist = []; http://yuiblog.com/blog/2006/11/13/javascript-we-hardly-new-ya/ Josh Powell On Apr 25, 5:03 am, Prajwala Manchikatla m.prajw...@gmail.com wrote: Just put var playlist = new Array(); statement above ajaxMenu function. On Fri, Apr 24, 2009 at 6:20 PM, throl...@googlemail.com throl...@googlemail.com wrote: I'm currently trying to build an array from an Ajax request, creating a new object for each item in the query. Here's the code: function ajaxMenu(whatTab){ // retrieve the xml playlist $(document).ready(function(){ var id = 0; var title = ''; // start menu $(#layout_left_menu_float).empty(); $(#layout_left_menu_float).append(ul); var playlist = new Array(); // load the xml and run a foreach loop $.ajax({ type: GET, url: srcUrl+playlist.xml, dataType: xml, success: function(xml) { $(xml).find('tab').each(function(){ findTab = $(this).find('id').text(); if(findTab != whatTab){ return true; } else { var i = '0'; $(this).find('item').each(function(index){ // Grab all details title = $(this).find('title').text(); type = $(this).find('type').text(); file = $(this).find('file').text(); qt = $(this).find('qt').text(); wmv = $(this).find('wmv').text(); content = $(this).find('content').text(); thumbnail = $(this).find('thumbnail').text(); // Establish playlist item and add link playlist[index] = new Object(); playlist[index]['id'] = index; playlist[index]['title'] = title; playlist[index]['type'] = type; playlist[index]['file'] = file; playlist[index]['qt'] = qt; playlist[index]['wmv'] = wmv; playlist[index]['content'] = content; playlist[index]['thumbnail'] = thumbnail; $(#layout_left_menu_float).append(itemLink (index,title,type)); }); return false; // speed fix, ends once correct tab found } }); // end each } // end success }); // end $.ajax // end menu $(#layout_left_menu_float).append(/ul); }); // end document ready } This function builds a menu from the items in a playlist, but at the same time I want to store the data in a global array to be used at any time, until it is overwritten when a new menu is created. How would I go about this? Any help will be most appreciated! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups jQuery Development group. To post to this group, send email to jquery-dev@googlegroups.com To unsubscribe from this group, send email to jquery-dev+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en -~--~~~~--~~--~--~---
[jquery-dev] Re: Update to jquery 1.3.2 from 1.3 : new problems with my code
Try: [src$=checked.png] instead of [src=\'images/checked.png\'] I'm trying to get rid of those quotes which may be causing a problem. On Mar 13, 6:40 am, alkariane alkari...@gmail.com wrote: Hi I don't know where to post my problem. So i try here too ^^ I've updated to the new version of Jquery 1.3.2 my code. (i used jquery 1.3). Since i've done that, my program is not working at all. I show you the problem : This instruction doesn't work anymore : $('td.entite'+(numEntite-1)+'.sortieimg[src=\'images/checked.png \']').each( function() { } ); Although, this works : $('td.'+idEntite+'.entreeimg').each( function() { if ($(this).attr('src')=='images/checked.png') { }} ); If i use again the old jquery my first instruction is working again. So i wonder what is the problem with the new jquery. Is there something i should know about the new version ? I'm not an expert in jquery, so please excuse me if the cause seems easy to you, but i really need to know why. Thanks for your help. Alkariane --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups jQuery Development group. To post to this group, send email to jquery-dev@googlegroups.com To unsubscribe from this group, send email to jquery-dev+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en -~--~~~~--~~--~--~---