|
I'm going to be banned one day for not using code tags...sorry
|
# ? Nov 13, 2011 01:51 |
|
|
# ? Jun 5, 2024 04:54 |
|
Lumpy posted:I could be missing the semantics of your use of "declared" and "defined"... I consider them "defined" but pointing the value undefined which, now that I think of it, is really splitting hairs, but regardless, it's still good to show folks what happens under the hood. I agree. I didn't mean to confuse anyone and your example is much clearer. I didn't realize that putting functions in horrible, random places was invalid according to the ECMA standard (works fine in Chrome) - I just thought it was a retarded thing to do. Thanks OddObserver.
|
# ? Nov 13, 2011 02:03 |
|
Hey JS thread, I've just spent the last few hours trying to pick up game programming in HTML5 and Javascript, making a quick clone of Asteroids. Right now I have the JS spawning and drawing the player ship and some of the larger asteroids, and the asteroids are floating around on their randomly-determined momentum, but I've not been able to get an event listener working to read keyboard input. Earlier I was calling the JS from the HTML like this: code:
code:
|
# ? Nov 15, 2011 19:04 |
|
BizarroAzrael posted:
From a quick googling, it looks like that canvas does not support onkeydown events. Try putting it on <body>.
|
# ? Nov 15, 2011 20:56 |
|
Is there a way in nodejs to get JSON.stringify() to not throw an error when it finds a circular reference? I'm using expressjs, and want to do things like res.write(JSON.stringify(req)), because its infinitely easier to read it in my browser's View Source window than to console.log() it and scroll up and down.
|
# ? Nov 17, 2011 17:40 |
|
Mindisgone posted:
and I have this in each option so the dropdown always reflects your choice after submitting code:
|
# ? Nov 21, 2011 17:51 |
|
Mindisgone posted:and I have this in each option so the dropdown always reflects your choice after submitting Two options come to mind off the top of my head: 1. Use AJAX to submit so you don't have to refresh. 2. Set a cookie w/ javascrpit on select, re-set selected index on page load Bonus suggestion: 3. Return the selected indexes you submitted with as part of the refresh
|
# ? Nov 21, 2011 23:15 |
|
BizarroAzrael posted:Hey JS thread, I've just spent the last few hours trying to pick up game programming in HTML5 and Javascript, making a quick clone of Asteroids. Right now I have the JS spawning and drawing the player ship and some of the larger asteroids, and the asteroids are floating around on their randomly-determined momentum, but I've not been able to get an event listener working to read keyboard input. You should use jQuery to handle key/mouse events, just bind a function to the event.
|
# ? Nov 22, 2011 03:16 |
|
BizarroAzrael posted:I thought that the controls function would be called when I pressed a button, but not the case. However, if I switch it to onclick it works. Is there something else I need to do to make this trigger right? There's generally no reason to bind events directly in the HTML like that, but as was mentioned, the problem is that you're binding the event to the canvas. I believe the canvas never actually receives focus, so you can't bind key events to it like that. Just set up the events in your JavaScript instead. Here's how you do it with jQuery: code:
code:
dizzywhip fucked around with this message at 00:18 on Dec 2, 2011 |
# ? Dec 1, 2011 20:33 |
|
Gordon Cole posted:If you're not using jQuery you can do it like this (there's probably going to be some cross-browser compatibility issues if you do it this way, although maybe not amongst browsers that support canvas): The third argument to addEventListener is required. Pass "false".
|
# ? Dec 1, 2011 20:37 |
How do I call a userscript function in the Firebug console?
|
|
# ? Dec 1, 2011 20:48 |
|
i've been tasked to get rid of some javascript popup windows, and make the popup content appear on the main page itself. the way it works is, there is a form on a main page. when submitted, javascript passes some variables to a cgi page. the cgi page spits out the data, which in turn, the javascript shows that data on a pop up window. i'm not familiar with cgi, but looking at the cgi script, it's just alot of print statements spitting out the data. would i need to know cgi to handle this? i would like the data to appear below the main page, but i'm not sure how to write the javascript so it won't be a pop up. i hope this makes sense. any help is appreciated. the javascript popup example code is shown below: code:
|
# ? Dec 1, 2011 22:16 |
|
fletcher posted:How do I call a userscript function in the Firebug console? If the function is declared in the global scope, probably just by typing some_function(your, arguments). I'm pretty sure userscripts work basically the same way as any other javascript. If the userscript has done what many of them do, namely wrap its namespace inside an anonymous function, you're hosed.
|
# ? Dec 1, 2011 22:42 |
|
CGI is just a gateway between the web server and the language. Commonly, CGI is used with languages like Perl, so I'm guessing this is a Perl script. But no, you don't have to know or care, as long as the script emits a HTML fragment. Let's pretend that when you browse to stuff.cgi, you get back: code:
code:
|
# ? Dec 1, 2011 23:11 |
Wheany posted:If the function is declared in the global scope, probably just by typing some_function(your, arguments). I'm pretty sure userscripts work basically the same way as any other javascript. code:
code:
code:
fletcher fucked around with this message at 00:13 on Dec 2, 2011 |
|
# ? Dec 1, 2011 23:13 |
|
quote:So now what you need to do is use AJAX to make an HTTP request, and stuff that somewhere in your document. If you're using a framework like jQuery, it could be done like this: thank you for this. yeah, i think initially they want to do away with this old code and they want me to update it with the latest stuff. i've modified jquery scripts before, but i've never done something from scratch. thanks again, i'll probably be posting more on the jquery thread, as i'll most likely have lots of questions.
|
# ? Dec 1, 2011 23:46 |
|
Suspicious Dish posted:The third argument to addEventListener is required. Pass "false". Shows how often I use plain JavaScript!
|
# ? Dec 2, 2011 00:16 |
|
i have this javascript that opens and collapses 2 menu buttonscode:
what do i have to do, or look for, so i can make menu1 collapse when menu 2 is open, and vice versa. here is my html code code:
stoops fucked around with this message at 21:08 on Dec 2, 2011 |
# ? Dec 2, 2011 16:38 |
|
Well, you did not mention that you are using Prototype with Scriptaculous. That might have made it easier to help you. The thing is, when I use a library like jQuery or Prototype, I try to use it for all my DOM queries, because the syntax is just so much nicer/more maintainable. In jQuery I would do something like this (I don't know the Prototype syntax): code:
|
# ? Dec 3, 2011 04:01 |
|
Stoph posted:Well, you did not mention that you are using Prototype with Scriptaculous. That might have made it easier to help you. The thing is, when I use a library like jQuery or Prototype, I try to use it for all my DOM queries, because the syntax is just so much nicer/more maintainable. sorry about that. i'm still green on prototype, but this helps, thanks.
|
# ? Dec 5, 2011 15:21 |
|
Hey all, I've been trying to learn my way around javascript, and here's a function I borrowed from a tutorial, then hacked up to make clickable tabs that display different divs appear. It's all working fine, but I'm sure it could be optimized. I swear I'm not in school for this or anything, but could someone grade my work and point out things that I need to work on? I'm using jQuery and the backgroundColor animation plugin. code:
code:
Edit: Stoop, looks like we're trying to do something similar. If you switch to jQuery, maybe you can borrow something from me? biochemist fucked around with this message at 06:03 on Dec 12, 2011 |
# ? Dec 12, 2011 05:59 |
|
biochemist posted:Edit: Stoop, looks like we're trying to do something similar. If you switch to jQuery, maybe you can borrow something from me? I appreciate, but I ended up finding another prototype accordion. I do tend to be in the same boat as you. I always find tutorials, hack them to death, get what I want to work, but then wonder if I could have optimize it better. I may switch to using Jquery later on as i find way more plugins,etc than prototype, but maybe I'm not looking right?
|
# ? Dec 12, 2011 15:58 |
|
biochemist posted:Hey all, I've been trying to learn my way around javascript, and here's a function I borrowed from a tutorial, then hacked up to make clickable tabs that display different divs appear. It's all working fine, but I'm sure it could be optimized. I swear I'm not in school for this or anything, but could someone grade my work and point out things that I need to work on? If I were you, I would use CSS3 transitions to make the clickable tab effect, and structure your HTML like this: code:
code:
|
# ? Dec 12, 2011 16:11 |
|
biochemist posted:Hey all, I've been trying to learn my way around javascript, and here's a function I borrowed from a tutorial, then hacked up to make clickable tabs that display different divs appear. It's all working fine, but I'm sure it could be optimized. I swear I'm not in school for this or anything, but could someone grade my work and point out things that I need to work on? A few things: 1. Cache your selectors. I say it 99% of the time anyone posts jQuery. If you are every going to use a selector more than once, store it. For example in this block in your code: code:
2. I can't tell since you didn't post it, but based on your selectors, your HTML is probably not very semantic / efficient. You are probably writing a lot more code than you need to due to your markup. 3. You are making empty callback functions. Don't do that. 4. Do you have a function for each tab that's like the 'About' one? If so, refactor. 5. You are missing semi-colons at the end of some lines. (this is me channeling jslint and being anal) 6. You are calling animate() on lots of elements when it seems like only the one that would previously be "selected" needs it. This is inefficient. EDIT: 7. CSS animations are a nifty way of doing this without code, as mentioned, but you lose IE support. 8. Remember that web page animations on UI elements steal time away from people's lives that they will never get back. Ask yourself: are your color / size animations worth taking chunks away from peoples time on earth 300ms at a time? Lumpy fucked around with this message at 03:25 on Dec 13, 2011 |
# ? Dec 13, 2011 03:20 |
|
Is there a shortcut way to use the value of a variable as an object property name in a JSON expression? The resulting object I want is:code:
code:
|
# ? Dec 14, 2011 17:32 |
|
CapnBry posted:Is there a shortcut way to use the value of a variable as an object property name in a JSON expression? The resulting object I want is: No (Python lets you do this, but not JavaScript). The reason that the JSON spec requires quotes around keys is so that they don't clash with JavaScript keywords like "do" and "for" and such. They are optional in JavaScript, and {foo: "bar"} means the same thing as {"foo": "bar"}.
|
# ? Dec 14, 2011 21:31 |
|
I think this might be the place for this...using Google's custom search API, I'm trying to write a script that censors random results. I have absolutely zero clue how to go about doing this. Can anyone point me in the right direction? Google's docs show how to restrict certain sites, which is all well and good, but I want those results to still show up, and have a note about why they are filtered.
|
# ? Dec 15, 2011 03:39 |
|
CapnBry posted:Is there a shortcut way to use the value of a variable as an object property name in a JSON expression? The resulting object I want is: Make Doug Crockford cry and open a world of awful!!! code:
|
# ? Dec 15, 2011 05:26 |
|
How do I get a textarea to have a limit of 500 words? Anything I've found in my searching either counts characters, not words; or doesn't actually work when I copy/paste the code. EDIT: Got IT Found a code that counted 500 words (well spaces really, I don't care about a double space bug). But it then erased to 500 characters for some reason. So I took that code and fixed it. The Merkinman fucked around with this message at 16:43 on Dec 15, 2011 |
# ? Dec 15, 2011 14:56 |
|
Lumpy posted:Make Doug Crockford cry and open a world of awful!!! code:
|
# ? Dec 15, 2011 16:11 |
|
Lumpy posted:Make Doug Crockford cry and open a world of awful!!! PS I love server-sent events. Go go real time BBQ updates in my browser!
|
# ? Dec 15, 2011 19:11 |
|
How do I get around this error: Variable 'XMLHttpRequest' has not been declared This is happening in IE 8 and .NET framework 2.0. All the stuff I've been reading seems to imply that it should just work. This might be a stupid question but I don't really know anything about javascript or ajax and both our web guys are out this week. The only thing I've gotten to work is ActiveXObject("MSXML2.ServerXMLHTTP"); and they said they don't want to use ActiveX.
|
# ? Dec 19, 2011 19:02 |
|
opie posted:How do I get around this error: Check out http://msdn.microsoft.com/en-us/library/ms535874 to understand how this works under IE. I would however suggest using a library like jQuery to do this kind of thing, they do a good job of abstracting out all of the browser specific code.
|
# ? Dec 19, 2011 22:03 |
|
I'm pretty bad with the Javascripts. I want to a different image to load depending on the URL of the site. I've attempted this:code:
|
# ? Dec 20, 2011 21:44 |
|
Canine Blues Arooo posted:I'm pretty bad with the Javascripts. I want to a different image to load depending on the URL of the site. I've attempted this: I think location.href also returns the http:// prefix which could be causing your comparison to fail.
|
# ? Dec 20, 2011 21:53 |
|
code:
But you shouldn't be doing this with JS
|
# ? Dec 21, 2011 06:08 |
|
ElCondemn posted:Check out http://msdn.microsoft.com/en-us/library/ms535874 to understand how this works under IE. I would however suggest using a library like jQuery to do this kind of thing, they do a good job of abstracting out all of the browser specific code. opie fucked around with this message at 07:35 on Dec 21, 2011 |
# ? Dec 21, 2011 07:27 |
|
What are you trying to do that needs XMLHttpRequest on the server?
|
# ? Dec 21, 2011 08:19 |
|
Canine Blues Arooo posted:I'm pretty bad with the Javascripts. I want to a different image to load depending on the URL of the site. I've attempted this: What are you allowed to do on your server? If you can add libraries, add one (like jQuery), because that will allow you to do it "the right way" the easiest. What goes wrong (aside from syntax errors): Well, one thing is that Javascript is executed immediately, so in a structure like this: code:
What you need to do is: 1) Put your image swap code in a function, then 2a)(better) run your function when the DOM has been loaded (event: document.DOMContentLoaded), or 2b)(worse) run your function when the whole document has loaded (event: window.load).
|
# ? Dec 21, 2011 15:05 |
|
|
# ? Jun 5, 2024 04:54 |
|
Suspicious Dish posted:What are you trying to do that needs XMLHttpRequest on the server? The latter is certainly possible. I have done almost zero web programming in my life, especially in the last 5 years. I just happened to get this task because it was part of another thing in the product I generally work on.
|
# ? Dec 21, 2011 15:37 |