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
fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
Is there any performance difference between using arrays vs. using JSON?

Adbot
ADBOT LOVES YOU

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
Lets say I have an element and I use onmouseover and onmouseout to toggle the visibility of another smaller element that is to appear on top it. I'd like for the smaller element to remain visible when the mouse moves over the smaller element. Of course this currently is not the case, since it fires the onmouseout on the main element when I mouse over the smaller element. What is a good solution to this?

edit: In case I explained that terribly, I found an example. In gmail, when you are viewing an email and mouse over the green name of the person who sent it, a little box pops up to email/chat/etc that user. When you mouse off the name, if box disappears. If you mouse off the name (and on to the little popup), the popup does not disappear.

It seems like I could get it behaving the way I want with a timer, that way I can detect if they mouse off the element and on to the popup. Is there a different approach?

fletcher fucked around with this message at 02:59 on Feb 5, 2010

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

supster posted:

If the element you are binding the hover event to is a parent of the smaller element then you'll always be hovering the parent element even if it's inside the smaller element.

That said unless the smaller element is 100% contained (visibly on the screen) you should still use the setTimeout trick so that if the mouse goes outside the parent element's visiblity while moving between inner elements you don't lose your the popup.

Ah, I guess that was my issue. The smaller element wasn't actually a child, they were siblings, since the "main" element was an img.

Using setTimeout seems to work great. Thanks for your input!

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Munkeymon posted:

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

Probably not!

http://docs.jquery.com/Using_jQuery_with_Other_Libraries

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
How do I call a userscript function in the Firebug console?

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

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.

If the userscript has done what many of them do, namely wrap its namespace inside an anonymous function, you're hosed.

code:
// ==UserScript==
// @name           test
// @namespace      test
// @description    test
// @include        [url]http://forums.somethingawful.com/showthread.php?noseen=0&threadid=3070034&pagenumber=31#pti12[/url]
// ==/UserScript==

alert('hello');

function sayHi() {
	alert('say hi');
}
Reload this thread, I get the hello alert. Then in the Firebug console:

code:
>>> sayHi();
ReferenceError: sayHi is not defined
[Break On This Error] sayHi(); 
edit: this worked
code:
unsafeWindow.sayHi = function() {
    alert('hi');
}

fletcher fucked around with this message at 00:13 on Dec 2, 2011

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Funking Giblet posted:

Nothing wrong with doing it "by hand", beats loading a few 100k of script.

Ehhh I would have to disagree with that. It's only 33KB minified, and you can load it from Google's CDN (meaning it is probably already in the users browser cache anyways). Then you can write his thing as:

code:
$.get("levels/level1content.json", function(data) {
    document.write(data[0].x);
}, "json");
Quite a bit easier to read/write/understand, and it also works in IE6, unlike his implementation.

fletcher fucked around with this message at 20:43 on Jun 26, 2012

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
edit: whoops I should probably put this in the jQuery thread

fletcher fucked around with this message at 23:59 on Nov 4, 2013

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
The only way to do it is probably as a browser extension, like ColorZilla does.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Mr. Wynand posted:

Oh yeah? You better tell Firefox that.

e: i'm not sure you can actually save TO pdf... it might only go the other way around :/

That was the first thing I thought of too. I mean if we can render them with js now, probably not too far off from authoring them in js.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
Even just a -1 will do it, not sure what the deal is there.

http://jsfiddle.net/HdL8W/

* removed the 400x400 attributes on the canvas since they were confusing
* added a border to the canvas so we can position the rectangle a little easier
* put a space between new & Array instead of newArray to get rid of javascript error

edit: oh probably because the pixels are 0 indexed so a size of 250x250 gives you pixels 0 to 249 to work with so you want it to be (244, 244) to (249, 249) for the bottom right rectangle

fletcher fucked around with this message at 01:48 on Dec 13, 2013

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Pollyanna posted:

...Oh :smith: Sorry, I'm not used to JSON. What I do at the moment is take a massive array and create an <option> tag for each element, which slows everything the gently caress down. I was hoping to use Select2's data functions to speed that up, but I may be a little lost.

In your template, assign it to a javascript variable:

code:
<script>
    var whatever = {{ stock_symbols_json }};
</script>
Then in your code that sets up the select2 control, you can just refer to your 'whatever' variable since it's in the global scope.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Wheany posted:

Can you seriously not debug greasemonkey scripts like a civilized person? Is dumping variables to the console the only way to know what the hell is going on inside a script?

In Chrome I can go to Sources->Content Scripts->apbdobdcekdieksnciesxksdiskkdsisdi->script.js and see my greasemonkey script and set breakpoints and stuff

In Firefox/Firebug I'm also able to see my script in the sources tab, breakpoints seem to work fine there too

I have // @grant window in my script, not sure if that impacts the ability to use the debugger or not

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
Maybe your webserver is returning the file with the wrong charset? Check the response headers on the network tab:

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
That's what you're supposed to do in Flask when it's Python code that is being executed server side, but you're in JavaScript land and that code is executed by your browser. JavaScript has no idea about Flask stuff and what url_for() is.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
q1 being in array index 0 is confusing. What do you plan on doing with radioArray after this?

