|
Thanks for the input guys. That was enlightening, especially the speed test.
|
# ? Nov 20, 2012 19:36 |
|
|
# ? Jun 6, 2024 06:30 |
|
Boz0r posted:I'm trying to do a drag'n'drop functionality on a website, but JavaScript is messing with me. Well, after quickly lookng at https://developer.mozilla.org/en-US/docs/DragDrop/Drag_Operations , it looks like the first argument in setData should be the data type, so "text/plain" and not "Text". And getData only takes one argument, the type of data to get.
|
# ? Nov 20, 2012 21:08 |
|
Blinkz0rz posted:Can you elaborate a little bit more on the web app you're working on? I've been thinking about developing a similar system and I'm curious if you could discuss issues you've run into with with offline data. Sure, I'm building a GTD style task management + notetaking application, a lot of the application is built upon a text parser which means you can set your appointments, project, errands, as you think of them in your notes. The app does the organizing. My thinking is to build an offline prototype that shows off the ethos behind the interaction and the execution, and I'm planning on running a kickstarter to help fund the remainder of development, to see whether what I'm building is actually worth knuckling down and finish. The storage layer is very much experimental, I wrote all the indexedDB by hand, from having never done any javascript storage work before. The biggest obstacle was getting past the asynchronous nature of indexedDB calls. I made a little library to handle that using callbacks, so I can do multiple queries in the one request and get it back only when all asynchronous calls were done. It's in coffeescript, hacky as poo poo, but you should be able to get the picture. https://gist.github.com/5d34635659a79014cec3 Realistically this problem will be solved much better by others so if I'm successful with the prototype I'd rip out the storage layer and look into library options. Maybe JayData. This is especially important for mobile support since most browsers have not yet adopted indexedDB. IndexedDB can be slowww, but my queries could be made much more efficient so I could improve things there, there is a lot of talk about how it is much less efficient with large data stores though. IndexedDB won't accept boolean values for indexed attributes (bahhh), so some of what would be booleans are unfortunately "true" or "false" strings at the moment. Which is annoying. As I said, I would very likely move to a library that can do all the nitty gritty for me. I was learning javascript as I was making this, and the storage layer was made in an early part of the game so it's pretty poo poo. Gets the job done for the moment but getting slow with a large data store. Dunno whether this helps any, as I said I'm pretty new to javascript applications where it is actually used extensively.
|
# ? Nov 20, 2012 21:56 |
|
Wheany posted:Well, after quickly lookng at https://developer.mozilla.org/en-US/docs/DragDrop/Drag_Operations , it looks like the first argument in setData should be the data type, so "text/plain" and not "Text". And getData only takes one argument, the type of data to get. In the w3school's examples they use "Text". I tried with "text/plain", though, and it still doesn't work code:
|
# ? Nov 20, 2012 23:04 |
|
Boz0r posted:In the w3school's examples they use "Text". I tried with "text/plain", though, and it still doesn't work Is event.target.id actually something (and not "")?
|
# ? Nov 21, 2012 00:47 |
|
Can you even use getData on a drag event? I thought that was a drop event method.JavaScript code:
The Gripper fucked around with this message at 07:36 on Nov 21, 2012 |
# ? Nov 21, 2012 07:31 |
|
The Release Notes for FF17 (just released) claim that it supports ECMAScript's String.contains : https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/contains But I can’t get it to work. Is this because I am stupid? Edit: It got backed out of 17 and 18 because of a collision with bloody MooTools! Sergeant Rock fucked around with this message at 17:39 on Nov 21, 2012 |
# ? Nov 21, 2012 10:35 |
|
Jabor posted:Is event.target.id actually something (and not "")? Yeah, it's "div3", and the setData() returns true when assigning. The Gripper posted:Can you even use getData on a drag event? I thought that was a drop event method. I don't really know, but why wouldn't it? In my situtation it doesn't return anything in the drop method either.
|
# ? Nov 21, 2012 10:59 |
|
I'm having trouble wrapping my head around looping through JS objects. I have a 2D object that holds the valid & invalid locations for a player. If the location is valid, it calls a JS closure holding location information. If it's invalid, the value of the direction is -1. I want to have navigation buttons (n, s, e, w) disable for invalid locations. I'm using jQuery for this right now, but I'm at a loss for how to loop through my 2D object. Here's what I have in mind with pseudo code: code:
and here's my 2D object: (incomplete, but you get the idea) code:
|
# ? Nov 21, 2012 17:05 |
|
Fluue posted:I'm having trouble wrapping my head around looping through JS objects. 1. Those are objects, not arrays (you use the term 'array' in your pseudo code) 2. To iterate through an object, you can use a for loop like so: JavaScript code:
Life might be easier if you do use arrays, and constants for the directions (ex: windowAll[DIRECTION_NORTH]) Here's some terrible, terrible code I hasitly wrote that iterates through your objects: http://jsfiddle.net/d9RLh/ EDIT: The reason you use / test for hasOwnProperty is to avoid processing properties that exist on the object prototype, and only dealing with the one you've defined on the object. Lumpy fucked around with this message at 18:06 on Nov 21, 2012 |
# ? Nov 21, 2012 18:02 |
|
I got my poo poo working. Apparently I set drop() to ondragend instead of ondrop.
|
# ? Nov 21, 2012 19:13 |
|
Lumpy posted:1. Those are objects, not arrays (you use the term 'array' in your pseudo code) Once again, life is made easier by using a library, like underscore, where _.each doesn't care whether you are iterating over an object or an array.
|
# ? Nov 21, 2012 19:44 |
|
Jabor posted:What attack are you actually protecting against here? You can use Javascript closures in order to keep the variables scoped to that closure, if you use something like Array.push within that closure however it can be overriden and revealed to Javascript outside the closure. If someone has managed to include Javascript on your page it will be able to access the internal members of that closure. I agree that it's probably nothing you should particularly concern yourself with because - like you said - there are bigger problems afoot if someone has injected Javascript into your page. But someone asked why they would do that, and that's literally the only potential reason I can think of.
|
# ? Nov 21, 2012 23:09 |
|
Gnack posted:You can use Javascript closures in order to keep the variables scoped to that closure, if you use something like Array.push within that closure however it can be overriden and revealed to Javascript outside the closure. If someone has managed to include Javascript on your page it will be able to access the internal members of that closure. I agree that it's probably nothing you should particularly concern yourself with because - like you said - there are bigger problems afoot if someone has injected Javascript into your page. But someone asked why they would do that, and that's literally the only potential reason I can think of. That would be cool as hell for getting access to a site's js closures from greasemonkey, but I dont think its possible because scope is based on where functions are defined. For example, in this script, you wont have access to secret from the custom push() function, and instead it throws an error: http://jsfiddle.net/t65hD/
|
# ? Nov 22, 2012 00:01 |
|
Wheany posted:Once again, life is made easier by using a library, like underscore, where _.each doesn't care whether you are iterating over an object or an array. Absolutely, but one should understand what one is doing before using libraries to make life easier. Otherwise one winds up working with an army of people who "know javascript" but who can't comprehend any code that doesn't start with jQuery(
|
# ? Nov 22, 2012 00:40 |
|
barbarianbob posted:That would be cool as hell for getting access to a site's js closures from greasemonkey, but I dont think its possible because scope is based on where functions are defined. Yeah I wish I could remember the example I saw presented - after looking at your example I'm wondering if I'm misremembering something.
|
# ? Nov 22, 2012 12:23 |
|
Lumpy posted:Absolutely, but one should understand what one is doing before using libraries to make life easier. Otherwise one winds up working with an army of people who "know javascript" but who can't comprehend any code that doesn't start with jQuery( Which is why I told him to use underscore Well, using for... in is just fine, except for two gotchas, I think: The first one is hasOwnProperty, which you covered already, the other is that in for (p in someObject), p doesn't get assigned the actual properties, only their names, so you need to do theActualProperty = someObject[p];, which has burned me several times in the past.
|
# ? Nov 22, 2012 14:36 |
|
I've been playing with a little chat site, and I'm trying to get the chat view to scroll to the bottom of the messages after the initial messages (will eventually be the last 10-20 or so) are loaded when you join a room. I'm using Angular, and my controller loads the messages fine, but I'm pretty sure what happens is that the scrollTop happens before the messages are all loaded. code:
|
# ? Nov 26, 2012 00:27 |
|
The problem is that you're using a scope item in a callback. Because of that, the angular $scope is not actually watching for changes during that callback, so the scope is updating later than the end of the callback. Of course this type of code is common as hell so you just need to tell angular to apply the scope changes by using $scope.$apply()code:
|
# ? Nov 26, 2012 04:57 |
|
Actually, the $http service should be calling $apply automatically, so manipulating the scope should be fine. In general, any time you're integrating directly with a built-in Angular service, you don't need to worry about calling $apply manually. The more likely problem is that the DOM doesn't re-render immediately after you set messages, so your scrollHeight is off. I could be wrong, but I don't think calling $apply will cause the DOM to re-render immediately. It's hacky, but I believe the only solution I've been able to come up with for this particular situation is to wrap the scrolling code in a setTimeout of 0. Also, you might not care about this, but it's considered bad form to deal with the DOM in Angular controllers. The "proper" way to implement this kind of behavior would be to set up a directive for the scrolling and fire off an event that the directive handles to tell it to scroll to the bottom. This way you keep your DOM code separate from your controllers, which makes it easier to write tests. If you're just doing this for kicks or whatever it's not that big of a deal though.
|
# ? Nov 26, 2012 06:55 |
|
Ah okay, admittedly I've mainly been working with offline storage so I didn't even twig that it was an angular service. Duh, still learning. That said though, the scope application wouldn't happen til after completion of the callback, or is that wrong?
|
# ? Nov 26, 2012 07:08 |
|
Yeah that's correct, so it won't be happening until after scrollTop is called. Again, I'm not sure if $apply will somehow cause the DOM to be rerendered immediately, but if that's the case, then your solution should work. Actually, one thing I forgot to take into account is that if the callback is wrapped in a $digest (which works like $apply, but it wraps the code that is affecting the scope), then Angular will throw an exception if you try to call $apply or $digest. They'll have to test it out to see how it works.
|
# ? Nov 26, 2012 07:14 |
|
Gordon Cole posted:Also, you might not care about this, but it's considered bad form to deal with the DOM in Angular controllers. The "proper" way to implement this kind of behavior would be to set up a directive for the scrolling and fire off an event that the directive handles to tell it to scroll to the bottom. This way you keep your DOM code separate from your controllers, which makes it easier to write tests. If you're just doing this for kicks or whatever it's not that big of a deal though. Right, I originally was appending the new message to the DOM but then I learned Angular automatically does it for me (I render it in a ng-repeat), so I'm not sure why I went back to doing it that way. Durr.
|
# ? Nov 26, 2012 18:12 |
|
I am pretty new to javascript/jQuery and have a quick question about how to handle some AJAX. So basically I have a form for deleting items that consists of a select box and a button, right now I have it so that when the button is clicked it uses the .post() method and calls a seperate php file to process it and delete what was selected from the database. Now comes the issue of having the select box reflect the changes (since an item just got deleted), I tried just doing a .replaceWith() on the div with a new select box, which shows correctly but the button no longer works. What is the optimal way of having your form elements reflect changes through ajax and the form work through multiple submits?
|
# ? Nov 28, 2012 22:28 |
|
I'm trying to write a boids-like application (e.g. https://www.youtube.com/watch?v=M028vafB0l8) in javascript, but I've never done any graphics in js before. Any suggestions? I'm looking mainly for speed + ease of use. Portability would also be nice. I don't need anything complicated. Easy circle and square drawing is probably enough. edit: a major thing is drawing *many* shapes at once quickly. Many meaning on the scale of hundreds (hopefully) theratking fucked around with this message at 04:36 on Nov 30, 2012 |
# ? Nov 30, 2012 04:14 |
|
Basic <canvas> should be friendly enough.
|
# ? Nov 30, 2012 04:34 |
|
Yeah actually that'll work just fine. A library would probably be overkill for this. Thanks!
|
# ? Nov 30, 2012 04:38 |
|
Anyone familiar with AutoIt know whether you can use it to fill out a web form coded in Javascript?
|
# ? Nov 30, 2012 07:10 |
|
I'm trying to create a text effect where the letters of a string get scrambled until they are all in the right place. Here's the code thus far: http://jsfiddle.net/F5NC3/ The problem is that it seems that only the final, correct string is output, but I need the <span> to update upon each random shuffling of the original string. I hope that made sense. Any ideas?
|
# ? Nov 30, 2012 22:54 |
|
Bodhi Tea posted:I'm trying to create a text effect where the letters of a string get scrambled until they are all in the right place. You overwrite the existing text with your current iteration's text. Try this: JavaScript code:
edit: The span is actually updating after each loop, but the loop runs fast enough for it to not be visible.
|
# ? Nov 30, 2012 23:08 |
|
Wheany posted:edit: The span is actually updating after each loop, but the loop runs fast enough for it to not be visible. Thanks, I suspected as much. That's what that ".delay(1800)" was put in for, but I think I'm using that command wrong. Any ideas on how I can slow it down enough for each update to be visible?
|
# ? Nov 30, 2012 23:23 |
|
http://jsfiddle.net/F5NC3/9/ Try this, rather than using a while function you could recur the calls using setTimeout. That said, other people know much more than js than me so I may be misguided. edit: I left delay in the jQuery call cause I'm slack, but it doesn't need to be there anymore. Maluco Marinero fucked around with this message at 23:33 on Nov 30, 2012 |
# ? Nov 30, 2012 23:27 |
|
Bodhi Tea posted:...That's what that ".delay(1800)" was put in for, but I think I'm using that command wrong... It's mostly for effects, and it makes it easy to serialize steps like this. Instead of a for loop, where you can't pause between iterations, you can keep adding to the queue until the letters are where they should be. You can also add delays between steps in the queue. A more sane way to do something like this would probably be to use setInterval(), and have it clearInterval() when the letters are in the correct order.
|
# ? Nov 30, 2012 23:35 |
|
Just glancing over it quickly, it appears that the problem is that the delays are getting queued up immediately after each other, so they're essentially getting run in parallel instead of consecutively. Here's basically what you're doing, conceptually: JavaScript code:
This is basically what you'd want to do instead: JavaScript code:
|
# ? Nov 30, 2012 23:41 |
|
Yeah. I wasn't aware of setInterval, js noob here. I'd probably use that, I prefer to use guard conditionals when I'm using if else stuff so I'd prefer that. edit: It also reminds me of troubles I had with recursion when I was getting started with javascript and asynchronous stuff. You can't use a while loop to wait for a result because while loops own the whole process until they finish. That means anything asynchronous (like a jquery delay call), won't run at all until the while loop is actually finished. I've got that right yeah? Maluco Marinero fucked around with this message at 23:51 on Nov 30, 2012 |
# ? Nov 30, 2012 23:46 |
|
Thanks everyone for the help. It's exactly what I needed.
|
# ? Dec 1, 2012 01:55 |
|
I'm having trouble getting this Greasemonkey/Tampermonkey script to work. http://pastebin.com/kaFtTgy3 This script is supposed to change the "#" links in this forum's author column to single-page post links. But I don't know JS all that well. This would be easy with PHP! Help! Replace: code:
code:
|
# ? Dec 2, 2012 08:01 |
|
Adraeus posted:I'm having trouble getting this Greasemonkey/Tampermonkey script to work. Obviously write this smarter, but this should work (paste into your browsers javascript console to see!) JavaScript code:
Lumpy fucked around with this message at 22:00 on Dec 2, 2012 |
# ? Dec 2, 2012 21:58 |
|
Adraeus posted:I'm having trouble getting this Greasemonkey/Tampermonkey script to work. code:
|
# ? Dec 2, 2012 22:53 |
|
|
# ? Jun 6, 2024 06:30 |
|
Lumpy posted:Obviously write this smarter, but this should work (paste into your browsers javascript console to see!) I wasn't sure if JS allowed you to use $1, $2, etc., variables in strings. Now I see how that's done. And clearly I didn't escape the catch-all RegEx that I tried. Thank you! Movac posted:
Oh, gosh. querySelectorAll() sounds like a really useful function. I thought about using slice(), but I didn't quite understand whether I should use slice(), extract(), or replace(). Your code works great! Thank you, too. Now to turn this into a copy-to-clipboard onclick deal. EDIT: Apparently, that's not possible without Flash. Adraeus fucked around with this message at 23:38 on Dec 2, 2012 |
# ? Dec 2, 2012 23:30 |