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
Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



I can't figure out why the result would be i = 0:

code:
Array.prototype.blah = function(){i = 0;}
function wtf()
{
	ary = new Array();
	i = 10;
	ary.blah();
	alert('i = ' + i);
}
How does the blah function have access to things in the wtf function's scope? I could understand if blah was inside wtf, but not this.

Adbot
ADBOT LOVES YOU

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Lumpy posted:

Because you have i set up as a global. Because you didn't use this or var in front of it.

Fucks sake. I promise I'll stay home when I'm sick next time.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



If you're using those with the for loop form for(something in somethingElse), Chrome will apply them in whatever order it wants rather than the one you expect. Opera may as well, but I know Chrome does.

Supervillin, what options did you use? I'm not getting any complaints about unescaped characters (nor do I see anything wrong with the expressions myself).

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



I have this code in a frame (the kind with a frameset and everything):

code:
<script type="text/javascript" src="http://www.google-analytics.com/urchin.js"></script>
<script type="text/javascript">
pageTracker = false;
this.document.onload = function(){
pageTracker = _gat._getTracker("blah");
pageTracker.track = pageTracker._trackPageview;
trackURL("http://"+this.top.location.hostname+this.top.location.pathname);
alert('wtf');
};
</script>
The alert never goes off. I also tried document.onload and $(document).ready and $(document).load. .ready goes off before urchin.js has been parsed and .load also never happens. Can anyone see what I'm doing wrong here? I mean aside from working on a site with frames because that I can't do anything about unless I quit my job.

edit: unfucking mixed newlines

Munkeymon fucked around with this message at 21:41 on Mar 30, 2010

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Nigglypuff posted:

Try $(window).load(...) instead.

That does work and .ready() probably does as well.

I'm just an idiot for copying and pasting an old version of Google's URL. _gat didn't exist when I was calling it because urchin.js doesn't define a _gat object - ga.js defines a _gat object.

Munkeymon fucked around with this message at 18:06 on Mar 31, 2010

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



I'd like to replace this junk:
code:
function getFlexApp(appName){
	if(navigator.appName.indexOf ("Microsoft") !=-1){
		return window[appName];
	}else{
		return document[appName];
	}
}
with $(appName) using Prototype, but the element returned by prototype doesn't seem to expose the JavaScript functions we use to communicate with the Flash object (at least in Firefox). I'm just messing with prototype for the first time today, but I was under the impression Prototype just added helpers to objects without wrapping them like jQuery does. Could Prototype's interference cause the element to drop function definitions?

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Supervillin posted:

Pretty sure Prototype will treat that argument as an ID, so if you try $('whatever') it returns document.getElementById('whatever'), not window.whatever or document.whatever. So it's probably returning null.

I don't use Prototype so could be wrong, but that's what their docs say.

That's the impression I got, too, but getElementById does return null while the dollar function actually returns an element.

Edit: maybe the Prototype $() has to return something other than null since null wouldn't chain. Anyway, it's not a huge deal - just one of many ugly things.

Munkeymon fucked around with this message at 15:03 on Apr 6, 2010

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Is there a more reliable way of finding the viewable pixel real estate than Prototype's viewport methods? I'm trying to make images shrink to fit the viewport but after a resize, the methods report the document dimensions instead of the dimensions of the window. Since HTML flows down like it's going out of style, I end up with wacky numbers for viewport height (ie bigger than my monitor) and pictures that flow off the screen given otherwise working resize code. This behavior doesn't seem to be entirely consistent since it was working fine at the end of last week in my tests and this morning the same tests are failing.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Lumpy posted:

jQuery(window).height();
jQuery(window).wdth();
:v:

I suppose reverse engineering that would be easier than trying to get jQuery to play nice with Prototype :\

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.




Oh nice - of course the test server just took a poo poo so I can't do anything with it but, hey, at least now I know.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



dancavallaro posted:

What is an example of a use case where it makes sense to use == over ===?

Do you find that it matters in most situations? Serious question.

The code I deal with at work is terrible in many ways and depends on the ambiguity that type coercion provides to not fall over constantly, but I still find that, even when I think about it, I almost never see the point in putting the extra restriction on the conditional. I mean, do I really care that the answer was a string '2' instead of a Number 2 when either one can and will work? I know that's a trivial example, but I'm having a hard time thinking of an instance where it mattered.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Does anyone know of a premade plugin or code chunk, preferably for scriptaculous, that I can use to make the content of a div drag-scrollable? Think PDF or google maps style navigation where you click and yank the whole of the content around.

