[jQuery] Re: .load(function() not working
http://dev.jquery.com/ticket/3930 On May 8, 9:16 pm, surreal5335 surrea...@hotmail.com wrote: Sorry about the awful horizontal scrolling, its not meant to be like that. My belief is that once I am able to get the .load function working again, that problem will also fix itself bc the jcarousellite plugin will opperate properly again. Or atleast it will fix one of the problems toward reslolving the big issue. All the images at the bottom of the screen are not suppose to be there (which is causing the horizontal scroll) by hiding them with the .load function, it will be fixed. Hate to say it but the suggestion you made didnt take, I tried it with and without the .ready function. As for the browser, I have been using firefox 3 the entire time. when it was working and afterwards as well. It was working great until I made some changes to the code (but only elements to hide, fade, slidedown, etc.) afterwards it hasnt worked since and tried everything to revert it back but cant figure it out what it wants from me. Could I try the onload function? and put that in the header? I really appreciate all the help
[jQuery] Re: Parsing XML with IE?
It's explained here: http://groups.google.com/group/jquery-en/browse_frm/thread/95718c9aab2c7483/af37adcb54b816c3?lnk=gstq=parsexmlpli=1 On May 7, 10:24 pm, ScottChiefBaker scott.ba...@gmail.com wrote: I created a simple test case: http://www.perturb.org/tmp/jquery-test.html On May 7, 12:41 pm, ScottChiefBaker scott.ba...@gmail.com wrote: The following example works great in Firefox, and Chrome but fails miserably in IE (6,7,8). I'm running JQuery 1.3.2 if it makes a difference: $('resp',rootrespvalue/resp/root).text(); That evaluates to vaule in everything except IE. Am I missing something?
[jQuery] Re: Problem with dynamic XML
It's easy, see this thread: http://groups.google.com/group/jquery-en/browse_frm/thread/95718c9aab2c7483/af37adcb54b816c3?lnk=gstq=parsexml#af37adcb54b816c3 On Feb 1, 5:56 am, pp...@fragrance-world.net fragrance2...@gmail.com wrote: I have the following code: var cartXml = $(datacarttotalsitems33/items/carttotals/ data); alert(cartXml.find(items).text()); this will spit out 33 in both safari and firefox However in IE it does not produce anything Here is what I have figured out so far: if I change to the following: alert($(divspanp33/items/span/p).find(p).text()); this works in IE, Safari, and firefox it seems with IE you need to use real html tag names and not ones that are made up. Does anyone know how I can fix this?
[jQuery] Re: $(this).ready with images
Unfortunately it's not that simple, thanks to IE: http://groups.google.com/group/jquery-dev/browse_thread/thread/24b107e84adeaaee/ http://dev.jquery.com/ticket/3930 On Jan 31, 4:20 pm, frederik.r...@gmail.com frederik.r...@gmail.com wrote: Ok! That's great! Thanks for the explanation!
[jQuery] Re: Selection by CSS background-color
It doesn't work because browsers return a CSSStyleDeclaration object, or something similar, you can try it with firebug: $('body')[0].style But I have just released a plugin that enables you to solve this very easily. I put some other stuff into it too that you probably don't need but that can be easily removed. Here it is: http://plugins.jquery.com/project/EnhancedAttributeSelectors and this how it can be used: $(div[~background-color=firebrick]); The standard way would be to make a pseudo selector for this but somehow I like this approach more. If you don't, then have a look at the plugins page, I'm sure someone has made a lighter pseudo selector for this. On Jan 29, 8:47 pm, kevotheclone kevothecl...@gmail.com wrote: Thanks for the reply Shane! Yes looping through the parent is an option that I was hoping to avoid. Rigth now my Timeline only displays 30 projects (each one composed of 2 div elements), but SIMILE Timeline generates many more div elements within the parent containing div; 380 to be exact. So I'll have to loop through 380 to find the a few div elements that have the appropriate background color. Since I don't generate any of the Timeline elements I'm kind of at SIMILE mercy (and I don't wat to alter their code). I guess performance wise me examining 380 div elements isn't any different than waht JQuery would have to do, but I was hoping for a nice elegant JQuery one liner. It does seem like $(div[style*= firebrick]); should work. Find all div elements whose style attribute contains firebrick. Can anyone explain the logic why this doesn't work? Is this a bug or a documented exception that I failed to find/read? Thanks again to Shane and the rest of the JQuery community!
[jQuery] Re: Recommendation Required - Custom Classes Library
Then what if you just use Class.Extras and all its dependencies as it is? Now that sounds too easy :) On Jan 23, 9:21 am, Neil Craig neil.big.cr...@gmail.com wrote: I am not sure how Mootools 1.2+ is constructed but version 1.11 can easily be broken into pieces that excludes the parts that extend the DOM/HTML elements. The files that one should use is: Core, Class, Class.Extras, String, Number, Function, Array On Jan 21, 11:58 am, Balazs Endresz balazs.endr...@gmail.com wrote: I only heard about this one, looks a bit different from Mootools but much smaller:http://www.danwebb.net/2008/1/31/low-pro-for-jquery Though I wonder if it's possible to port the whole Mootools implementation to jQuery? You can maybe keep some parts of Core, Native and Class, and hack it to work with jQuery ... now that sounds like a whole new framework :) I don't know Mootools that much at all but maybe it's not as hard as it sounds... On Jan 21, 8:18 am, Neil Craig neil.big.cr...@gmail.com wrote: Bump :) On Jan 20, 10:36 am, Neil Craig neil.big.cr...@gmail.com wrote: I was wondering, which Custom Classes Library is best to use along with jQuery. Up to now, I've been using Mootools to create custom classes that can be easily extended through its inheritance model. It also has custom events that I have used extensively. Which library do you recommend that has the same functionality as described above that can co-exist with jQuery peacefully? This could make for an interesting discussion
[jQuery] Re: colon in xml tag on webkit - cannot select
As far as I know currently it's really hard to make it work properly on all browsers, I'm sure there's a few tickets regarding this issue in the bug tracker. On Jan 22, 11:55 pm, burrowing owl burrowing...@gmail.com wrote: Okay, I have a fix for this, though it doesn't address the underlying problem of parsing tags that contain colons. function mungeTag( tag, munge ) { // in case browser does not grok tags with colons reM = /.*(\:)(.*)/; if ( munge ){ tag = tag.replace( reM, $2 ); } return tag; } var munge = 0; // until a test indicates that our browser's javascript cannot parse this type of tag // at which point munge is set to 1 // all tags that have colons are wrapped with mungeTag() tag = mungeTag( dc\\:creator, munge ); $(this).find(tag).each(function(){ bookCreatorArr.push( $(this).text() ); }); bookCreator = bookCreatorArr.join(, ); Not elegant, but works for my purposes. Obviously if the same element contains title and dc:title tags, you have differentiate them somehow. With the google feed it's possible to do this by checking attributes. Again, not pretty. On Jan 21, 12:03 pm, burrowing owl burrowing...@gmail.com wrote: Using jquery 1.2.6, but I quickly tested this on 1.3 as well. I am parsing the google books search feedhttp://code.google.com/apis/books/docs/gdata/developers_guide_protoco... (about 1/3 down the page is an example feed). This feed has tags like openSearch:totalResults, dc:creator, dc:title. This code succeeds in IE and firefox, but not in Chrome or Safari. 1 $.get( URLstem+query, {}, function(xml){ 2 numberResults = $('feed', xml).find('openSearch\ \:totalResults').text(); The variable numberResults comes back empty, not even zero or -1. If I change line 2 to 2 numberResults = $('feed', xml).find ('totalResults').text(); The variable numberResults comes back correctly with the number in between the openSearch:totalResults/openSearch:totalResults tag. But only in Safari/Chrome, and not in IE or Firefox. If there's no way to fix this in Line 2, I'm thinking of testing for the type of browser, or running a regex on the entire feed to remove the prefixes, so that dc:title would become title etc. I don't like either of those options. Thanks for any ideas.
[jQuery] Re: XML Sorting using jQuery - is it possible?
jQuery can parse most text to xml but that doesn't work in all cases: http://groups.google.com/group/jquery-en/browse_frm/thread/95718c9aab2c7483/af37adcb54b816c3?lnk=gstq=parsexml#af37adcb54b816c3 You can also copy Array.prototype.sort to $.fn and it will work on the jQuery object as well: function parseXML( xml ) { if( window.ActiveXObject window.GetObject ) { var dom = new ActiveXObject( 'Microsoft.XMLDOM' ); dom.loadXML( xml ); return dom; } if( window.DOMParser ) return new DOMParser().parseFromString( xml, 'text/xml' ); throw new Error( 'No XML parser available' ); } var xml = 'base'; xml += 'item type=cone/item'; xml += 'item type=btwo/item'; xml += 'item type=dthree/item'; xml += 'item type=fthree/item'; xml += 'item type=athree/item'; xml += '/base'; $.fn.sort=[].sort; //copy the array method $(parseXML(xml).childNodes[0].childNodes) .sort(function(a,b){ //using the native sort here var at = $(a).attr('type'), bt = $(b).attr('type'); return (at bt) ? -1 : 1; }); On Jan 22, 4:36 pm, skube sku...@gmail.com wrote: Thanks for the reply, but that doesn't seem to be an XML object at all. Isn't that simply a string that looks like XML. Also, by using get () aren't you simply converting that string into an array anyway? On Jan 22, 3:00 am, Ricardo Tomasi ricardob...@gmail.com wrote: What kind ofsorting? xml= 'base';xml+= 'item type=cone/item';xml+= 'item type=btwo/item';xml+= 'item type=dthree/item';xml+= 'item type=fthree/item';xml+= 'item type=athree/item';xml+= '/base'; var sorted = $(xml).filter('item').get().sort(function(a,b){ var at = $(a).attr('type'), bt = $(b).attr('type'); return (at bt) ? -1 : 1; }); $(sorted).each(function(){ console.log( this ); }); https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Global... - ricardo On Jan 21, 10:01 pm, skube sku...@gmail.com wrote: It seems jQuery is really great at traversing anXMLobject. It is quite easy to gather and filter node data. However I can't seem to find any information regardingsortingXMLusing jQuery. Is it possible? Or is there a plug-in? I have a project which requires me to read anXMLfile, then filter and sort the data. Filtering I can do, but I have no idea how to sort XML. Since arrays are easily sortable in JS, my idea is to convert the XMLinto an array first, then filter the array (which is not as easy as filteringXMLw/ jQuery) then sort the array. Does anyone have any better ideas? thanks, skube
[jQuery] Re: Recommendation Required - Custom Classes Library
I only heard about this one, looks a bit different from Mootools but much smaller: http://www.danwebb.net/2008/1/31/low-pro-for-jquery Though I wonder if it's possible to port the whole Mootools implementation to jQuery? You can maybe keep some parts of Core, Native and Class, and hack it to work with jQuery ... now that sounds like a whole new framework :) I don't know Mootools that much at all but maybe it's not as hard as it sounds... On Jan 21, 8:18 am, Neil Craig neil.big.cr...@gmail.com wrote: Bump :) On Jan 20, 10:36 am, Neil Craig neil.big.cr...@gmail.com wrote: I was wondering, which Custom Classes Library is best to use along with jQuery. Up to now, I've been using Mootools to create custom classes that can be easily extended through its inheritance model. It also has custom events that I have used extensively. Which library do you recommend that has the same functionality as described above that can co-exist with jQuery peacefully? This could make for an interesting discussion
[jQuery] Re: jquery parse xml can't run ie7?
http://groups.google.com/group/jquery-en/browse_frm/thread/95718c9aab2c7483/af37adcb54b816c3?lnk=gstq=parsexml#af37adcb54b816c3 On Jan 21, 5:19 am, frank Shi frankshi...@gmail.com wrote: html titlehello/title head script src=../media/js/jquery-1.3.min.js type=text/javascript/ script script function ParseXml(xml){ var xml='?xml version=1.0 encoding=UTF-8 ?'; xml+='root'; xml+='resultcompany33/company/result'; xml+='resultcompany222/company/result'; xml+='/root'; alert(xml); $(xml).find(result).each(function() { var id=$(this).children(company); alert(id.text()); }); } /script /head body input name=Show type=button value=ParseXml() onclick=ParseXml () /body html above code in chrome, firefox run normally, ie7 cant' alert(id.text ()) why?
[jQuery] Re: how to do '++' in jQuery
Moreover, as of 1.3 this works like .css, so there's no animation at all: $(xx).animate({ width: +=10px }, 0); (In 1.2 if you set the duration to 0 then the default value is used.) On Jan 21, 1:00 pm, Liam Potter radioactiv...@gmail.com wrote: like this $(xx).animate({ width: +=10px },1000); this will add 10 pixels to the width, in a second. Kean wrote: Probably there's a better way. Doesn't look elegant. $('xx').width($('xx').width()++) ; On Jan 21, 2:05 am, David .Wu chan1...@gmail.com wrote: some times we want to do some animation we use xxx.width++ in jQuery we give value like this $('xx').width(value) how to do ++ thing in this way?
[jQuery] Re: simple jQuery img src Question
Also, see this discussion about using the load event with images: http://groups.google.com/group/jquery-dev/browse_thread/thread/24b107e84adeaaee On Jan 21, 8:55 pm, Bohdan Ganicky bohdan.gani...@gmail.com wrote: Fixed braces: $('#image').fadeOut(500, function() { $(this).attr('src','images/'+newImg).load(function() { $(this).fadeIn(1000); }); }); -- Bohdan On Jan 21, 8:54 pm, Bohdan Ganicky bohdan.gani...@gmail.com wrote: In theory it would be something like this: $('#image').fadeOut(500, function() { $(this).attr('src','images/'+newImg).load(function() { $(this).fadeIn(1000); }); } ...but I'm not at all sure if the load() captures the src attribute change like that. -- Bohdan On Jan 21, 7:54 pm, LoicDuros loic.du...@gmail.com wrote: Hi, I'm new to JQuery and used to use Scriptaculous. I would like to make the following: A function to fade out an image, then change the src of the image, and once the new src is loaded, to fade in the image back (so that it's fading in with the new image loaded). Here is how I did it using Scriptaculous, however, the site will now use jQuery and so I have to reproduce the same thing with it - is there such a thing as observe in jQuery: function navAction(newImg) { new Effect.Fade('image', {duration:0.5, afterFinish:function(){ document.getElementById('image').src = 'images/' + newImg; $(document.getElementById(image)).observe('load', display); } }); } function display(event){ new Effect.Appear('image', {duration:1}); }
[jQuery] Re: Class selectors not working when using jQuery 1.3 with Mootools 1.11
This was mentioned on the jquery-dev group or somewhere else, I don't remember exactly. It's about Mootools not extending properly the document object I think, I'm sure it has been fixed in the trunk. I suspect this is it: http://github.com/jeresig/sizzle/commit/0a9df6e0b68a91dd1f59bfd6e7941843cba32a7a On Jan 20, 3:26 am, Neil Craig neil.big.cr...@gmail.com wrote: Hi I'm working on a project that used to implement Mootools 1.11. It has been decided however that we switch over to jQuery since it is much faster and more light-weight. However, because we have created numerous widgets in Mootools, we still have to use it while the jQuery equivalent widgets are being developed. We have implemented the noConflict method with various degrees of success. We have noticed that after upgrading from jQuery 1.2.6 to 1.3, that using the old Mootools 1.11 along with jQuery, renders the class selector useless. Executing something like jQuery(.myClass) or jQuery(div.myClass) returns an error: context.getElementsByClassName is not a function. It occurs in the following section: if ( document.documentElement.getElementsByClassName ) { Expr.order.splice(1, 0, CLASS); Expr.find.CLASS = function(match, context) { return context.getElementsByClassName(match[1]); }; } Strangely enough the expression if ( document.documentElement.getElementsByClassName ) yields a result of true, but context.getElementsByClassName is still undefined. The context in this case is the document object itself. I'm suspecting that it has got something to do with Mootools that is throwing a spanner into the works. Has anyone encountered a similar problem? Or has anyone got some comments on the subject?
[jQuery] Re: 1.3, attributeStartsWith and '['
Hello, it's a known issue: http://dev.jquery.com/ticket/3778 There's some solution in the ticket but needs a proper patch and a bit testing. I'll try to make it tonight if I can get home in time ;) On jan. 19, 10:46, Jedrzej Majko jdr...@gmail.com wrote: Hello, I have strange problem with attribute StartsWith in new version of jQuery. This code gives 'FOUND' in 1.2.6 and 'NOT FOUND' in 1.3. There's a problem with [name^='item['], [name^='item[1]'] works fine. Is this a bug, or expected behavior? Code: !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd; html xmlns=http://www.w3.org/1999/xhtml; xml:lang=en lang=en head meta http-equiv=Content-Type content=text/html; charset=UTF-8 / script type=text/javascript src=http://jqueryjs.googlecode.com/ files/jquery-1.3.js/script script type=text/javascript $(document).ready(function(){ if($([name^='item[']).length==0){ alert('NOT FOUND'); } else { alert('FOUND'); } }); /script /head body input type=text name=item[1] value=1/ /body /html
[jQuery] Re: Modifying an XML document with jQuery
These worked for me. Do you have a test page? On Jan 19, 7:27 am, dandieb...@gmail.com dandieb...@gmail.com wrote: I have essentially the same problem. I have some XML returned from an AJAX call and need to modify the XML slightly before using it on the web page. In reference to the original post, how do you use jQuery to modify the original XML document into the desired document: Original XML: group name=jquery member id=001/member /group Desired XML: group name=jquery member id=001 name=peter/member /group
[jQuery] Re: 1.3, attributeStartsWith and '['
Unforunately it's just turned out that there's anothor isssue behind this. You can follow the ticket if you want update on this, I guess it will be solved soon. On Jan 19, 10:46 am, Jedrzej Majko jdr...@gmail.com wrote: Hello, I have strange problem with attribute StartsWith in new version of jQuery. This code gives 'FOUND' in 1.2.6 and 'NOT FOUND' in 1.3. There's a problem with [name^='item['], [name^='item[1]'] works fine. Is this a bug, or expected behavior? Code: !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd; html xmlns=http://www.w3.org/1999/xhtml; xml:lang=en lang=en head meta http-equiv=Content-Type content=text/html; charset=UTF-8 / script type=text/javascript src=http://jqueryjs.googlecode.com/ files/jquery-1.3.js/script script type=text/javascript $(document).ready(function(){ if($([name^='item[']).length==0){ alert('NOT FOUND'); } else { alert('FOUND'); } }); /script /head body input type=text name=item[1] value=1/ /body /html
[jQuery] Re: implemented css class not in html but is in generated html, failed to find
This should definitely work, with a live test page it would be much easier to say anything about it. What version of jQuery are you using and on which browser does it occur? On Jan 16, 2:48 pm, CreativeMind aftab.pu...@gmail.com wrote: $('li.tabs-selected') also shows undefined.. i m unable to find li with the help of class 'tabs-selected'.. On Jan 16, 1:28 am, Balazs Endresz balazs.endr...@gmail.com wrote: Now that's another one: $('li').hasClass('.tabs-selected') and $('li').is('.tabs-selected') only tell you if li has that class or not, if you want to select by class do this: $('li.tabs-selected') On Jan 15, 9:11 pm, CreativeMind aftab.pu...@gmail.com wrote: hi, here is the html source of a list. li class=xsnazzy a href=#frMap style=text-decoration:none;text-indent:5px;b class='xtop' b class='xb1 '/bb class='xb2 color_a'/bb class='xb3 '/b b class='xb4 color_a'/b/bspan class=xboxcontent h1Map/h1/span/a/li -- here is the generated html source of a list. li class=xsnazzy top-left tabs-selected a href=#frMap style=text-decoration: none; text-indent: 5px; b class=xtopb class=xb1/bb class=xb2 color_a/b b class=xb3/bb class=xb4 color_a/b/b span class=xboxcontenth1Map/h1/span/a/li --- the problem is when i try to find $('li').hasClass('.tabs-selected'), or $('li').is('.tabs-selected') it returns me undefined... but it exists in the generated html..how can i find that class.
[jQuery] Re: implemented css class not in html but is in generated html, failed to find
Try 1.2.6 or 1.3! There was some problem with 1.2.4 and 1.2.5, it was very quickly updated to 1.2.6. On Jan 16, 3:54 pm, CreativeMind aftab.pu...@gmail.com wrote: jQuery1.2.4 and browsers are IE and ff..the html source view of both browsers shows single class implemented that is 'xsnazzy' but the generated source of both browsers shows three classes implemented (xsnazzy top-left tabs-selected).. On Jan 16, 7:41 pm, Balazs Endresz balazs.endr...@gmail.com wrote: This should definitely work, with a live test page it would be much easier to say anything about it. What version of jQuery are you using and on which browser does it occur? On Jan 16, 2:48 pm, CreativeMind aftab.pu...@gmail.com wrote: $('li.tabs-selected') also shows undefined.. i m unable to find li with the help of class 'tabs-selected'.. On Jan 16, 1:28 am, Balazs Endresz balazs.endr...@gmail.com wrote: Now that's another one: $('li').hasClass('.tabs-selected') and $('li').is('.tabs-selected') only tell you if li has that class or not, if you want to select by class do this: $('li.tabs-selected') On Jan 15, 9:11 pm, CreativeMind aftab.pu...@gmail.com wrote: hi, here is the html source of a list. li class=xsnazzy a href=#frMap style=text-decoration:none;text-indent:5px;b class='xtop' b class='xb1 '/bb class='xb2 color_a'/bb class='xb3 '/b b class='xb4 color_a'/b/bspan class=xboxcontent h1Map/h1/span/a/li -- here is the generated html source of a list. li class=xsnazzy top-left tabs-selected a href=#frMap style=text-decoration: none; text-indent: 5px; b class=xtopb class=xb1/bb class=xb2 color_a/b b class=xb3/bb class=xb4 color_a/b/b span class=xboxcontenth1Map/h1/span/a/li --- the problem is when i try to find $('li').hasClass('.tabs-selected'), or $('li').is('.tabs-selected') it returns me undefined... but it exists in the generated html..how can i find that class.
[jQuery] Re: Possible 1.3 bug
In jquery.liveFilter.js a pseudo selector defined as a string, which was deprected since 1.2 if I remember right. jQuery.extend( jQuery.expr[':'], { insContains : jQuery(a).text().toUpperCase().indexOf(m [3].toUpperCase())=0 }); This should be a function instead: jQuery.expr[':'].insContains = function(a,i,m){ return jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase())=0 } On Jan 15, 4:09 pm, tpb976 tpb...@gmail.com wrote: It seems the problem has to do with creating custom selectors. I have a custom selector that I created and I am receiving this exact error. I am currently looking into the problem to see what I can figure out. On Jan 15, 9:05 am, Diego diego.a...@gmail.com wrote: Hi (me again), the problem was being caused by the moreSelectors plugin on this page:http://www.softwareunity.com/jquery/JQueryMoreSelectors/ On Jan 15, 2:40 pm, Diego diego.a...@gmail.com wrote: FYI. I found my offending code. It's a combination of these selectors: :text, :password, :file, :select, :button I just can't figure out why! On Jan 15, 7:39 am, emmj...@gmail.com emmj...@gmail.com wrote: I was checking all of my random plugins/scripts to make sure they all work with jQuery 1.3 and I found one that is having problems. An example of it is available at:http://digitalinferno.net/temp/ If you enter some text into the input firebug will report that filter is not a function in http://digitalinferno.net/temp/js/jquery.jsonline1961 Anyone know if this is a bug or if I have to change something in my code for the new 1.3 release?
[jQuery] Re: Issue upgrading to 1.3
Looks like it's related to this: http://dev.jquery.com/ticket/3837 On Jan 14, 9:32 pm, Joe Morgan thewast...@gmail.com wrote: Hello, When I attempt to upgrade my site from 1.2.6 to 1.3, I get an unresponsive script error that causes my browser (both IE7 and FF3) to hang if the script is not stopped. I've tracked down the bit of script causing the problem: $(ul#loginSection li#emilyLogin:not(.loggedIn), ul#loginSection li#joeLogin:not(.loggedIn)).click( function(){} ); As you can see, the problem exists even when the function defined for the click event is empty, leading me to wonder if it is some problem in the CSS selector that is being used, given the engine changes from 1.2.6 to 1.3. Am I doing something incorrectly? - Joe
[jQuery] Re: function text() in jquery
$('#testText').contents(':not(select)')[0].nodeValue; $('#testText').contents('[nodeType=3]')[0].nodeValue; I fear these aren't going to work in 1.3 as the new selector engine doesn't handle textnodes anymore! On Jan 15, 5:09 pm, kazuar kazuar...@gmail.com wrote: thanks a lot ricardobeat. work like a charm :) ricardobeat wrote: There are two alternatives: $('#testText').contents(':not(select)')[0].nodeValue; this one is unsupported but works too: $('#testText').contents('[nodeType=3]')[0].nodeValue; Notice that both will keep the linebreaks. if text() could handle textnodes this would be much easier. - ricardo On Jan 12, 2:43 pm, kazuar kazuar...@gmail.com wrote: Hi, I thank you all for your help. I guess I'll go with Bohdan's suggestion. I'll put the text inside another tag (probably p tag...). thanks again for all your help, if you think of anything else please let me know. Kazuar Bohdan Ganicky wrote: Hello, maybe it could be easier to use the good old DOM in this scenario: var textNode = $('#testText').get().firstChild; // now we have the textNode var textRaw = textNode.nodeValue; // now we have the text string with all the white-space around var text = $.trim(textRaw); // we strip the trailing white-space using the jQuery trim function Of course this works as expected only if the text you're looking for is placed in the #testText's first textNode. I'd recommend using more meaningful markup instead and putting the text inside p element. ;) -- Bohdan Ganicky On Jan 12, 11:55 am, kazuar kazuar...@gmail.com wrote: hello, Im kinda new in jquery so maybe its a begginer question. I have a page with a div containing some text and a combobox. something like that div id=testText hello this is text and this is combobox selectoption value='1'1/optionoption value='2'2/optionoption value='3'3/option/select/div I wrote a function which return the text from the div. alert($('#testText').text()); My problem is that the function also return the text inside the combobox. is there a way to filter out the combobox text? the only workaround I can think of is to wrap my text in another div and call its text. This workaround will be a bit complicated for me because the text on my page is dynamic and it can come after the input field or before the input field so I just want to get the text inside the div without the input fields text... (This only happens with combobox). tnx, Kazuar -- View this message in context:http://www.nabble.com/function-text%28%29-in-jquery-tp21410667s27240p... Sent from the jQuery General Discussion mailing list archive at Nabble.com. -- View this message in context:http://www.nabble.com/function-text%28%29-in-jquery-tp21410667s27240p... Sent from the jQuery General Discussion mailing list archive at Nabble.com. -- View this message in context:http://www.nabble.com/function-text%28%29-in-jquery-tp21410667s27240p... Sent from the jQuery General Discussion mailing list archive at Nabble.com.
[jQuery] Re: implemented css class not in html but is in generated html, failed to find
I don't see any elements with that classname inside a span. On Jan 15, 7:24 pm, CreativeMind aftab.pu...@gmail.com wrote: hi, here is the html source of a list. li class=xsnazzy a href=#frMap style=text-decoration:none;text-indent:5px;b class='xtop' b class='xb1 '/bb class='xb2 color_a'/bb class='xb3 '/b b class='xb4 color_a'/b/bspan class=xboxcontent h1Map/h1/span/a/li -- here is the html source of a list. li class=xsnazzy top-left tabs-selected a href=#frMap style=text-decoration: none; text-indent: 5px; b class=xtopb class=xb1/bb class=xb2 color_a/b b class=xb3/bb class=xb4 color_a/b/b span class=xboxcontenth1Map/h1/span/a/li --- the problem is when i try to find $('li span').find('.tabs-selected'), it returns me undefined... but it exists in the generated html..how can i find that class.
[jQuery] Re: .is(:event)
Hi, try this plugin: http://james.padolsey.com/javascript/debug-jquery-events-with-listhandlers/ On Jan 15, 5:24 pm, KidsKilla kidski...@gmail.com wrote: hi everyone! is there any possibility to find out if there is event binded to the element? some kind of $(#id).is(:event(click)) now i'm using $(#id).is([onclick]); but it don't works if event is binded with jQuery
[jQuery] Re: Selector Question from a newb
If you are using 1.3 it might be related to this: http://dev.jquery.com/ticket/3848 Anyway, if you select by ID then you don't need any other selectors as IDs are unique. On Jan 15, 7:06 pm, John li...@johndubchak.com wrote: This has probably been asked several times on the list but I'm having trouble finding a resolution. I have a simple problem where I dynamically add html to a div when the user clicks a link based on an event handler, which works fine. However, I am further trying to bind events to a couple of buttons that are part of the dynamic html that has just been added. Using the following selector, I am able to view the newly added html table and see the input button listed: $('#' + parentId + ' #submitForm table') But, nothing is returned when I try to use something similar to get the submit button: $('#' + parentId + ' #submitForm table #button_id') I've tried a number of different selectors, including '' and ' ' (space) but can't seem to find it correctly in the DOM. Thanks for any help. John
[jQuery] Re: implemented css class not in html but is in generated html, failed to find
Now that's another one: $('li').hasClass('.tabs-selected') and $('li').is('.tabs-selected') only tell you if li has that class or not, if you want to select by class do this: $('li.tabs-selected') On Jan 15, 9:11 pm, CreativeMind aftab.pu...@gmail.com wrote: hi, here is the html source of a list. li class=xsnazzy a href=#frMap style=text-decoration:none;text-indent:5px;b class='xtop' b class='xb1 '/bb class='xb2 color_a'/bb class='xb3 '/b b class='xb4 color_a'/b/bspan class=xboxcontent h1Map/h1/span/a/li -- here is the generated html source of a list. li class=xsnazzy top-left tabs-selected a href=#frMap style=text-decoration: none; text-indent: 5px; b class=xtopb class=xb1/bb class=xb2 color_a/b b class=xb3/bb class=xb4 color_a/b/b span class=xboxcontenth1Map/h1/span/a/li --- the problem is when i try to find $('li').hasClass('.tabs-selected'), or $('li').is('.tabs-selected') it returns me undefined... but it exists in the generated html..how can i find that class.
[jQuery] Re: [jssm] Help with jssm hash rewrite please (history plugin)
I guess it's made that way because you should be able to load other files as well. Though, at the end of the plugin you can hack it easily and your events should be modified a bit too (adding the current file name based on the url as the hash won't include it). On Jan 15, 9:10 pm, cbandes byronb...@gmail.com wrote: I'm trying to set up my ajax site to use jssm (http://trac.nathanhammond.com/jssm/ ) for history-management. It's working pretty well - history is preserved and links are bookmarkable. But it is doing some weird stuff with the href rewrite. For foo.aspx?page=1 it is replacing that with foo.aspx#foo.aspx? page=1$rid=1 I don't understand why it needs to repeat the foo.aspx part after the hash, it's pretty gross looking. Is there any way around this? The documentation for jssm is pretty thin...
[jQuery] Re: Help with jssm hash rewrite please (history plugin)
Discussion subject changed to Help with jssm hash rewrite please (history plugin) by Balazs Endresz What the ...? I didn't change the subject. Strange... On Jan 15, 10:54 pm, Balazs Endresz balazs.endr...@gmail.com wrote: I guess it's made that way because you should be able to load other files as well. Though, at the end of the plugin you can hack it easily and your events should be modified a bit too (adding the current file name based on the url as the hash won't include it). On Jan 15, 9:10 pm, cbandes byronb...@gmail.com wrote: I'm trying to set up my ajax site to use jssm (http://trac.nathanhammond.com/jssm/ ) for history-management. It's working pretty well - history is preserved and links are bookmarkable. But it is doing some weird stuff with the href rewrite. For foo.aspx?page=1 it is replacing that with foo.aspx#foo.aspx? page=1$rid=1 I don't understand why it needs to repeat the foo.aspx part after the hash, it's pretty gross looking. Is there any way around this? The documentation for jssm is pretty thin...
[jQuery] Re: jQuery selector question - Having : in attribute name
Just investigated it: http://dev.jquery.com/ticket/3729 The colon is valid I think, but it's true, there are some restrictions. On Jan 14, 2:27 pm, naden n...@naden.de wrote: That sucks. jQuery has no problem with $( 'a' ).attr( 'ajax:id' ); Therefore it would be nice to use it in the selector too. thanks anyway have to change it. On 14 Jan., 14:05, jQuery Lover ilovejqu...@gmail.com wrote: Slightly :) You can not have special character in your html ATTRIBUTES. You should rename ajax:id to something else. Ex: ajax_id or ajaxId. - Read jQuery HowTo Resource - http://jquery-howto.blogspot.com On Wed, Jan 14, 2009 at 5:16 PM, naden n...@naden.de wrote: Your right. The docs said: Note: if you wish to use any of the meta-characters described above as a literal part of a name, you must escape the character with two backslashes (\). For example: #foo\\:bar #foo\\[bar\\] #foo\\.bar and so I did. I used \\: to escape the : or I'm gettin you wrong?
[jQuery] Re: Smooth animation
It's hard to tell anything else than I've just said based on this information. If you use .animate() with each coordinates you get then you have to set the duration to a smaller number as jQuery queues up sequential animations by default, so the new one is only executed if the previous one is finished. This makes the animation smoother but it will react slower to sudden changes in the movement depending on the duration. You can also stop the current animation as you get new coordinates and start an other one based on them. For smooth movements animating is also necessary even if you update the position on every mousemove event (see the discussion I mentioned). But using purely the server for smooth animations ... I don't really now how fast web sockets are (network connection and CPU time used) but it sounds a bit hard to carry out -- at least for me :) On Jan 12, 11:11 pm, meneldor menel...@gmail.com wrote: I compute where to move my object server side for better control. I use thathttp://www.devpro.it/xmlsocket/. I wanna use the browser only as client to visualize all elements. On 12 Ян, 23:56, Balazs Endresz balazs.endr...@gmail.com wrote: Server side animation? What application is that? :) I'd be really interested why would you do that, but I'd suggest using .animate() for each coordinate you get from the server instead of setting its height and width. And send coordinates less frequently -- maybe just once and do the computation on the client. Also, maybe this will be helpful too:http://groups.google.com/group/jquery-en/browse_thread/thread/51fe8e8... On Jan 12, 3:02 pm, meneldor menel...@gmail.com wrote: Hi, group. Im trying to make animation using jquery, but its controlled server side using XMLSocket. When jQuery receive coordinates from server it moving my DIV across the browser but its too fast. I cant understand how to do smooth animation. My server script (perl) compute the same x,y coordinates like jquery (i saw how in jQuery core) but i dont know how jquery delay all these x and y coordinates properly to make animation smooth. Ill be happy if someone explain me how it works. Excuse me for my english. Best Regards!
[jQuery] Re: using setTimeout to apply fade-in effect to multiple divs in sequence
I've actually made a bit nicer abstraction as a jQuery plugin a while ago, I think it's much more useful for such things, I almost forgot about it: http://jsbin.com/unini/edit This is how your code looks like with it: $(#container :first-child).asyncEach(function(){ $(this).fadeIn('slow'); }, 500); No global variables, can be reused on multiple elements, you can stop it, add custom easing and there's a `complete` callback function too! On Jan 13, 3:49 pm, legofish pen...@gmail.com wrote: Thank you so much for the reply. I had figured it out but your way is much more elegant. here's what I had done: $(.box).hide(); var currentBox = $(#container :first-child); fadeMyBoxes(currentBox); function fadeMyBoxes(thisbox){ thisbox.fadeIn('slow'); if (thisbox.is(:last-child)){ clearTimeout(t); } else { var t =setTimeout( function(){fadeMyBoxes(thisbox.next());},50); } }; On Jan 10, 10:04 am, Balazs Endresz balazs.endr...@gmail.com wrote: It can be done with setInterval too but doing it recursively withsetTimeoutis a bit better: var i=0, elements=$('.box'), length=elements.length; functionfade(delay){ elements.eq(i++).fadeOut(); if(i=length) setTimeout(arguments.callee, delay); //arguments.callee is a reference to the current function } fade(500); On Jan 10, 3:05 am, legofish pen...@gmail.com wrote: Hi, I have 20 divs all with the class .box on my page. I want to apply the fadeIn() effect to all of them. I dont want them to allfadein at the same time. I want them tofade-in one by one, with a slight time offset. I dont want to use callback functions, because I dont want to wait until thefadeis completely finished on one div before fading the next div. I want thefadeeffect on the next div to start a short time after the effect on the previous one has started. So I think I need to usesetTimeoutand some kind of a recursive method, but I'm not very good with JS so I was hoping someone would find this trivial and could help answer my question. my thanks in advance.
[jQuery] Re: Can I get the contents from respose by ajax
Use filter with $.ajax: $('#response').html($(res).filter('#a').text()); On Jan 12, 9:30 am, David .Wu chan1...@gmail.com wrote: And I found the load is not work either, because it still get the construct not the value for example div id=test/div $(document).ready(function) { $('#test').load('ajax.php #a'); }); and the result was div id=testdiv id=a123/div/div, what I exactly want is div id=test123/div On 1月11日, 下午8時13分, Balazs Endresz balazs.endr...@gmail.com wrote: As jQuery parses this html the output will contain three elements: title, meta, and the div instead of the single html. So .find() won't work because it will search in the descendant elements, but filter will return '#a' because it's an element of the current jQuery object. $('html/html') doesn't work either, I guess it's not possible to create an html element so easily. You can also try setting the dataType option to html (or maybe xml). On Jan 11, 11:13 am, David .Wu chan1...@gmail.com wrote: I tried all your suggestion, but got some weired result. ajax.html !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd; html xmlns=http://www.w3.org/1999/xhtml; head meta http-equiv=Content-Type content=text/html; charset=utf-8 / titleajax/title script type=text/javascript src=js/jquery-1.2.6.js/script /head body div id=response/div input name=btn type=button value=ajax id=btn / script language=javascript !-- $(document).ready(function() { $('#btn').click(function() { $.ajax( { url:'ajax.php', cache:false, success:function(res) { $('#response').html($('#a',res).text()); //got nothing $('#response').html($(res + ' #a').text()); //got ajaxtest contents $('#response').html($(res).find('#a').text()); //got nothing } }); }); }); //-- /script /body /html ajax.php !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd; html xmlns=http://www.w3.org/1999/xhtml; head meta http-equiv=Content-Type content=text/html; charset=utf-8 / titleajax/title /head body div id=atest contents/div /body /html On 1月10日, 上午2時11分, dropcube ronnyh...@gmail.com wrote: is there any way to get the value 123 straight from div? yes, just apply a jQuery selector to the response content and get whatever you need. In this example: $('#a', res).text(); OR $(res).find('#a').text(); You can also try with $.load that allows you to specify a jQuery selector in the URL.
[jQuery] Re: function text() in jquery
$(#testText).clone().remove('select').text() won't work as the remove method doesn't remove the elements from the jQuery object, just from the DOM. Here's how it should work: var e = $(#testText).clone(); var select = e.find('select')[0]; e[0].removeChild(select); alert( e.text() ); On Jan 12, 3:01 pm, kazuar kazuar...@gmail.com wrote: anyone? kazuar wrote: hello, Im kinda new in jquery so maybe its a begginer question. I have a page with a div containing some text and a combobox. something like that div id=testText hello this is text and this is combobox selectoption value='1'1/optionoption value='2'2/optionoption value='3'3/option/select/div I wrote a function which return the text from the div. alert($('#testText').text()); My problem is that the function also return the text inside the combobox. is there a way to filter out the combobox text? the only workaround I can think of is to wrap my text in another div and call its text. This workaround will be a bit complicated for me because the text on my page is dynamic and it can come after the input field or before the input field so I just want to get the text inside the div without the input fields text... (This only happens with combobox). tnx, Kazuar -- View this message in context:http://www.nabble.com/function-text%28%29-in-jquery-tp21410667s27240p... Sent from the jQuery General Discussion mailing list archive at Nabble.com.
[jQuery] Re: Smooth animation
Server side animation? What application is that? :) I'd be really interested why would you do that, but I'd suggest using .animate() for each coordinate you get from the server instead of setting its height and width. And send coordinates less frequently -- maybe just once and do the computation on the client. Also, maybe this will be helpful too: http://groups.google.com/group/jquery-en/browse_thread/thread/51fe8e89ff19d94a On Jan 12, 3:02 pm, meneldor menel...@gmail.com wrote: Hi, group. Im trying to make animation using jquery, but its controlled server side using XMLSocket. When jQuery receive coordinates from server it moving my DIV across the browser but its too fast. I cant understand how to do smooth animation. My server script (perl) compute the same x,y coordinates like jquery (i saw how in jQuery core) but i dont know how jquery delay all these x and y coordinates properly to make animation smooth. Ill be happy if someone explain me how it works. Excuse me for my english. Best Regards!
[jQuery] Re: Can I get the contents from respose by ajax
As jQuery parses this html the output will contain three elements: title, meta, and the div instead of the single html. So .find() won't work because it will search in the descendant elements, but filter will return '#a' because it's an element of the current jQuery object. $('html/html') doesn't work either, I guess it's not possible to create an html element so easily. You can also try setting the dataType option to html (or maybe xml). On Jan 11, 11:13 am, David .Wu chan1...@gmail.com wrote: I tried all your suggestion, but got some weired result. ajax.html !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd; html xmlns=http://www.w3.org/1999/xhtml; head meta http-equiv=Content-Type content=text/html; charset=utf-8 / titleajax/title script type=text/javascript src=js/jquery-1.2.6.js/script /head body div id=response/div input name=btn type=button value=ajax id=btn / script language=javascript !-- $(document).ready(function() { $('#btn').click(function() { $.ajax( { url:'ajax.php', cache:false, success:function(res) { $('#response').html($('#a',res).text()); //got nothing $('#response').html($(res + ' #a').text()); //got ajaxtest contents $('#response').html($(res).find('#a').text()); //got nothing } }); }); }); //-- /script /body /html ajax.php !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd; html xmlns=http://www.w3.org/1999/xhtml; head meta http-equiv=Content-Type content=text/html; charset=utf-8 / titleajax/title /head body div id=atest contents/div /body /html On 1月10日, 上午2時11分, dropcube ronnyh...@gmail.com wrote: is there any way to get the value 123 straight from div? yes, just apply a jQuery selector to the response content and get whatever you need. In this example: $('#a', res).text(); OR $(res).find('#a').text(); You can also try with $.load that allows you to specify a jQuery selector in the URL.
[jQuery] Re: about speed up references to window
Using myvar==undefined (or any variable, which is undefined) is about 30% faster than typeof myvar==undefined About window, I don't know if that would speed up accessing it but being a local variable it may be a bit faster. I think the main purpose is to allow some minifiers to replace local variables with a shorter one. On Jan 7, 2:17 pm, Jinpu Hu huji...@gmail.com wrote: I see var window = this from latest svn code I use firebug debugger it. info:Exception: redeclaration of const window but in core.js var // Will speed up references to window, and allows munging its name. window = this, // Will speed up references to undefined, and allows munging its name. undefined, // Map over jQuery in case of overwrite _jQuery = window.jQuery, // Map over the $ in case of overwrite _$ = window.$, i want to know what does speed up references to window mean?
[jQuery] Re: XML in IE not reporting size or length correctly
Check these: http://groups.google.com/group/jquery-en/browse_frm/thread/95718c9aab2c7483/af37adcb54b816c3?lnk=gstq=parsexml#af37adcb54b816c3 http://dev.jquery.com/ticket/3143 On Jan 6, 12:02 am, maytr...@gmail.com maytr...@gmail.com wrote: XML in IE not reporting size or length correctly var strTest = rootelement1/elementelement2/ elementelement3/element/root; var $xmlTest = $((strTest), xml); var $xmlNode = $xmlTest.find(element); var nCount = $xmlNode.length; var nSize = $xmlTest.size(); alert(Count: + nCount + \nSize: + nSize); Results in FF: Count: 1 Size: 3 Results in IE7: Count: 0 Size:11 What am I missing? Thx Martin T.
[jQuery] Re: feature suggestion: .attr() without params returns the whole list of attributes
Why not use $(el).data() for that? On Jan 6, 12:57 pm, Alexandre Plennevaux aplennev...@gmail.com wrote: I would like to suggest a feature to add to jquery attributes commands: I 'm using custom attributes to store UI states. At some point i would find it handy to be able to just console.log($(this).attr() ) to see all the attributes and their value. Not a groundbreaking change, but a nice -to-have... thanks Alexandre
[jQuery] Re: feature suggestion: .attr() without params returns the whole list of attributes
You can, but it's undocumented and unnecessary :) But you can have your own namespace: $(el).data('myns.something', value); so $(el).data('myns'); will return all your properties. On Jan 6, 5:06 pm, Ricardo Tomasi ricardob...@gmail.com wrote: You can't see all data saved either.. On Jan 6, 12:01 pm, Balazs Endresz balazs.endr...@gmail.com wrote: Why not use $(el).data() for that? On Jan 6, 12:57 pm, Alexandre Plennevaux aplennev...@gmail.com wrote: I would like to suggest a feature to add to jquery attributes commands: I 'm using custom attributes to store UI states. At some point i would find it handy to be able to just console.log($(this).attr() ) to see all the attributes and their value. Not a groundbreaking change, but a nice -to-have... thanks Alexandre
[jQuery] Re: feature suggestion: .attr() without params returns the whole list of attributes
Hi Joe! Sorry, I was wrong, as the namespace is reversed. But maybe using it this way is easier and a bit faster: $(el).data('myns', {}); var mydata=$(el).data('myns'); //save a reference mydata.prop=0; //set mydata.prop; //get Btw. if you're still working on it the translation plugin has gotten modularized, so you can skip the the language detection and the ready event is firing properly too :) On Jan 6, 6:22 pm, Joe joseph.is...@gmail.com wrote: Balazs, That throws an error in the data method. Joe On Jan 6, 10:06 am, Ricardo Tomasi ricardob...@gmail.com wrote: You can't see all data saved either.. On Jan 6, 12:01 pm, Balazs Endresz balazs.endr...@gmail.com wrote: Why not use $(el).data() for that? On Jan 6, 12:57 pm, Alexandre Plennevaux aplennev...@gmail.com wrote: I would like to suggest a feature to add to jquery attributes commands: I 'm using custom attributes to store UI states. At some point i would find it handy to be able to just console.log($(this).attr() ) to see all the attributes and their value. Not a groundbreaking change, but a nice -to-have... thanks Alexandre
[jQuery] Re: Call object method onclick
Hmm, I don't think you should do this: Viewer = new Viewer; this will overwrite your class and you can't instantiate it again! rather: initialize: function() { var self=this; $(#thumbs img:first).click(function(){ self.doX() }); }, or initialize: function() { var self=this; $(#thumbs img:first).click(function(){ var el=this; //this is the element here (function(){ this.doX(); //this refers to your object here $(el).something(); }).call(self); }); }, On Jan 4, 5:57 pm, Alexandre Plennevaux aplennev...@gmail.com wrote: this worked for me:http://jsbin.com/utahi On Sun, Jan 4, 2009 at 5:31 PM, fatslags2...@gmail.com fatslags2...@googlemail.com wrote: function Viewer() { }; Viewer.prototype.constructor = Viewer; Viewer.prototype = { getFullAreaId: function() { return this._fullAreaId; }, setFullAreaId: function(fullAreaId) { this._fullAreaId = fullAreaId; }, initialize: function() { $(#thumbs img:first).click(/* execute this.doX on mouse click */); }, doX: function() { alert(this.getFullAreaId()); } }; How can I make the click event execute the doX method? Regards, FatSlags2004
[jQuery] Re: Invalid Json Primitive
Also, var params = '{wdgtype:1}'; should be var params = {wdgtype:1}; On Jan 1, 11:35 am, tep turkishexpor...@gmail.com wrote: Hello all, I am trying to create a widget within .NET that's why using JSONP. But when i run the code below, i get the error 'Invalid Json Primitive' on client side before calling web service , how can i handle that ? function test2() { var params = '{wdgtype:1}'; $.ajax({ type: POST, url: service.aspx/GetWidget, data: params, // Set Method Params beforeSend: function(xhr) { xhr.setRequestHeader(Content-length, params.length); xhr.setRequestHeader(Content-type, application/json; charset=utf-8);}, contentType: application/json; charset=utf-8, dataType: jsonp, jsonp:onJsonPLoad, success: function(msg) { $(#showyrmwidget).html(msg.d); }, error: function(xhr,msg,e){ alert(xhr.responseText);//Error Callback } }); } function onJsonPLoad(data) { alert(data); } [WebMethod()] public static string GetWidget(string wdgtype) { return test; } Thanks -- View this message in context:http://www.nabble.com/Invalid-Json-Primitive-tp21229536s27240p2122953... Sent from the jQuery General Discussion mailing list archive at Nabble.com.
[jQuery] Re: parsing xml
jQuery can't really parse xml, only html. But browsers can: http://www.w3schools.com/Xml/xml_parser.asp On Jan 2, 5:22 am, jhm jmay...@gmail.com wrote: jQuery needs a context for find() to work. That worked thanks! The xml file I was really using actually had a context similar. But it also had a header that was causing the problem. It was: ?xml version=1.0 encoding=UTF-8? Any idea why this would break it? Thanks!
[jQuery] Re: HELP: Screening questions for JavaScript developer candidates:
According to Microsoft, closures are the cause of memory leaks. This is of course deeply wrong, but it leads to Microsoft giving very bad advice to programmers on how to cope with Microsoft's bugs. http://javascript.crockford.com/memory/leak.html This article seems to be a lot more reasonable, so I don't think you should be scared :) On Dec 30, 10: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: closures and for loop question, NS_ERROR_XPC_BAD_CONVERT_JS
In the closure you have to set the arguments at the start too: return function(parentDiv,image) { ... }(parentDiv,image); but I think it won't work this way because your closure won't be executed right away (as it is inside an event handler) so it doesn't make much sense to put it there. Start the closure right after the loop and you don't have to care about it any more: for(i=0; iimgs.length; i++) (function(i){ ... })(i) But this is still unnecessary because you can just use $.each :) $.each(imgs, function(i,e){ ... }) On Dec 29, 2:07 pm, Joel jo...@planetjoel.com wrote: JQuery users, I'm receiving the following error: Error: [Exception... Could not convert JavaScript argument arg 0 [nsIDOMViewCSS.getComputedStyle] nsresult: 0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS) location: JS frame ::http://REMOVED.net/jquery-1.2.6.min.js:: anonymous :: line 22 data: no] Source File:http://REMOVED.net/jquery-1.2.6.min.js Line: 22 When I run this code: $(function () { var imgs = $(div).filter(.fc_Picture); var parentDiv; for(i=0; iimgs.length; i++) { var img = new Image(); parentDiv = imgs[i]; $(img) .load(function(parentDiv,image) { return function() { $(image).hide() $(parentDiv).removeClass('fc_loader'); $(parentDiv).append(image); $(image).fadeIn(); }(parentDiv,image); }) .attr('src','fc_image.php?imageid='+$(imgs[i]).attr ('id').split(_)[2]) .attr('width','50') } }); What I'm trying to do is have a set of images and each one loads with one of those cute little loader swirl things. I understand the pitfalls of for loops and closures (after much head scratching) but I still can't get it to work and to be honest I haven't the faintest what that error message means. Thanks for your help Joel
[jQuery] Re: writting plugin
Which is the right plugin writting way? Of course, there isn't any :) In javascript you can structure your code in almost countless ways. For a simple plugin here's what you need: http://www.learningjquery.com/2007/10/a-plugin-development-pattern but if you want to write object oriented plugins it's a bit more complicated (if you look at my profile or search on the list there are some quite long discussion about it) - though if you don't really know what is private and public just go for the link above. For a really good and short introduction to javascript I'd advise watching Douglas Crockford's videos on Yahoo Theatre. Briefly, the scope of the variable (or function) will be the function/closure it was declared in. This is the key to understand the differencies above. $myObj.fn.extend = $myObj.extend = $.extend I haven't seen this before but it is actually a very smart thing: it reuses jquery's extend function, which will work on any object because it uses the `this` keyword, so it will be able to extend $myObj too. (see here what extend is used for: http://docs.jquery.com/Utilities/jQuery.extend). $myObj.fn is most likely a reference to $myObj.prototype but it's not indicated in your code above. Hope I could help a bit, the mailing seems to be dead during the holidays :) On Dec 28, 12:11 pm, Saledan bastil...@gmail.com wrote: up, please! bye max On 26 Dic, 12:19, Saledan bastil...@gmail.com wrote: Hi, i'm trying to write a jQuery plugin, i have read some posts, documents and other plugin code, but i don't understand the right standard to write a plugin. I found some patterns... == example 1== (function($) { $.fn.myPlugin = function(o) { return this.each(function() { // do something }); }; })(jQuery); == example 2== (function($) { $.fn.myPlugin = function(o) { return this.each(function() { // do something }); }; // private function function functionA () {..do something..}; })(jQuery); == example 3== (function($) { $.fn.myPlugin = function(o) { return this.each(function() { // do something }); }; // Public function?!? $.fn.myPlugin.functionA () {..do something..} })(jQuery); == example 4== (function($) { $.fn.myPlugin = function(o) { return this.each(function() { // do something }); }; $.extend(myPlugin.prototype, { functionA : function() {..do something..}, functionB : function() {..do something..} } })(jQuery); == example 5== (function($) { $.fn.myPlugin = function(o) { return this.each(function() { // do something var functionA = function () {..do something..} }); }; })(jQuery); == example 6== (function($) { $.fn.myPlugin = function(o) { return this.each(function() { // do something }); }; $.fn.extend ({ functionA : function () {..do something..} }); })(jQuery); == example 7== (function($) { $.fn.myPlugin = function(o) { return this.each(function() { new myObj(); }); }; $.myObj = function () {..do something..}; $myObj = $.myObj; $myObj.fn.extend = $myObj.extend = $.extend; $myObj.fn.extend ({ functionA: function() {..do something..}, functionB: function() {..do something..} }); $myObj.extend ({ functionC: function() {..do something..} }); })(jQuery); Which is the right plugin writting way? I think that the last example is well done... but i don't understand this line $myObj.fn.extend = $myObj.extend = $.extend; and the differents between $myObj.fn.extend and $myObj.extend .. public or private function? the first is for public function? Please may you help me? Many thanks bye Max
[jQuery] Re: livequery matchedFn scope?
If you generate the IDs dinamically and somehow an empty string is passed as the selector the document will be selected, so all these are the same: $()[0]; $()[0]; $(document)[0]; On Dec 27, 9:25 pm, Stephen sathoma...@gmail.com wrote: Sorry to bother folks with what is probably a silly question, but I can't quite figure out the scope for livequery matched functions. For example, if I have the following: $(#id:not(.inactive)).livequery(function() {alert(this);}) Then the alert shows this to be the matched selector, which is what I would expect. But if I have the following: $(#id).not(.inactive).livequery(function() {alert(this);}) Then the alert shows this to be the entire document. What's the reason for the difference in behavior? If anyone can explain this behavior, then it will probably let me figure out my real problem. In case someone has a lot of spare time, though, and wants to help with the root problem, here it is. I'm using ajax to load a lot of dynamically generated content, and I'm doing a fair bit of livequery processing on that content. The processing includes collapsing various sections of the content by hiding them. With a straightforward implementation, the browser briefly displays the entire (expanded) content before livequery has a chance to complete it's processing, so users are treated to an annoying peek-a- boo effect as the full content briefly appears and then collapses down to something more manageable. My approach for solving this problem is to deliver the content within a div wrapper with a css property of display:none. As soon as the content arrives, I add a livequery handler that calls show() on the div wrapper. Since this handler goes to the end of the livequery queue, it fires only after all the other livequery processing is complete. Works like a charm on test pages where all the IDs are hard-coded. On the real page, though, the IDs aren't hard-coded, so I have to dynamically figure out which elements to show. I'm stuck on trying to find a handle to the content so that I can show it. I would expect this to be the delivered content in the matched function, but, instead, it's the entire document. TIA, Stephen P.S. This is on Safari if it matters. I've briefly tried Firefox and it seems to behave the same way, so I haven't done exhaustive testing other than in Safari.
[jQuery] Re: Adding scope support to .bind()
Hi, I think this would be really useful! I've also modified jQuery to do this a while ago (1.2.6) but with the new scope being the last argument, so it works without the data object as well: jQuery.fn.bind=function( type, data, fn, bind ) { return type == unload ? this.one(type, data, fn) : this.each (function(){ if( $.isFunction(data) ) jQuery.event.add( this, type, data, bind, fn ); else jQuery.event.add( this, type, fn, data, bind ); }); } jQuery.event = { add: function(elem, types, handler, data, bind) { if ( elem.nodeType == 3 || elem.nodeType == 8 ) return; if( bind != undefined ) handler = jQuery.bind(handler, bind); //change scope ... jQuery.each( (blur,focus,load,resize,scroll,unload,click,dblclick, + mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave, + change,select,submit,keydown,keypress,keyup,error).split(,), function(i, name){ // Handle event binding jQuery.fn[name] = function(fn, bind){ //second argument for the scope return fn ? this.bind(name, fn, bind) : this.trigger(name); }; }); where jQuery.bind is: jQuery.bind=function( fn, bind ){ var args = $.makeArray( arguments ).slice(2); if( args.length == 1 $.isArray( args[0] ) ) args = args[0]; return function(){ return fn.apply( bind, args ); } } On Dec 25, 10:38 am, Eduardo Lundgren eduardolundg...@gmail.com wrote: Hi guys, The .bind() method consider the scope of the handler the element whose the event is assigned - that is the correct as default. I've been playing with the event.js and implemented an alternative to call .bind(), specifying another scope, that looks useful for our api. I've attached the event.js modified from the rev. 5996 from the trunk. The changes are compatible with the current API. Here goes one example: var scopeTest = function() { this.name = iamanotherscope; this.internalHandler = function(event) { console.log(I am another scope method., this.name, event, event.data); }; }; var scope = new scopeTest(); $('div').bind('click', {data: true}, globalHandler); $('div').bind('click', {data: true}, scope.internalHandler); // handler, data, default scope $('div').bind('click', {data: true}, scope, scope.internalHandler); // handler, data, pre-defined scope Let me know if make sense for you. -- Eduardo Lundgren Software Engineer Liferay, Inc. Enterprise. Open Source. For Life. event.js 26KViewDownload
[jQuery] Re: Adding scope support to .bind()
True, but the new isFunction is a couple of times faster than the old one, though it's still many times faster to directly call Object.prototype.toString, which is far below 0.001ms. But as the callback function is the last parameter everywhere in jQuery it might be confusing to change this pattern, it just looked more like binding the function with a native method for me. On Dec 25, 7:06 pm, Eduardo Lundgren eduardolundg...@gmail.com wrote: Hi Balazs, Thanks for give us your opinion. When you use $.isFunction(data) on the bind method it is very expensive when you have a lot of iterations. Diff the file I attached with the original file (rev. 5996) I made only a small change on the bind() method, and it's compatible with data and with out API. On Thu, Dec 25, 2008 at 3:05 AM, Balazs Endresz balazs.endr...@gmail.comwrote: Hi, I think this would be really useful! I've also modified jQuery to do this a while ago (1.2.6) but with the new scope being the last argument, so it works without the data object as well: jQuery.fn.bind=function( type, data, fn, bind ) { return type == unload ? this.one(type, data, fn) : this.each (function(){ if( $.isFunction(data) ) jQuery.event.add( this, type, data, bind, fn ); else jQuery.event.add( this, type, fn, data, bind ); }); } jQuery.event = { add: function(elem, types, handler, data, bind) { if ( elem.nodeType == 3 || elem.nodeType == 8 ) return; if( bind != undefined ) handler = jQuery.bind(handler, bind); //change scope ... jQuery.each( (blur,focus,load,resize,scroll,unload,click,dblclick, + mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave, + change,select,submit,keydown,keypress,keyup,error).split(,), function(i, name){ // Handle event binding jQuery.fn[name] = function(fn, bind){ //second argument for the scope return fn ? this.bind(name, fn, bind) : this.trigger(name); }; }); where jQuery.bind is: jQuery.bind=function( fn, bind ){ var args = $.makeArray( arguments ).slice(2); if( args.length == 1 $.isArray( args[0] ) ) args = args[0]; return function(){ return fn.apply( bind, args ); } } On Dec 25, 10:38 am, Eduardo Lundgren eduardolundg...@gmail.com wrote: Hi guys, The .bind() method consider the scope of the handler the element whose the event is assigned - that is the correct as default. I've been playing with the event.js and implemented an alternative to call .bind(), specifying another scope, that looks useful for our api. I've attached the event.js modified from the rev. 5996 from the trunk. The changes are compatible with the current API. Here goes one example: var scopeTest = function() { this.name = iamanotherscope; this.internalHandler = function(event) { console.log(I am another scope method., this.name, event, event.data); }; }; var scope = new scopeTest(); $('div').bind('click', {data: true}, globalHandler); $('div').bind('click', {data: true}, scope.internalHandler); // handler, data, default scope $('div').bind('click', {data: true}, scope, scope.internalHandler); // handler, data, pre-defined scope Let me know if make sense for you. -- Eduardo Lundgren Software Engineer Liferay, Inc. Enterprise. Open Source. For Life. event.js 26KViewDownload -- Eduardo Lundgren Software Engineer Liferay, Inc. Enterprise. Open Source. For Life.
[jQuery] Re: How to trigger an event for a SELECT after removing an entry??
Change the value of the dropdown with .val('0001') - maybe before removing the first option. Or use triggerHandler but inline events won't fire that way, I guess. On Dec 22, 4:37 pm, ggerri a...@ggerri.com wrote: Hi Gurus I have a generated dropdown list with years and an onChange event. Sometimes the select field has a value '(All)' as first entry. I want to remove this entry and trigger the DOM Level 0 Event. This would be my page: head script type=text/javascript src=jquery.js/script script language=JavaScript type=text/javascript $(function() { //works but cant trigger event for select $('option:contains(Alle)').remove(); // should be something like this, but this doesnt work $('select:has(option:contains(All))').filter('option:contains (All)').remove().end().trigger('change'); }); /script /head body form id=form1 name=form1 method=post action= select id=PG1_ZEPLNZPJ_V01 class=urDdlWhl1 urV onchange=alert ('clicked') name=PG1_ZEPLNZPJ_V01 ct=DropDownListBox option selected= value=(All)/option option value=00012008/option option value=00022009/option option value=00032010/option option value=00042011/option option value=00052012/option option value=00062013/option option value=00072014/option /select /form /body /html Really ned some hints here :-) thanks guys ggerri
[jQuery] Re: remove ID
http://docs.jquery.com/Attributes/removeAttr Actually it only replaces the value with an empty string just as plain js: element.removeAttribute() On Dec 22, 5:49 pm, Mike Dodge dmikest...@gmail.com wrote: Is it possible to remove an ID from an element with Jquery or javascript for that matter? I've searched and all I can find is how to remove the whole element, I just want to remove the ID.Thanks Mike
[jQuery] Re: create a translate plugin using jQuery
Then just go for the first one: http://recurser.com/articles/2008/02/21/jquery-i18n-translation-plugin/ On Dec 20, 12:39 pm, rabab chakhmoune rabab.chakhmo...@gmail.com wrote: tkx for your answer, no i want to create a plugin using jquery i need't a google's machine to translate so i want a different steps to create plugin to translate and when i install or add my plugin, automatiqquely a my site web translate in frensh ok tkx for your help Merci beaucoup Rabab 2008/12/19, Balazs Endresz balazs.endr...@gmail.com: If you have the translation: http://recurser.com/articles/2008/02/21/jquery-i18n-translation-plugin/ Alternatively, if you want to use Google's machine translation: http://code.google.com/p/jquery-translate/ On Dec 19, 10:33 am, Rabab CHAKHMOUNE rabab.chakhmo...@gmail.com wrote: Hello I want to create a plugin to translate a site web (translate english to french) and i don't know what i need for begin my project to create this plugin. any one here can help me? tkx sorry for my english because i speak frensh Rabab -- SIMPLICITY OR COMPLEXITY IS NOT THE QUESTION
[jQuery] Re: create a translate plugin using jQuery
If you have the translation: http://recurser.com/articles/2008/02/21/jquery-i18n-translation-plugin/ Alternatively, if you want to use Google's machine translation: http://code.google.com/p/jquery-translate/ On Dec 19, 10:33 am, Rabab CHAKHMOUNE rabab.chakhmo...@gmail.com wrote: Hello I want to create a plugin to translate a site web (translate english to french) and i don't know what i need for begin my project to create this plugin. any one here can help me? tkx sorry for my english because i speak frensh Rabab
[jQuery] Re: Pro Javascript Techniques Doubt
The context of the closure after the loop should be changed, currently it points to the `window` object. It seems like a typo, as it's even noted that you have to ...make sure that it's properly scoped })(); }-}).call(this); } On Dec 18, 2:08 pm, Pablo Fernandez fernandezpabl...@gmail.com wrote: Hi, I'm reading Pro Javascript Techniques from John Resig, and I'm confused with an example. This is the code: // Create a new user object that accepts an object of properties function User( properties ) { // Iterate through the properties of the object, and make sure // that it's properly scoped (as discussed previously) for ( var i in properties ) { (function(){ // Create a new getter for the property this[ get + i ] = function() { return properties[i]; }; // Create a new setter for the property this[ set + i ] = function(val) { properties[i] = val; };})(); } } // Create a new user object instance and pass in an object of // properties to seed it with var user = new User({ name: Bob, age: 44}); // Just note that the name property does not exist, as it's private // within the properties object alert( user.name == null ); // However, we're able to access its value using the new getname() // method, that was dynamically generated alert( user.getname() == Bob ); // Finally, we can see that it's possible to set and get the age using // the newly generated functions user.setage( 22 ); alert( user.getage() == 22 ); Now running that on Firebug console (on FF3) throws that user.getname () is not a function. I tried doing this: var other = User other() window.getname() -- this works! And it worked! Any idea why? thanks everybody! PS: I know this is not an specific Jquery thing but a Javascript question, but I didn't know where to ask.
[jQuery] Re: Pro Javascript Techniques Doubt
Oops, I didn't notice it: you have to pass the `i` variable too: for ( var i in properties ) { (function(i){ That's why you need the closure at all. Without that you will get the last property from all getters. The reference of `this` will always change if you put it in an additional function, doesn't matter if it's inside an instantiated object. Well, you can call that either design error or feature too :) On Dec 18, 4:18 pm, Pablo Fernandez fernandezpabl...@gmail.com wrote: another thing... why inside the anonymous function 'this' refers to 'window' ?? it's totally misleading...
[jQuery] Re: Pro Javascript Techniques Doubt
I've just had a look at it and where this issue comes up in the book there's a new variable declared (like on page 153). No need to pass the argument this way, moreover not that easy to mistype: for ( var j in properties ) { (function(){ var i=j; ... I can't believe no one has spotted this: http://www.apress.com/book/errata/275 On Dec 18, 4:53 pm, Pablo Fernandez fernandezpabl...@gmail.com wrote: That did it, although I had to add this too -- }).call(this,i); in order to pass the parameter Thanks Balazs!!! On 18 dic, 12:29, Balazs Endresz balazs.endr...@gmail.com wrote: Oops, I didn't notice it: you have to pass the `i` variable too: for ( var i in properties ) { (function(i){ That's why you need the closure at all. Without that you will get the last property from all getters. The reference of `this` will always change if you put it in an additional function, doesn't matter if it's inside an instantiated object. Well, you can call that either design error or feature too :) On Dec 18, 4:18 pm, Pablo Fernandez fernandezpabl...@gmail.com wrote: another thing... why inside the anonymous function 'this' refers to 'window' ?? it's totally misleading...
[jQuery] Re: Pro Javascript Techniques Doubt
this[ set + i ] = function(val) { properties[i] = val; }; This code only defines a function but doesn't execute its contents right now, and as functions capture the variables defined outside of them if you change the value of i then it will change in properties [i] too. In other words the `i` in properties[i] is the same that you use for the loop. If you use a closure you can define a local variable that gets the value (not the reference!) of the current index so that won't change afterwards. Sounds complicated but it really isn't - once you get it :) On Dec 18, 5:52 pm, pablo fernandez fernandezpabl...@gmail.com wrote: That Does it too!! I still don't get why 'i' keeps always the last value if you don't do var i = j; :S On Thu, Dec 18, 2008 at 1:11 PM, Balazs Endresz balazs.endr...@gmail.com wrote: I've just had a look at it and where this issue comes up in the book there's a new variable declared (like on page 153). No need to pass the argument this way, moreover not that easy to mistype: for ( var j in properties ) { (function(){ var i=j; ... I can't believe no one has spotted this:http://www.apress.com/book/errata/275 On Dec 18, 4:53 pm, Pablo Fernandez fernandezpabl...@gmail.com wrote: That did it, although I had to add this too -- }).call(this,i); in order to pass the parameter Thanks Balazs!!! On 18 dic, 12:29, Balazs Endresz balazs.endr...@gmail.com wrote: Oops, I didn't notice it: you have to pass the `i` variable too: for ( var i in properties ) { (function(i){ That's why you need the closure at all. Without that you will get the last property from all getters. The reference of `this` will always change if you put it in an additional function, doesn't matter if it's inside an instantiated object. Well, you can call that either design error or feature too :) On Dec 18, 4:18 pm, Pablo Fernandez fernandezpabl...@gmail.com wrote: another thing... why inside the anonymous function 'this' refers to 'window' ?? it's totally misleading... -- Fernandez, Pablo.
[jQuery] Re: Pro Javascript Techniques Doubt
I mean the the getter/setter functions are the ones that doesn't get immediately executed. But if you're really new to this maybe you could start with something that's easier to digest, like Douglas Crockford's videos on YDN. I only say this because I also started to read this book (or was it the Pro JS Design Patterns?) when I knew next to nothing about javascript but it was quite frustrating experience then :) http://video.yahoo.com/search/?p=The+JavaScript+Programming+Language http://video.yahoo.com/search/?p=advanced+JavaScript On Dec 18, 7:45 pm, pablo fernandez fernandezpabl...@gmail.com wrote: Yeah it sounds complicated... I'm kinda newbe to this, I hope you don't mind if I ask these silly questions I thought the anonymous function got executed on this line for ( var i in properties ) { (function(){ this[ get + i ] = function() { return properties[i]; }; this[ set + i ] = function(val) { properties[i] = val; }; }).call(this)-- EXECUTE! (and use actual value of i) // now go on with the next i ; } Isn't this the logical way of seeing it? what am I missing? On Thu, Dec 18, 2008 at 3:38 PM, Balazs Endresz balazs.endr...@gmail.com wrote: this[ set + i ] = function(val) { properties[i] = val; }; This code only defines a function but doesn't execute its contents right now, and as functions capture the variables defined outside of them if you change the value of i then it will change in properties [i] too. In other words the `i` in properties[i] is the same that you use for the loop. If you use a closure you can define a local variable that gets the value (not the reference!) of the current index so that won't change afterwards. Sounds complicated but it really isn't - once you get it :) On Dec 18, 5:52 pm, pablo fernandez fernandezpabl...@gmail.com wrote: That Does it too!! I still don't get why 'i' keeps always the last value if you don't do var i = j; :S On Thu, Dec 18, 2008 at 1:11 PM, Balazs Endresz balazs.endr...@gmail.com wrote: I've just had a look at it and where this issue comes up in the book there's a new variable declared (like on page 153). No need to pass the argument this way, moreover not that easy to mistype: for ( var j in properties ) { (function(){ var i=j; ... I can't believe no one has spotted this:http://www.apress.com/book/errata/275 On Dec 18, 4:53 pm, Pablo Fernandez fernandezpabl...@gmail.com wrote: That did it, although I had to add this too -- }).call(this,i); in order to pass the parameter Thanks Balazs!!! On 18 dic, 12:29, Balazs Endresz balazs.endr...@gmail.com wrote: Oops, I didn't notice it: you have to pass the `i` variable too: for ( var i in properties ) { (function(i){ That's why you need the closure at all. Without that you will get the last property from all getters. The reference of `this` will always change if you put it in an additional function, doesn't matter if it's inside an instantiated object. Well, you can call that either design error or feature too :) On Dec 18, 4:18 pm, Pablo Fernandez fernandezpabl...@gmail.com wrote: another thing... why inside the anonymous function 'this' refers to 'window' ?? it's totally misleading... -- Fernandez, Pablo. -- Fernandez, Pablo.
[jQuery] Re: Multiple plugins in same namespace?
There are even two small plugins that enable you to do it quite easily: http://groups.google.com/group/jquery-dev/browse_thread/thread/b2f784b7575456dc/0cd276379f8a2f7d?show_docid=0cd276379f8a2f7d On Dec 13, 9:27 pm, Marion marion.newlev...@gmail.com wrote: Hi Mike, Thanks! all good suggestions. I went with $('#someid').myPlugin({ doThis: ..., doThat: ... }); One entry point, and lets me doThis and doThat both, which turned out to be useful. I'm still curious whether my original syntax could be made to work. I suspect the answer is not easily. Marion On Dec 13, 5:14 am, Mike Alsup mal...@gmail.com wrote: I'm trying to create a plugin with two entry points. You would use it like this: $('#someid').myPlugin.doThis(options); $('#anotherid').myPlugin.doThat(options); How about one of these approaches instead: $('#someid').myPluginDoThis(options); $('#anotherid').myPluginDoThat(options); or $('#someid').myPlugin('doThis', options); $('#anotherid').myPlugin('doThat',options); or $('#someid').myPlugin({ action: 'doThis' /* other options */}); $('#anotherid').myPlugin({ action: 'doThat' /* other options */ });
[jQuery] Re: jQuery with prototype - RTFM but still problem
Older versions of scriptaculous conflict with jQuery, try using 1.8+ http://groups.google.com/group/jquery-en/browse_thread/thread/1c0610237b8b8da1 On Dec 8, 5:18 pm, dpoakaspine [EMAIL PROTECTED] wrote: Hello, I read every clue to implement the 2 above libraries. Unfortunately it is still not working. I tried first including prototype then jquery. First jquery then prototype. noConflict() etc. ... Could y'all take a look athttp://www.cjd-rz.deand tell me what's wrong? I can't see an error! Help would be appreciated, Stefan
[jQuery] Re: setTimeout function call...
You can see setTimeout(funcName(), 2000); everywhere on the net but it's actually quite ridiculous as it's much easier (and faster) to just pass a function reference to it like this: setTimeout(sendit, 2000); also this will solve the scoping issues as well. If you want to pass some arguments too then: setTimeout(function(){ sendit(a,b) }, 2000); On Dec 3, 11:13 pm, QuadCom [EMAIL PROTECTED] wrote: Holy @!$! that was fast. Thanks guys, This is all in doc.ready. If I move the regular functions out, I cannot use the 'olde' var in them. If I set the 'olde' var outside of doc.ready, I can't use it inside doc.ready. I'm sure there is a simple fix for this but the little grey cells are smoking already. [code] // get the original email address for comparison var olde = $('#editaemail').val(); // Define global error vars var emailerror = 0; var passworderror = 0; // Save button on form starts the whole thing $('#editasave').click(function(){ newe = $('#editaemail').val(); url = '/myaccount/process.cfm?t=' + new Date().getTime(); $('#editasave').attr(disabled,disabled).attr(value,One Moment); if(olde != newe){ $('#editasave').attr(value,Checking Email); $.post(url, {checkname: newe}, chkmail, json); } else{ $('#emailerror, .emailerror').hide(); emailerror = 0; checkeditapass(); } }); // Checks the results of the post call to see if the email already exists in the DB // Displays error information and sets appropriate vars in the case of an error function chkmail(data){ if (data.exists == 1){ $('#emailerror, .emailerror').show(); emailerror = 1; } else{ $('#emailerror, .emailerror').hide(); var olde = $('#editaemail').val(); emailerror = 0; } //These always cause an 'undefined' error when the function is included within doc.ready setTimeout(checkeditapass(), 2000); } // Checks the password fields to make sure they are the same // Displays error information and sets appropriate vars in the case of an error function checkeditapass(){ $('#editasave').attr(value,Checking Passwords); p1 = $('#editapassword1').val(); p2 = $('#editapassword2').val(); if (p1 != p2){ $('#passerror, .passerror').show(); passworderror = 1; } else{ $('#passerror, .passerror').hide(); passworderror = 0; } //These always cause an 'undefined' error when the function is included within doc.ready setTimeout(checkeditavars(), 2000); } // Checks the global error vars and only submits the form if there are no errors function checkeditavars(){ if(emailerror == 0 passworderror == 0) { $('#editasave').attr(value,Saving Changes); setTimeout(sendit(), 2000); } else { $('#editasave').removeAttr(disabled).attr(value,Save Changes); } } // Actually sends the form data through form plugin and unblocks the UI function sendit(){ $('#editaform').ajaxSubmit(function(){ $('#editasave').attr(value,Changes Saved); url = '/myaccount/process.cfm?getdetail=1t=' + new Date().getTime (); $('#accountcontent').load(url, function(){ $.unblockUI(); }); });} [/code]
[jQuery] Re: Dynamic Event Handler
It's much cleaner to use $.each (no new variables will be introduced in the current scope), also with that you can avoid things like this. The problem is that in categories[index] index will be a reference to the variable you use in the loop, so every time the value of index changes it will change in the event handler as well. But not this way: $.each(categories, function(index){ var nav_id= categories[ index ]['nav_id']; var data_id = categories[ index ]['data_id']; $('#' + nav_id).click( function(){ $('#' + data_id).slideToggle('slow'); } ); }) http://docs.jquery.com/Utilities On Nov 28, 8:01 pm, Ryan [EMAIL PROTECTED] wrote: I have some 'NAV' elements, that when clicked should slideToggle their respective 'DATA' elements. I am trying to do this by traversing an Object with a for loop, and each elements IDs are stored in this data structure. However, once execute, each click of any of the NAV elements only slideToggles the last DATA element. Ex: Code: -- JAVASCRIPT var categories = new Array(); categories[1] = new Object; categories[1]['nav_id'] = 'NAV_1'; categories[1]['data_id'] = 'DATA_1'; categories[2] = new Object; categories[2]['nav_id'] = 'NAV_2'; categories[2]['data_id'] = 'DATA_2'; -- JQUERY for( var index in categories ){ var nav_id = categories[ index ]['nav_id']; var data_id = categories[ index ]['data_id']; $('#' + nav_id).click( function(){ $('#' + data_id).slideToggle('slow'); } ); } -- HTML div id='NAV_1' /div div id='NAV_2' /div div id='DATA_1' /div div id='DATA_2' /div -- each div is absolutely positioned in the page I could possible see that JQuery could get confused by this, but to me should be able to work somehow. Could there possibly be a way to do a foreach() through element id's that match a certain regular expression? Any help is greatly appreciated!
[jQuery] Re: Object-oriented plugins?
I personally use the same approach in the Translate plugin (maybe I should have told you that before :), but with that you don't need the 'new' keyword: $.translate() returns a new object (it's a bit similar to $.ajax or jQuery itself, you don't need 'new' there either). http://code.google.com/p/jquery-translate/ With Translate you can only control the behaviour through the options when using the jQuery method (though the object is available in callback functions), but in your case I think you can still consider letting the first variable call a method: $.fn.alerter = function(a){ if(typeof a!=string) { var alerter = new $.Alerter(this, a); $(this).data(alerter, alerter); //store the instance } else { var instance = $(this).data(alerter); //get the instance instance[a].apply(instance, $.makeArray(arguments).slice(1) ); // call method } return this; } I don't want to push this but it's really not a lot of code for a shorthand, as you don't need to deal with the instances in your code beacause they're handled by the plugin and you can call methods without breaking a chain, but it really depends on what you want the plugin to do. Some other discussions related to this topic if you're interested: http://groups.google.com/group/jquery-en/browse_thread/thread/9dc9be1cc298cbdd http://groups.google.com/group/jquery-dev/browse_thread/thread/48400f696b85a7cb http://groups.google.com/group/jquery-dev/browse_thread/thread/b2f784b7575456dc/0cd276379f8a2f7d?show_docid=0cd276379f8a2f7d http://groups.google.com/group/jquery-dev/browse_thread/thread/6c02b9b939c96bdb/5f244e161b9c1346?show_docid=5f244e161b9c1346 On Nov 26, 7:16 pm, Hector Virgen [EMAIL PROTECTED] wrote: I've been thinking about this over the weekend and came up with a way to write class-based plugins while still following the jQuery convention. Maybe someone else has done this before but I couldn't find any documentation on this subject. The idea is to extend the base jQuery object with the javascript class, and then extend jQuery.fn with a simple method that does nothing but instantiate the class and return this. The nice thing about this approach is that you can still make chainable plugins without polluting the jQuery.fn namespace with a ton of methods. $('#mydiv').myplugin().show(); But if you need access to the object, you can use the new construct. var myplugin = new $.MyPlugin($('#mydiv')); myplugin.doSomething(); Here is an example plugin that just alerts some text when the selected elements are clicked. But, if you create the plugin object manually with the new construct, you can change the message or invoke the alert without the click: (function($){ var Alerter = function(selector, options) { var obj = this; this.settings = { message: 'no message'}; $.extend(this.settings, options); selector.click(function() { obj.alert.call(obj);}); } Alerter.prototype.alert = function() { alert('Alerter said: ' + this.settings.message);} Alerter.prototype.message = function(message) { this.settings.message = message; return this;} $.extend({ Alerter: Alerter}); $.fn.extend({ alerter: function(options) { var alerter = new $.Alerter(this, options); return this; } }); })(jQuery); // Usage as jQuery plugin $('#mydiv').alerter({ message: 'foo' }); // Usage as object var alerter = new $.Alerter($('#anotherdiv'), { message: 'bar' }); // As an object, you can call methods on it easily alerter.message('new message'); alerter.alert(); // alerts Alerter said: new message Any thoughts on this approach? -Hector On Sun, Nov 23, 2008 at 5:15 AM, Scott González [EMAIL PROTECTED]wrote: Providing the method name as the first parameter is a bit awkward, perhaps looking at the alternatives would help: Add namespaces to jQuery. This isn't very jQuery-like. Example: $ (el).tabs.add(url, label).show(); Add a new jQuery method for every plugin instance method. This pollutes the jQuery namespace, so this should only be done when it really makes sense. Example: $(el).addTab(url, label); Use events. You can bind custom events in a namespace and then have users interact with your plugin by triggering those events. Example: $ (el).trigger('add.tabs', url, label); There may be other approaches as well. The jQuery UI approach allows plugins to expose as many methods as they want while only using one method in the jQuery namespace.
[jQuery] Re: Show and Hide methods on div tag stuttering animation
Most likely it's because the padding and margin properties are not animated: http://groups.google.com/group/jquery-dev/browse_thread/thread/5c990ab32a8ef733/f92692bb578495b6?show_docid=f92692bb578495b6 On Nov 26, 9:27 pm, Todd Stuart [EMAIL PROTECTED] wrote: Hello, I am using .show() and on a div object. In both IE and FF the display starts out nice and smooth and then seems to stutter at the end of the show. I have tried using .show(fast), .show(slow) also, but with the same results. Does anyone know a fix to this? Thanks, TS
[jQuery] Re: smoother .animate()?
Nice! Though, it's just come into my mind that there's a jQuery plugin even for especially this, which seems to work even smoother: http://webdev.stephband.info/parallax.html On Nov 23, 1:15 pm, bnlps [EMAIL PROTECTED] wrote: yay -- corrected; also, added Caching and Easing:http://pastie.org/private/pegbur0eetnzhoiqkpd5w thanks! -B On 22 Nov., 13:34, Balazs Endresz [EMAIL PROTECTED] wrote: I fear it won't help much but you can try caching some values outside the event handler: var mx=$(window).width(), my=$(window).height(), $k=$('#k'); Also, you set the duration in the wrong place, that should be in the second argument:http://docs.jquery.com/Effects/animate#paramsdurationeasingcallback And why is it 1ms? On Nov 21, 8:16 pm, bnlps [EMAIL PROTECTED] wrote: Hi, kids -- there's a nice Flash site ... marcecko dot com ( especially, the window-content-movement, mouse.x/y) ... ported to html/jQ, but couldn't find a way to realise the smooth sliding part while moving; it's f'd, scratchy. any solutions? or, a Flash-only thing? thanks! -B now, have a look: (tested on FF3, IE7 -- XP) - !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd; html xmlns=http://www.w3.org/1999/xhtml; lang=en xml:lang=en head titlejQx/title meta http-equiv=content-type content=text/html;charset=utf-8/ style type=text/css media=all !-- html{width:100%;height:100%;overflow:hidden;} body,div{margin:0;padding:0;} div{position:absolute;left:0px;top:0px;width:1600px;height:1200px;} span{position:absolute;} -- /style script type=text/javascript src=http://jqueryjs.googlecode.com/ files/jquery-1.2.6.min.js/script script type=text/javascript //![CDATA[ var mx,my; $(function(){ $().mousemove(function(e){ mx=$(window).width(); mx=Math.ceil((-e.pageX/mx*(16E2-mx))); my=$(window).height(); my=Math.ceil((-e.pageY/my*(12E2-my))); $('#k').dequeue().animate({left:mx,top:my,duration:1}); // ! // $('#k').css({left:mx,top:my}); ... 1:1 }); }); //]] /script /head body div id=k span style=top:0px;left:0px;height:50px;width:50px;background- color:#cff;/span span style=bottom:0px;left:1550px;height:50px;width:50px;background- color:#e10;/span span style=top:0px;left:1550px;height:50px;width:50px;background- color:#0cc;/span span style=top:1150px;left:0px;height:50px;width:50px;background- color:#3fa;/span span style=top:50px;left:300px;height:100px;width:300px;background- color:#333;/span span style=top:300px;left:200px;height:700px;width:150px;background- color:#f6c;/span span style=top:500px;left:400px;height:500px;width:850px;background- color:#aba;/span span style=top:300px;left:600px;height:100px;width:950px;background- color:#ff0;/span /div /body /html
[jQuery] Re: Object-oriented plugins?
To be honest, this seems a little awkward for me. This means I would have to write my plugin to check the first parameter to see if it's a string or an object, and if it's a string I then would have to make a switch to call the approriate method based on the string value. You don't need a switch, you can call a method like this: object['method_name'](); and also you can store the instance with $.data This is what UI's widget factory was built for: http://docs.jquery.com/UI/Developer_Guide As for UI widgets you can call the method directly with $.data: $(#tabbed).tabs(); $(#tabbed).data('tabs').add('test.html', 'new tab', 4); But I'm not sure if this would be the encouraged way of using plugins, actually I haven't heard about any convention you could follow when writing an OO plugin. This questions comes up from time to time and it seems it's up to you to pick a pattern. On Nov 23, 4:03 am, Hector Virgen [EMAIL PROTECTED] wrote: Does anyone know of a good example of an object-oriented plugin for jQuery? The reason I ask is that the jQuery convention is to return *this* at the end of the plugin to allow for chaining. While that's great for simple plugins, some of my advanced plugins instantiate object that I would like to access at various points in my script. From the looks of it, jQuery's tabs plugin seems to use an object stored somewhere (perhaps in the element). But to invoke methods on that object, you have to call the plugin again and pass it a string as its first parameter: http://docs.jquery.com/UI/Tabs/tabs#.22enable.22index jQuery#tabs( add, url, label, [index] ) To be honest, this seems a little awkward for me. This means I would have to write my plugin to check the first parameter to see if it's a string or an object, and if it's a string I then would have to make a switch to call the approriate method based on the string value. I would much rather be able to access the tabs instance directly: var tabs = $('#tabbed').tabs(); // tabs is instance of jQueryTabs tabs.add(url, label); // accessing instance directly But if tabs acted like that, it would break chaining. $('#tabbed').tabs().hide(); // This would error Is there another way to create object-oriented plugins, while still following the jQuery conventions? Thanks! -Hector
[jQuery] Re: Tablesorter pager and ajax
I've had a closer look at that page and triggering the update is only needed if you're updating just the table contents, I thought you were doing that. And as you are loading the same page again all the javascript will be loaded again too, which is unnencessary in this case, but most likely the main problem is that there will be two elements with the same id. On Nov 22, 5:22 pm, led [EMAIL PROTECTED] wrote: Please look athttp://realferias.com/pager.asp. When the table is in a file that is loaded, the tablesorter and the pager fails. i?m using the $(table).trigger(update); but nothing. On Nov 22, 11:03 am, Balazs Endresz [EMAIL PROTECTED] wrote: You triggered the update before the data loaded, you have to do that in a function as the third argument: $('#foo').click(function() { $('#centro').empty(); $('#centro').hide(); $('#centro').fadeIn(3000).load('results_casa_mes.asp', { nm_mes: $('#teste4').val(), pessoas: $('#pessoas').val(), tipo: $('#tipo').val(), localidade: $('#localidade').val() }, function(){ $(table).trigger(update); } ); }); On Nov 22, 11:57 am, led [EMAIL PROTECTED] wrote: $('#foo').click(function() { $('#centro').empty(); $('#centro').hide(); $('#centro').fadeIn(3000).load('results_casa_mes.asp',{ nm_mes: document.getElementById('teste4').value, pessoas: document.getElementById('pessoas').value, tipo: document.getElementById ('tipo').value, localidade: document.getElementById ('localidade').value }); $(table).trigger(update); }); I've tried this with no luck On 21 Nov, 18:30, Balazs Endresz [EMAIL PROTECTED] wrote: http://tablesorter.com/docs/example-ajax.html inside the callback (the third argument for .load ) // let the plugin know that we made a update $(table).trigger(update); On Nov 21, 5:43 pm, led [EMAIL PROTECTED] wrote: I've noted that tablesorter and the pager don't work in ajax response such as the content returned in the jquery load(), with or without previous Table tags How can i fix this . See this demo of the problem in http://realferias.com/pager.asp-Hide quoted text - - Show quoted text -
[jQuery] Re: Tablesorter pager and ajax
You triggered the update before the data loaded, you have to do that in a function as the third argument: $('#foo').click(function() { $('#centro').empty(); $('#centro').hide(); $('#centro').fadeIn(3000).load('results_casa_mes.asp', { nm_mes: $('#teste4').val(), pessoas: $('#pessoas').val(), tipo: $('#tipo').val(), localidade: $('#localidade').val() }, function(){ $(table).trigger(update); } ); }); On Nov 22, 11:57 am, led [EMAIL PROTECTED] wrote: $('#foo').click(function() { $('#centro').empty(); $('#centro').hide(); $('#centro').fadeIn(3000).load('results_casa_mes.asp',{ nm_mes: document.getElementById('teste4').value, pessoas: document.getElementById('pessoas').value, tipo: document.getElementById ('tipo').value, localidade: document.getElementById ('localidade').value }); $(table).trigger(update); }); I've tried this with no luck On 21 Nov, 18:30, Balazs Endresz [EMAIL PROTECTED] wrote: http://tablesorter.com/docs/example-ajax.html inside the callback (the third argument for .load ) // let the plugin know that we made a update $(table).trigger(update); On Nov 21, 5:43 pm, led [EMAIL PROTECTED] wrote: I've noted that tablesorter and the pager don't work in ajax response such as the content returned in the jquery load(), with or without previous Table tags How can i fix this . See this demo of the problem in http://realferias.com/pager.asp
[jQuery] Re: smoother .animate()?
I fear it won't help much but you can try caching some values outside the event handler: var mx=$(window).width(), my=$(window).height(), $k=$('#k'); Also, you set the duration in the wrong place, that should be in the second argument: http://docs.jquery.com/Effects/animate#paramsdurationeasingcallback And why is it 1ms? On Nov 21, 8:16 pm, bnlps [EMAIL PROTECTED] wrote: Hi, kids -- there's a nice Flash site ... marcecko dot com ( especially, the window-content-movement, mouse.x/y) ... ported to html/jQ, but couldn't find a way to realise the smooth sliding part while moving; it's f'd, scratchy. any solutions? or, a Flash-only thing? thanks! -B now, have a look: (tested on FF3, IE7 -- XP) - !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd; html xmlns=http://www.w3.org/1999/xhtml; lang=en xml:lang=en head titlejQx/title meta http-equiv=content-type content=text/html;charset=utf-8/ style type=text/css media=all !-- html{width:100%;height:100%;overflow:hidden;} body,div{margin:0;padding:0;} div{position:absolute;left:0px;top:0px;width:1600px;height:1200px;} span{position:absolute;} -- /style script type=text/javascript src=http://jqueryjs.googlecode.com/ files/jquery-1.2.6.min.js/script script type=text/javascript //![CDATA[ var mx,my; $(function(){ $().mousemove(function(e){ mx=$(window).width(); mx=Math.ceil((-e.pageX/mx*(16E2-mx))); my=$(window).height(); my=Math.ceil((-e.pageY/my*(12E2-my))); $('#k').dequeue().animate({left:mx,top:my,duration:1}); // ! // $('#k').css({left:mx,top:my}); ... 1:1 }); }); //]] /script /head body div id=k span style=top:0px;left:0px;height:50px;width:50px;background- color:#cff;/span span style=bottom:0px;left:1550px;height:50px;width:50px;background- color:#e10;/span span style=top:0px;left:1550px;height:50px;width:50px;background- color:#0cc;/span span style=top:1150px;left:0px;height:50px;width:50px;background- color:#3fa;/span span style=top:50px;left:300px;height:100px;width:300px;background- color:#333;/span span style=top:300px;left:200px;height:700px;width:150px;background- color:#f6c;/span span style=top:500px;left:400px;height:500px;width:850px;background- color:#aba;/span span style=top:300px;left:600px;height:100px;width:950px;background- color:#ff0;/span /div /body /html
[jQuery] Re: Tablesorter pager and ajax
http://tablesorter.com/docs/example-ajax.html inside the callback (the third argument for .load ) // let the plugin know that we made a update $(table).trigger(update); On Nov 21, 5:43 pm, led [EMAIL PROTECTED] wrote: I've noted that tablesorter and the pager don't work in ajax response such as the content returned in the jquery load(), with or without previous Table tags How can i fix this . See this demo of the problem in http://realferias.com/pager.asp
[jQuery] Re: Am I using 'this' too often?
Are you using this: http://tablesorter.com ? Because it's quite easy to update: http://tablesorter.com/docs/example-ajax.html On nov. 10, 23:58, George [EMAIL PROTECTED] wrote: Thanks for the linkhttp://docs.jquery.com/UI/Developer_Guide You are absolutely right about understanding. Our professor of math was saying First you have to use it, then you will understand it. I found it to be very true. I had been using JQuery for some time... It's just I am working on a new project which requires the tablesorter plug-in functionality married with AJAX. Unfortunately I were not able to use tablesorter as is. Since data comes from AJAX and tablesorter plug in does not allow me reload data into grid easily. I spent some time with it trying to fit it in but finally gave up and decided that it's time to write my own thing. And that is how I realized that I know too little about modern JavaScript language. I used to think that I know it pretty well when in reality all I could do is to use alert and setInteval functions :) George. On Nov 10, 3:11 pm, Balazs Endresz [EMAIL PROTECTED] wrote: The thing with the other libraries is that jQuery mainly promotes writing a simple functional plugin, beacause in many cases object- oriented code is really not necessary. Of course in other cases it is, like when building a widget:http://docs.jquery.com/UI/Developer_Guide So I think if you want to write your application that doesn't need to be a jquery plugin, just use a general design pattern if that's more suitable. And most likely it will be convenient to write some custom jQuery plugins too, but that is really simple:http://docs.jquery.com/Plugins/Authoring Using jQuery should be very easy, and you don't have to understand it in depth first, just play with the examples and see what happens. Understanding how to construct a javascript application is quite a different thing. Of course they meet some time in the future, e.g. if you're building a complex jQuery plugin, but this shouldn't be the point to start I think, just start learning these separately! Cheers, Balazs On Nov 10, 7:24 pm, George [EMAIL PROTECTED] wrote: I see your point... I had discovered recently the lack of JavaScript knowledge. And since I mostly doing web development I realized that I am missing out a lot. Unfortunately the object oriented approach JavaScript using is different from other object oriented languages I know (C++, C#, Java) So I am trying to get up to speed with JavaScript and making up my own problems/tasks. Like I am learning how 'this' works with JavaScript... So the code I wrote is not promoted by another library :) It's promoted by my background in C++ and C# mostly :) So I chose JQuery as a library to use but before I can freely start using it I want to understand how things work. Cause as of right now if you tell me to write JQuery from scratch I will not be ably even to start :) And even having full source available does not help much since I often do not understand what is going on Thanks George. On Nov 10, 12:50 pm, Olivier Percebois-Garve [EMAIL PROTECTED] wrote: Well, using the pattern for plugin creation will make your life easier, and this will make more sense. Reading your code, it feels like you are using the structuration promoted by another library On Mon, Nov 10, 2008 at 6:29 PM, George [EMAIL PROTECTED] wrote: I had looked there probably 10 times :) Are you implying that I need to convert my code to being Plug-In? Other than that I do not see how this page http://docs.jquery.com/Plugins/Authoring answers my question... Sorry, but please spell it out for me. The Plug-In would be the next step for me.. But as of now I am trying to nail down the use of 'this' in JavaScript as it's a bit different from what I am used to. George. On Nov 10, 11:43 am, Olivier Percebois-Garve [EMAIL PROTECTED] wrote: you may want to have a look herehttp://docs.jquery.com/Plugins/Authoring On Mon, Nov 10, 2008 at 5:20 PM, George [EMAIL PROTECTED] wrote: Being newbie in JavaScript I am trying to code my own helper object that does pagination. So here is a snippet of my code. MyData.prototype = { blablabla... PageUp: function() { this.iFrom += this.pageSize; this.CheckPageIndex(); }, CheckPageIndex: function() { if( this.iFrom = this.data.length ) this.iFrom = Math.floor((this.data.length - 1)/ this.pageSize) * this.pageSize; if( this.iFrom 0 ) this.iFrom = 0; } } Why do I need to call CheckPageIndex using this.CheckPageIndex when called from PageUp? It's in the same object... Without
[jQuery] Re: mooTools to jQuery conversion job
That page has about three body and html tags so maybe you have to correct it to work, usage example at the bottom: http://jsbin.com/ibuje/edit It could have been done with UI's widget factory as well: http://docs.jquery.com/UI/Developer_Guide but no dependency this way. What compromises? :) On Nov 14, 9:18 pm, WatermarkShaun [EMAIL PROTECTED] wrote: I love a particular news scoller example done in MooTools (http:// woork.bravehost.com/newsticker/index.html). Not knowing jQuery enough, I don't have time to convert it over (and using both frameworks is not an option). I would think this could be done quickly by one that knows jQuery well (with very little compromises). Anyone up for the job ($)? Or at least recommend a better place to post this request?
[jQuery] Re: would compressing merging multiple jquery plugin's violate any license?
Not really -- this goes for the MIT license: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. At least, I think, you have to include the name of the license and the copyright owner too. On Nov 11, 4:19 am, Daniel Freiman [EMAIL PROTECTED] wrote: Actually, it may depend on the license of the plugin, but from jquery's side you're fine. On Mon, Nov 10, 2008 at 10:18 PM, Daniel Freiman [EMAIL PROTECTED]wrote: http://docs.jquery.com/Licensing Jquery is released under the MIT license. In other words, do what ever you want. - Daniel Freiman Required disclaimer: I am not a lawyer. On Mon, Nov 10, 2008 at 5:55 PM, henry [EMAIL PROTECTED] wrote: would compressing merging multiple jquery plugin's into 1 JS file violate any license?
[jQuery] Re: Am I using 'this' too often?
The plugin authoring page won't help you much building a class in javascript. If you want to use the this keyword less you can use private variables: http://javascript.crockford.com/private.html and there are some more great sources here: http://www.crockford.com/javascript/ But transforming a complex generic js class to a jQuery plugin is another story as a plugin should generally return a jQuery object. Some patterns regarding this issue came up here: http://groups.google.com/group/jquery-en/browse_thread/thread/9dc9be1cc298cbdd After reading the article on private variables it should be clear, but briefly the the problem is that if you don't use the this keyword then CheckPageIndex will be a reference to a variable in the closure (function) you use it, or if it doesn't exist there then it will be a global variable. And this way you don't have any closure that could remember the variable. So you need to define things in a closure (function). Anyway, it's much better explained in the article :) On Nov 10, 6:29 pm, George [EMAIL PROTECTED] wrote: I had looked there probably 10 times :) Are you implying that I need to convert my code to being Plug-In? Other than that I do not see how this pagehttp://docs.jquery.com/Plugins/Authoring answers my question... Sorry, but please spell it out for me. The Plug-In would be the next step for me.. But as of now I am trying to nail down the use of 'this' in JavaScript as it's a bit different from what I am used to. George. On Nov 10, 11:43 am, Olivier Percebois-Garve [EMAIL PROTECTED] wrote: you may want to have a look herehttp://docs.jquery.com/Plugins/Authoring On Mon, Nov 10, 2008 at 5:20 PM, George [EMAIL PROTECTED] wrote: Being newbie in JavaScript I am trying to code my own helper object that does pagination. So here is a snippet of my code. MyData.prototype = { blablabla... PageUp: function() { this.iFrom += this.pageSize; this.CheckPageIndex(); }, CheckPageIndex: function() { if( this.iFrom = this.data.length ) this.iFrom = Math.floor((this.data.length - 1)/ this.pageSize) * this.pageSize; if( this.iFrom 0 ) this.iFrom = 0; } } Why do I need to call CheckPageIndex using this.CheckPageIndex when called from PageUp? It's in the same object... Without 'this' I get an error 'CheckPageIndex is undefined'. Coming from object oriented languages like C++ I have a trouble understanding it. Or am I doing it wrong and there is a way not to specify 'this' to many times? Thanks George- Hide quoted text - - Show quoted text -
[jQuery] Re: Am I using 'this' too often?
The thing with the other libraries is that jQuery mainly promotes writing a simple functional plugin, beacause in many cases object- oriented code is really not necessary. Of course in other cases it is, like when building a widget: http://docs.jquery.com/UI/Developer_Guide So I think if you want to write your application that doesn't need to be a jquery plugin, just use a general design pattern if that's more suitable. And most likely it will be convenient to write some custom jQuery plugins too, but that is really simple: http://docs.jquery.com/Plugins/Authoring Using jQuery should be very easy, and you don't have to understand it in depth first, just play with the examples and see what happens. Understanding how to construct a javascript application is quite a different thing. Of course they meet some time in the future, e.g. if you're building a complex jQuery plugin, but this shouldn't be the point to start I think, just start learning these separately! Cheers, Balazs On Nov 10, 7:24 pm, George [EMAIL PROTECTED] wrote: I see your point... I had discovered recently the lack of JavaScript knowledge. And since I mostly doing web development I realized that I am missing out a lot. Unfortunately the object oriented approach JavaScript using is different from other object oriented languages I know (C++, C#, Java) So I am trying to get up to speed with JavaScript and making up my own problems/tasks. Like I am learning how 'this' works with JavaScript... So the code I wrote is not promoted by another library :) It's promoted by my background in C++ and C# mostly :) So I chose JQuery as a library to use but before I can freely start using it I want to understand how things work. Cause as of right now if you tell me to write JQuery from scratch I will not be ably even to start :) And even having full source available does not help much since I often do not understand what is going on Thanks George. On Nov 10, 12:50 pm, Olivier Percebois-Garve [EMAIL PROTECTED] wrote: Well, using the pattern for plugin creation will make your life easier, and this will make more sense. Reading your code, it feels like you are using the structuration promoted by another library On Mon, Nov 10, 2008 at 6:29 PM, George [EMAIL PROTECTED] wrote: I had looked there probably 10 times :) Are you implying that I need to convert my code to being Plug-In? Other than that I do not see how this page http://docs.jquery.com/Plugins/Authoring answers my question... Sorry, but please spell it out for me. The Plug-In would be the next step for me.. But as of now I am trying to nail down the use of 'this' in JavaScript as it's a bit different from what I am used to. George. On Nov 10, 11:43 am, Olivier Percebois-Garve [EMAIL PROTECTED] wrote: you may want to have a look herehttp://docs.jquery.com/Plugins/Authoring On Mon, Nov 10, 2008 at 5:20 PM, George [EMAIL PROTECTED] wrote: Being newbie in JavaScript I am trying to code my own helper object that does pagination. So here is a snippet of my code. MyData.prototype = { blablabla... PageUp: function() { this.iFrom += this.pageSize; this.CheckPageIndex(); }, CheckPageIndex: function() { if( this.iFrom = this.data.length ) this.iFrom = Math.floor((this.data.length - 1)/ this.pageSize) * this.pageSize; if( this.iFrom 0 ) this.iFrom = 0; } } Why do I need to call CheckPageIndex using this.CheckPageIndex when called from PageUp? It's in the same object... Without 'this' I get an error 'CheckPageIndex is undefined'. Coming from object oriented languages like C++ I have a trouble understanding it. Or am I doing it wrong and there is a way not to specify 'this' to many times? Thanks George- Hide quoted text - - Show quoted text -- Hide quoted text - - Show quoted text -
[jQuery] Re: Attribute selector with namespace
There's a ticket on this issue: http://dev.jquery.com/ticket/3023 On Nov 7, 11:48 pm, Brian J. Cardiff [EMAIL PROTECTED] wrote: thanks but that it isn't working in this scenario for: span x:foo=barLorem/span the expression: $('span').filter(function(){return $(this).attr(x:foo);}) returns the span element but neither: $('[x:foo]') no: $('[x\\:foo]') find it any clue? Brian J. Cardiff bcardiff(?)gmail.com . On Fri, Nov 7, 2008 at 6:11 PM, MorningZ [EMAIL PROTECTED] wrote: http://docs.jquery.com/Frequently_Asked_Questions#How_do_I_select_an_... On Nov 7, 2:06 pm, Brian J. Cardiff [EMAIL PROTECTED] wrote: Is there a way to specify an AttributeFilter for attributes within a certain namespace? I try some alternatives but it seems that is not implemented. For example: span x:foo=barLorem/span I would need that something like $('[x:foo]') find the span element. Thanks. Brian J. Cardiff bcardiff(?)gmail.com .
[jQuery] Re: Understanding JQuery/Javascript.
$.fn.extend extends $.fn if you pass only one parameter. It's useful if you're adding more methods (plugins) but if you just want to add a single plugin it's the same as $.fn.tablesorterPager = function(){ ... } Accordingly $.extend extends $, which is the same as $.tablesorterPager=function(){ ... } On Nov 7, 3:40 am, George [EMAIL PROTECTED] wrote: Hi guys, I need some help with understanding JQuery/Javacript. I am far away form being a Javascript guru so I am not sure I understand why something done this (or other) way. I am looking at tablesorterPager plug-in and it's written following way (function($) { $.extend({ tablesorterPager: new function() { ...blablabla.. } }); // extend plugin scope $.fn.extend({ tablesorterPager: $.tablesorterPager.construct }); })(jQuery); If I were to write this plug in I would do it like this (function($) { $.fn.tablesorterPager = function() { .blabblabla } })(jQuery); Questions: Any advantages of writing it the way it's written? Basically what is this $.extend({}) for? What does it achive. Thanks George.
[jQuery] Re: Can I make jquery not fail silently??
You can still write a simple plugin: jQuery.fn.fail=function(){ return this.length ? this : null; } Now $('#non-existing-id').fail().toggle() will fail, but will work if it's not empty. Consider this for example: $('#non-existing-id').add('.anotherClass'); if it failed you cannot add other elements to the empty set and you can't even write a plugin like this one above. On Nov 5, 10:08 am, brian [EMAIL PROTECTED] wrote: It's not a failure to run a query and find nothing - that's a perfectly valid use case. I understand where you are coming from on the querying side, but shouldn't calling a method on an empty object fail? How can I fade in...nothing? I'm going to still think of this as a huge design flaw. There needs to be a way to specify that it should fail on empty results. /s for strict or whatever. This post is for 1) bitching purposes and 2) indexing purposes so that future searchers find definitive proof that jquery fails silently and that this is not considered a bug, despite obvious appearances.
[jQuery] Re: search for text and replace or remove the element entirely
Try this: http://flesler.blogspot.com/2008/05/textnode-translator-for-javascript.html On Nov 3, 9:26 pm, Devin [EMAIL PROTECTED] wrote: I think perhaps I wasn't totally clear on what I meant. My example was poor. I want to search a string of text and replace all of the commas , with the pipe | ,for example. On Nov 3, 8:16 am, Jilani Jidni [EMAIL PROTECTED] wrote: please try this $(#tableId tr td).each(function(){ this.text(your value); }); this should be work for you. -- with regards Jilani Jidni On Mon, Nov 3, 2008 at 6:41 PM, Devin [EMAIL PROTECTED] wrote: Hi I'm trying to devise a way to check each cell in a table for a particular value. When the value is found, I want to remove the row from the document. Or, when its found I want to do a replace. (ie $ (this).innerHTML.replace(name, Devin) I know that syntax is wrong but I think it gets across what I'm trying to do) Thanks. D- Hide quoted text - - Show quoted text -
[jQuery] Re: Plugin with API questions.
By extending with $.extend you can't do that because the scope of the parameter is outside the plugin. You have to declare them inside $.fn.sample so they all will have the same scope: (function($) { $.fn.sample = function(options) { // local variable bound to the current instance: var parameter = options.parameter1; // now this method has access to the private member: $.fn.showParameter = function() { alert(parameter); } return this.each(function() { // processing code here }); } })(jQuery); A bit more on this subject: http://groups.google.com/group/jquery-en/browse_thread/thread/9dc9be1cc298cbdd/3e7a4b00ead74dd9 On Oct 31, 1:22 pm, dns [EMAIL PROTECTED] wrote: I'm developing a plugin and I'm having some issues. I put together a small test plugin to demonstrate the problem I'm having. Here's the sample plugin. It simply saves a parameter passed into the plugin into a local variable, and displays that variable at a later time. (function($) { // local variable var parameter = not set; // Prototype Methods $.fn.extend({ sample: function(options) { parameter = options.parameter1; return this.each(function() { // processing code here }); }, showParameter: function() { alert(parameter); } }); })(jQuery); This simple plugin works fine if I only use 1 DOM element. The problem occurs when I use this plugin on multiple divs. For example, consider this html page: html head title/title script type=text/javascript src=../js/jquery-1.2.6.min.js/ script script type=text/javascript src=../js/jquery.sample.js/ script script type=text/javascript var sample1; var sample2; $(function() { sample1 = $(#div1).sample({ parameter1 : This is parameter 11 }); sample2 = $(#div2).sample({ parameter1 : This is parameter 22 }); sample1.showParameter(); sample2.showParameter(); }); /script /head body div id=div1/div div id=div2/div /body /html The problem I am having is that both variables (sample1 and sample2) in the html page display the alert This is parameter 22. I was expecting the variable sample1 to display This is parameter 11 and variable sample2 to display This is parameter 22. I've tried many different plugin patterns (for examplehttp://www.learningjquery.com/2007/10/a-plugin-development-pattern) but no luck. It's almost like my parameter in the plugin has global scope (maybe it does and it's just my lack of javascript knowledge). Any thoughts, feedback, or suggestions would be appreciated. Thanks.
[jQuery] Re: Clarifications one the jQuery.prototype.init.prototype line
Hi, there was a similar question recently: http://groups.google.com/group/jquery-en/browse_thread/thread/2bd68d2a05b83ed3 On Oct 30, 4:41 pm, quickredfox [EMAIL PROTECTED] wrote: Can anyone explain to me in detail, what exactly this line of code does: jQuery.prototype.init.prototype = jQuery.prototype; I just can't wrap my mind around it clearly... figure it has some- kinda relation to the map-over functions at the top of jQuery but... I need some sort of walk-through...
[jQuery] Re: JQuery Selector and Java Script Variable
In your case the proplem is that you're using .text() instead of .value() on the textarea. The strangest thing is why does .text() even work unless you change the content? It's quite misleading because it shouldn't work on input elements: http://docs.jquery.com/Attributes/text On Oct 18, 6:09 pm, RotinPain [EMAIL PROTECTED] wrote: I met a similar issue, but i can determine it happens only with Firefox (3.0.3). The variable selector seems to be the problem. I explained the whole thing here:http://jsbin.com/aciwi in short, $([id=' + variableId + ']).text( variableValue ); won't always work with FF (it works in first steps) but document.getElementById( variableId ).value = variableValue; will always work I can't succes in making my code working with jsbin (i tried several ways to) because the code use ajax with xml and I can't make the relation between them. You can view the jquery code here:http://jsbin.com/aciwi That should load a sample xml here :http://jsbin.com/ebupo But it does not Anyway, i posted the same code here at my own ftp: jquery/html page:http://rotinpain.ifrance.com/tests/test4xml.html xml data source:http://rotinpain.ifrance.com/tests/test4xml.xml Let me know if you see something that i didn't. i'm fairly new to jquery but i think the code is ok.
[jQuery] Re: trouble with passing parameters to a callback function
This is a classic issue, you just have to use another closure: for (var i = 0; i img_list.length;i++) (function(i){ $(new Image()).load(function () { ClassName.CallBackFunction.apply(this,[$(this),i]); }).attr(src,$(img_list[i]).attr(src)); })(i) but it's a bit easier with $.each: $.each( img_list, function(i){ $(new Image()).load(function () { ClassName.CallBackFunction.apply(this,[$(this),i]); }).attr(src,$(img_list[i]).attr(src)); }) A short description about what is really happening: http://www.mennovanslooten.nl/blog/post/62 On Oct 18, 7:46 am, GTakacs1976 [EMAIL PROTECTED] wrote: This is my code: var ClassName = {}; ClassName.CallBackFunction = function(index,i) { alert($(index).attr('src') + ' ' + i); } function() { for (var i = 0; i img_list.length;i++){ $(new Image()).load(function () { ClassName.CallBackFunction.apply(this,[$(this),i]); }).attr(src,$(img_list[i]).attr(src)); } However when the alert comes up it always shows the same value for i, not the value that was in effect at the time the load function was called. If I change my code to: function() { for (var i = 0; i img_list.length;i++){ $(new Image()).load( ClassName.CallBackFunction.apply(this,[$(this),i]) ).attr(src,$(img_list[i]).attr(src)); } I get the correct value for i but now the $(this) points to the wrong item. How can I have both the $(this) and the value of i passed to the callback function? Or is it a having my cake and eating it too situation? -- View this message in context:http://www.nabble.com/trouble-with-passing-parameters-to-a-callback-f... Sent from the jQuery General Discussion mailing list archive at Nabble.com.
[jQuery] Re: jQuery Truncating Help
I haven't tried it, but in the plugin near line 25 instead of myStr.length you could try something like $this.text(). So that it will check the length of the text instead of the innerHTML. But it may need some more hacking, I don't know. On Oct 6, 11:40 pm, Zachary [EMAIL PROTECTED] wrote: Does no one have any answers to this question...It has been quite a while and I could really use some suggestions. Thanks. On Oct 3, 9:21 am, zacharyd [EMAIL PROTECTED] wrote: I have been working with Brian Reindel's Truncate plug-intrying to get ti to do what I need. It seems simple enough, but I continue to struggle. The plug-in is designed to truncate the html content within a tag to a certain length...taking into consideration the whole last word. It works great...however I need to truncate a list item that contains both text and a link; like so: liThis is the text that leads to: # A link that needs to be truncated ./li The function currently looks like this: $('li a').truncate( { length: 35, minTrail: 10, moreText: '', lessText: '', ellipsisText: ... }); But this obviously only takes care of the link...if the text behind it is too long it will still push the truncated link down to the next line...If I try to do the li it completely removes the link tag no matter its lengthand if I try to change the selector in the plugin from $(this).html() to $(this).text() it removes the anchor tag completelythough it works just fine. Basically I need some way to keep my anchor tag in operation, yet take the whole text contained within the li into consideration when determining where to truncate. Your help is much appreciated...Please let me know if you have any questions to further clarify my problem. Thanks. btw...the Plugin is located here in case you'd like to see it or use it yourself:http://www.reindel.com/truncate/ -- View this message in context:http://www.nabble.com/jQuery-Truncating-Help-tp19791107s27240p1979110... Sent from the jQuery General Discussion mailing list archive at Nabble.com.
[jQuery] Re: text() as a wrapped set?
The argument was missing at the end: $.fn._text = $.fn.text; $.fn.text = function( toTextNode ) { if( toTextNode === true ) return this.pushStack( [ document.createTextNode( this._text() ) ] ); return this._text( toTextNode ); } On Sep 30, 3:46 pm, Balazs Endresz [EMAIL PROTECTED] wrote: You made me think about confusing the maintainers :) This would certainly do that but wouldn't break any code: $.fn._text = $.fn.text; $.fn.text = function( toTextNode ) { if( toTextNode === true ) return this.pushStack( [ document.createTextNode( this._text() ) ] ); return this._text(); } So you could do: $(a).text(true).appendTo(#sanbox); and even $(a).text(true).end() would return $('a') On Sep 26, 3:17 pm, 703designs [EMAIL PROTECTED] wrote: Oh, and break everything that depends on the text method. On Sep 26, 9:16 am, 703designs [EMAIL PROTECTED] wrote: I could also do something along these lines: $.fn.oldText = $.fn.text; $.fn.text = function() { return $(document.createTextNode(this.oldText())); } That is, of course, if I'd like to confuse the hell out of future maintainers :) On Sep 25, 1:15 am, Balazs Endresz [EMAIL PROTECTED] wrote: I think the easiest way is to write another plugin: $.fn.$text=function(){ return $( document.createTextNode( this.text() ) ) } $(a).$text().appendTo(#sanbox); but you can extend the String prototype too: String.prototype.jqueryify=function(){ return $( document.createTextNode( this ) ) } $('a').text().jqueryify().appendTo(#sanbox); On Sep 24, 8:27 pm, 703designs [EMAIL PROTECTED] wrote: Because the text method returns a string, it's missing appendTo and other methods. Now, of course I can do this: $(#sandbox).text($(a).text()); But I'd prefer to do this: $(a).text().appendTo(#sanbox); What goes between text and appendTo? Or is the first example the best way to do this?
[jQuery] Re: text() as a wrapped set?
You made me think about confusing the maintainers :) This would certainly do that but wouldn't break any code: $.fn._text = $.fn.text; $.fn.text = function( toTextNode ) { if( toTextNode === true ) return this.pushStack( [ document.createTextNode( this._text() ) ] ); return this._text(); } So you could do: $(a).text(true).appendTo(#sanbox); and even $(a).text(true).end() would return $('a') On Sep 26, 3:17 pm, 703designs [EMAIL PROTECTED] wrote: Oh, and break everything that depends on the text method. On Sep 26, 9:16 am, 703designs [EMAIL PROTECTED] wrote: I could also do something along these lines: $.fn.oldText = $.fn.text; $.fn.text = function() { return $(document.createTextNode(this.oldText())); } That is, of course, if I'd like to confuse the hell out of future maintainers :) On Sep 25, 1:15 am, Balazs Endresz [EMAIL PROTECTED] wrote: I think the easiest way is to write another plugin: $.fn.$text=function(){ return $( document.createTextNode( this.text() ) ) } $(a).$text().appendTo(#sanbox); but you can extend the String prototype too: String.prototype.jqueryify=function(){ return $( document.createTextNode( this ) ) } $('a').text().jqueryify().appendTo(#sanbox); On Sep 24, 8:27 pm, 703designs [EMAIL PROTECTED] wrote: Because the text method returns a string, it's missing appendTo and other methods. Now, of course I can do this: $(#sandbox).text($(a).text()); But I'd prefer to do this: $(a).text().appendTo(#sanbox); What goes between text and appendTo? Or is the first example the best way to do this?
[jQuery] Re: text() as a wrapped set?
I think the easiest way is to write another plugin: $.fn.$text=function(){ return $( document.createTextNode( this.text() ) ) } $(a).$text().appendTo(#sanbox); but you can extend the String prototype too: String.prototype.jqueryify=function(){ return $( document.createTextNode( this ) ) } $('a').text().jqueryify().appendTo(#sanbox); On Sep 24, 8:27 pm, 703designs [EMAIL PROTECTED] wrote: Because the text method returns a string, it's missing appendTo and other methods. Now, of course I can do this: $(#sandbox).text($(a).text()); But I'd prefer to do this: $(a).text().appendTo(#sanbox); What goes between text and appendTo? Or is the first example the best way to do this?
[jQuery] Re: help needed with new node replace
Write plugins! It's easy: $.fn.myReplaceWith = function () { var ret = $( arguments[0] ); this.replaceWith( ret ); return ret; }; On Sep 22, 3:15 pm, redcom [EMAIL PROTECTED] wrote: If anyone knows a jQuery way to replace a node and return the new node object that would be great (replaceWith returns the old object)
[jQuery] Re: jQuery prototype magic
In other words 'new jQuery.fn.init( selector, context )' doesn't return a new jQuery object but a new 'init' object. But the init object doesn't have any methods, of course, so the ones of jQuery have to be copied over. So you couldn't access the methods because 'init' didn't have them before. (It could have been 'new jQuery().init( selector, context )' but that would cause an ifinite loop as this is inside the function named jQuery.) I didn't see it first but the instanceof operator helped a bit :) -Balazs On Sep 17, 2:56 am, Andrei Maxim [EMAIL PROTECTED] wrote: Hi all, I've recently grabbed the latest edition of the Rhino book and I'm trying to build some small JavaScript libraries in order to get the hang of coding in JS. I've been also reading lots of blog posts and I've been looking at the code of several major JS frameworks and libraries, like jQuery, Prototype and script.aculo.us and I'm trying to understand why the author wrote that code. For some reason, I've been growing very fond of the pattern used in jQuery to create the jQuery object. Here's the code I'm talking about, taken from v1.2.6: var jQuery = window.jQuery = window.$ = function( selector, context ) { // The jQuery object is actually just the init constructor 'enhanced' return new jQuery.fn.init( selector, context ); }; [...] jQuery.fn = jQuery.prototype = { init: function( selector, context ) { // Make sure that a selection was provided selector = selector || document; // Handle $(DOMElement) if ( selector.nodeType ) { this[0] = selector; this.length = 1; return this; } [...] }; // Give the init function the jQuery prototype for later instantiation jQuery.fn.init.prototype = jQuery.fn; When I tried to add my custom object, I had some problems with accessing the functions I defined inside jQuery.prototype. Only after a couple of hours I added a line similar to jQuery.fn.init.prototype = jQuery.fn and then it magically worked. However, I don't get what's going on. From what I understood reading JavaScript docs, jQuery.fn = jQuery.prototype means that we reference jQuery object's prototype and I'm guessing this is used just to simplify the code (I might be extremely wrong on this). Also, the defined functions are shared by each jQuery object. But why do we need to add jQuery.fn.init.prototype = jQuery.fn for things to work? Thanks a lot, Andrei
[jQuery] Re: Plugin developement
It depends on what the public method returns. If it returns the jQuery object (the 'this' inside the plugin) then you have to call $ ('#example').pluginname.doSomethingPublic().pluginname.doSomethingElse(). If you want to chain your methods directly you have to return 'this' inside your public methods, which refers to $.fn.pluginname (not to the jquery object!). But doing this will prevent you from chaining jquery methods (most of the plugins are chainable). If you don't like this and would like to get the jquery object back, you can do that with another public method: $.fn.pluginname.returnJQuery = function(){ return _jquery; } where _jquery is defined where your _options object: var _jquery=this; so $().pluginname.doSomethingPublic().doSomethingElse().returnJQuery() will return the original jQuery object. The only problem(?) with both is that it's a bit different from how jQuery is generally used. That's why, I think, the jMaps approach is somewhat better. On szept. 3, 14:32, mwk [EMAIL PROTECTED] wrote: Hi, Wow, thanks to both of you. Wouldn't have thought about such an construct. Maybe because i'm not that familiar with javascript at all. Somehow i thought you can't access an object while creating it. But also the way Balazs was mentioning about jmap looks interesting. I will have a closer look into it soon. For now i will try out the way mentioned above. The only thing i don't like in this solution is, that after calling the method u can't add another right after like : $('#example').pluginname.doSomethingPublic().doSomethingElse(); is there a solution to it, except the way jmap does.
[jQuery] Re: Plugin developement
If you declare the public method inside $.fn.pluginname then it will be able to access the private things too, but this way the public function won't be declared just after $().pluginname() was called. So you can't call $.fn.pluginname.doSomethingPublic() before that. But you can get around this by calling methods like in jMaps: http://jmaps.digitalspaghetti.me.uk/#init which would look like this: $().pluginname('doSomethingPublic', param0, param1, ...) and call the methods by a switch statement inside the plugin. You can also store your plugin under $.pluginname instead and use $.fn.pluginname only to create a new instance of it. Some tutorial would be indeed really good about things like this, but you can also inspect how other plugins handle it. Hope I helped Balazs On Sep 2, 12:10 pm, mwk [EMAIL PROTECTED] wrote: Is there realy nobody out there, who can point me into the right direction? A link to a tutorial would be already great. If somebody doesn't understand the question, please tell me, i will try to explain it further.
[jQuery] Re: How to retrieve jQuery.query?
It would be good to know why you need this, I can hardly imagine what is this good for. Anyway, here's how you can do it: jQuery.fn.find=function( selector ) { this.query=selector; //this is the only line you have to modify var elems = jQuery.map(this, function(elem){ return jQuery.find( selector, elem ); }); return this.pushStack( /[^+] [^+]/.test( selector ) || selector.indexOf(..) -1 ? jQuery.unique( elems ) : elems ); } Now you can get the query string: $('body .class').prevObject.query //-'body .class' $('body').find('.class').prevObject.prevObject.query //-'body' but $('#id').prevObject.query //-undefined $().find('#id').prevObject.query //-'#id' On Aug 30, 11:23 pm, Tzury [EMAIL PROTECTED] wrote: Say a user called $('div.foo') I would like to get this 'div.foo' from within my plug-in context. I look through the code and couldn't find a property which contain this data; I was thinking that 'query' is the appropriate name for this property example usage: $.fn.MyPlugIn = function (){ if (/table|thead|tbody|th|tr|td/.test($.query){ // do the table thing } else { // do the chair thing ;-) } } $('table').MyPlugIn(); $('div').MyPlugIn
[jQuery] Re: Selecting text nodes
I think this will do it: http://flesler.blogspot.com/2008/05/textnode-translator-for-javascript.html Or alternatively you can try: http://code.google.com/p/jquery-translate/wiki/NodesContainingText This is a part of the Translate plugin, so it's a bit larger. A main diference is if an element contains textnodes and other elements too then its .html() will be returned and can parse the document asynchronously (useful on large documents, no browser freeze). On Aug 24, 11:46 pm, Tom B. [EMAIL PROTECTED] wrote: Thanks for the quick response, Karl. I'm not sure if this would quite do it--It looks like you can get an array of the contents of the text nodes, and you could do a .replace() on those array elements, but I'm not sure how you would then insert the new text back into the text nodes. It seems like a selector like the ones in the Selectors part of the API doc would be the ideal route. Any ideas? -Tom On Aug 24, 5:28 pm, Karl Swedberg [EMAIL PROTECTED] wrote: I wrote a plugin that may help: http://plugins.learningjquery.com/textchildren/ --Karl Karl Swedbergwww.englishrules.comwww.learningjquery.com On Aug 24, 2008, at 4:20 PM, Tom B. wrote: Does anyone have code for a text node selector? I saw this post: http://groups.google.com/group/jquery-en/browse_thread/thread/2dda271... but the function textNodes didn't seem to work with the current version of jQuery. I'm a bit new to jQuery, but I ultimately want to do a regex find and replace on all of the text nodes in a tree (the function needs to select children, grandchildren, etc), so any tips on the best way to do that would be greatly appreciated. Many thanks, Tom
[jQuery] Re: JQuery exists - anything in core or a plugin that does this?
perhaps: jQuery.fn.exists=function(fn){ if(this[0]) fn(this) return this } On Aug 22, 3:45 pm, James [EMAIL PROTECTED] wrote: The use case I was looking at was along the lines of: $(div#navigator).exists(function(matches) { $.getScript(scripts/navigator.js, function() { matches.makeNavigator(); }); }); Regards, James On Aug 22, 2:25 pm, James [EMAIL PROTECTED] wrote: OK fair point. To me though: $(img).exists(function(matches) { }); is a bit more of an elegant solution and a bit more readable (and saves you repeating the selector that might be quite long), but that's probably because $(img).length 0 doesn't sound particularly intuitive to me. I guess if there was a simple $(img).exists() then the if () statement would be a bit more intuitive. Regards, James On Aug 22, 2:07 pm, MorningZ [EMAIL PROTECTED] wrote: a quick plugin to do a simple if statement? if ($(img).length 0) { $(img).doSomething(); }
[jQuery] Re: SELECTOR MADNESS! How To Grab Lowest Child Node's Text?!
Hi! I replied in the previous thread but it hasn't appeared in Google groups, just here: http://www.nabble.com/Selector-Madness!--How-to-Select-all-the-Text-on-a-Page--td17018965s27240.html So there is a translate plugin that works this way: http://code.google.com/p/jquery-translate/ On May 5, 9:32 pm, Joe [EMAIL PROTECTED] wrote: Last week I had a question on how to traverse the DOM and find all elements that had some text (p, a, li, h1, etc.) so I could manipulate it with Google's translation API. Well with some help from the community I was able to accomplish this feat. http://groups.google.com/group/jquery-en/browse_thread/thread/c63da32... However, I have a bigger problem. Now, when I grab theallproperelements: $a = $(' #container * ').contents(); And parse thru them tofindwhich ones have text, it does just that BUT if an unordered list is within a div and that UL has text it will show up not only with the UL, but within the DIV as well. $a.each(function() { ... translate stuff here ..}); So in iteration one, wefindthe DIV, and then locate any andALLtext in the DIV. Quite a bit for the header navigation. Example Result for Div: HOME BUSINESS CONTACT ABOUT Then the next iteration is the UL, and it finds its text, which is basically the same as the DIV's text result. Example Result for UL: HOME BUSINESS CONTACT ABOUT Then the next iteration is the LI element, which has the proper text but, The next iteration is the A element which is finally the text I actually want to translate. Example Result for LI and A: HOME So myquestionis how can Itraversedown and grab thelastchild on that particular branch of theDOM. Surely there's a way to check if current node has or does not have a child, but how with jQuery? Thanks! BTW, Ariel Fleisler's recommendation from the previous post appears to be the best approach, but my pure Javascript mixing with jQuery skills are not quite up to snuff to hash that out...
[jQuery] Re: Selector Madness! How to Select all the Text on a Page?
Hi! Here's a plugin that does it for you: http://code.google.com/p/jquery-translate/ It grabs the text the way you described, but if a tag has childnodes and textnodes too then it grabs its innerhtml. So i.e. if a paragraph has 'a' tags inside then the paragraphs innerhtml will be translated. On larger sites the looping unfortunately can take a couple of seconds but in most cases it's bearable. joemccann wrote: Okay I have read and reread http://www.learningjquery.com/2006/11/how-to-get-anything-you-want-part-1 and http://www.learningjquery.com/2006/12/how-to-get-anything-you-want-part-2 and still cannot figure out how to grab all the text (not the markup) on a page. I am toying with the Google Translation API and am attempting to parse all text, translate, and put it back. I have the looping logic (and the 500 char limit issue with Google) sorted out, but I can't get the fundamental part down...GRABBING ALL THE TEXT. So let's say you have markup like so ul li somelink blabh blah 1 /li li somelink blabh blah 2 /li li somelink blabh blah 3 /li /ul and even h1some heading/h1 and pSome paragraph text/p etc. etc. I want to be able to grab all the text and manipulate it. I've tried $(#mainContainerDiv *).each(...some function), but this crashed the system. I would like to do something like this: $(#mainContainerDiv *.text.each(some function...), but this clearly won't work. Any help is greatly appreciated. -- View this message in context: http://www.nabble.com/Selector-Madness%21--How-to-Select-all-the-Text-on-a-Page--tp17018965s27240p17043744.html Sent from the jQuery General Discussion mailing list archive at Nabble.com.