code:
$('#submit').click(function(){
    $('input[type=radio][value=y]:checked').each(function() {
        alert($(this).attr('name')+' is a yes');
    });
});

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
Right on. The alerts can be handy for debugging. Are you familiar with the developer tools that are built into modern browsers? (hit f12!) I like to use console.log('hi there') and console.dir(myObject) when debugging things, it can be a little less annoying than the alerts.

If you do need the array, I would suggest with going with something like this:

code:
$('#submit').click(function(){
    var formArray = $('form').serializeArray();
    console.dir(formArray);
});
Keep hackin' away on it and ask some more questions when you get stuck :)

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
adserver.company.com and www.company.com are both subdomains of company.com so you don't have to worry about cross-domain anything (which is good because cross-domain cookies do no exist).

Take a look at the domain attribute of the cookie string. You'll want to specify domain=.company.com so the cookie can be used by all subdomains of company.com.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
I'm running into some JS errors after incorporating dropzone.js into my app. Everything works fine in dev mode (separate & unminified assets) but after I do a real build (JS assets are combined & minified using uglifyjs) I run into "undefined is not a function". So I'm assuming it's something to do with the combine/minify step but I'm having a hard time narrowing it down further.

edit: I added a semicolon to the end of the dropzone.js file and it seems to have fixed the issue...but surely somebody else would have run into that issue if the problem was in fact caused by dropzone.js. So I'm not entirely convinced I have the correct fix, if anybody has some advice for me.

fletcher fucked around with this message at 03:06 on May 20, 2014

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
^^ Looks like it was in fact a bug in the dropzone library: https://github.com/enyo/dropzone/issues/589

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
'a' is the index of the array (i.e. data[0], data[1], etc)

'b' is the object at that array index

Check out this fiddle for an example: http://jsfiddle.net/EuSms/1/

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

fuf posted:

Is this the right place for obscure Node questions?

I need to watch a directory for new files, including files that might be in a subdirectory.

I've tried 3 modules:
https://github.com/mikeal/watch
https://github.com/yuanchuan/node-watch
https://github.com/bevry/watchr

but they all have the same problem: if I copy a directory that contains a file into the watch folder, they only pick up on the "new directory" event, and ignore the file.

If I create the directory first, then copy the file into it, both events get picked up fine. But I need to copy folders that already contain files into my watch directory and have them all picked up at once.

Any ideas? Is this the kind of thing that I should raise an issue about on github? (kinda scared because I've never done that)

Or should I give up on the modules and write my own "walker" function that gets called periodically?

In the "created" handler that picks up the "new dirctory" event, can't you just list the files in that new directory and do whatever you want with them?

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Raskolnikov2089 posted:

I've been staring at this for the last 1/2 hour trying to figure out where my syntax error is.

code:
var k = [NaN, 5, 7];

 function testNaN(){
	if(isNaN(k[0]){
		console.log("Not a Number");
	}
	else{
		console.log("A Number!");
	}
};

Or can I not use isNaN() on an index value?

You're missing a closing parenthesis on the line with the if statement

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Raskolnikov2089 posted:

Ughhhhh okay, thats enough for the night.

Thank you.

Is your debugger not giving you useful error messages? All I did was paste it into jsfiddle, open the Firebug console, hit Run, and it gave me a very clear error message:

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

0zzyRocks posted:

I wrote a jQuery plugin to handle styling of a file input. Check it out, it hasn't been updated in a while but it may be of some use to you. https://github.com/ozzyogkush/jquery.styledFileInput

I appreciate the thought, but...it hasn't been updated in over 2 years and there's still no documentation or even an example of what it does? :effort:

edit: oh there is an example.html, make it a live demo!

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Wheany posted:

Hmm, since I would be receiving HTML with Xmlhttprequest, I guess I could just replace img src with img data-src or something before using innerhtml to create a DOM tree, then set the src attribute only on the images I actually want loaded.

I've done this, it worked out pretty well

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Storgar posted:

I dunno... Just seems like a natural way of doing it to me? I have a REST api where I can get a list of posts. I want to make that the only method of obtaining such objects (rather than a having a second way of populating the page with a server-side function outside the REST api). How do people usually do it?

Seems fine to me.

Also, what percentage of users even disable javascript? Is it even worth the effort for graceful degradation these days?

Adbot
ADBOT LOVES YOU

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
Somebody wanted inline table editing in our Confluence instance for work so they added a plugin for it. It drives me nuts though, so I'm trying to write a userscript to disable it on all pages. Currently the only way we can disable it with a built in mechanism is on a per-page basis.

It seems like Jira takes all these plugins and combines them into a batch.js file. It's basically got a setTimeout in there looking for tables so it can apply the inline editing on top of them

I'm trying to come up with an easy way to short circuit this thing in a userscript so it doesn't work anymore but I couldn't think of a simple way to do it. Any suggestions?

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