All I can find on Goolge is poo poo about building a drag and drop interface and I know about Draggable, but it's not really meant for this. When I drag the content up past the top and/or left edge of the viewport, the canvas shrinks and the scrollbars become useless. Other than that, it's almost perfect and the snap effect using a callback is letting me do some neat things pretty easily.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Golbez posted:

Oh, I wasn't saying you were disagreeing, I was just astonished that anyone would have used such comments at all these days. Bugzilla has no business hiding its Javascript from IE 2.0. It might have made sense during the Clinton administration, but not any longer.

It's almost as if Bugzilla is really freakin old

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.




You mention Firefox in the article, but even the latest 3.x doesn't seem to support Object.create() so you might want to explicitly mention which browsers (or just which JS engines) it's going to work on if it's that badly supported.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Lumpy posted:

Javascript will add semi-colons for you. And that's a Bad Thing.

A new guy at my company uses GNU style brace formatting and forgets semicolons all the time. When writing Javascript. Yeah, everything you just thought and probably more.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Lumpy posted:

code:
// I assume 'snapshotLength' is a built in property or something as it's never defined....
                if (myCount < evil.snapshotLength) {  
                ...
	event.preventDefault();
	evil = document.evaluate("TBODY/TR/TD/DIV/A[contains(@class,'count')]",
	            document.getElementById("forum"), null, 7, null);

snapshotLength is the number of items in the snapshot returned by the document.evaluate call that's doing an XPath query on the current DOM. I don't know for sure why they don't stuff them into a regular array, but I'd guess they wanted to make it extra clear that you can't just add more nodes into the result of evaluate and expect them to show up in the DOM.

https://developer.mozilla.org/en/XPathResult

It's pretty neat because you can use it like jQuery's selectors* when you write a user script for browsers that aren't total garbage.

*Actually, I read that jQuery's selector engine just uses XPath queries on browsers that support them, but have been to lazy to verify

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



I wrote this to make it easier to slap a quick canvas element into jsconsole

code:
(function _loader(window){
	if(!window.document.getElementById('thecanvas')){
		var can = document.createElement('canvas');
		can.setAttribute('height', '200');
		can.setAttribute('width', '200');
		can.setAttribute('id', 'thecanvas');
		can.setAttribute('style', 'border: 1px solid black');
		window.document.getElementById('input').parentNode.appendChild(can);
		window.can = can;
		window.ctx = can.getContext("2d");
	}
})(window);
And it works fine in FF 3.6 when I load it using load('http://localhost/addCanvas.js')*, but not in Opera and I can't figure out why. It doesn't even seem to be running _loader. Does anyone see anything wrong that I'm not?

*I tired using my IP, too in case it was a security thing, but no dice.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Flamadiddle posted:

Is this standard behaviour for all uses of .match? I understand that the whole string matches the expression, but I don't want to capture that match... Should I be using a non-capturing group around the whole expression?

If you use the global flag on the expression, the match object will only contain matching subsequences. Using the expression /\d{2}(?=\/)/g on your previous example, you only get "14" and "03" back in the match object. All that said, why is it a problem to have the whole string in the match object?

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Knackered posted:

It's an anonymous function that's executed straight away, so you don't need to give the function a name. Remove the name and it works just fine in Opera.

Hope this isn't too late.

code:
(function (window){
	if(!window.document.getElementById('thecanvas')){
		var can = document.createElement('canvas');
		can.setAttribute('height', '200');
		can.setAttribute('width', '200');
		can.setAttribute('id', 'thecanvas');
		can.setAttribute('style', 'border: 1px solid black');
		window.document.getElementById('input').parentNode.appendChild(can);
		window.can = can;
		window.ctx = can.getContext("2d");
	}
})(window);

I was going to extend it to delete the old canvas and load a new one, so I wanted the creator to have a name. Then I started messing with it to get it to work and ended up leaving the name on.

Anyway, I forgot to post a follow-up, but it turns out the Opera just won't load it from the local machine over HTTP. Sticking it on my cheapo web host fixed the problem.

Munkeymon fucked around with this message at 17:29 on Mar 22, 2011

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Is validationErrors is defined somewhere?

You know you can use try/catch blocks, right? Wrap that whole thing in a try block and alert the exception's message property:
code:
function validateForm(myForm)
{
  try{
	var reason = "";
	reason += validateEmail(myForm.email);
	reason += validatePhone(myForm.phone);
	reason += valdiateTextOnly(myForm.address, "physical address"); 
	reason += valdiateTextOnly(myForm.state, "state"); 
	reason += valdiateTextOnly(myForm.city, "city"); 
	reason += validateZip(myForm.zipcode);
	reason += valdiateTextOnly(myForm.name, "name"); 
	
	 
    if (reason != "") {
	validationErrors.innerHTML = "Error: <br>" + reason;
      return false;
    }

    return true;
  }catch(ex){
    alert(ex.message)
    return false;//so you don't have to refresh the stupid page
  }
}

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



I'm not great at CSS, but I think that's what's doing it and not the JS - especially since when I open your example page in FF, I just get two JavaScript errors that indicate the plugin code isn't running:
code:
jQuery is not defined
[url]http://sjenningsdesign.com/theacademy/js/superfish.js[/url]
Line 120

$("ul.sf-menu").superfish is not a function
[url]http://sjenningsdesign.com/theacademy/navtest.html[/url]
Line 15
edit: you do need to put jQuery plugins after the jQuery link in your header

Munkeymon fucked around with this message at 23:10 on Mar 24, 2011

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



If that's all you want to do, just set the innerHtml property to an empty string (or a space if the empty fucks up somehow): document.getElementById('inputfieldcellPHONE').innerHtml = '&nbsp;';

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Are you sure you're doing this when the DOM is loaded? If you just stick it in a bare script node in the header, it will run before the browser is ready to manipulate the HTML.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



http://www.webreference.com/programming/javascript/onloads/ might help with the onload thing

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Use http://nodejs.org/docs/v0.4.8/api/fs.html#fs.readdirSync and a normal for loop, then

Munkeymon fucked around with this message at 15:30 on Jul 5, 2011

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Edit: nevermind - it wasn't anywhere near what I was thinking it was and this question was totally invalid

Munkeymon fucked around with this message at 16:37 on Jul 5, 2011

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



I'm looking at using a canvas element to do some animating that involves rendering text on a slant. I get that easel could make it slightly less annoying to render text into a canvas and then render that canvas rotated on a different canvas, but I was hoping there would be a library that has that sort of functionality encapsulated already. Anyone know of one?

Edit: managed to misread the easel docs. I think it'll do what I need no prob

Munkeymon fucked around with this message at 22:48 on Aug 17, 2011

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



That would use just as much memory which was what everyone seems to be concerned about.

A DAWG (which is a specialized trie) is the best way to store a list of words for quick membership checking. If it's a static list, the code could be loaded as a pre-built object graph and that would be very quick.

Unless you have a huge list, Lumpy's idea is probably not going to be an issue for a modern browser on reasonably fast hardware. Still could be fun to implement if you like to do that sort of thing.

edit: clarity

Munkeymon fucked around with this message at 19:19 on Aug 18, 2011

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



ynohtna posted:

http://jsfiddle.net in conjunction with your browser's web developer tools is a good start for interactive exploration.

If you just want to poke at the JavaScript language without messing with HTML, there's also http://jsconsole.com/ and http://www.jconsole.com/

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Wheany posted:

IE has F12 developer tools (or whatever the gently caress they're called) built-in

It really is just called 'F12 developer tools' of all things

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



sonic bed head posted:

A Javascript array is just a HashMap in Java, an associative array in PHP, a dict in Python.

Object - an object ls basically a key-based lookup. An array is a special case of object where it acts a lot like a C# List as long as you use numbers in the square brackets, will tell you how big it is (or let you tell it how big to be) using the special length property and has a bunch of nice helper methods stuck on.* You can still tack arbitrary stuff on to an array just like an object if you really want to:

code:
ary = []
ary[0] = 1
ary.fart = 2
ary.lengh === 1 //this would be true
ary[3] = 'what'
ary.length === 4
ary.length = 1 //note single equals - this will truncate the array
ary.fart === 2 //still there!
* This is not meant to be an exact and perfect description of how an array is different from an object or even how an object 'really' works - rtfm etc.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



subx posted:

I think things just not being typed is where I get confused. Just being able to tack random poo poo onto a variable feels weird.

It can be a lot of fun when you get used to it :)

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Sagacity posted:

What's dodgy about Pouet? It's quite awesome.

It looks and feels like oldschool :filez: sites.

Not that I would know anything about those...

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



thelightguy posted:

Considering that the demoscene grew out of the warez scene, why wouldn't they share similar visual elements?

I'm not complaining - just explaining

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



This here is the Javascript thread. Javascript actually has nothing to do with Java - it was named that way for marketing purposes (Java was supposed to be the Next Big Thing at the time).

Here is the Java thread: http://forums.somethingawful.com/showthread.php?threadid=2780384

That said, you probably don't need to download API docs if you can get to them in a web browser, so I don't know why that would be part of a guide at all.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



neogeo0823 posted:

I'm pretty sure this is the right place to ask this, but if it's not please let me know and I'll take it elsewhere. I'll also preface this by saying I have absolutely zero programming knowledge.

Me and a bunch of goons play a particular online game. Said game is a browser based, mostly text based game. Lately, we've began to grow really tired of manually sorting through individual user stats and numbers, and we're looking for a way to automate as much of the process as we can. The problem is that none of us really have any coding knowledge to speak of, which is why I'm here, on behalf of the whole alliance.

Basically, what we want is a Grease Monkey script that can pull the source code of a user's profile page, sift out all the important numbers, and then dump them into a Google Docs spreadsheet.

I've looked through the beginner guides a bit, but ho-ho-holy poo poo that stuff looks like friggin' Greek to me. Would anyone be so kind as to be willing to help us get a script written, either by teaching one or more of us, providing us with some basic examples to work off of, or by writing it for us?

If you're thinking about dumping many user automatically, this is probably a job for something like scrapy rather than a GreaseMonkey script

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



neogeo0823 posted:

After looking at the overview of that program, I'm not sure that it would work the way we need it to. The reason I was thinking of going with a GreaseMonkey script was because we've got a couple of those that we run for other things already, and there's a couple bits of important info that can only be viewed by the user logging in and viewing their own profile. This is something every user does every time they log in, so having our members install a script that adds all the info to a spreadsheet as they log in solves a lot of headaches about having to make sure the data is both accurate and up to date.

Oh, I think see what you're getting at: you want everyone's browser to upload their information to some central location when they happen to log in because only they can see it, right? I was thinking you wanted to scrape a whole lot of other peoples' information in mass by visiting their profiles with a script enabled, which would be fairly silly.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Wheany posted:

Well, you can definitely scrape that information from the page when a player visits the page with their browser. Then you could save the data into the browser's local storage automatically.

If you did this, the player would have to visit each other player's profile page (or wherever that data in the screenshots are stored), then after visiting all the interesting pages, you might click on a "dump data" button which would show some text box with the collected data formatted in some way (probably comma- or tab-separated), which you might be able to paste into Google docs.

I'd say that the above should at least be doable without relying on any sort of external APIs.

e:


:(

It's at least not a terrible idea. Sure, it's doable and it'd work, but it's more, repetitive work than writing a scraper (when that's possible - obviously not in this case).

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Boz0r posted:

Thanks, I get it now. I think the code is supposed to be a horrible mess to demonstrate the variable scope. We had to guess whether the result would be 1, 2, 3 or 4.

EDIT: If I print the value of g at the first line of f() when debugging it writes this:
code:
function g() {return 4;}
That's confusing.

http://bonsaiden.github.com/JavaScript-Garden/#function.scopes

Specifically under Hoisting:

quote:

JavaScript hoists declarations. This means that both var statements and function declarations will be moved to the top of their enclosing scope.

Your original example becomes something like
JavaScript code:
var f = function() {
	var g;
	//these next two might end up anywhere but should produce an error, apparently
	function g() {return 2;}
	function g() {return 3;}
	function g() {return 4;}
	//this here is the first line of code that will execute rather than declare things
	g = function() {return 1;}
	if (true) { }
	else { }
	return g();
}
var result = f();
when it's actually evaluated before it's run.

edit:ed to better reflect reality. Also, holy poo poo I can finally hit tab in the editor without it selecting a different page element!

Munkeymon fucked around with this message at 21:08 on Jan 22, 2013

Adbot
ADBOT LOVES YOU

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Huh, I'm surprised I didn't notice that during my stupid JavaScript tricks exploratory phase.

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