|
Supervillin posted:Haven't looked at jQuery's source in a while so I'm not sure how they implement getting that path (since obviously it's JS, not CSS), but that might be why IE6 barfs. I'm 95% sure I've used the ">" selector with jQuery before and it works in IE6. I haven't tried in a while but I believe that jQuery handles it for you.
|
# ? Apr 1, 2009 17:36 |
|
|
# ? Jun 9, 2024 04:59 |
|
SuckerPunched posted:I have a pretty strong hunch that Firefox is the broken one in this case, allowing you to hide <option> tags. Thank you I will give this a whirl. Supervillin posted:Adding/removing items is the "right" way, like SuckerPunched said, but also IE6 doesn't recognize the child selector ">" in CSS. Haven't looked at jQuery's source in a while so I'm not sure how they implement getting that path (since obviously it's JS, not CSS), but that might be why IE6 barfs. IE6 has no problem with that selector when trying to select a child that has a class or id associated with it, since I do this in other parts of the application and it works fine.
|
# ? Apr 1, 2009 19:12 |
|
Withdrawn, found error.
Sylink fucked around with this message at 22:05 on Apr 1, 2009 |
# ? Apr 1, 2009 20:09 |
|
Sylink posted:This is a general javascript questions. Perhaps you will have better luck posting in the general javascript questions thread: http://forums.somethingawful.com/showthread.php?threadid=3070034
|
# ? Apr 1, 2009 21:35 |
|
Oh I saw a post about people asking javascript questions in here. Ill check that out too, I found the problem anyways.
|
# ? Apr 1, 2009 22:05 |
|
Supervillin posted:Adding/removing items is the "right" way, like SuckerPunched said, but also IE6 doesn't recognize the child selector ">" in CSS. Haven't looked at jQuery's source in a while so I'm not sure how they implement getting that path (since obviously it's JS, not CSS), but that might be why IE6 barfs. edit: slightly beaten, but none of the previous replies shared the same details
|
# ? Apr 1, 2009 22:50 |
|
I'm using the Jquery UI for some resizable elements. Is there way to retrieve the height/width values of the new box size?
|
# ? Apr 2, 2009 03:26 |
|
Sylink posted:I'm using the Jquery UI for some resizable elements. Is there way to retrieve the height/width values of the new box size? http://docs.jquery.com/CSS
|
# ? Apr 2, 2009 04:44 |
|
Is it possible to animate repositioning of elements with jquery? Currently trying this, code:
|
# ? Apr 12, 2009 19:29 |
|
Sylink posted:But the position part isn't occurring , even if I add position:absolute it does not work. Are you using position: relative in the parent element?
|
# ? Apr 12, 2009 23:13 |
|
No would that affect it?
|
# ? Apr 13, 2009 00:00 |
|
Sylink posted:No would that affect it? Yes. You have to have the parent element explicitly set to position:relative
|
# ? Apr 13, 2009 01:01 |
|
So... This is going to be a stupid question I have a list of username's that I need to fetch via JSON and populate a select box but, I'll need to populate more select boxes with the same data (basically adding users to a list, press + button get new select box populated with users) so I'd like to avoid making the HTTP fetch every time the + button is pressed Essentially I'd like to store the JSON data in a variable and reuse it over it over. What I can't figure out is how to do essentially (which I know is wrong) code:
|
# ? Apr 13, 2009 18:44 |
|
ATLbeer posted:The reason why I don't think I can use the normal $.getJSON("url", function(data){do stuff here}); pattern is that I can't seem to get data back OUT of the function(data) space. Is the proper pattern to create an object and pass it as a parameter to be manipulated in the function? Looking at the documentation, you'd probably have to do it this way: code:
Zorilla fucked around with this message at 19:14 on Apr 13, 2009 |
# ? Apr 13, 2009 18:58 |
|
Zorilla posted:Looking at the documentation, you'd probably have to do it this way: code:
That URI returns this data code:
|
# ? Apr 13, 2009 19:11 |
|
ATLbeer posted:FireBug logs out at console "undefined" for user_list What happens when you do console.log(user_list) from inside the function? Or with the data variable? Here is another idea: code:
|
# ? Apr 13, 2009 19:15 |
|
Zorilla posted:What happens when you do console.log(user_list) from inside the function? Or with the data variable? code:
dummydata dummydata second version code:
GET http://hqiq/ajax/data/listusers/ 200 OK 48ms jquery.min.js (line 19) [{"username": "test"}] ---------------------------------------- ! I hate javascript vvv The dashes were added by me as a separator between showing the AJAX call to the JSON URI actually worked and the data it returned and then the console.log ATLbeer fucked around with this message at 19:34 on Apr 13, 2009 |
# ? Apr 13, 2009 19:23 |
|
Looks like the second idea is getting somewhere. What's with the dashes, is that part of the AJAX response displayed when doing console.log()? Hopefully, $.ajax().responseText isn't just limited to strings or else that is what's wrong with that example. edit: or you probably also need to use async: false, otherwise the function just finishes immediately with no return value. Zorilla fucked around with this message at 19:38 on Apr 13, 2009 |
# ? Apr 13, 2009 19:26 |
|
$.getJSON is asynchronous, so it returns immediately, but the function that you pass as the second parameter will not be called until the HTTP response actually arrives. Try this:code:
|
# ? Apr 13, 2009 19:32 |
|
Nigglypuff posted:$.getJSON is asynchronous, so it returns immediately, but the function that you pass as the second parameter will not be called until the HTTP response actually arrives. Try this: code:
Woah... When I comment out in the inner block console.log .... It doesn't work! code:
inside block...[object Object] code:
ATLbeer fucked around with this message at 19:41 on Apr 13, 2009 |
# ? Apr 13, 2009 19:36 |
|
The line that says "inside block" is no longer there after you commented it out. That seems normal to me. The reason they appear in backwards order is because $.getJSON() finishes immediately while the function(data) callback may take 1-2 seconds to run, as it has to wait for the HTTP request to finish. As a result, the second console.log() runs first. That brings up another thing: when you do console.log('outside block...' + user_list);, the callback hasn't run yet, which means user_list hasn't yet gotten a chance to be assigned the data. That would be why the resulting value is still "dummydata" at that point. Try this: code:
Zorilla fucked around with this message at 19:52 on Apr 13, 2009 |
# ? Apr 13, 2009 19:44 |
|
Yeah, figured out that getJSON is an async call I dropped the getJSON code in the (document).ready block, declared the user_list in the global namespace and left the rest of the logic in the action call for the button press Since user_list is populated on page load and the action us called on user press. I can't 100.00% guarantee the user_list variable will be populated by the time the button is pressed but, it almost always will be for all real-world cases It might fail an automated unit test though.
|
# ? Apr 13, 2009 19:57 |
|
ATLbeer posted:Yeah, figured out that getJSON is an async call Yeah, that's why I think you should do this synchronously: code:
code:
Zorilla fucked around with this message at 20:04 on Apr 13, 2009 |
# ? Apr 13, 2009 20:02 |
|
If the button gets clicked before the user_list variable is populated, you could set up a timer to wait until the data arrives and *then* populate the list. Something like this maybe?code:
|
# ? Apr 13, 2009 20:04 |
|
Zorilla posted:Yeah, that's why I think you should do this synchronously: The "async: false" worked perfectly.. Much cleaner implemntation than spreading it around into different files. I'm working on someone else's javascript and HTML wireframe and wiring up to a Django backend. They have a lot of code already to construct and add a custom select drop down that works great. They just had the populated the select box in one of the inner functions with some default "lorum ipsom" data not pulling it from the web service. I just needed to fix that bit. Thanks for all the help.
|
# ? Apr 13, 2009 20:07 |
|
Help me out here Goons.code:
I'm obviously missing something here. First I thought that the click function cannot know about anything defined outside its scope, but I'm puzzled as to why it would know about the last id in the sequence. It's as if all the A's point to the same anonymous function. Now I can probably get it to work by using $(this) in the A-tag and using that as a start to fetch the hidden input and get its value, but I'd rather do it properly. I also took a look at the 'bind' method that yielded the same result. Thanks!
|
# ? Apr 14, 2009 21:59 |
|
MrData posted:You're handling parsedJSON.sequences like it's a jQuery selection instead of a plain old JSON object. How are you assigning that variable its value? Is it just a JSON object like [{"id": "stuff", "name": "junk"}] or is it created by doing something like parsedJSON.sequences = $('div.selectme'); ? If parsedJSON.sequences is just a basic JSON object, maybe something like this would work? code:
Zorilla fucked around with this message at 23:53 on Apr 14, 2009 |
# ? Apr 14, 2009 23:03 |
|
Zorilla posted:You're handling parsedJSON.sequences like it's a jQuery selection instead of a plain old JSON object. How are you assigning that variable its value? Is it just a JSON object like [{"id": "stuff", "name": "junk"}] or is it something created by doing something like parsedJSON.sequences = $('div.selectme'); ? parsedJSON.sequences is a plain old JSON object, that contains multiple sub-objects (like the example you posted) that I want to iterate over. I haven't posted the line of code that converts the JSON string I get back from my PHP call to an object, but I didn't think that would be relevant. I've seen in a number of blog posts that you can use jQuery to iterate over JSON object arrays using .each(), and I guess that part works fine for me. Within the .each() loop, I can use $(this).attr("id") to get the id-attribute of the current object in the loop. I would very much welcome any pointers you could give (as to general jQuery misunderstandings or this particular issue).
|
# ? Apr 14, 2009 23:18 |
|
Ok, I've been repeatedly updating my previous post to provide an example that I think might work. I can't test it though, so it may still need adjustments. Probably the biggest thing to keep note of in my example is the difference between jQuery.each and Core/each. I switched to using the former because it's a generic iterator meant to handle objects and arrays. You were using Core/each before, and that's designed to use jQuery selections like $('div.selectme');. Zorilla fucked around with this message at 23:25 on Apr 14, 2009 |
# ? Apr 14, 2009 23:21 |
|
Zorilla posted:Ok, I've been repeatedly updating my previous post to provide an example that I think might work. I can't test it though, so it may still need adjustments. Thanks for the clarification, I will read up on the difference. Just tried out the code you posted, but it's still pretty much the same effect. code:
code:
I seems that the anonymous method that's assigned to the a-tag click event has no idea what 'this' is, and so it can't spit out the id.
|
# ? Apr 14, 2009 23:32 |
|
How about parent.id or this.parent.id? If those don't work, you may have to define a variable in the parent function and use it in the click callback (as seen in the updated example).
Zorilla fucked around with this message at 23:47 on Apr 14, 2009 |
# ? Apr 14, 2009 23:40 |
|
Welp, after some more Googling around this seems to work fine:code:
edit: your updated code also works! MrData fucked around with this message at 23:50 on Apr 14, 2009 |
# ? Apr 14, 2009 23:47 |
|
You had a function within a function. The problem was that this was referring to the immediate function and not the parent one whose object had the properties you wanted.
|
# ? Apr 14, 2009 23:54 |
|
MrData posted:Welp, after some more Googling around this seems to work fine: If you're ever planning on learning real javascript (more than UI fancyness, maybe some actual application), sans jQuery foolishness...never learn what you just said. jQuery very stupidly overwrites the this variable that's used very frequently in javascript for other things. That's my biggest problem with jQuery and why I'm still a Prototype user for anything other than adding nice event handlers.
|
# ? Apr 15, 2009 01:36 |
|
sonic bed head posted:If you're ever planning on learning real javascript (more than UI fancyness, maybe some actual application), sans jQuery foolishness...never learn what you just said. jQuery very stupidly overwrites the this variable that's used very frequently in javascript for other things. That's my biggest problem with jQuery and why I'm still a Prototype user for anything other than adding nice event handlers. Meh, I just remember to do: code:
|
# ? Apr 15, 2009 02:19 |
|
sonic bed head posted:If you're ever planning on learning real javascript (more than UI fancyness, maybe some actual application), sans jQuery foolishness...never learn what you just said. jQuery very stupidly overwrites the this variable that's used very frequently in javascript for other things. That's my biggest problem with jQuery and why I'm still a Prototype user for anything other than adding nice event handlers. In javascript, this is not a variable — it's a nullary operator that returns the receiver of the current function context. You can't directly assign it a value, and it is never captured by a closure. When invoked, every function receives a new value of this, regardless of where the function was defined, or what value of this existed in the enclosing scope of the definition. I'm confused about what you thing jQuery is doing wrong here. The nature of Javascript means that an API which takes callbacks/closures as method parameters has no way knowing what value of this existed in the scope where the callbacks were created, so it has to set a new value of this, or allow it to default to the global object, which is rarely what people want. As far as I know, the convention in both jQuery and Prototype is to automatically bind this in event handlers to the object which received the event. For list iteration with callbacks, jQuery automatically sets this to be the current list element, whereas Prototype passes the element to the closure as an argument. In either case it is simply a matter of API convention, and not objectively stupid. It is a weakness of Javascript that the this pseudovariable rarely behaves the way people expect it to behave, and it can uglify otherwise pretty closure-passing code. But do you really feel that jQuery in particular handles this badly?
|
# ? Apr 15, 2009 10:26 |
|
Nigglypuff posted:In javascript, this is not a variable — it's a nullary operator that returns the receiver of the current function context. You can't directly assign it a value, and it is never captured by a closure. When invoked, every function receives a new value of this, regardless of where the function was defined, or what value of this existed in the enclosing scope of the definition. Actually, you're right, my problem isn't exactly with resetting this, my problem is the very confusing syntax that makes saving this to a temporary variable necessary. Let's take MrData's code as an example. If, instead of implicitly using this in the jQuery.each function, jQuery provided us with an argument that is the current element, this wouldn't be an issue. There would be confusion as to where to get the current items reference from and there would be no having to figure out that you're supposed to use the boilerplate that Lumpy posted earlier. jQuery is just so unintuitive compared to Prototype for a lot of things. Prototype lets you bind whatever object to this by passing it as an argument to the bind or bindAsEventListener functions, but whatever it is, you control it, and if you don't explicitly set it, it is, as you said, the anonymous function's this. Don't get me wrong, I love jQuery for all things DOM, for all things event handler, the ability to attach names to handlers and unbind and bind them in a single line is amazing. I just think that for any real javascript project, Prototype is a much better toolbox.
|
# ? Apr 15, 2009 12:06 |
|
So playing around with Ajax and I'm trying to animate adding new information when a button is clicked with the code below:code:
Now I create the span empty, so nothing shows up, then I try to hide it and then append it while hidden. This is so I can slide it down and each row can appear in a slide down. Trying to animate append through append(data).slideDown etc does not work properly. The problem is if I leave the span empty the animation doesn't occur, the data just appears. If I put one character in then it works but you see the extra character flicker in then get hidden suddenly followed by the fade, thats why I left it empty in the first place. You can see whats going on live here http://www.ktfoundry.com/ajax/
|
# ? Apr 24, 2009 21:37 |
|
Sylink posted:Would chaining work? code:
|
# ? Apr 25, 2009 01:08 |
|
|
# ? Jun 9, 2024 04:59 |
|
I actually found a solution. It turns out slideDown just sucks and I made the new spans hidden to begin with. With fadeIn it works nicely.
|
# ? Apr 25, 2009 03:41 |