Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
spiritual bypass
Feb 19, 2008

Grimey Drawer

noapparentfunction posted:

I have a relatively simple slider code on this test page I uploaded. It uses jQuery, but my only problem with this premade application is that it uses those rounded browser buttons to operate. Is there a way to convert these to standard links, preferably ones that use images?

http://noapparentfunction.com/test4/

Thanks.

I think you could use an onClick=function() on pretty much any HTML element instead of checking each of the buttons to see if they're clicked.

Adbot
ADBOT LOVES YOU

spiritual bypass
Feb 19, 2008

Grimey Drawer

Avenging Dentist posted:

A-are you seriously doing validation on the client side? :barf:

Seems fine to me if it's there to complement existing server validation.

spiritual bypass
Feb 19, 2008

Grimey Drawer
I recommend that you not bother trying to do that yourself and instead use jQuery with the validation plugin. It's dead simple and looks impressive on the page, too.

spiritual bypass
Feb 19, 2008

Grimey Drawer

Soks posted:

Would there be a way to emulate additional onscroll events if the scroll bar was made in Java or something?

Just make the page a giant Java applet.

spiritual bypass
Feb 19, 2008

Grimey Drawer

Soks posted:

Is there a way for Java Script to get the entire length of the page

If you're thinking what I think you're thinking, then just use percentages instead.

spiritual bypass
Feb 19, 2008

Grimey Drawer
I've had great success with qtip for jQuery

spiritual bypass
Feb 19, 2008

Grimey Drawer
I'm trying to keep track of the URL of a frame on my page. Is it possible to do this with JavaScript?

php:
<?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<html>
    <head>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function() {
                alert($("#inside").toString());
            });
        </script>
    </head>
    <frameset cols="100%" noresize="noresize">
        <frame id="inside" src="content.php">
    </frameset>
</html>
?>
I'm expecting toString() to tell me what's available in that object, but I just keep getting [Object object]
All I really want is the URL. What should I be doing instead?

spiritual bypass
Feb 19, 2008

Grimey Drawer
Thanks for posting that; looks like I can just use DOM methods with name instead of id like

inside.location

spiritual bypass
Feb 19, 2008

Grimey Drawer
gently caress it, man. Get jQuery.

spiritual bypass
Feb 19, 2008

Grimey Drawer
Actually, that SVG mouseover is not working for me in Firefox 3.6 on Linux either.

spiritual bypass
Feb 19, 2008

Grimey Drawer
It seems to be getting the onmouseover and onmouseout events, but I'm not seeing anything on my screen.

code:
function onmouseover(evt) {
   document.defaultView.parent.spacemouseover(7);
}
This shows up when I use paused mode, but nothing happens when I step into.

spiritual bypass
Feb 19, 2008

Grimey Drawer
I have some variables that are being treated as undefined, but I don't understand why.
I have a JS file included that looks like this
code:
$(document).ready(function() {
	$("#tabs").tabs();

	var image = 1;
});
and then come html with events

code:
<a href="#" onclick="
	image = image + 1;
	$('#demos').attr('src', 'image-' + image + '.png');
">next slide</a>
but when I use it, it says that 'image' is undefined. Am I missing some scoping issue? Should I just bind all those buttons in my document.ready? The tabs from the first code sample get initialized just fine.

spiritual bypass
Feb 19, 2008

Grimey Drawer
Thanks, Lumpy. That's the explanation I was looking for.

I hadn't done any (serious) JS in a couple months and somehow had the idea that everything was a global.

spiritual bypass
Feb 19, 2008

Grimey Drawer
I think NYT's website does something like that for word definitions when you highlight text. Maybe you could take a peek over there and see what's going on.

spiritual bypass
Feb 19, 2008

Grimey Drawer
Netbeans has an excellent JS debugger :colbert:

spiritual bypass
Feb 19, 2008

Grimey Drawer
Hoo boy, time to implement a coding standard!

spiritual bypass
Feb 19, 2008

Grimey Drawer
Browser Domination Sado-Masochism

spiritual bypass
Feb 19, 2008

Grimey Drawer
An infinite loop will stop FF3 in its tracks for a couple minutes iirc...

spiritual bypass
Feb 19, 2008

Grimey Drawer
It's convenient to blame IE, but code that looks so awkward should be reconsidered!

spiritual bypass
Feb 19, 2008

Grimey Drawer
Have you written an encryptor in another language? Try doing a line-by-line straightforward port of it to JS.
Next, read a book or two on JS and see if you can't go back and do it again with a better understanding of scope and prototypes and perhaps a library like Parallel.js

spiritual bypass
Feb 19, 2008

Grimey Drawer
When it comes to animation, setTimeout is a bad habit. If you're targeting modern browsers, requestAnimationFrame is a much better option https://developer.mozilla.org/en-US/docs/Web/API/window.requestAnimationFrame

What you're already doing probably works fine, but this is worth investigating when you want to take your animations to the next level.

spiritual bypass
Feb 19, 2008

Grimey Drawer
"e-12" is scientific notation. It means "x10-12"

What you'd expect from real arithmetic is zero, but what you're getting back instead is an extremely small number due to floating point arithmetic. Computers only represent integers as exact values; other numbers are stored as approximations that are close enough for most purposes.

http://en.wikipedia.org/wiki/IEEE_floating_point

spiritual bypass
Feb 19, 2008

Grimey Drawer
You can avoid the recursion problem by handling this inside a for loop. Use jquery's ajax method synchronously and they'll fire one-by-one as many times as you need. This is going to take loving forever, but it sounds like that's out of your hands :shrug:

spiritual bypass
Feb 19, 2008

Grimey Drawer
Sounds like something that should be handled server-side. Deal with the form inside your one-page app, then provide a link to another page that serves a file, perhaps? Maybe add a parameter to the file serving page to require a disposable key.

spiritual bypass
Feb 19, 2008

Grimey Drawer

stoops posted:

I did this in php with a preg_split. Is there something like that in javascript?

Not sure how to answer the rest of your question from the top of my head, but here's a start on that string split: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split

Javascript splits strings with either another string or regex from the same method. It's really nice.

spiritual bypass
Feb 19, 2008

Grimey Drawer
Maybe this library would make things simpler?

http://craig.is/killing/mice

spiritual bypass
Feb 19, 2008

Grimey Drawer
The Principles of Object Oriented Javascript is a nice short read that'll teach you a ton. I also second the recommendation of the two books in the last post.

spiritual bypass
Feb 19, 2008

Grimey Drawer
This thing looks promising: http://spy-js.com/

Does your code do lots of scope traversal? Getting variables from above the current scope is a common source of JS performance problems. You could try making local copies if that's what's happening.

Does any of your program iterate over large sets of data that don't need to be processed in any particular order? Running the computations in parallel may help as well: http://adambom.github.io/parallel.js/

spiritual bypass
Feb 19, 2008

Grimey Drawer
You should all be using IntelliJ, seriously. Worth every penny. Hopefully they'll add the upcoming CLion as an extension and make it the most comprehensive IDE around.

spiritual bypass
Feb 19, 2008

Grimey Drawer

loquacius posted:

I've fooled around with the idea of using JQuery to spit the object's markup into the parent document, but that's not a good solution since the iframe's content comes from a different server

That won't work, either, since you can't read the contents of an iframe on another server.

spiritual bypass
Feb 19, 2008

Grimey Drawer
Two problems: there's line numbers in your JS and the JS was set to run onLoad, but your binding of the behavior is right in the HTML. Binding a function in an attribute only works for functions that are already declared, not tied to the load event, so switching it to <head> solves the problem.

You might not understand that second part at this point in your learning, which is perfectly normal.

spiritual bypass
Feb 19, 2008

Grimey Drawer
An editor with better syntax highlighting would've put some sort of error notification there :)

spiritual bypass
Feb 19, 2008

Grimey Drawer

unpacked robinhood posted:

How would you go about creating a graph

I'm not sure if there's a good off-the-shelf solution for it. It's relatively easy to generate SVG, though, so if you can find the right algorithm you could generate the markup yourself

spiritual bypass
Feb 19, 2008

Grimey Drawer
Node is a language/server combo like Python + Gunicorn. You'd need to find a heavy backend framework like Django for Node that has a similar feature.

spiritual bypass
Feb 19, 2008

Grimey Drawer

Knifegrab posted:

I feel really dumb but I am still confused, can anyone point me to a specific example or something? The repo is private but the repo itself has dependencies that must be npm installed as well.

There's an example in the docs: https://docs.npmjs.com/files/package.json#repository

spiritual bypass
Feb 19, 2008

Grimey Drawer

FSMC posted:

I'm writing a browser bookmarklet/extension and have just started using unit tests.

Sounds like you've got a problem either selecting the right section of the document or parsing its contents?
You could include as part of a your tests a set of copy/pastes of input data that would normally come from the service you're scraping. This is sometimes called a "fixture." Add a couple consts or functions with a couple versions of passing and failing data as appropriate and then write and test the functions that parse it. Testing the fetch code could be harder, but if you've really separated the fetching logic from the parsing logic, there shouldn't be much room for error. I usually say skip the tests that interact with 3rd party services if the rest is solid.

spiritual bypass
Feb 19, 2008

Grimey Drawer
That selector doesn't appear to be in your markup

spiritual bypass
Feb 19, 2008

Grimey Drawer
That ought to cover the purely technical answer for the face-value interpretation, but do you mind describing the use case a little more?

spiritual bypass
Feb 19, 2008

Grimey Drawer
Ah, ok. I was thinking that if the true update needs were indeterminate, it might do better with a websocket instead of xhr polling, but it sounds like that's not the case.

Adbot
ADBOT LOVES YOU

spiritual bypass
Feb 19, 2008

Grimey Drawer
Wordpress ends up being pretty slow as an API backend. Each request fires all the same hooks as a full pageload. I've heard of better experiences doing headless Drupal, but I don't really like using CMSes in general myself.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply